130 lines
4.2 KiB
Java
130 lines
4.2 KiB
Java
package eu.m724.giants;
|
|
|
|
import org.bukkit.Material;
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.plugin.Plugin;
|
|
import org.bukkit.potion.PotionEffect;
|
|
import org.bukkit.potion.PotionEffectType;
|
|
import org.bukkit.util.Vector;
|
|
|
|
import java.io.File;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.logging.Logger;
|
|
|
|
public class Configuration {
|
|
private final File file;
|
|
private final Logger logger;
|
|
|
|
String updater;
|
|
|
|
boolean ai;
|
|
|
|
double attackDamage;
|
|
int attackDelay;
|
|
Vector attackReach;
|
|
int jumpMode;
|
|
int jumpCondition;
|
|
int jumpDelay;
|
|
double jumpHeight = -1;
|
|
|
|
double chance;
|
|
List<String> worldBlacklist;
|
|
Set<PotionEffect> effects = new HashSet<>();
|
|
Set<Drop> drops = new HashSet<>();
|
|
|
|
public Configuration(Plugin plugin, File file) {
|
|
this.file = file;
|
|
this.logger = Logger.getLogger(plugin.getLogger().getName() + ".Configuration");
|
|
}
|
|
|
|
public void load() {
|
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
|
|
|
updater = config.getString("updater", "true");
|
|
if (updater.equalsIgnoreCase("true")) {
|
|
updater = "release";
|
|
} else if (updater.equalsIgnoreCase("false")) {
|
|
updater = null;
|
|
}
|
|
|
|
ai = config.getBoolean("ai");
|
|
|
|
chance = config.getDouble("chance");
|
|
attackDamage = config.getDouble("attackDamage");
|
|
attackDelay = config.getInt("attackDelay");
|
|
|
|
jumpMode = config.getInt("jumpMode");
|
|
jumpCondition = config.getInt("jumpCondition");
|
|
jumpDelay = config.getInt("jumpDelay");
|
|
jumpHeight = config.getDouble("jumpHeight", defaultJumpHeight());
|
|
|
|
double _attackReach = config.getDouble("attackReach");
|
|
double _attackVerticalReach = config.getDouble("attackVerticalReach");
|
|
attackReach = new Vector(_attackReach, _attackVerticalReach, _attackReach);
|
|
|
|
worldBlacklist = config.getStringList("blacklist");
|
|
|
|
for (String line : config.getStringList("effects")) {
|
|
String[] parts = line.split(":");
|
|
|
|
try {
|
|
PotionEffectType effectType = PotionEffectType.getByName(parts[0]);
|
|
if (effectType == null) {
|
|
throw new IllegalArgumentException("Invalid PotionEffectType");
|
|
}
|
|
int amplifier = Integer.parseInt(parts[1]);
|
|
effects.add(new PotionEffect(effectType, Integer.MAX_VALUE, amplifier));
|
|
} catch (IllegalArgumentException e) {
|
|
logger.warning("Parsing a potion effect failed:");
|
|
logger.warning(line);
|
|
logger.warning(e.getMessage());
|
|
}
|
|
}
|
|
|
|
for (Map<?, ?> dropMap : config.getMapList("drops")) {
|
|
try {
|
|
ItemStack itemStack;
|
|
if (dropMap.containsKey("itemStack")) {
|
|
itemStack = (ItemStack) dropMap.get("itemStack");
|
|
} else {
|
|
Material material = Material.getMaterial((String) dropMap.get("material"));
|
|
if (material == null) {
|
|
throw new IllegalArgumentException("Invalid Material");
|
|
}
|
|
itemStack = new ItemStack(material, 1);
|
|
}
|
|
|
|
int min = (int) dropMap.get("quantityMin");
|
|
int max = (int) dropMap.get("quantityMax");
|
|
double chance;
|
|
try {
|
|
chance = (double) dropMap.get("chance");
|
|
} catch (ClassCastException e) { // pointlessest error ever
|
|
chance = ((Integer) dropMap.get("chance")).doubleValue();
|
|
}
|
|
|
|
drops.add(new Drop(itemStack, min, max, chance));
|
|
} catch (IllegalArgumentException e) {
|
|
logger.warning("Parsing a drop failed:");
|
|
logger.warning(e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
public double defaultJumpHeight() {
|
|
switch (jumpMode) {
|
|
case 1:
|
|
case 2:
|
|
return 0.42;
|
|
case 3:
|
|
case 4:
|
|
return 1.2;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
}
|