diff --git a/src/main/java/net/lewmc/kryptonite/kos/config/Spigot.java b/src/main/java/net/lewmc/kryptonite/kos/config/Spigot.java new file mode 100644 index 0000000..20b3565 --- /dev/null +++ b/src/main/java/net/lewmc/kryptonite/kos/config/Spigot.java @@ -0,0 +1,155 @@ +package net.lewmc.kryptonite.kos.config; + +import net.lewmc.kryptonite.Kryptonite; +import net.lewmc.kryptonite.utils.ConfigurationUtil; +import org.bukkit.command.CommandSender; + +/** + * The Spigot class manages the spigot.yml configuration file. + */ +public class Spigot { + private final Kryptonite plugin; + private final CommandSender user; + + /** + * Constructor for the Spigot class. + * @param plugin Kryptonite - Reference to the main plugin class. + * @param user CommandSender - The user who sent the command. + */ + public Spigot(Kryptonite plugin, CommandSender user) { + this.plugin = plugin; + this.user = user; + } + + /** + * Configuration values supported by this format. + */ + public enum Key { + VIEW_DISTANCE { + @Override + public String toString() { return "world-settings.default.view-distance"; } + }, + MOB_SPAWN_RANGE { + @Override + public String toString() { return "world-settings.default.mob-spawn-range"; } + }, + ENTITY_ACTIVATION_RANGE_ANIMALS { + @Override + public String toString() { return "world-settings.default.entity-activation-range.animals"; } + }, + ENTITY_ACTIVATION_RANGE_MONSTERS { + @Override + public String toString() { return "world-settings.default.entity-activation-range.monsters"; } + }, + ENTITY_ACTIVATION_RANGE_RAIDERS { + @Override + public String toString() { return "world-settings.default.entity-activation-range.raiders"; } + }, + ENTITY_ACTIVATION_RANGE_MISC { + @Override + public String toString() { return "world-settings.default.entity-activation-range.misc"; } + }, + ENTITY_ACTIVATION_RANGE_WATER { + @Override + public String toString() { return "world-settings.default.entity-activation-range.water"; } + }, + ENTITY_ACTIVATION_RANGE_VILLAGERS { + @Override + public String toString() { return "world-settings.default.entity-activation-range.villagers"; } + }, + ENTITY_ACTIVATION_RANGE_FLYING_MONSTERS { + @Override + public String toString() { return "world-settings.default.entity-activation-range.flying-monsters"; } + }, + ENTITY_TRACKING_RANGE_PLAYERS { + @Override + public String toString() { return "world-settings.default.entity-tracking-range.players"; } + }, + ENTITY_TRACKING_RANGE_ANIMALS { + @Override + public String toString() { return "world-settings.default.entity-tracking-range.animals"; } + }, + ENTITY_TRACKING_RANGE_MONSTERS { + @Override + public String toString() { return "world-settings.default.entity-tracking-range.monsters"; } + }, + ENTITY_TRACKING_RANGE_MISC { + @Override + public String toString() { return "world-settings.default.entity-tracking-range.misc"; } + }, + ENTITY_TRACKING_RANGE_OTHER { + @Override + public String toString() { return "world-settings.default.entity-tracking-range.other"; } + }, + TICK_INACTIVE_VILLAGERS { + @Override + public String toString() { return "world-settings.default.entity-activation-range.tick-inactive-villagers"; } + }, + NERF_SPAWNER_MOBS { + @Override + public String toString() { return "world-settings.default.nerf-spawner-mobs"; } + }, + MERGE_RADIUS_ITEM { + @Override + public String toString() { return "world-settings.default.merge-radius.item"; } + }, + MERGE_RADIUS_EXP { + @Override + public String toString() { return "world-settings.default.merge-radius.exp"; } + }, + TICKS_PER_HOPPER_TRANSFER { + @Override + public String toString() { return "world-settings.default.ticks-per.hopper-transfer"; } + }, + TICKS_PER_HOPPER_CHECK { + @Override + public String toString() { return "world-settings.default.ticks-per.hopper-check"; } + } + } + + /** + * Sets a requested key to a requested value. + * @param key Key - The requested key. + * @param value int - The requested value. + */ + public void setInt(Bukkit.Key key, int value) { + this.plugin.restartRequired = true; + ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); + cfg.load("spigot.yml"); + cfg.set(key.toString(), value); + cfg.save(); + } + + /** + * Gets a requested key's value. + * @param key Key - The requested key. + */ + public int getInt(Bukkit.Key key) { + ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); + cfg.load("spigot.yml"); + return cfg.getInt(key.toString()); + } + + /** + * Sets a requested key to a requested value. + * @param key Key - The requested key. + * @param value int - The requested value. + */ + public void setBoolean(Bukkit.Key key, boolean value) { + this.plugin.restartRequired = true; + ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); + cfg.load("spigot.yml"); + cfg.set(key.toString(), value); + cfg.save(); + } + + /** + * Gets a requested key's value. + * @param key Key - The requested key. + */ + public boolean getBoolean(Bukkit.Key key) { + ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); + cfg.load("spigot.yml"); + return cfg.getBoolean(key.toString()); + } +} diff --git a/src/main/java/net/lewmc/kryptonite/legacy/kos/config/Spigot.java b/src/main/java/net/lewmc/kryptonite/legacy/kos/config/Spigot.java deleted file mode 100644 index 37581c6..0000000 --- a/src/main/java/net/lewmc/kryptonite/legacy/kos/config/Spigot.java +++ /dev/null @@ -1,81 +0,0 @@ -package net.lewmc.kryptonite.legacy.kos.config; - -import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.utils.LogUtil; -import org.bukkit.configuration.InvalidConfigurationException; - -import java.io.File; -import java.io.IOException; - -public class Spigot { - private final Kryptonite plugin; - private final File file = new File("spigot.yml"); - - public Spigot(final Kryptonite plugin) { - this.plugin = plugin; - try { - plugin.getConfig().load(this.file); - } catch (IOException | InvalidConfigurationException e) { - LogUtil log = new LogUtil(plugin); - log.severe("Error whilst loading Spigot configuration:"); - log.severe(e.getMessage()); - } - } - - public void viewDistance(Object value) { - this.plugin.getConfig().set("world-settings.default.view-distance", value); - } - - public void mobSpawnRange(int value) { - this.plugin.getConfig().set("world-settings.default.mob-spawn-range", value); - } - - public void entityActivationRange(int animals, int monsters, int raiders, int misc, int water, int villagers, int flying) { - this.plugin.getConfig().set("world-settings.default.entity-activation-range.animals", animals); - this.plugin.getConfig().set("world-settings.default.entity-activation-range.monsters", monsters); - this.plugin.getConfig().set("world-settings.default.entity-activation-range.raiders", raiders); - this.plugin.getConfig().set("world-settings.default.entity-activation-range.misc", misc); - this.plugin.getConfig().set("world-settings.default.entity-activation-range.water", water); - this.plugin.getConfig().set("world-settings.default.entity-activation-range.villagers", villagers); - this.plugin.getConfig().set("world-settings.default.entity-activation-range.flying-monsters", flying); - } - - public void entityTrackingRange(int players, int animals, int monsters, int misc, int other) { - this.plugin.getConfig().set("world-settings.default.entity-tracking-range.players", players); - this.plugin.getConfig().set("world-settings.default.entity-tracking-range.animals", animals); - this.plugin.getConfig().set("world-settings.default.entity-tracking-range.monsters", monsters); - this.plugin.getConfig().set("world-settings.default.entity-tracking-range.misc", misc); - this.plugin.getConfig().set("world-settings.default.entity-tracking-range.other", other); - } - - public void tickInacativeVillagers(boolean value) { - this.plugin.getConfig().set("world-settings.default.entity-activation-range.tick-inactive-villagers", value); - } - - public void nerfSpawnerMobs(boolean value) { - this.plugin.getConfig().set("world-settings.default.nerf-spawner-mobs", value); - } - - public void mergeRadius(double item, double exp) { - this.plugin.getConfig().set("world-settings.default.merge-radius.item", item); - this.plugin.getConfig().set("world-settings.default.merge-radius.exp", exp); - } - - public void hopperTransfer(int value) { - this.plugin.getConfig().set("world-settings.default.ticks-per.hopper-transfer", value); - } - - public void hopperCheck(int value) { - this.plugin.getConfig().set("world-settings.default.ticks-per.hopper-check", value); - } - - public void save() { - try { - this.plugin.getConfig().save(this.file); - } catch (IOException e) { - LogUtil log = new LogUtil(plugin); - log.severe("Error whilst saving Spigot configuration:"); - log.severe(e.getMessage()); - } - } -}