97 lines
3.2 KiB
Java
97 lines
3.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;
|
|
|
|
boolean ai;
|
|
boolean attack;
|
|
|
|
double chance;
|
|
double attackDamage;
|
|
int attackDelay;
|
|
|
|
Vector attackReach;
|
|
|
|
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);
|
|
|
|
ai = config.getBoolean("ai");
|
|
attack = config.getBoolean("attack");
|
|
|
|
chance = config.getDouble("chance");
|
|
attackDamage = config.getDouble("attackDamage");
|
|
attackDelay = config.getInt("attackDelay");
|
|
|
|
double _attackReach = config.getDouble("attackReach");
|
|
double _expandUp = config.getDouble("expandUp");
|
|
attackReach = new Vector(_attackReach, _expandUp, _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");
|
|
float chance = (int) dropMap.get("chance");
|
|
|
|
drops.add(new Drop(itemStack, min, max, chance));
|
|
} catch (IllegalArgumentException e) {
|
|
logger.warning("Parsing a drop failed:");
|
|
logger.warning(e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|