40 lines
1.6 KiB
Java
40 lines
1.6 KiB
Java
package games.dmg.spigottyrant;
|
|
|
|
import org.bukkit.Material;
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
public final class PluginSettingsValidator {
|
|
private PluginSettingsValidator() {
|
|
}
|
|
|
|
public static PluginSettings validate(PluginSettings settings) {
|
|
validateItem(settings.assassinItem(), "assassin-item");
|
|
validateItem(settings.fixerItem(), "fixer-item");
|
|
validateItem(settings.tamerItem(), "tamer-item");
|
|
validateItem(settings.capturedMobItem(), "captured-mob-item");
|
|
validateItem(settings.tyrantControlItem(), "tyrant-control-item");
|
|
validateItem(settings.vigilanteControlItem(), "vigilante-control-item");
|
|
for (String entityType : settings.deniedMobTypes()) {
|
|
try {
|
|
EntityType.valueOf(entityType);
|
|
} catch (IllegalArgumentException exception) {
|
|
throw new IllegalArgumentException(
|
|
entityType + " in denied-mob-types is not a known entity type",
|
|
exception
|
|
);
|
|
}
|
|
}
|
|
if (!settings.deniedMobTypes().contains("ENDER_DRAGON")) {
|
|
throw new IllegalArgumentException("denied-mob-types must include ENDER_DRAGON");
|
|
}
|
|
return settings;
|
|
}
|
|
|
|
private static void validateItem(PluginSettings.AbilityItemSettings item, String key) {
|
|
Material material = Material.matchMaterial(item.material());
|
|
if (material == null || material == Material.AIR) {
|
|
throw new IllegalArgumentException(key + " material must identify an item");
|
|
}
|
|
}
|
|
}
|