From 4c43b92e13944c5145a9c2ae3fafc3769a806202 Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 28 Aug 2025 13:56:10 +0100 Subject: [PATCH 01/21] Bump DRP --- dependency-reduced-pom.xml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index b1acc7d..97d846f 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -4,7 +4,7 @@ net.lewmc kryptonite Kryptonite - 2.0.1 + 2.1.0-SNAPSHOT @@ -73,8 +73,18 @@ provided + + + lewmc + https://repo.lewmc.net/releases + + + lewmc + https://repo.lewmc.net/snapshots + + - UTF-8 21 + UTF-8 From 6dbea331afb157b27ea55d60db31232cd9da8d2d Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 28 Aug 2025 14:26:57 +0100 Subject: [PATCH 02/21] [Leaf] parallel-world-tracking --- .../net/lewmc/kryptonite/kos/config/Leaf.java | 16 +++ .../lewmc/kryptonite/kos/gui/KOS_LeafGui.java | 100 +++++++++++++++++- 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/lewmc/kryptonite/kos/config/Leaf.java b/src/main/java/net/lewmc/kryptonite/kos/config/Leaf.java index dcc1c71..22ad809 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/config/Leaf.java +++ b/src/main/java/net/lewmc/kryptonite/kos/config/Leaf.java @@ -29,6 +29,22 @@ public enum Key { PARALLEL_WORLD_TRACING_ENABLED { @Override public String toString() { return "async.parallel-world-tracing.enabled"; } + }, + PARALLEL_WORLD_TRACING_THREADS { + @Override + public String toString() { return "async.parallel-world-tracing.threads"; } + }, + PARALLEL_WORLD_TRACING_LOG_CONTAINER_CREATION_STACKTRACES { + @Override + public String toString() { return "async.parallel-world-tracing.log-container-creation-stacktraces"; } + }, + PARALLEL_WORLD_TRACING_DISABLE_HARD_THROW { + @Override + public String toString() { return "async.parallel-world-tracing.disable-hard-throw"; } + }, + PARALLEL_WORLD_TRACING_RUN_ASYNC_TASKS_SYNC { + @Override + public String toString() { return "async.parallel-world-tracing.run-async-tasks-sync"; } } } diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_LeafGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_LeafGui.java index a91a3ea..eb41938 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_LeafGui.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_LeafGui.java @@ -51,6 +51,10 @@ public void show() { */ private void addElements() { this.parallelWorldTracingEnabled('a'); + this.parallelWorldTracingThreads('b'); + this.parallelWorldTracingLogContainerCreationStacktraces('c'); + this.parallelWorldTracingDisableHardThrow('d'); + this.parallelWorldTracingRunAsyncTasksSync('e'); KOS_GuiConstants consts = new KOS_GuiConstants(this.plugin, this.gui); consts.addConstants(); @@ -63,7 +67,7 @@ private void addElements() { private String[] getElements() { return new String[]{ - "a ", + "abcdefghi", " ", " w x y " }; @@ -98,6 +102,100 @@ private void parallelWorldTracingEnabled(char id) { } } + private void parallelWorldTracingThreads(char id) { + int value = this.leaf.getInt(Leaf.Key.PARALLEL_WORLD_TRACING_THREADS); + this.gui.addElement(new StaticGuiElement(id, + new ItemStack(Material.WHITE_CONCRETE), + 1, + click -> this.setInt(Leaf.Key.PARALLEL_WORLD_TRACING_THREADS, click, value, false), + ChatColor.WHITE + "Parallel World Tracing Threads", + ChatColor.GRAY + String.valueOf(value), + ChatColor.GRAY + "Consider setting to the amount of worlds you have.", + ChatColor.BLUE + "Click to toggle true/false." + )); + } + + private void parallelWorldTracingLogContainerCreationStacktraces(char id) { + boolean value = this.leaf.getBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_LOG_CONTAINER_CREATION_STACKTRACES); + if (value) { + this.gui.addElement(new StaticGuiElement(id, + new ItemStack(Material.RED_CONCRETE), + 1, + click -> { this.leaf.setBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_LOG_CONTAINER_CREATION_STACKTRACES, false); return true; }, + ChatColor.DARK_RED + "Parallel World Tracing Log Container Creation Stacktraces", + ChatColor.RED + "true", + ChatColor.RED + "Useful for debugging concurrency issues.", + ChatColor.RED + "May cause console spam.", + ChatColor.BLUE + "Click to toggle true/false." + )); + } else { + this.gui.addElement(new StaticGuiElement(id, + new ItemStack(Material.LIME_CONCRETE), + 1, + click -> { this.leaf.setBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_LOG_CONTAINER_CREATION_STACKTRACES, true); return true; }, + ChatColor.DARK_GREEN + "Parallel World Tracing Log Container Creation Stacktraces", + ChatColor.GREEN + "false", + ChatColor.GREEN + "Useful for debugging concurrency issues.", + ChatColor.GREEN + "Ideal value.", + ChatColor.BLUE + "Click to toggle true/false." + )); + } + } + + private void parallelWorldTracingDisableHardThrow(char id) { + boolean value = this.leaf.getBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_DISABLE_HARD_THROW); + if (value) { + this.gui.addElement(new StaticGuiElement(id, + new ItemStack(Material.RED_CONCRETE), + 1, + click -> { this.leaf.setBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_DISABLE_HARD_THROW, false); return true; }, + ChatColor.DARK_RED + "Parallel World Tracing Disable Hard Throw", + ChatColor.RED + "true", + ChatColor.RED + "Could prevent crashes in unstable experimental phases.", + ChatColor.RED + "Use with caution.", + ChatColor.BLUE + "Click to toggle true/false." + )); + } else { + this.gui.addElement(new StaticGuiElement(id, + new ItemStack(Material.LIME_CONCRETE), + 1, + click -> { this.leaf.setBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_DISABLE_HARD_THROW, true); return true; }, + ChatColor.DARK_GREEN + "Parallel World Tracing Disable Hard Throw", + ChatColor.GREEN + "false", + ChatColor.GREEN + "Could prevent crashes in unstable experimental phases.", + ChatColor.GREEN + "Ideal value.", + ChatColor.BLUE + "Click to toggle true/false." + )); + } + } + + private void parallelWorldTracingRunAsyncTasksSync(char id) { + boolean value = this.leaf.getBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_RUN_ASYNC_TASKS_SYNC); + if (value) { + this.gui.addElement(new StaticGuiElement(id, + new ItemStack(Material.RED_CONCRETE), + 1, + click -> { this.leaf.setBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_RUN_ASYNC_TASKS_SYNC, false); return true; }, + ChatColor.DARK_RED + "Parallel World Tracing Disable Hard Throw", + ChatColor.RED + "true", + ChatColor.RED + "Might be needed for compatibility with certain plugins.", + ChatColor.RED + "Impact to performance.", + ChatColor.BLUE + "Click to toggle true/false." + )); + } else { + this.gui.addElement(new StaticGuiElement(id, + new ItemStack(Material.LIME_CONCRETE), + 1, + click -> { this.leaf.setBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_RUN_ASYNC_TASKS_SYNC, true); return true; }, + ChatColor.DARK_GREEN + "Parallel World Tracing Disable Hard Throw", + ChatColor.GREEN + "false", + ChatColor.GREEN + "Might be needed for compatibility with certain plugins.", + ChatColor.GREEN + "Ideal value.", + ChatColor.BLUE + "Click to toggle true/false." + )); + } + } + private boolean setInt(Leaf.Key key, GuiElement.Click click, int value, boolean canBeDefault) { click.getGui().close(); if (click.getType() == ClickType.RIGHT) { From d5fad702d7b7512273b8210a4f9676f6a04e6be5 Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 28 Aug 2025 14:30:17 +0100 Subject: [PATCH 03/21] Update plugin.yml --- src/main/resources/plugin.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7fdbf30..fc1c587 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ main: net.lewmc.kryptonite.Kryptonite author: LewMC description: The Kryptonite of lag. website: https://lewmc.net -api-version: '1.20' +api-version: '1.21' load: POSTWORLD commands: kryptonite: @@ -18,5 +18,5 @@ commands: edb: description: Exploit Database usage: / - aliases: ['exploit'] + aliases: ['exploit','exploitdb'] folia-supported: true \ No newline at end of file From c80ec3d1512a813b0217dc75a323f4f670c0b7b2 Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 28 Aug 2025 14:44:22 +0100 Subject: [PATCH 04/21] Leaf detection (#55) --- src/main/java/net/lewmc/kryptonite/Kryptonite.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/net/lewmc/kryptonite/Kryptonite.java b/src/main/java/net/lewmc/kryptonite/Kryptonite.java index f013641..a75e3fb 100644 --- a/src/main/java/net/lewmc/kryptonite/Kryptonite.java +++ b/src/main/java/net/lewmc/kryptonite/Kryptonite.java @@ -161,6 +161,12 @@ private void checkSoftware() { this.SupportedConfigurations.add(ConfigurationOptions.PUFFERFISH); supportedConfigs = supportedConfigs + ", Pufferfish"; } + + File leafConfig = new File("config/leaf-global.yml"); + if (leafConfig.exists()) { + this.SupportedConfigurations.add(ConfigurationOptions.LEAF); + supportedConfigs = supportedConfigs + ", Leaf"; + } this.log.info("Supported configurations loaded: "+supportedConfigs+"."); } From 800bd0e0528accfdb3e920f0d7a5b36a9bee70ed Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 28 Aug 2025 18:41:59 +0100 Subject: [PATCH 05/21] Update to new importing system & migrate to Foundry. --- dependency-reduced-pom.xml | 16 +- pom.xml | 20 ++ .../java/net/lewmc/kryptonite/Kryptonite.java | 11 +- .../lewmc/kryptonite/config/Minecraft.java | 90 ++++++ .../kryptonite/kos/gui/KOS_GuiConstants.java | 6 +- .../kryptonite/kos/gui/KOS_ManualGUI.java | 15 +- .../kryptonite/kos/gui/KOS_MinecraftGui.java | 165 ++++++++++ .../kos/gui/KOS_ServerPropertiesGui.java | 282 ------------------ .../net/lewmc/kryptonite/utils/LogUtil.java | 15 + .../lewmc/kryptonite/utils/UpdateUtil.java | 5 +- .../utils/config/BooleanConfigItem.java | 98 ++++++ .../utils/config/DoubleConfigItem.java | 122 ++++++++ .../utils/config/GenericConfigItem.java | 132 ++++++++ .../utils/config/IntegerConfigItem.java | 122 ++++++++ .../utils/config/StringConfigItem.java | 99 ++++++ 15 files changed, 901 insertions(+), 297 deletions(-) create mode 100644 src/main/java/net/lewmc/kryptonite/config/Minecraft.java create mode 100644 src/main/java/net/lewmc/kryptonite/kos/gui/KOS_MinecraftGui.java delete mode 100644 src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ServerPropertiesGui.java create mode 100644 src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java create mode 100644 src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java create mode 100644 src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java create mode 100644 src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java create mode 100644 src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 97d846f..1589604 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -15,7 +15,7 @@ maven-compiler-plugin - 3.13.0 + 3.14.0 ${java.version} ${java.version} @@ -40,6 +40,10 @@ com.tcoded.folialib net.lewmc.kryptonite.lib.folialib + + net.lewmc.foundry + net.lewmc.kryptonite.lib.foundry + @@ -64,6 +68,16 @@ jitpack https://jitpack.io + + lewmc + LewMC Repository + https://repo.lewmc.net/releases + + + lewmc-snapshots + LewMC Repository + https://repo.lewmc.net/snapshots + diff --git a/pom.xml b/pom.xml index 041db52..b4c13e1 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,10 @@ com.tcoded.folialib net.lewmc.kryptonite.lib.folialib + + net.lewmc.foundry + net.lewmc.kryptonite.lib.foundry + @@ -78,6 +82,16 @@ jitpack https://jitpack.io + + lewmc + LewMC Repository + https://repo.lewmc.net/releases + + + lewmc-snapshots + LewMC Repository + https://repo.lewmc.net/snapshots + @@ -110,6 +124,12 @@ 0.4.4 compile + + net.lewmc + foundry + 1.2.0 + compile + diff --git a/src/main/java/net/lewmc/kryptonite/Kryptonite.java b/src/main/java/net/lewmc/kryptonite/Kryptonite.java index a75e3fb..8e650e1 100644 --- a/src/main/java/net/lewmc/kryptonite/Kryptonite.java +++ b/src/main/java/net/lewmc/kryptonite/Kryptonite.java @@ -1,12 +1,13 @@ package net.lewmc.kryptonite; import com.tcoded.folialib.FoliaLib; +import net.lewmc.foundry.FoundryConfig; +import net.lewmc.foundry.Logger; import net.lewmc.kryptonite.commands.ExploitDBCommand; import net.lewmc.kryptonite.commands.KryptoniteCommand; import net.lewmc.kryptonite.commands.OptimiseCommand; import net.lewmc.kryptonite.event.JoinEvent; import net.lewmc.kryptonite.utils.CompatablityUtil; -import net.lewmc.kryptonite.utils.LogUtil; import net.lewmc.kryptonite.utils.UpdateUtil; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -18,7 +19,7 @@ public final class Kryptonite extends JavaPlugin { - private final LogUtil log = new LogUtil(this); + private Logger log; public enum ConfigurationOptions { SERVER_PROPERTIES, BUKKIT, @@ -32,9 +33,15 @@ public enum ConfigurationOptions { public List SupportedConfigurations = new ArrayList<>(); public boolean restartRequired = false; public boolean updatePending = false; + public FoundryConfig foundryConfig; @Override public void onEnable() { + this.foundryConfig = new FoundryConfig(this); + this.foundryConfig.setVerbose(this.getConfig().getBoolean("verbose")); + this.foundryConfig.setPluginId("kr"); + this.log = new Logger(this.foundryConfig); + this.log.info(""); this.log.info("█▄▀ █▀█ █▄█ █▀█ ▀█▀ █▀█ █▄ █ █ ▀█▀ █▀▀"); this.log.info("█ █ █▀▄ █ █▀▀ █ █▄█ █ ▀█ █ █ ██▄"); diff --git a/src/main/java/net/lewmc/kryptonite/config/Minecraft.java b/src/main/java/net/lewmc/kryptonite/config/Minecraft.java new file mode 100644 index 0000000..3ec67c6 --- /dev/null +++ b/src/main/java/net/lewmc/kryptonite/config/Minecraft.java @@ -0,0 +1,90 @@ +package net.lewmc.kryptonite.config; + +import net.lewmc.kryptonite.Kryptonite; +import net.lewmc.kryptonite.utils.config.BooleanConfigItem; +import net.lewmc.kryptonite.utils.config.GenericConfigItem; +import net.lewmc.kryptonite.utils.config.IntegerConfigItem; + +import java.util.*; + +/** + * Configuration data for server.properties + * @since 2.1.0 + */ +public class Minecraft { + /** + * Holds configuration data for the server.properties file. + */ + public HashMap values = new HashMap<>(); + + /** + * Constructs the server.properties data. + * @param plugin Kryptonite - Reference to the main Kryptonite class. + */ + public Minecraft(Kryptonite plugin) { + String file = "server.properties"; + + values.put("network-compression-threshold", new IntegerConfigItem( + file, + "network-compression-threshold", + "Network Compression Threshold", + List.of( + "The cap for the size of a packet before the", + "server attempts to compress it."), + -1, + 1000, + "256", + plugin + )); + + values.put("view-distance", new IntegerConfigItem( + file, + "view-distance", + "View Distance", + List.of("The distance players can see. Using client", + "mods such a Distant Horizons or Bobby allow", + "players to see further without any", + "performance hits for the server." + ), + 1, + 50, + "5 - 10", + plugin + )); + + values.put("simulation-distance", new IntegerConfigItem( + file, + "simulation-distance", + "Simulation Distance", + List.of("The distance mobs will be simulated."), + 1, + 50, + "5 - "+values.get("view-distance").getCurrentValue(), + plugin + )); + + values.put("sync-chunk-writes", new BooleanConfigItem( + file, + "sync-chunk-writes", + "Sync Chunk Writes", + List.of("Forces the server to write chunks on the main", + "thread which impacts performance." + ), + false, + plugin + )); + + values.put("allow-flight", new BooleanConfigItem( + file, + "allow-flight", + "Allow Flight", + List.of("This prevents players from getting kicked by", + "the server for 'flying' while riding a horse", + "or climbing on scaffolding. Doesn't actually", + "allow players to fly." + ), + null, + plugin + )); + } +} \ No newline at end of file diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_GuiConstants.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_GuiConstants.java index 9a80c2c..8fd42ec 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_GuiConstants.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_GuiConstants.java @@ -29,7 +29,7 @@ public KOS_GuiConstants(Kryptonite plugin, InventoryGui gui) { * Adds the 'w', 'x', and 'y' (help, alerts, and exit) positions to the selected GUI. */ public void addConstants() { - this.gui.addElement(new StaticGuiElement('w', + this.gui.addElement(new StaticGuiElement('t', new ItemStack(Material.BOOK), 1, click -> { @@ -43,7 +43,7 @@ public void addConstants() { )); if (plugin.restartRequired) { - this.gui.addElement(new StaticGuiElement('x', + this.gui.addElement(new StaticGuiElement('u', new ItemStack(Material.YELLOW_CONCRETE), 1, click -> true, @@ -60,7 +60,7 @@ public void addConstants() { )); } - this.gui.addElement(new StaticGuiElement('y', + this.gui.addElement(new StaticGuiElement('v', new ItemStack(Material.OAK_DOOR), 1, click -> { diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java index a93196c..bc87c14 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java @@ -50,21 +50,22 @@ private void addElements() { 1, click -> { click.getGui().close(); - KOS_ServerPropertiesGui spGui = new KOS_ServerPropertiesGui(this.plugin, this.user); - spGui.show(); + new KOS_MinecraftGui(this.plugin, this.user).show(); return true; }, - ChatColor.BLUE + "Server", - ChatColor.AQUA + "Manage the Server configuration." + ChatColor.BLUE + "Minecraft", + ChatColor.AQUA + "Manage Minecraft's configuration." )); } else { this.gui.addElement(new StaticGuiElement('p', new ItemStack(Material.BARRIER), 1, click -> true, - ChatColor.DARK_RED + "Server", - ChatColor.RED + "Manage the Server configuration.", - ChatColor.RED + "Your server does not support this." + ChatColor.DARK_RED + "Minecraft", + ChatColor.RED + "Manage Minecraft's configuration.", + ChatColor.RED + "Your server does not support this, but it", + ChatColor.RED + "should. Please contact LewMC for help at", + ChatColor.RED + "lewmc.net/help" )); } diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_MinecraftGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_MinecraftGui.java new file mode 100644 index 0000000..ac56e5f --- /dev/null +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_MinecraftGui.java @@ -0,0 +1,165 @@ +package net.lewmc.kryptonite.kos.gui; + +import de.themoep.inventorygui.GuiElement; +import de.themoep.inventorygui.InventoryGui; +import de.themoep.inventorygui.StaticGuiElement; +import net.lewmc.kryptonite.Kryptonite; +import net.lewmc.kryptonite.config.Minecraft; +import net.lewmc.kryptonite.utils.config.BooleanConfigItem; +import net.lewmc.kryptonite.utils.config.GenericConfigItem; +import net.lewmc.kryptonite.utils.config.IntegerConfigItem; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * KOS Minecraft (server.properties) GUI + */ +public class KOS_MinecraftGui { + private final Kryptonite plugin; + private final CommandSender user; + private final Minecraft config; + private InventoryGui gui; + + /** + * Constructor for the KOS Server Properties GUI + * @param plugin Kryptonite - Reference to the main plugin class. + * @param user CommandSender - The user who sent the command. + */ + public KOS_MinecraftGui(Kryptonite plugin, CommandSender user) { + this.plugin = plugin; + this.user = user; + + this.config = new Minecraft(plugin); + } + + /** + * Shows the KOS Server Properties GUI + */ + public void show() { + InventoryHolder holder = this.user.getServer().getPlayer(this.user.getName()); + this.gui = new InventoryGui(this.plugin, holder, "KOS - Server Configuration", this.getElements()); + this.addElements(); + + this.gui.build(); + this.gui.show((Player) this.user); + } + + /** + * Adds pre-programmed elements to the GUI + */ + private void addElements() { + int index = 0; + for (Map.Entry entry : this.config.values.entrySet()) { + GenericConfigItem config = entry.getValue(); + char id = (char) ('a' + index); + + ItemStack display = buildDisplayItem(config); + + this.gui.addElement(new StaticGuiElement( + id, + display, + 1, + click -> { + handleClick(config, click); + return true; + } + )); + + index++; + } + + // Keep your constant controls + KOS_GuiConstants consts = new KOS_GuiConstants(this.plugin, this.gui); + consts.addConstants(); + } + + private ItemStack buildDisplayItem(GenericConfigItem config) { + boolean ideal = config.isIdeal(); + Material material = ideal ? Material.LIME_CONCRETE : Material.RED_CONCRETE; + + ItemStack item = new ItemStack(material); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName((ideal ? ChatColor.DARK_GREEN : ChatColor.DARK_RED) + config.getName()); + + List lore = new ArrayList<>(); + lore.add((ideal ? ChatColor.GREEN : ChatColor.RED) + "Current: " + config.getCurrentValue()); + + String idealValue = config.getIdealValue(); + if (idealValue != null) { + lore.add(ChatColor.GRAY + "Ideal: " + idealValue); + } else { + lore.add(ChatColor.GRAY + "Any value is fine"); + } + + if (config.getDescription() != null) { + lore.addAll(config.getDescription().stream() + .map(line -> ChatColor.BLUE + line) + .toList()); + } + + meta.setLore(lore); + item.setItemMeta(meta); + + return item; + } + + private void handleClick(GenericConfigItem config, GuiElement.Click click) { + click.getGui().close(); + + if (config instanceof BooleanConfigItem boolItem) { + boolItem.setCurrentValue(!boolItem.getCurrentValue()); + } else if (config instanceof IntegerConfigItem intItem) { + int current = intItem.getCurrentValue(); + if (click.getType() == ClickType.RIGHT) { + intItem.setCurrentValue(current + 1); + } else if (click.getType() == ClickType.SHIFT_RIGHT) { + intItem.setCurrentValue(current + 10); + } else if (click.getType() == ClickType.LEFT && current != 0) { + intItem.setCurrentValue(current - 1); + } else if (click.getType() == ClickType.SHIFT_LEFT && current >= 10) { + intItem.setCurrentValue(current - 10); + } + } + this.show(); + } + + + + /** + * Determines where the elements should be positioned. + * @return String[] - The position of the elements. + */ + private String[] getElements() { + int size = this.config.values.size(); + int rows = (int) Math.ceil(size / 9.0); + + // +1 row for the constant footer row + String[] layout = new String[rows + 1]; + + int index = 0; + for (int r = 0; r < rows; r++) { + StringBuilder row = new StringBuilder(" "); + for (int c = 0; c < 9 && index < size; c++) { + char id = (char) ('a' + index); + row.setCharAt(c, id); + index++; + } + layout[r] = row.toString(); + } + + layout[rows] = " t u v "; + + return layout; + } + +} diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ServerPropertiesGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ServerPropertiesGui.java deleted file mode 100644 index 379db95..0000000 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ServerPropertiesGui.java +++ /dev/null @@ -1,282 +0,0 @@ -package net.lewmc.kryptonite.kos.gui; - -import de.themoep.inventorygui.GuiElement; -import de.themoep.inventorygui.InventoryGui; -import de.themoep.inventorygui.StaticGuiElement; -import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.kos.config.ServerProperties; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; - -import java.util.Objects; - -/** - * KOS Server Properties GUI - */ -public class KOS_ServerPropertiesGui { - private final Kryptonite plugin; - private final CommandSender user; - private InventoryGui gui; - private ServerProperties properties; - - /** - * Constructor for the KOS Server Properties GUI - * @param plugin Kryptonite - Reference to the main plugin class. - * @param user CommandSender - The user who sent the command. - */ - public KOS_ServerPropertiesGui(Kryptonite plugin, CommandSender user) { - this.plugin = plugin; - this.user = user; - - this.properties = new ServerProperties(this.plugin); - } - - /** - * Shows the KOS Server Properties GUI - */ - public void show() { - InventoryHolder holder = this.user.getServer().getPlayer(this.user.getName()); - this.gui = new InventoryGui(this.plugin, holder, "KOS - Server Configuration", this.getElements()); - this.addElements(); - - this.gui.build(); - this.gui.show((Player) this.user); - } - - /** - * Adds pre-programmed elements to the GUI - */ - private void addElements() { - this.networkCompressionThreshold('a'); - this.viewDistance('b'); - this.simulationDistance('c'); - this.syncChunkWrites('d'); - this.allowFlight('e'); - - KOS_GuiConstants consts = new KOS_GuiConstants(this.plugin, this.gui); - consts.addConstants(); - } - - /** - * Determines where the elements should be positioned. - * @return String[] - The position of the elements. - */ - private String[] getElements() { - - return new String[]{ - " a b c d ", - " e ", - " w x y " - }; - } - - private void networkCompressionThreshold(char id) { - int value = this.properties.getInt(ServerProperties.Key.NETWORK_COMPRESSION_THRESHOLD); - if (value == 256) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(ServerProperties.Key.NETWORK_COMPRESSION_THRESHOLD, click, value), - ChatColor.DARK_GREEN + "Network Compression Threshold", - ChatColor.GREEN + "256", - ChatColor.GREEN + "Ideal value", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 256) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(ServerProperties.Key.NETWORK_COMPRESSION_THRESHOLD, click, value), - ChatColor.DARK_RED + "Network Compression Threshold", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too low.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(ServerProperties.Key.NETWORK_COMPRESSION_THRESHOLD, click, value), - ChatColor.DARK_RED + "Network Compression Threshold", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void viewDistance(char id) { - int value = this.properties.getInt(ServerProperties.Key.VIEW_DISTANCE); - - if (value < 5) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(ServerProperties.Key.VIEW_DISTANCE, click, value), - ChatColor.DARK_RED + "View distance", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value > 10) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(ServerProperties.Key.VIEW_DISTANCE, click, value), - ChatColor.DARK_RED + "View distance", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - large impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value > 8) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(ServerProperties.Key.VIEW_DISTANCE, click, value), - ChatColor.DARK_RED + "View distance", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "High - moderate impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(ServerProperties.Key.VIEW_DISTANCE, click, value), - ChatColor.DARK_GREEN + "View distance", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void simulationDistance(char id) { - int viewDistance = this.properties.getInt(ServerProperties.Key.VIEW_DISTANCE); - int simuDistance = this.properties.getInt(ServerProperties.Key.SIMULATION_DISTANCE); - - if (simuDistance < 5) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(ServerProperties.Key.SIMULATION_DISTANCE, click, simuDistance), - ChatColor.DARK_RED + "Simulation Distance", - ChatColor.RED + String.valueOf(simuDistance), - ChatColor.RED + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (simuDistance <= viewDistance) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(ServerProperties.Key.SIMULATION_DISTANCE, click, simuDistance), - ChatColor.DARK_GREEN + "Simulation Distance", - ChatColor.GREEN + String.valueOf(simuDistance), - ChatColor.GREEN + "Lower or equal to view distance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(ServerProperties.Key.SIMULATION_DISTANCE, click, simuDistance), - ChatColor.DARK_RED + "Simulation Distance", - ChatColor.RED + String.valueOf(simuDistance), - ChatColor.RED + "Higher than view distance - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void syncChunkWrites(char id) { - String value = this.properties.getString(ServerProperties.Key.SYNC_CHUNK_WRITES); - - if (Objects.equals(value, "false")) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.properties.set(ServerProperties.Key.SYNC_CHUNK_WRITES, "true"); - this.show(); - return true; - }, - ChatColor.DARK_RED + "Sync Chunk Writes", - ChatColor.RED + "false", - ChatColor.RED + "False - impact to player experience.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.properties.set(ServerProperties.Key.SYNC_CHUNK_WRITES, "false"); - this.show(); - return true; - }, - ChatColor.DARK_GREEN + "Sync Chunk Writes", - ChatColor.GREEN + "true", - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void allowFlight(char id) { - String value = this.properties.getString(ServerProperties.Key.ALLOW_FLIGHT); - - if (Objects.equals(value, "false")) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.properties.set(ServerProperties.Key.ALLOW_FLIGHT, "true"); - this.show(); - return true; - }, - ChatColor.DARK_RED + "Allow Flight", - ChatColor.RED + "false", - ChatColor.RED + "False - players may be kicked if it lags.", - ChatColor.BLUE + "Click to toggle true/false" - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.properties.set(ServerProperties.Key.ALLOW_FLIGHT, "false"); - this.show(); - return true; - }, - ChatColor.DARK_GREEN + "Allow Flight", - ChatColor.GREEN + "true", - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Click to toggle true/false" - )); - } - } - - private boolean setInt(ServerProperties.Key key, GuiElement.Click click, int value) { - click.getGui().close(); - if (click.getType() == ClickType.RIGHT) { - this.properties.set(key, String.valueOf(value + 1)); - } else if (click.getType() == ClickType.SHIFT_RIGHT) { - this.properties.set(key, String.valueOf(value + 10)); - } else if (click.getType() == ClickType.LEFT && value != 0) { - this.properties.set(key, String.valueOf(value - 1)); - } else if (click.getType() == ClickType.SHIFT_LEFT && value >= 10) { - this.properties.set(key, String.valueOf(value - 10)); - } - this.show(); - return true; - } -} diff --git a/src/main/java/net/lewmc/kryptonite/utils/LogUtil.java b/src/main/java/net/lewmc/kryptonite/utils/LogUtil.java index 4f03893..eddc472 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/LogUtil.java +++ b/src/main/java/net/lewmc/kryptonite/utils/LogUtil.java @@ -14,10 +14,13 @@ /** * LogUtil manages logging of information. + * @deprecated */ +@Deprecated public class LogUtil { private final Kryptonite plugin; + @Deprecated private enum Type { LOG_INFO { @Override public String toString() { return "INFO"; } @@ -33,7 +36,9 @@ private enum Type { /** * Constructor for the LogUtil class. * @param plugin Kryptonite - Reference to the main plugin class. + * @deprecated */ + @Deprecated public LogUtil(Kryptonite plugin) { this.plugin = plugin; } @@ -41,7 +46,9 @@ public LogUtil(Kryptonite plugin) { /** * Logs informational messages if verbose mode is on. * @param message String - The message to log. + * @deprecated */ + @Deprecated public void veboseInfo(String message) { message = "[Kryptonite] " + message; @@ -55,7 +62,9 @@ public void veboseInfo(String message) { /** * Logs informational messages. * @param message String - The message to log. + * @deprecated */ + @Deprecated public void info(String message) { message = "[Kryptonite] " + message; @@ -65,7 +74,9 @@ public void info(String message) { /** * Logs warning messages. * @param message String - The message to log. + * @deprecated */ + @Deprecated public void warn(String message) { message = "[Kryptonite] " + message; @@ -75,7 +86,9 @@ public void warn(String message) { /** * Logs severe messages. * @param message String - The message to log. + * @deprecated */ + @Deprecated public void severe(String message) { message = "[Kryptonite] " + message; @@ -86,7 +99,9 @@ public void severe(String message) { * Logs informational messages. * @param type Type - The type of message to log. * @param message String - The message to log. + * @deprecated */ + @Deprecated private void logToFile(Type type, final String message) { if (this.plugin.getConfig().getBoolean("logfile")) { FoliaLib foliaLib = new FoliaLib(this.plugin); diff --git a/src/main/java/net/lewmc/kryptonite/utils/UpdateUtil.java b/src/main/java/net/lewmc/kryptonite/utils/UpdateUtil.java index ce90c0d..2cbd50e 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/UpdateUtil.java +++ b/src/main/java/net/lewmc/kryptonite/utils/UpdateUtil.java @@ -1,6 +1,7 @@ package net.lewmc.kryptonite.utils; import com.tchristofferson.configupdater.ConfigUpdater; +import net.lewmc.foundry.Logger; import net.lewmc.kryptonite.Kryptonite; import java.io.File; @@ -11,11 +12,11 @@ public class UpdateUtil { private final Kryptonite plugin; - private final LogUtil log; + private final Logger log; public UpdateUtil(Kryptonite plugin) { this.plugin = plugin; - this.log = new LogUtil(plugin); + this.log = new Logger(plugin.foundryConfig); } public void VersionCheck() { diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java new file mode 100644 index 0000000..ac2b706 --- /dev/null +++ b/src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java @@ -0,0 +1,98 @@ +package net.lewmc.kryptonite.utils.config; + +import net.lewmc.foundry.Files; +import net.lewmc.foundry.Logger; +import net.lewmc.kryptonite.Kryptonite; +import net.lewmc.kryptonite.utils.PropertiesUtil; + +import java.util.List; + +/** + * A boolean version of GenericConfigItem + * @since 2.1.0 + */ +public class BooleanConfigItem extends GenericConfigItem { + /** + * The ideal value. + */ + private final Boolean idealValue; + + /** + * The Boolean config item. + * @param file String - The file the config item is located in. + * @param key String - The key of the config item within the file. + * @param name String - The config item's human-readable name. + * @param description List of Strings - The config item's description, for the GUI each String is a new line. + * @param idealValue Boolean - String list of ideal values. + * @param plugin Kryptonite - Reference to the main Kryptonite class. + */ + public BooleanConfigItem(String file, String key, String name, List description, Boolean idealValue, Kryptonite plugin) { + super(file, key, name, description, plugin); + this.idealValue = idealValue; + } + + /** + * Retrieves the current value of the config item. + * @return Boolean - The config's current value. + */ + @Override + public Boolean getCurrentValue() { + if (this.file.contains(".properties")) { + PropertiesUtil p = new PropertiesUtil(this.file); + return Boolean.parseBoolean(p.getProperty(key)); + } else if (this.file.contains(".yml") || file.contains(".yaml")) { + Files f = new Files(this.plugin.foundryConfig, this.plugin); + f.load(this.file); + boolean value = f.getBoolean(key); + f.close(); + return value; + } else { + new Logger(this.plugin.foundryConfig).severe("Unable to load file: '"+this.file+"' extension not supported."); + return false; + } + } + + /** + * Sets the current value of the config item. + * @param value Boolean - The config's current value. + */ + @Override + public void setCurrentValue(Boolean value) { + if (this.file.contains(".properties")) { + propFile.setProperty(this.key, String.valueOf(value)); + } else if (file.contains(".yml") || file.contains(".yaml")) { + yamlFile.load(this.file); + yamlFile.set(this.key, value); + yamlFile.save(); + } + } + + /** + * Checks if the value will be valid. + * @param value Boolean - The value to check. + * @return boolean - Is it valid? + */ + @Override + public boolean willBeValid(Boolean value) { + return true; + } + + /** + * Checks if the config value is ideal. + * @return boolean - Is it ideal? + */ + @Override + public boolean isIdeal() { + if (idealValue == null) { return true; } + return getCurrentValue().equals(idealValue); + } + + /** + * Returns the ideal value in human-readable, string format. + * @return String - The ideal value. + */ + @Override + public String getIdealValue() { + return idealValue == null ? "any" : Boolean.toString(idealValue); + } +} diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java new file mode 100644 index 0000000..1b223a3 --- /dev/null +++ b/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java @@ -0,0 +1,122 @@ +package net.lewmc.kryptonite.utils.config; + +import net.lewmc.foundry.Logger; +import net.lewmc.kryptonite.Kryptonite; + +import java.util.List; + +/** + * A double version of GenericConfigItem + * @since 2.1.0 + */ +public class DoubleConfigItem extends GenericConfigItem { + /** + * The minimum allowed value. + */ + private final Double minValue; + + /** + * The maximum allowed value. + */ + private final Double maxValue; + + /** + * The ideal value in String format (e.g. "7" or "1-5" meaning 1 to 5) + */ + private final String idealValue; + + /** + * The double config item. + * @param file String - The file the config item is located in. + * @param key String - The key of the config item within the file. + * @param name String - The config item's human-readable name. + * @param description List of Strings - The config item's description, for the GUI each String is a new line. + * @param minValue Double - The minimum allowed value. + * @param maxValue Double - The maximum allowed value. + * @param idealValue String - The ideal value in String format (e.g. "7" or "1-5" meaning 1 to 5) + * @param plugin Kryptonite - Reference to the main Kryptonite class. + */ + public DoubleConfigItem(String file, String key, String name, List description, Double minValue, Double maxValue, String idealValue, Kryptonite plugin) { + super(file, key, name, description, plugin); + this.minValue = minValue; + this.maxValue = maxValue; + this.idealValue = idealValue; + } + + /** + * Retrieves the current value of the config item. + * @return Double - The config's current value. + */ + @Override + public Double getCurrentValue() { + if (this.file.contains(".properties")) { + try { + return Double.parseDouble(propFile.getProperty(key)); + } + catch (NumberFormatException e) { + Logger l = new Logger(this.plugin.foundryConfig); + l.severe("Unable to parse key '"+this.key+"' in file '"+this.file+"' NumberFormatException"); + l.severe(e.getMessage()); + return 0.0; + } + } else if (this.file.contains(".yml") || file.contains(".yaml")) { + Double value = yamlFile.getDouble(key); + yamlFile.close(); + return value; + } else { + new Logger(this.plugin.foundryConfig).severe("Unable to load file: '"+this.file+"' extension not supported."); + return 0.0; + } + } + + /** + * Sets the current value of the config item. + * @param value Double - The config's current value. + */ + @Override + public void setCurrentValue(Double value) { + if (this.file.contains(".properties")) { + propFile.setProperty(this.key, String.valueOf(value)); + } else if (file.contains(".yml") || file.contains(".yaml")) { + yamlFile.set(this.key, value); + yamlFile.save(); + } + } + + /** + * Checks if the value will be valid. + * @param value Double - The value to check. + * @return boolean - Is it valid? + */ + @Override + public boolean willBeValid(Double value) { + return value >= minValue && value <= maxValue; + } + + /** + * Checks if the config value is ideal. + * @return boolean - Is it ideal? + */ + @Override + public boolean isIdeal() { + if (idealValue == null) { return true; } + Double current = this.getCurrentValue(); + if (idealValue.contains("-")) { + String[] parts = idealValue.split("-"); + double minIdeal = Double.parseDouble(parts[0]); + double maxIdeal = Double.parseDouble(parts[1]); + return current >= minIdeal && current <= maxIdeal; + } else { + return current == Double.parseDouble(idealValue); + } + } + + /** + * Returns the ideal value in human-readable, string format. + * @return String - The ideal value. + */ + @Override + public String getIdealValue() { + return idealValue == null ? "any" : idealValue; + } +} diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java new file mode 100644 index 0000000..e6cf34d --- /dev/null +++ b/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java @@ -0,0 +1,132 @@ +package net.lewmc.kryptonite.utils.config; + +import net.lewmc.foundry.Files; +import net.lewmc.foundry.Logger; +import net.lewmc.kryptonite.Kryptonite; +import net.lewmc.kryptonite.utils.PropertiesUtil; + +import java.io.File; +import java.util.List; + +/** + * A generic ConfigItem + * @since 2.1.0 + * @param + */ +public abstract class GenericConfigItem { + /** + * Handles .yaml and .yml files. + */ + protected Files yamlFile; + + /** + * Handles .properties files. + */ + protected PropertiesUtil propFile; + + /** + * The file the config item is located in. + */ + protected String file; + + /** + * The key of the config item within the file. + */ + protected String key; + + /** + * The config item's human-readable name. + */ + protected String name; + + /** + * The config item's description, for the GUI each String is a new line. + */ + protected List description; + + /** + * Reference to the main Kryptonite class + */ + protected Kryptonite plugin; + + /** + * The generic config item. + * @param file String - The file the config item is located in. + * @param key String - The key of the config item within the file. + * @param name String - The config item's human-readable name. + * @param description List of Strings - The config item's description, for the GUI each String is a new line. + * @param plugin Kryptonite - Reference to the main Kryptonite class. + */ + public GenericConfigItem(String file, String key, String name, List description, Kryptonite plugin) { + this.file = plugin.getServer().getWorldContainer() + File.separator + file; + this.key = key; + this.name = name; + this.description = description; + this.plugin = plugin; + + if (file.contains(".properties")) { + this.propFile = new PropertiesUtil(file); + } else if (file.contains(".yaml") || file.contains(".yml")) { + this.yamlFile = new Files(plugin.foundryConfig, plugin); + this.yamlFile.loadNoReformat(new File(this.file)); + } else { + new Logger(plugin.foundryConfig).severe("Unable to load file '"+file+"' file extension not supported."); + new Logger(plugin.foundryConfig).severe("Expect additional errors."); + } + + } + + /** + * Should fetch the current value of the config item. + * @return T - The config's current value. + */ + public abstract T getCurrentValue(); + + /** + * Should set the current value of the config item. + * @param value T - The config's current value. + */ + public abstract void setCurrentValue(T value); + + /** + * Should check if the config value is valid. + * @return boolean - Is it valid? + */ + public boolean isValid() { + return this.willBeValid(this.getCurrentValue()); + } + + /** + * Should check if the config value will be valid. + * @return boolean - Is it valid? + */ + public abstract boolean willBeValid(T value); + + /** + * Should check if the config value is ideal. + * @return boolean - Is it ideal? + */ + public abstract boolean isIdeal(); + + /** + * Returns the ideal value in human-readable, string format. + * @return String - The ideal value. + */ + public abstract String getIdealValue(); + + /** + * Returns the config item's name. + * @return String - The name. + */ + public String getName() { + return this.name; + } + + /** + * Returns the config item's description. + * @return List of Strings - The description. + */ + public List getDescription() { + return this.description; + } +} \ No newline at end of file diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java new file mode 100644 index 0000000..5593162 --- /dev/null +++ b/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java @@ -0,0 +1,122 @@ +package net.lewmc.kryptonite.utils.config; + +import net.lewmc.foundry.Logger; +import net.lewmc.kryptonite.Kryptonite; + +import java.util.List; + +/** + * An integer version of GenericConfigItem + * @since 2.1.0 + */ +public class IntegerConfigItem extends GenericConfigItem { + /** + * The minimum allowed value. + */ + private final int minValue; + + /** + * The maximum allowed value. + */ + private final int maxValue; + + /** + * The ideal value in String format (e.g. "7" or "1-5" meaning 1 to 5) + */ + private final String idealValue; + + /** + * The integer config item. + * @param file String - The file the config item is located in. + * @param key String - The key of the config item within the file. + * @param name String - The config item's human-readable name. + * @param description List of Strings - The config item's description, for the GUI each String is a new line. + * @param minValue int - The minimum allowed value. + * @param maxValue int - The maximum allowed value. + * @param idealValue String - The ideal value in String format (e.g. "7" or "1-5" meaning 1 to 5) + * @param plugin Kryptonite - Reference to the main Kryptonite class. + */ + public IntegerConfigItem(String file, String key, String name, List description, int minValue, int maxValue, String idealValue, Kryptonite plugin) { + super(file, key, name, description, plugin); + this.minValue = minValue; + this.maxValue = maxValue; + this.idealValue = idealValue; + } + + /** + * Retrieves the current value of the config item. + * @return int - The config's current value. + */ + @Override + public Integer getCurrentValue() { + if (this.file.contains(".properties")) { + try { + return Integer.parseInt(propFile.getProperty(key)); + } + catch (NumberFormatException e) { + Logger l = new Logger(this.plugin.foundryConfig); + l.severe("Unable to parse key '"+this.key+"' in file '"+this.file+"' NumberFormatException"); + l.severe(e.getMessage()); + return 0; + } + } else if (this.file.contains(".yml") || file.contains(".yaml")) { + int value = yamlFile.getInt(key); + yamlFile.close(); + return value; + } else { + new Logger(this.plugin.foundryConfig).severe("Unable to load file: '"+this.file+"' extension not supported."); + return 0; + } + } + + /** + * Sets the current value of the config item. + * @param value Integer - The config's current value. + */ + @Override + public void setCurrentValue(Integer value) { + if (this.file.contains(".properties")) { + propFile.setProperty(this.key, String.valueOf(value)); + } else if (file.contains(".yml") || file.contains(".yaml")) { + yamlFile.set(this.key, value); + yamlFile.save(); + } + } + + /** + * Checks if the value will be valid. + * @param value Integer - The value to check. + * @return boolean - Is it valid? + */ + @Override + public boolean willBeValid(Integer value) { + return value >= minValue && value <= maxValue; + } + + /** + * Checks if the config value is ideal. + * @return boolean - Is it ideal? + */ + @Override + public boolean isIdeal() { + if (idealValue == null) { return true; } + int current = this.getCurrentValue(); + if (idealValue.contains("-")) { + String[] parts = idealValue.split("-"); + int minIdeal = Integer.parseInt(parts[0].trim()); + int maxIdeal = Integer.parseInt(parts[1].trim()); + return current >= minIdeal && current <= maxIdeal; + } else { + return current == Integer.parseInt(idealValue); + } + } + + /** + * Returns the ideal value in human-readable, string format. + * @return String - The ideal value. + */ + @Override + public String getIdealValue() { + return idealValue == null ? "any" : idealValue; + } +} diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java new file mode 100644 index 0000000..32e67e4 --- /dev/null +++ b/src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java @@ -0,0 +1,99 @@ +package net.lewmc.kryptonite.utils.config; + +import net.lewmc.foundry.Logger; +import net.lewmc.kryptonite.Kryptonite; + +import java.util.List; + +/** + * A string version of GenericConfigItem + * @since 2.1.0 + */ +public class StringConfigItem extends GenericConfigItem { + /** + * String list of allowed values. + */ + private final List allowedValues; + + /** + * String list of ideal values. + */ + private final List idealValues; + + /** + * The String config item. + * @param file String - The file the config item is located in. + * @param key String - The key of the config item within the file. + * @param name String - The config item's human-readable name. + * @param description List of Strings - The config item's description, for the GUI each String is a new line. + * @param allowedValues List of Strings - String list of allowed values. + * @param idealValues List of Strings - String list of ideal values. + * @param plugin Kryptonite - Reference to the main Kryptonite class. + */ + public StringConfigItem(String file, String key, String name, List description, List allowedValues, List idealValues, Kryptonite plugin) { + super(file, key, name, description, plugin); + this.allowedValues = allowedValues; + this.idealValues = idealValues; + } + + /** + * Retrieves the current value of the config item. + * @return String - The config's current value. + */ + @Override + public String getCurrentValue() { + if (this.file.contains(".properties")) { + return propFile.getProperty(key); + } else if (this.file.contains(".yml") || file.contains(".yaml")) { + String value = yamlFile.getString(key); + yamlFile.close(); + return value; + } else { + new Logger(this.plugin.foundryConfig).severe("Unable to load file: '"+this.file+"' extension not supported."); + return null; + } + } + + /** + * Sets the current value of the config item. + * @param value Integer - The config's current value. + */ + @Override + public void setCurrentValue(String value) { + if (this.file.contains(".properties")) { + propFile.setProperty(this.key, value); + } else if (file.contains(".yml") || file.contains(".yaml")) { + yamlFile.set(this.key, value); + yamlFile.save(); + } + } + + /** + * Checks if the value will be valid. + * @param value String - The value to check. + * @return boolean - Is it valid? + */ + @Override + public boolean willBeValid(String value) { + return this.allowedValues.contains(value); + } + + /** + * Checks if the config value is ideal. + * @return boolean - Is it ideal? + */ + @Override + public boolean isIdeal() { + if (idealValues == null) { return true; } + return idealValues.contains(this.getCurrentValue()); + } + + /** + * Returns the ideal value in human-readable, string format. + * @return String - The ideal value. + */ + @Override + public String getIdealValue() { + return idealValues == null ? "any" : idealValues.toString(); + } +} From 95a7958ce316e7fa90548e1dc097c4ee64780e84 Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 28 Aug 2025 19:02:31 +0100 Subject: [PATCH 06/21] Migrate to new system. (Part of #55) --- .../java/net/lewmc/kryptonite/Kryptonite.java | 4 +- .../lewmc/kryptonite/config/Minecraft.java | 3 +- .../java/net/lewmc/kryptonite/edb/Check.java | 13 +- .../java/net/lewmc/kryptonite/edb/Patch.java | 11 +- .../net/lewmc/kryptonite/kos/AutoKOS.java | 8 +- ...necraftGui.java => KOS_ConfigItemGui.java} | 139 ++++++++++-------- .../kryptonite/kos/gui/KOS_ManualGUI.java | 10 +- .../net/lewmc/kryptonite/report/Report.java | 2 +- .../lewmc/kryptonite/utils/SoftwareUtil.java | 4 +- .../utils/config/ConfigCollection.java | 14 ++ 10 files changed, 116 insertions(+), 92 deletions(-) rename src/main/java/net/lewmc/kryptonite/kos/gui/{KOS_MinecraftGui.java => KOS_ConfigItemGui.java} (50%) create mode 100644 src/main/java/net/lewmc/kryptonite/utils/config/ConfigCollection.java diff --git a/src/main/java/net/lewmc/kryptonite/Kryptonite.java b/src/main/java/net/lewmc/kryptonite/Kryptonite.java index 8e650e1..c22eb05 100644 --- a/src/main/java/net/lewmc/kryptonite/Kryptonite.java +++ b/src/main/java/net/lewmc/kryptonite/Kryptonite.java @@ -21,7 +21,7 @@ public final class Kryptonite extends JavaPlugin { private Logger log; public enum ConfigurationOptions { - SERVER_PROPERTIES, + MINECRAFT, BUKKIT, SPIGOT, PAPER_WORLD, @@ -129,7 +129,7 @@ private void checkSoftware() { File serverProperties = new File("server.properties"); if (serverProperties.exists()) { - this.SupportedConfigurations.add(ConfigurationOptions.SERVER_PROPERTIES); + this.SupportedConfigurations.add(ConfigurationOptions.MINECRAFT); supportedConfigs = supportedConfigs + "Server Properties"; } diff --git a/src/main/java/net/lewmc/kryptonite/config/Minecraft.java b/src/main/java/net/lewmc/kryptonite/config/Minecraft.java index 3ec67c6..aeb50b6 100644 --- a/src/main/java/net/lewmc/kryptonite/config/Minecraft.java +++ b/src/main/java/net/lewmc/kryptonite/config/Minecraft.java @@ -2,6 +2,7 @@ import net.lewmc.kryptonite.Kryptonite; import net.lewmc.kryptonite.utils.config.BooleanConfigItem; +import net.lewmc.kryptonite.utils.config.ConfigCollection; import net.lewmc.kryptonite.utils.config.GenericConfigItem; import net.lewmc.kryptonite.utils.config.IntegerConfigItem; @@ -11,7 +12,7 @@ * Configuration data for server.properties * @since 2.1.0 */ -public class Minecraft { +public class Minecraft extends ConfigCollection { /** * Holds configuration data for the server.properties file. */ diff --git a/src/main/java/net/lewmc/kryptonite/edb/Check.java b/src/main/java/net/lewmc/kryptonite/edb/Check.java index 01b0964..f8b4178 100644 --- a/src/main/java/net/lewmc/kryptonite/edb/Check.java +++ b/src/main/java/net/lewmc/kryptonite/edb/Check.java @@ -1,9 +1,8 @@ package net.lewmc.kryptonite.edb; +import net.lewmc.foundry.Logger; import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.kos.config.ServerProperties; import net.lewmc.kryptonite.utils.ConfigurationUtil; -import net.lewmc.kryptonite.utils.LogUtil; import net.lewmc.kryptonite.utils.PropertiesUtil; import net.lewmc.kryptonite.utils.SoftwareUtil; import org.bukkit.command.CommandSender; @@ -12,14 +11,14 @@ public class Check { private final Kryptonite plugin; private final SoftwareUtil softwareUtil; - private final LogUtil log; + private final Logger log; private final CommandSender player; public Check(Kryptonite plugin, CommandSender player) { this.player = player; this.plugin = plugin; this.softwareUtil = new SoftwareUtil(plugin); - this.log = new LogUtil(plugin); + this.log = new Logger(plugin.foundryConfig); } public boolean edb1() { @@ -406,7 +405,7 @@ public boolean edb11() { } public boolean edb12() { - if (this.softwareUtil.supportsServerProperties()) { + if (this.softwareUtil.supportsMinecraft()) { PropertiesUtil sp = new PropertiesUtil("server.properties"); if (!Objects.equals(sp.getProperty("online-mode"), "true")) { @@ -432,8 +431,4 @@ public boolean edb12() { public void logThis(String id, String value, String current, String expected) { this.log.warn("[" + id + "][FAIL] '" + value + "' is '" + current + "' - expected '" + expected + "'"); } - - public void warnThis(String id, String value, String current, String expected) { - this.log.warn("[" + id + "][WARN] '" + value + "' is '" + current + "' - expected '" + expected + "'"); - } } diff --git a/src/main/java/net/lewmc/kryptonite/edb/Patch.java b/src/main/java/net/lewmc/kryptonite/edb/Patch.java index 8b3a485..61a6b9e 100644 --- a/src/main/java/net/lewmc/kryptonite/edb/Patch.java +++ b/src/main/java/net/lewmc/kryptonite/edb/Patch.java @@ -1,29 +1,20 @@ package net.lewmc.kryptonite.edb; import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.edb.gui.EDB_MainGui; import net.lewmc.kryptonite.utils.ConfigurationUtil; -import net.lewmc.kryptonite.utils.LogUtil; import net.lewmc.kryptonite.utils.PropertiesUtil; import net.lewmc.kryptonite.utils.SoftwareUtil; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.InvalidConfigurationException; -import org.checkerframework.checker.units.qual.C; - -import java.io.File; -import java.io.IOException; public class Patch { private final Kryptonite plugin; private final SoftwareUtil softwareUtil; - private final LogUtil log; private final Check check; private final CommandSender user; public Patch(Kryptonite plugin, CommandSender sender) { this.plugin = plugin; this.softwareUtil = new SoftwareUtil(plugin); - this.log = new LogUtil(plugin); this.check = new Check(plugin, sender); this.user = sender; } @@ -228,7 +219,7 @@ public boolean edb11() { } public boolean edb12() { - if (softwareUtil.supportsServerProperties()) { + if (softwareUtil.supportsMinecraft()) { PropertiesUtil propertiesUtil = new PropertiesUtil("server.properties"); propertiesUtil.setProperty("online-mode", "true"); diff --git a/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java b/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java index 0abd152..4a4e951 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java +++ b/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java @@ -1,9 +1,9 @@ package net.lewmc.kryptonite.kos; +import net.lewmc.foundry.Logger; import net.lewmc.kryptonite.Kryptonite; import net.lewmc.kryptonite.kos.config.*; import net.lewmc.kryptonite.utils.ConfigurationUtil; -import net.lewmc.kryptonite.utils.LogUtil; import net.lewmc.kryptonite.utils.MessageUtil; import net.lewmc.kryptonite.utils.SoftwareUtil; import org.bukkit.command.CommandSender; @@ -15,7 +15,7 @@ */ public class AutoKOS { private final Kryptonite plugin; - private final LogUtil log; + private final Logger log; private final SoftwareUtil softwareUtil; private final MessageUtil message; private final CommandSender user; @@ -27,7 +27,7 @@ public class AutoKOS { */ public AutoKOS(Kryptonite plugin, CommandSender user) { this.plugin = plugin; - this.log = new LogUtil(plugin); + this.log = new Logger(plugin.foundryConfig); this.softwareUtil = new SoftwareUtil(plugin); this.message = new MessageUtil(user); this.user = user; @@ -79,7 +79,7 @@ public void run(boolean pregeneratedWorld, String profile) { } private void runVanilla() { - if (this.softwareUtil.supportsServerProperties()) { + if (this.softwareUtil.supportsMinecraft()) { this.log.info("[KOS] 1/6 - Running Vanilla optimisations"); ServerProperties properties = new ServerProperties(this.plugin); diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_MinecraftGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java similarity index 50% rename from src/main/java/net/lewmc/kryptonite/kos/gui/KOS_MinecraftGui.java rename to src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java index ac56e5f..697e7f8 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_MinecraftGui.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java @@ -6,6 +6,7 @@ import net.lewmc.kryptonite.Kryptonite; import net.lewmc.kryptonite.config.Minecraft; import net.lewmc.kryptonite.utils.config.BooleanConfigItem; +import net.lewmc.kryptonite.utils.config.ConfigCollection; import net.lewmc.kryptonite.utils.config.GenericConfigItem; import net.lewmc.kryptonite.utils.config.IntegerConfigItem; import org.bukkit.ChatColor; @@ -22,24 +23,29 @@ import java.util.Map; /** - * KOS Minecraft (server.properties) GUI + * KOS Config Item GUI */ -public class KOS_MinecraftGui { +public class KOS_ConfigItemGui { private final Kryptonite plugin; private final CommandSender user; - private final Minecraft config; + private final ConfigCollection config; private InventoryGui gui; /** - * Constructor for the KOS Server Properties GUI + * Constructor for the KOS Config Item GUI * @param plugin Kryptonite - Reference to the main plugin class. * @param user CommandSender - The user who sent the command. + * @param type Kryptonite.ConfigurationOptions - The type of GUI to display. */ - public KOS_MinecraftGui(Kryptonite plugin, CommandSender user) { + public KOS_ConfigItemGui(Kryptonite plugin, CommandSender user, Kryptonite.ConfigurationOptions type) { this.plugin = plugin; this.user = user; - this.config = new Minecraft(plugin); + if (type == Kryptonite.ConfigurationOptions.MINECRAFT) { + this.config = new Minecraft(plugin); + } else { + this.config = null; + } } /** @@ -58,54 +64,67 @@ public void show() { * Adds pre-programmed elements to the GUI */ private void addElements() { - int index = 0; - for (Map.Entry entry : this.config.values.entrySet()) { - GenericConfigItem config = entry.getValue(); - char id = (char) ('a' + index); - - ItemStack display = buildDisplayItem(config); - - this.gui.addElement(new StaticGuiElement( - id, - display, - 1, - click -> { - handleClick(config, click); - return true; - } - )); - - index++; - } + if (this.config != null) { + int index = 0; + for (Map.Entry entry : this.config.values.entrySet()) { + GenericConfigItem config = entry.getValue(); + char id = (char) ('a' + index); + + ItemStack display = buildDisplayItem(config); + + this.gui.addElement(new StaticGuiElement( + id, + display, + 1, + click -> { + handleClick(config, click); + return true; + } + )); + + index++; + } - // Keep your constant controls - KOS_GuiConstants consts = new KOS_GuiConstants(this.plugin, this.gui); - consts.addConstants(); + KOS_GuiConstants consts = new KOS_GuiConstants(this.plugin, this.gui); + consts.addConstants(); + } } private ItemStack buildDisplayItem(GenericConfigItem config) { boolean ideal = config.isIdeal(); - Material material = ideal ? Material.LIME_CONCRETE : Material.RED_CONCRETE; + + Material material; + + if (config.isValid()) { + material = (ideal) ? Material.LIME_CONCRETE : Material.RED_CONCRETE; + } else { + material = Material.BLACK_CONCRETE; + } ItemStack item = new ItemStack(material); ItemMeta meta = item.getItemMeta(); - meta.setDisplayName((ideal ? ChatColor.DARK_GREEN : ChatColor.DARK_RED) + config.getName()); - List lore = new ArrayList<>(); - lore.add((ideal ? ChatColor.GREEN : ChatColor.RED) + "Current: " + config.getCurrentValue()); - String idealValue = config.getIdealValue(); - if (idealValue != null) { - lore.add(ChatColor.GRAY + "Ideal: " + idealValue); + if (config.isValid()) { + meta.setDisplayName(((ideal) ? ChatColor.DARK_GREEN : ChatColor.DARK_RED) + config.getName()); + lore.add(((ideal) ? ChatColor.DARK_GREEN : ChatColor.DARK_RED) + String.valueOf(config.getCurrentValue())); + if (config.getDescription() != null) { + lore.addAll(config.getDescription().stream() + .map(line -> ((ideal) ? ChatColor.GREEN : ChatColor.RED) + line) + .toList()); + } } else { - lore.add(ChatColor.GRAY + "Any value is fine"); + meta.setDisplayName(ChatColor.DARK_GRAY + config.getName()); + lore.add(ChatColor.GRAY + String.valueOf(config.getCurrentValue())); + if (config.getDescription() != null) { + lore.addAll(config.getDescription().stream() + .map(line -> ChatColor.GRAY + line) + .toList()); + } } - if (config.getDescription() != null) { - lore.addAll(config.getDescription().stream() - .map(line -> ChatColor.BLUE + line) - .toList()); - } + String idealValue = config.getIdealValue(); + lore.add(ChatColor.WHITE + "Ideal value: " + ((idealValue != null) ? idealValue : "Any")); meta.setLore(lore); item.setItemMeta(meta); @@ -140,26 +159,30 @@ private void handleClick(GenericConfigItem config, GuiElement.Click click) { * @return String[] - The position of the elements. */ private String[] getElements() { - int size = this.config.values.size(); - int rows = (int) Math.ceil(size / 9.0); - - // +1 row for the constant footer row - String[] layout = new String[rows + 1]; - - int index = 0; - for (int r = 0; r < rows; r++) { - StringBuilder row = new StringBuilder(" "); - for (int c = 0; c < 9 && index < size; c++) { - char id = (char) ('a' + index); - row.setCharAt(c, id); - index++; + if (this.config != null) { + int size = this.config.values.size(); + int rows = (int) Math.ceil(size / 9.0); + + // +1 row for the constant footer row + String[] layout = new String[rows + 1]; + + int index = 0; + for (int r = 0; r < rows; r++) { + StringBuilder row = new StringBuilder(" "); + for (int c = 0; c < 9 && index < size; c++) { + char id = (char) ('a' + index); + row.setCharAt(c, id); + index++; + } + layout[r] = row.toString(); } - layout[r] = row.toString(); - } - layout[rows] = " t u v "; + layout[rows] = " t u v "; - return layout; + return layout; + } else { + return new String[] {"",""," t u v "}; + } } } diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java index bc87c14..a6bcd14 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java @@ -44,13 +44,13 @@ public void show() { * Adds pre-programmed elements to the GUI */ private void addElements() { - if (this.plugin.SupportedConfigurations.contains(Kryptonite.ConfigurationOptions.SERVER_PROPERTIES)) { + if (this.plugin.SupportedConfigurations.contains(Kryptonite.ConfigurationOptions.MINECRAFT)) { this.gui.addElement(new StaticGuiElement('p', new ItemStack(Material.COMMAND_BLOCK_MINECART), 1, click -> { click.getGui().close(); - new KOS_MinecraftGui(this.plugin, this.user).show(); + new KOS_ConfigItemGui(this.plugin, this.user, Kryptonite.ConfigurationOptions.MINECRAFT).show(); return true; }, ChatColor.BLUE + "Minecraft", @@ -212,7 +212,7 @@ private void addElements() { } if (this.plugin.SupportedConfigurations.contains(Kryptonite.ConfigurationOptions.LEAF)) { - this.gui.addElement(new StaticGuiElement('g', + this.gui.addElement(new StaticGuiElement('l', new ItemStack(Material.OAK_LEAVES), 1, click -> { @@ -225,7 +225,7 @@ private void addElements() { ChatColor.AQUA + "Manage the Leaf configuration." )); } else { - this.gui.addElement(new StaticGuiElement('f', + this.gui.addElement(new StaticGuiElement('l', new ItemStack(Material.BARRIER), 1, click -> true, @@ -247,7 +247,7 @@ private String[] getElements() { return new String[]{ " p b s g ", - " o u f ", + " o u f l ", " w x y " }; } diff --git a/src/main/java/net/lewmc/kryptonite/report/Report.java b/src/main/java/net/lewmc/kryptonite/report/Report.java index e3c415f..9bd7dd9 100644 --- a/src/main/java/net/lewmc/kryptonite/report/Report.java +++ b/src/main/java/net/lewmc/kryptonite/report/Report.java @@ -20,7 +20,7 @@ public void runReport(Kryptonite plugin, CommandSender user) { } private void runKOSReport() { - if (this.softwareUtil.supportsServerProperties()) { + if (this.softwareUtil.supportsMinecraft()) { message.Info("Reporting [1/7] Gathering server configuration."); } else { message.Info("Reporting [1/7] Server not supported, skipping..."); diff --git a/src/main/java/net/lewmc/kryptonite/utils/SoftwareUtil.java b/src/main/java/net/lewmc/kryptonite/utils/SoftwareUtil.java index bc39de4..1f840c8 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/SoftwareUtil.java +++ b/src/main/java/net/lewmc/kryptonite/utils/SoftwareUtil.java @@ -11,8 +11,8 @@ public SoftwareUtil(Kryptonite plugin) { this.plugin = plugin; } - public boolean supportsServerProperties() { - return this.plugin.SupportedConfigurations.contains(Kryptonite.ConfigurationOptions.SERVER_PROPERTIES); + public boolean supportsMinecraft() { + return this.plugin.SupportedConfigurations.contains(Kryptonite.ConfigurationOptions.MINECRAFT); } public boolean supportsCraftBukkit() { diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/ConfigCollection.java b/src/main/java/net/lewmc/kryptonite/utils/config/ConfigCollection.java new file mode 100644 index 0000000..adac8f8 --- /dev/null +++ b/src/main/java/net/lewmc/kryptonite/utils/config/ConfigCollection.java @@ -0,0 +1,14 @@ +package net.lewmc.kryptonite.utils.config; + +import java.util.HashMap; + +/** + * Configuration data template for config files. + * @since 2.1.0 + */ +public abstract class ConfigCollection { + /** + * Holds configuration data for the relevant file. + */ + public HashMap values; +} \ No newline at end of file From 92574340cc3729af2e9b0d0bd4dc9c7f8bdd5dad Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 28 Aug 2025 19:15:28 +0100 Subject: [PATCH 07/21] Fixed some errors, deprecated older stuff. --- src/main/java/net/lewmc/kryptonite/Metrics.java | 5 ++++- .../net/lewmc/kryptonite/config/Minecraft.java | 2 +- .../java/net/lewmc/kryptonite/kos/AutoKOS.java | 16 +++++++++------- .../net/lewmc/kryptonite/kos/config/Bukkit.java | 2 ++ .../net/lewmc/kryptonite/kos/config/Leaf.java | 2 ++ .../lewmc/kryptonite/kos/config/PaperWorld.java | 2 ++ .../lewmc/kryptonite/kos/config/Pufferfish.java | 2 ++ .../net/lewmc/kryptonite/kos/config/Purpur.java | 2 ++ .../kryptonite/kos/config/ServerProperties.java | 2 ++ .../net/lewmc/kryptonite/kos/config/Spigot.java | 2 ++ .../lewmc/kryptonite/kos/gui/KOS_BukkitGui.java | 4 ++-- .../lewmc/kryptonite/kos/gui/KOS_LeafGui.java | 2 ++ .../kryptonite/kos/gui/KOS_PaperWorld_1.java | 2 ++ .../kryptonite/kos/gui/KOS_PaperWorld_2.java | 2 ++ .../kryptonite/kos/gui/KOS_PaperWorld_3.java | 2 ++ .../kryptonite/kos/gui/KOS_PaperWorld_4.java | 2 ++ .../kryptonite/kos/gui/KOS_PaperWorld_5.java | 2 ++ .../kryptonite/kos/gui/KOS_PregeneratedGUI.java | 2 ++ .../kryptonite/kos/gui/KOS_PufferfishGui.java | 3 ++- .../lewmc/kryptonite/kos/gui/KOS_PurpurGui.java | 2 ++ .../kryptonite/kos/gui/KOS_SpigotGui_1.java | 2 ++ .../kryptonite/kos/gui/KOS_SpigotGui_2.java | 3 ++- .../lewmc/kryptonite/utils/PermissionUtil.java | 4 ++++ .../utils/config/BooleanConfigItem.java | 6 +++--- .../utils/config/DoubleConfigItem.java | 6 +++--- .../utils/config/GenericConfigItem.java | 8 ++++---- .../utils/config/IntegerConfigItem.java | 6 +++--- .../utils/config/StringConfigItem.java | 6 +++--- src/main/resources/profiles/FarmFriendly.kos | 1 + src/main/resources/profiles/YouHaveTrouble.kos | 1 + 30 files changed, 74 insertions(+), 29 deletions(-) diff --git a/src/main/java/net/lewmc/kryptonite/Metrics.java b/src/main/java/net/lewmc/kryptonite/Metrics.java index b999915..2fcc409 100644 --- a/src/main/java/net/lewmc/kryptonite/Metrics.java +++ b/src/main/java/net/lewmc/kryptonite/Metrics.java @@ -46,7 +46,10 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; - +/** + * @deprecated + */ +@Deprecated public class Metrics { private final Plugin plugin; diff --git a/src/main/java/net/lewmc/kryptonite/config/Minecraft.java b/src/main/java/net/lewmc/kryptonite/config/Minecraft.java index aeb50b6..a27fc63 100644 --- a/src/main/java/net/lewmc/kryptonite/config/Minecraft.java +++ b/src/main/java/net/lewmc/kryptonite/config/Minecraft.java @@ -60,7 +60,7 @@ public Minecraft(Kryptonite plugin) { List.of("The distance mobs will be simulated."), 1, 50, - "5 - "+values.get("view-distance").getCurrentValue(), + "5 - "+values.get("view-distance").getValue(), plugin )); diff --git a/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java b/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java index 4a4e951..48ccc5d 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java +++ b/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java @@ -2,6 +2,7 @@ import net.lewmc.foundry.Logger; import net.lewmc.kryptonite.Kryptonite; +import net.lewmc.kryptonite.config.Minecraft; import net.lewmc.kryptonite.kos.config.*; import net.lewmc.kryptonite.utils.ConfigurationUtil; import net.lewmc.kryptonite.utils.MessageUtil; @@ -82,15 +83,16 @@ private void runVanilla() { if (this.softwareUtil.supportsMinecraft()) { this.log.info("[KOS] 1/6 - Running Vanilla optimisations"); - ServerProperties properties = new ServerProperties(this.plugin); + Minecraft m = new Minecraft(this.plugin); - properties.set(ServerProperties.Key.NETWORK_COMPRESSION_THRESHOLD, this.patches.getString("server.network-compression-threshold")); - properties.set(ServerProperties.Key.SIMULATION_DISTANCE, this.patches.getString("server.distance.simulation")); - properties.set(ServerProperties.Key.VIEW_DISTANCE, this.patches.getString("server.distance.view")); - properties.set(ServerProperties.Key.SYNC_CHUNK_WRITES, this.patches.getString("server.sync-chunk-writes")); + m.values.get("network-compression-threshold").setValue(this.patches.getInt("server.network-compression-threshold")); + m.values.get("simulation-distance").setValue(this.patches.getInt("server.distance.simulation")); + m.values.get("view-distance").setValue(this.patches.getInt("server.distance.view")); + m.values.get("sync-chunk-writes").setValue(this.patches.getBoolean("server.sync-chunk-writes")); + m.values.get("allow-flight").setValue(this.patches.getBoolean("server.allow-flight")); } else { - this.log.info("[KOS] 2/6 - Server does not support Server Properties, skipping..."); - this.log.warn("[KOS] 2/6 - This shouldn't happen, please open an issue at github.com/lewmc/kryptonite"); + this.log.info("[KOS] 1/6 - Server does not support Server Properties, skipping..."); + this.log.warn("[KOS] 1/6 - This shouldn't happen, please contact LewMC for help at lewmc.net/help"); } } diff --git a/src/main/java/net/lewmc/kryptonite/kos/config/Bukkit.java b/src/main/java/net/lewmc/kryptonite/kos/config/Bukkit.java index 1a0ae7c..c068ef3 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/config/Bukkit.java +++ b/src/main/java/net/lewmc/kryptonite/kos/config/Bukkit.java @@ -7,7 +7,9 @@ /** * The Bukkit class manages the bukkit.yml configuration file. + * @deprecated */ +@Deprecated public class Bukkit { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/config/Leaf.java b/src/main/java/net/lewmc/kryptonite/kos/config/Leaf.java index 22ad809..992deeb 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/config/Leaf.java +++ b/src/main/java/net/lewmc/kryptonite/kos/config/Leaf.java @@ -7,7 +7,9 @@ /** * The leaf class manages the leaf.yml configuration file. + * @deprecated */ +@Deprecated public class Leaf { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/config/PaperWorld.java b/src/main/java/net/lewmc/kryptonite/kos/config/PaperWorld.java index 09590a2..2a7c157 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/config/PaperWorld.java +++ b/src/main/java/net/lewmc/kryptonite/kos/config/PaperWorld.java @@ -7,7 +7,9 @@ /** * The PaperWorld class manages the paper-world-defaults.yml configuration file. + * @deprecated */ +@Deprecated public class PaperWorld { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/config/Pufferfish.java b/src/main/java/net/lewmc/kryptonite/kos/config/Pufferfish.java index 7a9884b..f5584cc 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/config/Pufferfish.java +++ b/src/main/java/net/lewmc/kryptonite/kos/config/Pufferfish.java @@ -7,7 +7,9 @@ /** * The Pufferfish class manages the pufferfish.yml configuration file. + * @deprecated */ +@Deprecated public class Pufferfish { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/config/Purpur.java b/src/main/java/net/lewmc/kryptonite/kos/config/Purpur.java index 1904fbe..0b81852 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/config/Purpur.java +++ b/src/main/java/net/lewmc/kryptonite/kos/config/Purpur.java @@ -7,7 +7,9 @@ /** * The Purpur class manages the purpur.yml configuration file. + * @deprecated */ +@Deprecated public class Purpur { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/config/ServerProperties.java b/src/main/java/net/lewmc/kryptonite/kos/config/ServerProperties.java index 21e3f6a..4f1f348 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/config/ServerProperties.java +++ b/src/main/java/net/lewmc/kryptonite/kos/config/ServerProperties.java @@ -6,7 +6,9 @@ /** * The ServerProperties class manages the server.properties configuration file. + * @deprecated */ +@Deprecated public class ServerProperties { private final PropertiesUtil util; private final Kryptonite plugin; diff --git a/src/main/java/net/lewmc/kryptonite/kos/config/Spigot.java b/src/main/java/net/lewmc/kryptonite/kos/config/Spigot.java index e8879bf..b622c95 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/config/Spigot.java +++ b/src/main/java/net/lewmc/kryptonite/kos/config/Spigot.java @@ -7,7 +7,9 @@ /** * The Spigot class manages the spigot.yml configuration file. + * @deprecated */ +@Deprecated public class Spigot { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_BukkitGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_BukkitGui.java index ca1134c..9be5f96 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_BukkitGui.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_BukkitGui.java @@ -13,11 +13,11 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; -import java.util.Objects; - /** * KOS Bukkit GUI + * @deprecated */ +@Deprecated public class KOS_BukkitGui { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_LeafGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_LeafGui.java index eb41938..37bf6ac 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_LeafGui.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_LeafGui.java @@ -15,7 +15,9 @@ /** * KOS Leaf GUI + * @deprecated */ +@Deprecated public class KOS_LeafGui { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_1.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_1.java index b8cefab..c217e12 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_1.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_1.java @@ -15,7 +15,9 @@ /** * KOS Paper World GUI (Page 1/5) + * @deprecated */ +@Deprecated public class KOS_PaperWorld_1 { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_2.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_2.java index db60002..e915675 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_2.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_2.java @@ -15,7 +15,9 @@ /** * KOS Paper World GUI (Page 2/5) + * @deprecated */ +@Deprecated public class KOS_PaperWorld_2 { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_3.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_3.java index 5102886..3b35495 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_3.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_3.java @@ -16,7 +16,9 @@ /** * KOS Paper World GUI (Page 3/5) + * @deprecated */ +@Deprecated public class KOS_PaperWorld_3 { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_4.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_4.java index 18b1b77..a244fa7 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_4.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_4.java @@ -15,7 +15,9 @@ /** * KOS Paper World GUI (Page 4/5) + * @deprecated */ +@Deprecated public class KOS_PaperWorld_4 { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_5.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_5.java index eeff083..7924bbb 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_5.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_5.java @@ -15,7 +15,9 @@ /** * KOS Paper World GUI (Page 5/5) + * @deprecated */ +@Deprecated public class KOS_PaperWorld_5 { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PregeneratedGUI.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PregeneratedGUI.java index 9929b8c..7811e9a 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PregeneratedGUI.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PregeneratedGUI.java @@ -15,7 +15,9 @@ /** * KOS Auto GUI + * @deprecated */ +@Deprecated public class KOS_PregeneratedGUI { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PufferfishGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PufferfishGui.java index 368b59b..fe82e43 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PufferfishGui.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PufferfishGui.java @@ -6,7 +6,6 @@ import net.lewmc.kryptonite.Kryptonite; import net.lewmc.kryptonite.kos.config.Pufferfish; import net.lewmc.kryptonite.kos.config.ServerProperties; -import net.lewmc.kryptonite.kos.config.Spigot; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.CommandSender; @@ -17,7 +16,9 @@ /** * KOS Pufferfish GUI + * @deprecated */ +@Deprecated public class KOS_PufferfishGui { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PurpurGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PurpurGui.java index 4797266..7bff096 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PurpurGui.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PurpurGui.java @@ -15,7 +15,9 @@ /** * KOS Purpur GUI + * @deprecated */ +@Deprecated public class KOS_PurpurGui { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_1.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_1.java index 09ce313..922bc1a 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_1.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_1.java @@ -16,7 +16,9 @@ /** * KOS Spigot GUI (Page 1/2) + * @deprecated */ +@Deprecated public class KOS_SpigotGui_1 { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_2.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_2.java index d74479b..08d1c9b 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_2.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_2.java @@ -4,7 +4,6 @@ import de.themoep.inventorygui.InventoryGui; import de.themoep.inventorygui.StaticGuiElement; import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.kos.config.ServerProperties; import net.lewmc.kryptonite.kos.config.Spigot; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -16,7 +15,9 @@ /** * KOS Spigot GUI (Page 2/2) + * @deprecated */ +@Deprecated public class KOS_SpigotGui_2 { private final Kryptonite plugin; private final CommandSender user; diff --git a/src/main/java/net/lewmc/kryptonite/utils/PermissionUtil.java b/src/main/java/net/lewmc/kryptonite/utils/PermissionUtil.java index 2a9aa6c..560bb80 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/PermissionUtil.java +++ b/src/main/java/net/lewmc/kryptonite/utils/PermissionUtil.java @@ -6,6 +6,10 @@ import java.util.Objects; +/** + * @deprecated + */ +@Deprecated public class PermissionUtil { public boolean isOperator(CommandSender commandSender) { if (commandSender instanceof Player) { diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java index ac2b706..3f164d5 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java @@ -36,7 +36,7 @@ public BooleanConfigItem(String file, String key, String name, List desc * @return Boolean - The config's current value. */ @Override - public Boolean getCurrentValue() { + public Boolean getValue() { if (this.file.contains(".properties")) { PropertiesUtil p = new PropertiesUtil(this.file); return Boolean.parseBoolean(p.getProperty(key)); @@ -57,7 +57,7 @@ public Boolean getCurrentValue() { * @param value Boolean - The config's current value. */ @Override - public void setCurrentValue(Boolean value) { + public void setValue(Boolean value) { if (this.file.contains(".properties")) { propFile.setProperty(this.key, String.valueOf(value)); } else if (file.contains(".yml") || file.contains(".yaml")) { @@ -84,7 +84,7 @@ public boolean willBeValid(Boolean value) { @Override public boolean isIdeal() { if (idealValue == null) { return true; } - return getCurrentValue().equals(idealValue); + return getValue().equals(idealValue); } /** diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java index 1b223a3..f51424a 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java @@ -48,7 +48,7 @@ public DoubleConfigItem(String file, String key, String name, List descr * @return Double - The config's current value. */ @Override - public Double getCurrentValue() { + public Double getValue() { if (this.file.contains(".properties")) { try { return Double.parseDouble(propFile.getProperty(key)); @@ -74,7 +74,7 @@ public Double getCurrentValue() { * @param value Double - The config's current value. */ @Override - public void setCurrentValue(Double value) { + public void setValue(Double value) { if (this.file.contains(".properties")) { propFile.setProperty(this.key, String.valueOf(value)); } else if (file.contains(".yml") || file.contains(".yaml")) { @@ -100,7 +100,7 @@ public boolean willBeValid(Double value) { @Override public boolean isIdeal() { if (idealValue == null) { return true; } - Double current = this.getCurrentValue(); + Double current = this.getValue(); if (idealValue.contains("-")) { String[] parts = idealValue.split("-"); double minIdeal = Double.parseDouble(parts[0]); diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java index e6cf34d..eda48d5 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java @@ -80,20 +80,20 @@ public GenericConfigItem(String file, String key, String name, List desc * Should fetch the current value of the config item. * @return T - The config's current value. */ - public abstract T getCurrentValue(); + public abstract T getValue(); /** - * Should set the current value of the config item. + * Should set the value of the config item. * @param value T - The config's current value. */ - public abstract void setCurrentValue(T value); + public abstract void setValue(T value); /** * Should check if the config value is valid. * @return boolean - Is it valid? */ public boolean isValid() { - return this.willBeValid(this.getCurrentValue()); + return this.willBeValid(this.getValue()); } /** diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java index 5593162..a4dad3f 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java @@ -48,7 +48,7 @@ public IntegerConfigItem(String file, String key, String name, List desc * @return int - The config's current value. */ @Override - public Integer getCurrentValue() { + public Integer getValue() { if (this.file.contains(".properties")) { try { return Integer.parseInt(propFile.getProperty(key)); @@ -74,7 +74,7 @@ public Integer getCurrentValue() { * @param value Integer - The config's current value. */ @Override - public void setCurrentValue(Integer value) { + public void setValue(Integer value) { if (this.file.contains(".properties")) { propFile.setProperty(this.key, String.valueOf(value)); } else if (file.contains(".yml") || file.contains(".yaml")) { @@ -100,7 +100,7 @@ public boolean willBeValid(Integer value) { @Override public boolean isIdeal() { if (idealValue == null) { return true; } - int current = this.getCurrentValue(); + int current = this.getValue(); if (idealValue.contains("-")) { String[] parts = idealValue.split("-"); int minIdeal = Integer.parseInt(parts[0].trim()); diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java index 32e67e4..5d4c9dd 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java @@ -41,7 +41,7 @@ public StringConfigItem(String file, String key, String name, List descr * @return String - The config's current value. */ @Override - public String getCurrentValue() { + public String getValue() { if (this.file.contains(".properties")) { return propFile.getProperty(key); } else if (this.file.contains(".yml") || file.contains(".yaml")) { @@ -59,7 +59,7 @@ public String getCurrentValue() { * @param value Integer - The config's current value. */ @Override - public void setCurrentValue(String value) { + public void setValue(String value) { if (this.file.contains(".properties")) { propFile.setProperty(this.key, value); } else if (file.contains(".yml") || file.contains(".yaml")) { @@ -85,7 +85,7 @@ public boolean willBeValid(String value) { @Override public boolean isIdeal() { if (idealValues == null) { return true; } - return idealValues.contains(this.getCurrentValue()); + return idealValues.contains(this.getValue()); } /** diff --git a/src/main/resources/profiles/FarmFriendly.kos b/src/main/resources/profiles/FarmFriendly.kos index 087ef71..da2b901 100644 --- a/src/main/resources/profiles/FarmFriendly.kos +++ b/src/main/resources/profiles/FarmFriendly.kos @@ -18,6 +18,7 @@ server: view: 8 simulation: 4 sync-chunk-writes: false + allow-flight: true # CraftBukkit Settings craftbukkit: diff --git a/src/main/resources/profiles/YouHaveTrouble.kos b/src/main/resources/profiles/YouHaveTrouble.kos index 4b80a35..1ddae81 100644 --- a/src/main/resources/profiles/YouHaveTrouble.kos +++ b/src/main/resources/profiles/YouHaveTrouble.kos @@ -19,6 +19,7 @@ server: view: 8 simulation: 4 sync-chunk-writes: false + allow-flight: true # CraftBukkit Settings craftbukkit: From 9f2be51df2c17681a383404bfe0f2a7a13c85954 Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 28 Aug 2025 19:32:09 +0100 Subject: [PATCH 08/21] Migrate. --- .../lewmc/kryptonite/config/LeafConfig.java | 95 ++++++++ .../{Minecraft.java => MinecraftConfig.java} | 20 +- .../net/lewmc/kryptonite/kos/AutoKOS.java | 4 +- .../net/lewmc/kryptonite/kos/config/Leaf.java | 120 ---------- .../kryptonite/kos/gui/KOS_ConfigItemGui.java | 64 +++-- .../lewmc/kryptonite/kos/gui/KOS_LeafGui.java | 218 ------------------ .../kryptonite/kos/gui/KOS_ManualGUI.java | 3 +- 7 files changed, 156 insertions(+), 368 deletions(-) create mode 100644 src/main/java/net/lewmc/kryptonite/config/LeafConfig.java rename src/main/java/net/lewmc/kryptonite/config/{Minecraft.java => MinecraftConfig.java} (83%) delete mode 100644 src/main/java/net/lewmc/kryptonite/kos/config/Leaf.java delete mode 100644 src/main/java/net/lewmc/kryptonite/kos/gui/KOS_LeafGui.java diff --git a/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java new file mode 100644 index 0000000..d47c382 --- /dev/null +++ b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java @@ -0,0 +1,95 @@ +package net.lewmc.kryptonite.config; + +import net.lewmc.kryptonite.Kryptonite; +import net.lewmc.kryptonite.utils.config.BooleanConfigItem; +import net.lewmc.kryptonite.utils.config.ConfigCollection; +import net.lewmc.kryptonite.utils.config.GenericConfigItem; +import net.lewmc.kryptonite.utils.config.IntegerConfigItem; + +import java.io.File; +import java.util.HashMap; +import java.util.List; + +/** + * Configuration data for leaf-global.yml + * @since 2.1.0 + */ +public class LeafConfig extends ConfigCollection { + /** + * Holds configuration data for the server.properties file. + */ + public HashMap values = new HashMap<>(); + + /** + * Constructs the server.properties data. + * @param plugin Kryptonite - Reference to the main Kryptonite class. + */ + public LeafConfig(Kryptonite plugin) { + String file = File.separator + "config" + File.separator + "leaf-global.yml"; + + values.put("async.parallel-world-tracing.enabled", new BooleanConfigItem( + file, + "async.parallel-world-tracing.enabled", + "Parallel World Tracing", + List.of( + "Parallel processing different worlds in separate", + "threads. Experimental feature, potentially unstable", + "Only use if you experience specific bottlenecks and", + "understand the risks. Learn more at leafmc.one/docs"), + false, + plugin + )); + + values.put("async.parallel-world-tracing.threads", new IntegerConfigItem( + file, + "async.parallel-world-tracing.threads", + "Parallel World Tracing Threads", + List.of("Number of threads dedicated to parallel world", + "ticking. Consider setting based on amount of worlds", + "in the server." + ), + 1, + 100, + null, + plugin + )); + + values.put("async.parallel-world-tracing.log-container-creation-stacktraces", new BooleanConfigItem( + file, + "async.parallel-world-tracing.log-container-creation-stacktraces", + "Parallel World Tracing Log Container Creation Stacktraces", + List.of( + "Log stacktraces when containers (like Tile Entities", + "or Entities) are created during parallel ticking.", + "Useful for debugging potential concurrency issues."), + false, + plugin + )); + + values.put("async.parallel-world-tracing.disable-hard-throw", new BooleanConfigItem( + file, + "async.parallel-world-tracing.disable-hard-throw", + "Parallel World Tracing Disable Hard Throw", + List.of( + "Disable hard throws (which usually stop the server)", + "related to parallel ticking errors. Might mask", + "underlying issues but could prevent crashes in", + "unstable experimental phases. Use with caution."), + false, + plugin + )); + + values.put("async.parallel-world-tracing.run-async-tasks-sync", new BooleanConfigItem( + file, + "async.parallel-world-tracing.run-async-tasks-sync", + "Parallel World Tracing Run Async Tasks Sync", + List.of( + "Run asynchronous tasks synchronously within the", + "parallel ticking system. Might be needed for", + "compatibility with certain plugins but largely", + "negates the performance benefits of parallel ticking."), + false, + plugin + )); + } +} \ No newline at end of file diff --git a/src/main/java/net/lewmc/kryptonite/config/Minecraft.java b/src/main/java/net/lewmc/kryptonite/config/MinecraftConfig.java similarity index 83% rename from src/main/java/net/lewmc/kryptonite/config/Minecraft.java rename to src/main/java/net/lewmc/kryptonite/config/MinecraftConfig.java index a27fc63..9498246 100644 --- a/src/main/java/net/lewmc/kryptonite/config/Minecraft.java +++ b/src/main/java/net/lewmc/kryptonite/config/MinecraftConfig.java @@ -12,7 +12,7 @@ * Configuration data for server.properties * @since 2.1.0 */ -public class Minecraft extends ConfigCollection { +public class MinecraftConfig extends ConfigCollection { /** * Holds configuration data for the server.properties file. */ @@ -22,7 +22,7 @@ public class Minecraft extends ConfigCollection { * Constructs the server.properties data. * @param plugin Kryptonite - Reference to the main Kryptonite class. */ - public Minecraft(Kryptonite plugin) { + public MinecraftConfig(Kryptonite plugin) { String file = "server.properties"; values.put("network-compression-threshold", new IntegerConfigItem( @@ -42,10 +42,10 @@ public Minecraft(Kryptonite plugin) { file, "view-distance", "View Distance", - List.of("The distance players can see. Using client", - "mods such a Distant Horizons or Bobby allow", - "players to see further without any", - "performance hits for the server." + List.of("The distance players can see. Using client mods", + "such as Distant Horizons or Bobby allow players", + "to see further without any performance impact", + "for the server." ), 1, 50, @@ -79,10 +79,10 @@ public Minecraft(Kryptonite plugin) { file, "allow-flight", "Allow Flight", - List.of("This prevents players from getting kicked by", - "the server for 'flying' while riding a horse", - "or climbing on scaffolding. Doesn't actually", - "allow players to fly." + List.of("This prevents players from getting kicked by the", + "server for 'flying' while riding a horse or", + "climbing on scaffolding. Doesn't actually allow", + "players to fly." ), null, plugin diff --git a/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java b/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java index 48ccc5d..d0dcab5 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java +++ b/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java @@ -2,7 +2,7 @@ import net.lewmc.foundry.Logger; import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.config.Minecraft; +import net.lewmc.kryptonite.config.MinecraftConfig; import net.lewmc.kryptonite.kos.config.*; import net.lewmc.kryptonite.utils.ConfigurationUtil; import net.lewmc.kryptonite.utils.MessageUtil; @@ -83,7 +83,7 @@ private void runVanilla() { if (this.softwareUtil.supportsMinecraft()) { this.log.info("[KOS] 1/6 - Running Vanilla optimisations"); - Minecraft m = new Minecraft(this.plugin); + MinecraftConfig m = new MinecraftConfig(this.plugin); m.values.get("network-compression-threshold").setValue(this.patches.getInt("server.network-compression-threshold")); m.values.get("simulation-distance").setValue(this.patches.getInt("server.distance.simulation")); diff --git a/src/main/java/net/lewmc/kryptonite/kos/config/Leaf.java b/src/main/java/net/lewmc/kryptonite/kos/config/Leaf.java deleted file mode 100644 index 992deeb..0000000 --- a/src/main/java/net/lewmc/kryptonite/kos/config/Leaf.java +++ /dev/null @@ -1,120 +0,0 @@ -package net.lewmc.kryptonite.kos.config; - -import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.utils.ConfigurationUtil; -import net.lewmc.kryptonite.utils.LogUtil; -import org.bukkit.command.CommandSender; - -/** - * The leaf class manages the leaf.yml configuration file. - * @deprecated - */ -@Deprecated -public class Leaf { - private final Kryptonite plugin; - private final CommandSender user; - - /** - * Constructor for the leaf class. - * @param plugin Kryptonite - Reference to the main plugin class. - * @param user CommandSender - The user who sent the command. - */ - public Leaf(Kryptonite plugin, CommandSender user) { - this.plugin = plugin; - this.user = user; - } - - /** - * Configuration values supported by this format. - */ - public enum Key { - PARALLEL_WORLD_TRACING_ENABLED { - @Override - public String toString() { return "async.parallel-world-tracing.enabled"; } - }, - PARALLEL_WORLD_TRACING_THREADS { - @Override - public String toString() { return "async.parallel-world-tracing.threads"; } - }, - PARALLEL_WORLD_TRACING_LOG_CONTAINER_CREATION_STACKTRACES { - @Override - public String toString() { return "async.parallel-world-tracing.log-container-creation-stacktraces"; } - }, - PARALLEL_WORLD_TRACING_DISABLE_HARD_THROW { - @Override - public String toString() { return "async.parallel-world-tracing.disable-hard-throw"; } - }, - PARALLEL_WORLD_TRACING_RUN_ASYNC_TASKS_SYNC { - @Override - public String toString() { return "async.parallel-world-tracing.run-async-tasks-sync"; } - } - } - - /** - * Sets a requested key to a requested value. - * @param key Key - The requested key. - * @param value int - The requested value. - */ - public void setInt(Key key, int value) { - this.plugin.restartRequired = true; - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("leaf.yml"); - cfg.set(key.toString(), value); - cfg.save(); - - LogUtil log = new LogUtil(this.plugin); - log.veboseInfo("KOS>leaf.yml set '" + key + "' to '" + value + "'"); - } - - /** - * Gets a requested key's value. - * @param key Key - The requested key. - */ - public int getInt(Key key) { - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("leaf.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(Key key, boolean value) { - this.plugin.restartRequired = true; - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("leaf.yml"); - cfg.set(key.toString(), value); - cfg.save(); - - LogUtil log = new LogUtil(this.plugin); - log.veboseInfo("KOS>leaf.yml set '" + key + "' to '" + value + "'"); - } - - /** - * Gets a requested key's value. - * @param key Key - The requested key. - */ - public boolean getBoolean(Key key) { - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("leaf.yml"); - return cfg.getBoolean(key.toString()); - } - - /** - * Sets a requested key to a requested value. - * @param key Key - The requested key. - * @param value int - The requested value. - */ - public void setString(Key key, String value) { - this.plugin.restartRequired = true; - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("leaf.yml"); - cfg.set(key.toString(), value); - cfg.save(); - - LogUtil log = new LogUtil(this.plugin); - log.veboseInfo("KOS>leaf.yml set '" + key + "' to '" + value + "'"); - } -} diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java index 697e7f8..5211639 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java @@ -4,11 +4,9 @@ import de.themoep.inventorygui.InventoryGui; import de.themoep.inventorygui.StaticGuiElement; import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.config.Minecraft; -import net.lewmc.kryptonite.utils.config.BooleanConfigItem; -import net.lewmc.kryptonite.utils.config.ConfigCollection; -import net.lewmc.kryptonite.utils.config.GenericConfigItem; -import net.lewmc.kryptonite.utils.config.IntegerConfigItem; +import net.lewmc.kryptonite.config.LeafConfig; +import net.lewmc.kryptonite.config.MinecraftConfig; +import net.lewmc.kryptonite.utils.config.*; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.CommandSender; @@ -42,7 +40,9 @@ public KOS_ConfigItemGui(Kryptonite plugin, CommandSender user, Kryptonite.Confi this.user = user; if (type == Kryptonite.ConfigurationOptions.MINECRAFT) { - this.config = new Minecraft(plugin); + this.config = new MinecraftConfig(plugin); + } else if (type == Kryptonite.ConfigurationOptions.LEAF) { + this.config = new LeafConfig(plugin); } else { this.config = null; } @@ -107,7 +107,7 @@ private ItemStack buildDisplayItem(GenericConfigItem config) { if (config.isValid()) { meta.setDisplayName(((ideal) ? ChatColor.DARK_GREEN : ChatColor.DARK_RED) + config.getName()); - lore.add(((ideal) ? ChatColor.DARK_GREEN : ChatColor.DARK_RED) + String.valueOf(config.getCurrentValue())); + lore.add(((ideal) ? ChatColor.DARK_GREEN : ChatColor.DARK_RED) + String.valueOf(config.getValue())); if (config.getDescription() != null) { lore.addAll(config.getDescription().stream() .map(line -> ((ideal) ? ChatColor.GREEN : ChatColor.RED) + line) @@ -115,7 +115,7 @@ private ItemStack buildDisplayItem(GenericConfigItem config) { } } else { meta.setDisplayName(ChatColor.DARK_GRAY + config.getName()); - lore.add(ChatColor.GRAY + String.valueOf(config.getCurrentValue())); + lore.add(ChatColor.GRAY + String.valueOf(config.getValue())); if (config.getDescription() != null) { lore.addAll(config.getDescription().stream() .map(line -> ChatColor.GRAY + line) @@ -136,19 +136,51 @@ private void handleClick(GenericConfigItem config, GuiElement.Click click) { click.getGui().close(); if (config instanceof BooleanConfigItem boolItem) { - boolItem.setCurrentValue(!boolItem.getCurrentValue()); + if (boolItem.willBeValid(!boolItem.getValue())) { + boolItem.setValue(!boolItem.getValue()); + } } else if (config instanceof IntegerConfigItem intItem) { - int current = intItem.getCurrentValue(); + int current = intItem.getValue(); if (click.getType() == ClickType.RIGHT) { - intItem.setCurrentValue(current + 1); + if (intItem.willBeValid(intItem.getValue() + 1)) { + intItem.setValue(current + 1); + } } else if (click.getType() == ClickType.SHIFT_RIGHT) { - intItem.setCurrentValue(current + 10); - } else if (click.getType() == ClickType.LEFT && current != 0) { - intItem.setCurrentValue(current - 1); - } else if (click.getType() == ClickType.SHIFT_LEFT && current >= 10) { - intItem.setCurrentValue(current - 10); + if (intItem.willBeValid(intItem.getValue() + 10)) { + intItem.setValue(current + 10); + } + } else if (click.getType() == ClickType.LEFT) { + if (intItem.willBeValid(intItem.getValue() - 1)) { + intItem.setValue(current - 1); + } + } else if (click.getType() == ClickType.SHIFT_LEFT) { + if (intItem.willBeValid(intItem.getValue() - 10)) { + intItem.setValue(current - 10); + } } + } else if (config instanceof DoubleConfigItem doubleItem) { + Double current = doubleItem.getValue(); + if (click.getType() == ClickType.RIGHT) { + if (doubleItem.willBeValid(doubleItem.getValue() + 1.0)) { + doubleItem.setValue(current + 1.0); + } + } else if (click.getType() == ClickType.SHIFT_RIGHT) { + if (doubleItem.willBeValid(doubleItem.getValue() + 10.0)) { + doubleItem.setValue(current + 10.0); + } + } else if (click.getType() == ClickType.LEFT) { + if (doubleItem.willBeValid(doubleItem.getValue() - 1.0)) { + doubleItem.setValue(current - 1.0); + } + } else if (click.getType() == ClickType.SHIFT_LEFT) { + if (doubleItem.willBeValid(doubleItem.getValue() - 10.0)) { + doubleItem.setValue(current - 10.0); + } + } + } else if (config instanceof StringConfigItem stringItem) { + // TODO: Implement strings. } + this.show(); } diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_LeafGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_LeafGui.java deleted file mode 100644 index 37bf6ac..0000000 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_LeafGui.java +++ /dev/null @@ -1,218 +0,0 @@ -package net.lewmc.kryptonite.kos.gui; - -import de.themoep.inventorygui.GuiElement; -import de.themoep.inventorygui.InventoryGui; -import de.themoep.inventorygui.StaticGuiElement; -import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.kos.config.Leaf; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; - -/** - * KOS Leaf GUI - * @deprecated - */ -@Deprecated -public class KOS_LeafGui { - private final Kryptonite plugin; - private final CommandSender user; - private InventoryGui gui; - private final Leaf leaf; - - /** - * Constructor for the KOS Pufferfish GUI - * @param plugin Kryptonite - Reference to the main plugin class. - * @param user CommandSender - The user who sent the command. - */ - public KOS_LeafGui(Kryptonite plugin, CommandSender user) { - this.plugin = plugin; - this.user = user; - - this.leaf = new Leaf(plugin, user); - } - - /** - * Shows the KOS Pufferfish GUI - */ - public void show() { - InventoryHolder holder = this.user.getServer().getPlayer(this.user.getName()); - this.gui = new InventoryGui(this.plugin, holder, "KOS - Leaf Configuration", this.getElements()); - this.addElements(); - - this.gui.build(); - this.gui.show((Player) this.user); - } - - /** - * Adds pre-programmed elements to the GUI - */ - private void addElements() { - this.parallelWorldTracingEnabled('a'); - this.parallelWorldTracingThreads('b'); - this.parallelWorldTracingLogContainerCreationStacktraces('c'); - this.parallelWorldTracingDisableHardThrow('d'); - this.parallelWorldTracingRunAsyncTasksSync('e'); - - KOS_GuiConstants consts = new KOS_GuiConstants(this.plugin, this.gui); - consts.addConstants(); - } - - /** - * Determines where the elements should be positioned. - * @return String[] - The position of the elements. - */ - private String[] getElements() { - - return new String[]{ - "abcdefghi", - " ", - " w x y " - }; - } - - private void parallelWorldTracingEnabled(char id) { - boolean value = this.leaf.getBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_ENABLED); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> { this.leaf.setBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_ENABLED, false); return true; }, - ChatColor.GOLD + "Parallel World Tracing", - ChatColor.YELLOW + "true", - ChatColor.YELLOW + "Experimental feature, potentially unsafe.", - ChatColor.YELLOW + "Potential performance gain.", - ChatColor.YELLOW + "May cause issues with some plugins.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> { this.leaf.setBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_ENABLED, true); return true; }, - ChatColor.GOLD + "Parallel World Tracing", - ChatColor.YELLOW + "false", - ChatColor.YELLOW + "Experimental feature, potentially unsafe.", - ChatColor.YELLOW + "Potential performance gain.", - ChatColor.YELLOW + "May cause issues with some plugins.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void parallelWorldTracingThreads(char id) { - int value = this.leaf.getInt(Leaf.Key.PARALLEL_WORLD_TRACING_THREADS); - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.WHITE_CONCRETE), - 1, - click -> this.setInt(Leaf.Key.PARALLEL_WORLD_TRACING_THREADS, click, value, false), - ChatColor.WHITE + "Parallel World Tracing Threads", - ChatColor.GRAY + String.valueOf(value), - ChatColor.GRAY + "Consider setting to the amount of worlds you have.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - - private void parallelWorldTracingLogContainerCreationStacktraces(char id) { - boolean value = this.leaf.getBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_LOG_CONTAINER_CREATION_STACKTRACES); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { this.leaf.setBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_LOG_CONTAINER_CREATION_STACKTRACES, false); return true; }, - ChatColor.DARK_RED + "Parallel World Tracing Log Container Creation Stacktraces", - ChatColor.RED + "true", - ChatColor.RED + "Useful for debugging concurrency issues.", - ChatColor.RED + "May cause console spam.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> { this.leaf.setBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_LOG_CONTAINER_CREATION_STACKTRACES, true); return true; }, - ChatColor.DARK_GREEN + "Parallel World Tracing Log Container Creation Stacktraces", - ChatColor.GREEN + "false", - ChatColor.GREEN + "Useful for debugging concurrency issues.", - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void parallelWorldTracingDisableHardThrow(char id) { - boolean value = this.leaf.getBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_DISABLE_HARD_THROW); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { this.leaf.setBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_DISABLE_HARD_THROW, false); return true; }, - ChatColor.DARK_RED + "Parallel World Tracing Disable Hard Throw", - ChatColor.RED + "true", - ChatColor.RED + "Could prevent crashes in unstable experimental phases.", - ChatColor.RED + "Use with caution.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> { this.leaf.setBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_DISABLE_HARD_THROW, true); return true; }, - ChatColor.DARK_GREEN + "Parallel World Tracing Disable Hard Throw", - ChatColor.GREEN + "false", - ChatColor.GREEN + "Could prevent crashes in unstable experimental phases.", - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void parallelWorldTracingRunAsyncTasksSync(char id) { - boolean value = this.leaf.getBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_RUN_ASYNC_TASKS_SYNC); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { this.leaf.setBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_RUN_ASYNC_TASKS_SYNC, false); return true; }, - ChatColor.DARK_RED + "Parallel World Tracing Disable Hard Throw", - ChatColor.RED + "true", - ChatColor.RED + "Might be needed for compatibility with certain plugins.", - ChatColor.RED + "Impact to performance.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> { this.leaf.setBoolean(Leaf.Key.PARALLEL_WORLD_TRACING_RUN_ASYNC_TASKS_SYNC, true); return true; }, - ChatColor.DARK_GREEN + "Parallel World Tracing Disable Hard Throw", - ChatColor.GREEN + "false", - ChatColor.GREEN + "Might be needed for compatibility with certain plugins.", - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private boolean setInt(Leaf.Key key, GuiElement.Click click, int value, boolean canBeDefault) { - click.getGui().close(); - if (click.getType() == ClickType.RIGHT) { - this.leaf.setInt(key, value + 1); - } else if (click.getType() == ClickType.SHIFT_RIGHT) { - this.leaf.setInt(key, value + 10); - } else if (click.getType() == ClickType.LEFT && value != 0) { - this.leaf.setInt(key, value - 1); - } else if (click.getType() == ClickType.SHIFT_LEFT && value >= 10) { - this.leaf.setInt(key, value - 10); - } else if ((click.getType() == ClickType.LEFT || click.getType() == ClickType.SHIFT_LEFT) && value == 0 && canBeDefault) { - this.leaf.setString(key, "default"); - } - - this.show(); - return true; - } -} diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java index a6bcd14..1ef23ea 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java @@ -217,8 +217,7 @@ private void addElements() { 1, click -> { click.getGui().close(); - KOS_LeafGui leafGui = new KOS_LeafGui(this.plugin, this.user); - leafGui.show(); + new KOS_ConfigItemGui(this.plugin, this.user, Kryptonite.ConfigurationOptions.LEAF).show(); return true; }, ChatColor.BLUE + "Leaf", From 24da7a1235d7a8d66f4a4530eba40d9e4dba88e4 Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 28 Aug 2025 19:40:40 +0100 Subject: [PATCH 09/21] Add async-entity-tracker, async-target-finding, async-playerdata-save (#55) --- .../lewmc/kryptonite/config/LeafConfig.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java index d47c382..98235ac 100644 --- a/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java +++ b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java @@ -91,5 +91,100 @@ public LeafConfig(Kryptonite plugin) { false, plugin )); + + values.put("async.async-entity-tracker.enabled", new BooleanConfigItem( + file, + "async.async-entity-tracker.enabled", + "Async Entity Tracker Enabled", + List.of( + "Make entity tracking asynchronous, can improve", + "performance significantly, especially in situations", + "with massive numbers of entities in a small area." + + "If using NPC plugins, enable compat-mode as well."), + true, + plugin + )); + + values.put("async.async-entity-tracker.compat-mode", new BooleanConfigItem( + file, + "async.async-entity-tracker.compat-mode", + "Async Entity Tracker Compat Mode", + List.of( + "Enable compatibility mode for plugins like", + "Citizens or other NPC plugins that use real, player", + "type entities. You should enable compat-mode ONLY IF", + "you have installed Citizens or similar real-entity", + "NPC plugins and are experiencing issues."), + null, + plugin + )); + + values.put("async.async-entity-tracker.max-threads", new IntegerConfigItem( + file, + "async.async-entity-tracker.max-threads", + "Async Entity Tracker Max Threads", + List.of("Maximum number of threads for the async entity", + "tracker to use. When set to 0, 1/4 of available CPU", + "cores are used. Recommended to set to 1/2 of cores,", + "depending on server load and core count." + ), + 0, + 100, + null, + plugin + )); + + values.put("async.async-entity-tracker.keepalive", new IntegerConfigItem( + file, + "async.async-entity-tracker.keepalive", + "Async Entity Tracker Keepalive", + List.of("Thread keepalive time. Threads with no tasks will", + "be terminated if they remain idle for longer than", + "this duration. Measured in seconds."), + 1, + 120, + "50-70", + plugin + )); + + values.put("async.async-entity-tracker.queue-size", new IntegerConfigItem( + file, + "async.async-entity-tracker.queue-size", + "Async Entity Tracker Queue Size", + List.of("Maximum size of the queue for pending entity", + "tracking tasks. If set to 0, the queue size is", + "dynamically calculated as max-threads * 384. A limit", + "might prevent excessive memory usage under extreme", + "load but could potentially lead to tasks being", + "dropped or delayed"), + 0, + 500, + null, + plugin + )); + + values.put("async.async-target-finding", new BooleanConfigItem( + file, + "async.async-target-finding", + "Async Target Finding", + List.of( + "Moves the expensive entity target search", + "calculations (finding nearby entities to attack or", + "interact with) to a background thread"), + true, + plugin + )); + + values.put("async.async-playerdata-save", new BooleanConfigItem( + file, + "async.async-playerdata-save", + "Async Playerdata Save", + List.of( + "Make playerdata saving aynchronous. Warning: might", + "cause data loss in some circumstances - use with", + "extreme caution and ensure robust backups!"), + false, + plugin + )); } } \ No newline at end of file From f8089e1be2d7144cddce2ca1780eb8baf8bf7522 Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 28 Aug 2025 19:48:02 +0100 Subject: [PATCH 10/21] Un-deprecate --- .../java/net/lewmc/kryptonite/kos/gui/KOS_PregeneratedGUI.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PregeneratedGUI.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PregeneratedGUI.java index 7811e9a..9929b8c 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PregeneratedGUI.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PregeneratedGUI.java @@ -15,9 +15,7 @@ /** * KOS Auto GUI - * @deprecated */ -@Deprecated public class KOS_PregeneratedGUI { private final Kryptonite plugin; private final CommandSender user; From 82146ff2f700bc26e2ba5c69bad1e5066781e9e1 Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 28 Aug 2025 20:48:33 +0100 Subject: [PATCH 11/21] Update bits n bobs --- .../lewmc/kryptonite/config/LeafConfig.java | 27 +++++++++++++++++-- .../kryptonite/config/MinecraftConfig.java | 5 ++++ .../kryptonite/kos/gui/KOS_ConfigItemGui.java | 14 +++++++--- .../utils/config/BooleanConfigItem.java | 7 ++--- .../utils/config/DoubleConfigItem.java | 7 ++--- .../utils/config/GenericConfigItem.java | 18 +++++++++++-- .../utils/config/IntegerConfigItem.java | 7 ++--- .../utils/config/StringConfigItem.java | 8 +++--- 8 files changed, 74 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java index 98235ac..e296585 100644 --- a/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java +++ b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java @@ -25,7 +25,7 @@ public class LeafConfig extends ConfigCollection { * @param plugin Kryptonite - Reference to the main Kryptonite class. */ public LeafConfig(Kryptonite plugin) { - String file = File.separator + "config" + File.separator + "leaf-global.yml"; + String file = "config" + File.separator + "leaf-global.yml"; values.put("async.parallel-world-tracing.enabled", new BooleanConfigItem( file, @@ -36,6 +36,7 @@ public LeafConfig(Kryptonite plugin) { "threads. Experimental feature, potentially unstable", "Only use if you experience specific bottlenecks and", "understand the risks. Learn more at leafmc.one/docs"), + true, false, plugin )); @@ -48,6 +49,7 @@ public LeafConfig(Kryptonite plugin) { "ticking. Consider setting based on amount of worlds", "in the server." ), + (Boolean) values.get("async.parallel-world-tracing.enabled").getValue(), 1, 100, null, @@ -62,6 +64,7 @@ public LeafConfig(Kryptonite plugin) { "Log stacktraces when containers (like Tile Entities", "or Entities) are created during parallel ticking.", "Useful for debugging potential concurrency issues."), + (Boolean) values.get("async.parallel-world-tracing.enabled").getValue(), false, plugin )); @@ -75,6 +78,7 @@ public LeafConfig(Kryptonite plugin) { "related to parallel ticking errors. Might mask", "underlying issues but could prevent crashes in", "unstable experimental phases. Use with caution."), + (Boolean) values.get("async.parallel-world-tracing.enabled").getValue(), false, plugin )); @@ -88,6 +92,7 @@ public LeafConfig(Kryptonite plugin) { "parallel ticking system. Might be needed for", "compatibility with certain plugins but largely", "negates the performance benefits of parallel ticking."), + (Boolean) values.get("async.parallel-world-tracing.enabled").getValue(), false, plugin )); @@ -95,13 +100,14 @@ public LeafConfig(Kryptonite plugin) { values.put("async.async-entity-tracker.enabled", new BooleanConfigItem( file, "async.async-entity-tracker.enabled", - "Async Entity Tracker Enabled", + "Async Entity Tracker", List.of( "Make entity tracking asynchronous, can improve", "performance significantly, especially in situations", "with massive numbers of entities in a small area." + "If using NPC plugins, enable compat-mode as well."), true, + true, plugin )); @@ -115,6 +121,7 @@ public LeafConfig(Kryptonite plugin) { "type entities. You should enable compat-mode ONLY IF", "you have installed Citizens or similar real-entity", "NPC plugins and are experiencing issues."), + (Boolean) values.get("async.async-entity-tracker.enabled").getValue(), null, plugin )); @@ -128,6 +135,7 @@ public LeafConfig(Kryptonite plugin) { "cores are used. Recommended to set to 1/2 of cores,", "depending on server load and core count." ), + (Boolean) values.get("async.async-entity-tracker.enabled").getValue(), 0, 100, null, @@ -141,6 +149,7 @@ public LeafConfig(Kryptonite plugin) { List.of("Thread keepalive time. Threads with no tasks will", "be terminated if they remain idle for longer than", "this duration. Measured in seconds."), + (Boolean) values.get("async.async-entity-tracker.enabled").getValue(), 1, 120, "50-70", @@ -157,6 +166,7 @@ public LeafConfig(Kryptonite plugin) { "might prevent excessive memory usage under extreme", "load but could potentially lead to tasks being", "dropped or delayed"), + (Boolean) values.get("async.async-entity-tracker.enabled").getValue(), 0, 500, null, @@ -172,6 +182,7 @@ public LeafConfig(Kryptonite plugin) { "calculations (finding nearby entities to attack or", "interact with) to a background thread"), true, + true, plugin )); @@ -184,6 +195,18 @@ public LeafConfig(Kryptonite plugin) { "cause data loss in some circumstances - use with", "extreme caution and ensure robust backups!"), false, + true, + plugin + )); + + values.put("async.async-pathfinding.enabled", new BooleanConfigItem( + file, + "async.async-pathfinding.enabled", + "Async Pathfinding", + List.of( + "Make mob pathfinding calculations asynchronous."), + true, + true, plugin )); } diff --git a/src/main/java/net/lewmc/kryptonite/config/MinecraftConfig.java b/src/main/java/net/lewmc/kryptonite/config/MinecraftConfig.java index 9498246..4821ae9 100644 --- a/src/main/java/net/lewmc/kryptonite/config/MinecraftConfig.java +++ b/src/main/java/net/lewmc/kryptonite/config/MinecraftConfig.java @@ -32,6 +32,7 @@ public MinecraftConfig(Kryptonite plugin) { List.of( "The cap for the size of a packet before the", "server attempts to compress it."), + true, -1, 1000, "256", @@ -47,6 +48,7 @@ public MinecraftConfig(Kryptonite plugin) { "to see further without any performance impact", "for the server." ), + true, 1, 50, "5 - 10", @@ -58,6 +60,7 @@ public MinecraftConfig(Kryptonite plugin) { "simulation-distance", "Simulation Distance", List.of("The distance mobs will be simulated."), + true, 1, 50, "5 - "+values.get("view-distance").getValue(), @@ -71,6 +74,7 @@ public MinecraftConfig(Kryptonite plugin) { List.of("Forces the server to write chunks on the main", "thread which impacts performance." ), + true, false, plugin )); @@ -84,6 +88,7 @@ public MinecraftConfig(Kryptonite plugin) { "climbing on scaffolding. Doesn't actually allow", "players to fly." ), + true, null, plugin )); diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java index 5211639..8922f65 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java @@ -92,6 +92,7 @@ private void addElements() { private ItemStack buildDisplayItem(GenericConfigItem config) { boolean ideal = config.isIdeal(); + boolean dependencyIsEnabled = config.dependencyIsEnabled(); Material material; @@ -105,6 +106,7 @@ private ItemStack buildDisplayItem(GenericConfigItem config) { ItemMeta meta = item.getItemMeta(); List lore = new ArrayList<>(); + String idealValue = config.getIdealValue(); if (config.isValid()) { meta.setDisplayName(((ideal) ? ChatColor.DARK_GREEN : ChatColor.DARK_RED) + config.getName()); lore.add(((ideal) ? ChatColor.DARK_GREEN : ChatColor.DARK_RED) + String.valueOf(config.getValue())); @@ -113,6 +115,7 @@ private ItemStack buildDisplayItem(GenericConfigItem config) { .map(line -> ((ideal) ? ChatColor.GREEN : ChatColor.RED) + line) .toList()); } + lore.add(ChatColor.WHITE + "Ideal value: " + ((idealValue != null) ? idealValue : "Any")); } else { meta.setDisplayName(ChatColor.DARK_GRAY + config.getName()); lore.add(ChatColor.GRAY + String.valueOf(config.getValue())); @@ -121,11 +124,16 @@ private ItemStack buildDisplayItem(GenericConfigItem config) { .map(line -> ChatColor.GRAY + line) .toList()); } + if (!config.dependencyIsEnabled()) { + lore.add(ChatColor.WHITE + "This feature requires another feature that"); + lore.add(ChatColor.WHITE + "is currently disabled. Please enable it to"); + lore.add(ChatColor.WHITE + "setup this item."); + } else { + lore.add(ChatColor.WHITE + "Invalid value."); + lore.add(ChatColor.WHITE + "Ideal value: " + ((idealValue != null) ? idealValue : "Any")); + } } - String idealValue = config.getIdealValue(); - lore.add(ChatColor.WHITE + "Ideal value: " + ((idealValue != null) ? idealValue : "Any")); - meta.setLore(lore); item.setItemMeta(meta); diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java index 3f164d5..f38139e 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java @@ -23,11 +23,12 @@ public class BooleanConfigItem extends GenericConfigItem { * @param key String - The key of the config item within the file. * @param name String - The config item's human-readable name. * @param description List of Strings - The config item's description, for the GUI each String is a new line. + * @param dependencyIsEnabled Boolean - If the config's dependencies are enabled. If none, set to true. * @param idealValue Boolean - String list of ideal values. * @param plugin Kryptonite - Reference to the main Kryptonite class. */ - public BooleanConfigItem(String file, String key, String name, List description, Boolean idealValue, Kryptonite plugin) { - super(file, key, name, description, plugin); + public BooleanConfigItem(String file, String key, String name, List description, Boolean dependencyIsEnabled, Boolean idealValue, Kryptonite plugin) { + super(file, key, name, description, dependencyIsEnabled, plugin); this.idealValue = idealValue; } @@ -74,7 +75,7 @@ public void setValue(Boolean value) { */ @Override public boolean willBeValid(Boolean value) { - return true; + return !this.dependencyIsEnabled; } /** diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java index f51424a..5c39ba0 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java @@ -31,13 +31,14 @@ public class DoubleConfigItem extends GenericConfigItem { * @param key String - The key of the config item within the file. * @param name String - The config item's human-readable name. * @param description List of Strings - The config item's description, for the GUI each String is a new line. + * @param dependencyIsEnabled Boolean - If the config's dependencies are enabled. If none, set to true. * @param minValue Double - The minimum allowed value. * @param maxValue Double - The maximum allowed value. * @param idealValue String - The ideal value in String format (e.g. "7" or "1-5" meaning 1 to 5) * @param plugin Kryptonite - Reference to the main Kryptonite class. */ - public DoubleConfigItem(String file, String key, String name, List description, Double minValue, Double maxValue, String idealValue, Kryptonite plugin) { - super(file, key, name, description, plugin); + public DoubleConfigItem(String file, String key, String name, List description, Boolean dependencyIsEnabled, Double minValue, Double maxValue, String idealValue, Kryptonite plugin) { + super(file, key, name, description, dependencyIsEnabled, plugin); this.minValue = minValue; this.maxValue = maxValue; this.idealValue = idealValue; @@ -90,7 +91,7 @@ public void setValue(Double value) { */ @Override public boolean willBeValid(Double value) { - return value >= minValue && value <= maxValue; + return dependencyIsEnabled && (value >= minValue && value <= maxValue); } /** diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java index eda48d5..d38dc62 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java @@ -44,6 +44,11 @@ public abstract class GenericConfigItem { */ protected List description; + /** + * If the config's dependencies are enabled. If none, set to true + */ + protected Boolean dependencyIsEnabled; + /** * Reference to the main Kryptonite class */ @@ -55,13 +60,15 @@ public abstract class GenericConfigItem { * @param key String - The key of the config item within the file. * @param name String - The config item's human-readable name. * @param description List of Strings - The config item's description, for the GUI each String is a new line. + * @param dependencyIsEnabled Boolean - If the config's dependencies are enabled. If none, set to true. * @param plugin Kryptonite - Reference to the main Kryptonite class. */ - public GenericConfigItem(String file, String key, String name, List description, Kryptonite plugin) { + public GenericConfigItem(String file, String key, String name, List description, Boolean dependencyIsEnabled, Kryptonite plugin) { this.file = plugin.getServer().getWorldContainer() + File.separator + file; this.key = key; this.name = name; this.description = description; + this.dependencyIsEnabled = dependencyIsEnabled; this.plugin = plugin; if (file.contains(".properties")) { @@ -73,7 +80,6 @@ public GenericConfigItem(String file, String key, String name, List desc new Logger(plugin.foundryConfig).severe("Unable to load file '"+file+"' file extension not supported."); new Logger(plugin.foundryConfig).severe("Expect additional errors."); } - } /** @@ -129,4 +135,12 @@ public String getName() { public List getDescription() { return this.description; } + + /** + * Returns if the value's dependencies are enabled. + * @return boolean - Are they? + */ + public Boolean dependencyIsEnabled() { + return this.dependencyIsEnabled; + } } \ No newline at end of file diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java index a4dad3f..172eac0 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java @@ -31,13 +31,14 @@ public class IntegerConfigItem extends GenericConfigItem { * @param key String - The key of the config item within the file. * @param name String - The config item's human-readable name. * @param description List of Strings - The config item's description, for the GUI each String is a new line. + * @param dependencyIsEnabled Boolean - If the config's dependencies are enabled. If none, set to true. * @param minValue int - The minimum allowed value. * @param maxValue int - The maximum allowed value. * @param idealValue String - The ideal value in String format (e.g. "7" or "1-5" meaning 1 to 5) * @param plugin Kryptonite - Reference to the main Kryptonite class. */ - public IntegerConfigItem(String file, String key, String name, List description, int minValue, int maxValue, String idealValue, Kryptonite plugin) { - super(file, key, name, description, plugin); + public IntegerConfigItem(String file, String key, String name, List description, Boolean dependencyIsEnabled, int minValue, int maxValue, String idealValue, Kryptonite plugin) { + super(file, key, name, description, dependencyIsEnabled, plugin); this.minValue = minValue; this.maxValue = maxValue; this.idealValue = idealValue; @@ -90,7 +91,7 @@ public void setValue(Integer value) { */ @Override public boolean willBeValid(Integer value) { - return value >= minValue && value <= maxValue; + return dependencyIsEnabled && (value >= minValue && value <= maxValue); } /** diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java index 5d4c9dd..eb0d4fa 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java @@ -26,12 +26,13 @@ public class StringConfigItem extends GenericConfigItem { * @param key String - The key of the config item within the file. * @param name String - The config item's human-readable name. * @param description List of Strings - The config item's description, for the GUI each String is a new line. + * @param dependencyIsEnabled Boolean - If the config's dependencies are enabled. If none, set to true. * @param allowedValues List of Strings - String list of allowed values. * @param idealValues List of Strings - String list of ideal values. * @param plugin Kryptonite - Reference to the main Kryptonite class. */ - public StringConfigItem(String file, String key, String name, List description, List allowedValues, List idealValues, Kryptonite plugin) { - super(file, key, name, description, plugin); + public StringConfigItem(String file, String key, String name, List description, Boolean dependencyIsEnabled, List allowedValues, List idealValues, Kryptonite plugin) { + super(file, key, name, description, dependencyIsEnabled, plugin); this.allowedValues = allowedValues; this.idealValues = idealValues; } @@ -75,7 +76,8 @@ public void setValue(String value) { */ @Override public boolean willBeValid(String value) { - return this.allowedValues.contains(value); + return dependencyIsEnabled && this.allowedValues.contains(value); + } /** From 55427c2721641998908ba976b1d8147d6e56ea47 Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 28 Aug 2025 22:49:02 +0100 Subject: [PATCH 12/21] General fixes for #55 --- pom.xml | 2 +- .../lewmc/kryptonite/config/LeafConfig.java | 65 +++++++++---------- .../kryptonite/kos/gui/KOS_ConfigItemGui.java | 2 +- .../utils/config/BooleanConfigItem.java | 16 ++--- .../utils/config/ConfigCollection.java | 2 +- .../utils/config/DoubleConfigItem.java | 2 + .../utils/config/GenericConfigItem.java | 11 +++- .../utils/config/IntegerConfigItem.java | 4 +- .../utils/config/StringConfigItem.java | 2 + 9 files changed, 53 insertions(+), 53 deletions(-) diff --git a/pom.xml b/pom.xml index b4c13e1..fe73615 100644 --- a/pom.xml +++ b/pom.xml @@ -127,7 +127,7 @@ net.lewmc foundry - 1.2.0 + 1.3.0-SNAPSHOT compile diff --git a/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java index e296585..af2ac2a 100644 --- a/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java +++ b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java @@ -3,11 +3,9 @@ import net.lewmc.kryptonite.Kryptonite; import net.lewmc.kryptonite.utils.config.BooleanConfigItem; import net.lewmc.kryptonite.utils.config.ConfigCollection; -import net.lewmc.kryptonite.utils.config.GenericConfigItem; import net.lewmc.kryptonite.utils.config.IntegerConfigItem; import java.io.File; -import java.util.HashMap; import java.util.List; /** @@ -15,11 +13,6 @@ * @since 2.1.0 */ public class LeafConfig extends ConfigCollection { - /** - * Holds configuration data for the server.properties file. - */ - public HashMap values = new HashMap<>(); - /** * Constructs the server.properties data. * @param plugin Kryptonite - Reference to the main Kryptonite class. @@ -27,9 +20,9 @@ public class LeafConfig extends ConfigCollection { public LeafConfig(Kryptonite plugin) { String file = "config" + File.separator + "leaf-global.yml"; - values.put("async.parallel-world-tracing.enabled", new BooleanConfigItem( + values.put("async.parallel-world-ticking.enabled", new BooleanConfigItem( file, - "async.parallel-world-tracing.enabled", + "async.parallel-world-ticking.enabled", "Parallel World Tracing", List.of( "Parallel processing different worlds in separate", @@ -41,58 +34,58 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.parallel-world-tracing.threads", new IntegerConfigItem( + values.put("async.parallel-world-ticking.threads", new IntegerConfigItem( file, - "async.parallel-world-tracing.threads", + "async.parallel-world-ticking.threads", "Parallel World Tracing Threads", List.of("Number of threads dedicated to parallel world", "ticking. Consider setting based on amount of worlds", "in the server." ), - (Boolean) values.get("async.parallel-world-tracing.enabled").getValue(), + (Boolean) values.get("async.parallel-world-ticking.enabled").getValue(), 1, 100, null, plugin )); - values.put("async.parallel-world-tracing.log-container-creation-stacktraces", new BooleanConfigItem( + values.put("async.parallel-world-ticking.log-container-creation-stacktraces", new BooleanConfigItem( file, - "async.parallel-world-tracing.log-container-creation-stacktraces", + "async.parallel-world-ticking.log-container-creation-stacktraces", "Parallel World Tracing Log Container Creation Stacktraces", List.of( "Log stacktraces when containers (like Tile Entities", "or Entities) are created during parallel ticking.", "Useful for debugging potential concurrency issues."), - (Boolean) values.get("async.parallel-world-tracing.enabled").getValue(), + (Boolean) values.get("async.parallel-world-ticking.enabled").getValue(), false, plugin )); - values.put("async.parallel-world-tracing.disable-hard-throw", new BooleanConfigItem( + values.put("async.parallel-world-ticking.disable-hard-throw", new BooleanConfigItem( file, - "async.parallel-world-tracing.disable-hard-throw", + "async.parallel-world-ticking.disable-hard-throw", "Parallel World Tracing Disable Hard Throw", List.of( "Disable hard throws (which usually stop the server)", "related to parallel ticking errors. Might mask", "underlying issues but could prevent crashes in", "unstable experimental phases. Use with caution."), - (Boolean) values.get("async.parallel-world-tracing.enabled").getValue(), + (Boolean) values.get("async.parallel-world-ticking.enabled").getValue(), false, plugin )); - values.put("async.parallel-world-tracing.run-async-tasks-sync", new BooleanConfigItem( + values.put("async.parallel-world-ticking.run-async-tasks-sync", new BooleanConfigItem( file, - "async.parallel-world-tracing.run-async-tasks-sync", + "async.parallel-world-ticking.run-async-tasks-sync", "Parallel World Tracing Run Async Tasks Sync", List.of( "Run asynchronous tasks synchronously within the", "parallel ticking system. Might be needed for", "compatibility with certain plugins but largely", "negates the performance benefits of parallel ticking."), - (Boolean) values.get("async.parallel-world-tracing.enabled").getValue(), + (Boolean) values.get("async.parallel-world-ticking.enabled").getValue(), false, plugin )); @@ -104,7 +97,7 @@ public LeafConfig(Kryptonite plugin) { List.of( "Make entity tracking asynchronous, can improve", "performance significantly, especially in situations", - "with massive numbers of entities in a small area." + + "with massive numbers of entities in a small area.", "If using NPC plugins, enable compat-mode as well."), true, true, @@ -118,9 +111,9 @@ public LeafConfig(Kryptonite plugin) { List.of( "Enable compatibility mode for plugins like", "Citizens or other NPC plugins that use real, player", - "type entities. You should enable compat-mode ONLY IF", - "you have installed Citizens or similar real-entity", - "NPC plugins and are experiencing issues."), + "type entities. You should enable compat-mode ONLY", + "IF you have installed Citizens or similar real", + "entity NPC plugins and are experiencing issues."), (Boolean) values.get("async.async-entity-tracker.enabled").getValue(), null, plugin @@ -131,9 +124,9 @@ public LeafConfig(Kryptonite plugin) { "async.async-entity-tracker.max-threads", "Async Entity Tracker Max Threads", List.of("Maximum number of threads for the async entity", - "tracker to use. When set to 0, 1/4 of available CPU", - "cores are used. Recommended to set to 1/2 of cores,", - "depending on server load and core count." + "tracker to use. When set to 0, 1/4 of available", + "CPU cores are used. Recommended to set to 1/2,", + "of cores depending on server load and core count." ), (Boolean) values.get("async.async-entity-tracker.enabled").getValue(), 0, @@ -146,9 +139,9 @@ public LeafConfig(Kryptonite plugin) { file, "async.async-entity-tracker.keepalive", "Async Entity Tracker Keepalive", - List.of("Thread keepalive time. Threads with no tasks will", - "be terminated if they remain idle for longer than", - "this duration. Measured in seconds."), + List.of("Thread keepalive time. Threads with no tasks", + "will be terminated if they remain idle for", + "this duration. Measured in seconds longer than."), (Boolean) values.get("async.async-entity-tracker.enabled").getValue(), 1, 120, @@ -162,10 +155,10 @@ public LeafConfig(Kryptonite plugin) { "Async Entity Tracker Queue Size", List.of("Maximum size of the queue for pending entity", "tracking tasks. If set to 0, the queue size is", - "dynamically calculated as max-threads * 384. A limit", - "might prevent excessive memory usage under extreme", - "load but could potentially lead to tasks being", - "dropped or delayed"), + "dynamically calculated as max-threads * 384.", + "A limit might prevent excessive memory usage", + "under extreme load but could potentially lead", + "to tasks being dropped or delayed"), (Boolean) values.get("async.async-entity-tracker.enabled").getValue(), 0, 500, @@ -194,8 +187,8 @@ public LeafConfig(Kryptonite plugin) { "Make playerdata saving aynchronous. Warning: might", "cause data loss in some circumstances - use with", "extreme caution and ensure robust backups!"), - false, true, + false, plugin )); diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java index 8922f65..ab13f2b 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java @@ -199,7 +199,7 @@ private void handleClick(GenericConfigItem config, GuiElement.Click click) { * @return String[] - The position of the elements. */ private String[] getElements() { - if (this.config != null) { + if (this.config != null && this.config.values != null) { int size = this.config.values.size(); int rows = (int) Math.ceil(size / 9.0); diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java index f38139e..2fe9087 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/BooleanConfigItem.java @@ -1,9 +1,7 @@ package net.lewmc.kryptonite.utils.config; -import net.lewmc.foundry.Files; import net.lewmc.foundry.Logger; import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.utils.PropertiesUtil; import java.util.List; @@ -39,13 +37,11 @@ public BooleanConfigItem(String file, String key, String name, List desc @Override public Boolean getValue() { if (this.file.contains(".properties")) { - PropertiesUtil p = new PropertiesUtil(this.file); - return Boolean.parseBoolean(p.getProperty(key)); + return Boolean.parseBoolean(propFile.getProperty(key)); } else if (this.file.contains(".yml") || file.contains(".yaml")) { - Files f = new Files(this.plugin.foundryConfig, this.plugin); - f.load(this.file); - boolean value = f.getBoolean(key); - f.close(); + this.loadFile(); + Boolean value = yamlFile.getBoolean(key); + yamlFile.close(); return value; } else { new Logger(this.plugin.foundryConfig).severe("Unable to load file: '"+this.file+"' extension not supported."); @@ -62,7 +58,7 @@ public void setValue(Boolean value) { if (this.file.contains(".properties")) { propFile.setProperty(this.key, String.valueOf(value)); } else if (file.contains(".yml") || file.contains(".yaml")) { - yamlFile.load(this.file); + this.loadFile(); yamlFile.set(this.key, value); yamlFile.save(); } @@ -75,7 +71,7 @@ public void setValue(Boolean value) { */ @Override public boolean willBeValid(Boolean value) { - return !this.dependencyIsEnabled; + return this.dependencyIsEnabled; } /** diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/ConfigCollection.java b/src/main/java/net/lewmc/kryptonite/utils/config/ConfigCollection.java index adac8f8..6a54957 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/ConfigCollection.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/ConfigCollection.java @@ -10,5 +10,5 @@ public abstract class ConfigCollection { /** * Holds configuration data for the relevant file. */ - public HashMap values; + public HashMap values = new HashMap<>(); } \ No newline at end of file diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java index 5c39ba0..2059fc4 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java @@ -61,6 +61,7 @@ public Double getValue() { return 0.0; } } else if (this.file.contains(".yml") || file.contains(".yaml")) { + this.loadFile(); Double value = yamlFile.getDouble(key); yamlFile.close(); return value; @@ -79,6 +80,7 @@ public void setValue(Double value) { if (this.file.contains(".properties")) { propFile.setProperty(this.key, String.valueOf(value)); } else if (file.contains(".yml") || file.contains(".yaml")) { + this.loadFile(); yamlFile.set(this.key, value); yamlFile.save(); } diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java index d38dc62..d11466f 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java @@ -64,18 +64,23 @@ public abstract class GenericConfigItem { * @param plugin Kryptonite - Reference to the main Kryptonite class. */ public GenericConfigItem(String file, String key, String name, List description, Boolean dependencyIsEnabled, Kryptonite plugin) { - this.file = plugin.getServer().getWorldContainer() + File.separator + file; + this.file = file; this.key = key; this.name = name; this.description = description; this.dependencyIsEnabled = dependencyIsEnabled; this.plugin = plugin; + } + /** + * Loads the file. + */ + public void loadFile() { if (file.contains(".properties")) { - this.propFile = new PropertiesUtil(file); + this.propFile = new PropertiesUtil(plugin.getServer().getWorldContainer() + File.separator + file); } else if (file.contains(".yaml") || file.contains(".yml")) { this.yamlFile = new Files(plugin.foundryConfig, plugin); - this.yamlFile.loadNoReformat(new File(this.file)); + this.yamlFile.loadNoReformat(new File(this.plugin.getDataFolder(),"/../../"+file).getAbsoluteFile()); } else { new Logger(plugin.foundryConfig).severe("Unable to load file '"+file+"' file extension not supported."); new Logger(plugin.foundryConfig).severe("Expect additional errors."); diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java index 172eac0..2bed188 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java @@ -61,7 +61,8 @@ public Integer getValue() { return 0; } } else if (this.file.contains(".yml") || file.contains(".yaml")) { - int value = yamlFile.getInt(key); + this.loadFile(); + Integer value = yamlFile.getInt(key); yamlFile.close(); return value; } else { @@ -79,6 +80,7 @@ public void setValue(Integer value) { if (this.file.contains(".properties")) { propFile.setProperty(this.key, String.valueOf(value)); } else if (file.contains(".yml") || file.contains(".yaml")) { + this.loadFile(); yamlFile.set(this.key, value); yamlFile.save(); } diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java index eb0d4fa..48cb1c1 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/StringConfigItem.java @@ -46,6 +46,7 @@ public String getValue() { if (this.file.contains(".properties")) { return propFile.getProperty(key); } else if (this.file.contains(".yml") || file.contains(".yaml")) { + this.loadFile(); String value = yamlFile.getString(key); yamlFile.close(); return value; @@ -64,6 +65,7 @@ public void setValue(String value) { if (this.file.contains(".properties")) { propFile.setProperty(this.key, value); } else if (file.contains(".yml") || file.contains(".yaml")) { + this.loadFile(); yamlFile.set(this.key, value); yamlFile.save(); } From 75c270d28f08f22c0dcad77f4ba24d36c83ee9f9 Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 28 Aug 2025 22:53:32 +0100 Subject: [PATCH 13/21] Remove deprecated code. --- .../kos/config/ServerProperties.java | 91 ------------------- .../kryptonite/kos/gui/KOS_PufferfishGui.java | 3 - .../kryptonite/kos/gui/KOS_SpigotGui_1.java | 4 +- 3 files changed, 2 insertions(+), 96 deletions(-) delete mode 100644 src/main/java/net/lewmc/kryptonite/kos/config/ServerProperties.java diff --git a/src/main/java/net/lewmc/kryptonite/kos/config/ServerProperties.java b/src/main/java/net/lewmc/kryptonite/kos/config/ServerProperties.java deleted file mode 100644 index 4f1f348..0000000 --- a/src/main/java/net/lewmc/kryptonite/kos/config/ServerProperties.java +++ /dev/null @@ -1,91 +0,0 @@ -package net.lewmc.kryptonite.kos.config; - -import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.utils.LogUtil; -import net.lewmc.kryptonite.utils.PropertiesUtil; - -/** - * The ServerProperties class manages the server.properties configuration file. - * @deprecated - */ -@Deprecated -public class ServerProperties { - private final PropertiesUtil util; - private final Kryptonite plugin; - - /** - * Constructor for the ServerProperties class. - * @param plugin Kryptonite - Reference to the main plugin class. - */ - public ServerProperties(Kryptonite plugin) { - this.util = new PropertiesUtil("server.properties"); - this.plugin = plugin; - } - - /** - * Configuration values supported by this format. - */ - public enum Key { - NETWORK_COMPRESSION_THRESHOLD { - @Override - public String toString() { - return "network-compression-threshold"; - } - }, - SIMULATION_DISTANCE { - @Override - public String toString() { - return "simulation-distance"; - } - }, - VIEW_DISTANCE { - @Override - public String toString() { - return "view-distance"; - } - }, - SYNC_CHUNK_WRITES { - @Override - public String toString() { - return "sync-chunk-writes"; - } - }, - ALLOW_FLIGHT { - @Override - public String toString() { - return "allow-flight"; - } - } - } - - /** - * Sets a value. - * @param key Config - A valid configuration key. - * @param value String - The value to set. - */ - public void set(Key key, String value) { - plugin.restartRequired = true; - this.util.setProperty(key.toString(), value); - - LogUtil log = new LogUtil(this.plugin); - log.veboseInfo("KOS>server.properties set '" + key + "' to '" + value + "'"); - } - - /** - * Retrieves a string from the configuration. - * @param key Config - A valid configuration key. - * @return String - The value. - */ - public String getString(Key key) { - return this.util.getProperty(key.toString()); - } - - /** - * Retrieves an integer from the configuration. - * @param key Config - A valid configuration key. - * @return int - The value. - */ - public int getInt(Key key) { - return Integer.parseInt(this.util.getProperty(key.toString())); - } -} diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PufferfishGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PufferfishGui.java index fe82e43..766be6b 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PufferfishGui.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PufferfishGui.java @@ -5,7 +5,6 @@ import de.themoep.inventorygui.StaticGuiElement; import net.lewmc.kryptonite.Kryptonite; import net.lewmc.kryptonite.kos.config.Pufferfish; -import net.lewmc.kryptonite.kos.config.ServerProperties; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.CommandSender; @@ -22,7 +21,6 @@ public class KOS_PufferfishGui { private final Kryptonite plugin; private final CommandSender user; - private final int simulationDistance; private InventoryGui gui; private Pufferfish pufferfish; @@ -34,7 +32,6 @@ public class KOS_PufferfishGui { public KOS_PufferfishGui(Kryptonite plugin, CommandSender user) { this.plugin = plugin; this.user = user; - this.simulationDistance = (new ServerProperties(plugin).getInt(ServerProperties.Key.SIMULATION_DISTANCE) -1)*16; this.pufferfish = new Pufferfish(plugin, user); } diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_1.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_1.java index 922bc1a..9675b4f 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_1.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_1.java @@ -4,7 +4,7 @@ import de.themoep.inventorygui.InventoryGui; import de.themoep.inventorygui.StaticGuiElement; import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.kos.config.ServerProperties; +import net.lewmc.kryptonite.config.MinecraftConfig; import net.lewmc.kryptonite.kos.config.Spigot; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -34,7 +34,7 @@ public class KOS_SpigotGui_1 { public KOS_SpigotGui_1(Kryptonite plugin, CommandSender user) { this.plugin = plugin; this.user = user; - this.simulationDistance = (new ServerProperties(plugin).getInt(ServerProperties.Key.SIMULATION_DISTANCE) -1)*16; + this.simulationDistance = ((int) new MinecraftConfig(plugin).values.get("simulation-distance").getValue() -1)*16; this.spigot = new Spigot(plugin, user); } From d6c9209543bfea0003902d6b9696094d8b98b80b Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Tue, 16 Sep 2025 19:01:17 +0100 Subject: [PATCH 14/21] Add more values, fix not showing up --- .../lewmc/kryptonite/config/LeafConfig.java | 89 +++++++++++++++++-- 1 file changed, 84 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java index af2ac2a..5a065c1 100644 --- a/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java +++ b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java @@ -1,11 +1,11 @@ package net.lewmc.kryptonite.config; import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.utils.config.BooleanConfigItem; -import net.lewmc.kryptonite.utils.config.ConfigCollection; -import net.lewmc.kryptonite.utils.config.IntegerConfigItem; +import net.lewmc.kryptonite.utils.config.*; import java.io.File; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; /** @@ -14,7 +14,12 @@ */ public class LeafConfig extends ConfigCollection { /** - * Constructs the server.properties data. + * Holds configuration data for the leaf-global.yml file. + */ + public HashMap values = new HashMap<>(); + + /** + * Constructs the leaf-global.yml data. * @param plugin Kryptonite - Reference to the main Kryptonite class. */ public LeafConfig(Kryptonite plugin) { @@ -141,7 +146,7 @@ public LeafConfig(Kryptonite plugin) { "Async Entity Tracker Keepalive", List.of("Thread keepalive time. Threads with no tasks", "will be terminated if they remain idle for", - "this duration. Measured in seconds longer than."), + "this duration. Measured in seconds."), (Boolean) values.get("async.async-entity-tracker.enabled").getValue(), 1, 120, @@ -202,5 +207,79 @@ public LeafConfig(Kryptonite plugin) { true, plugin )); + + values.put("async.async-pathfinding.max-threads", new IntegerConfigItem( + file, + "async.async-pathfinding.max-threads", + "Async Pathfinding Max Threads", + List.of("Maximum number of threads for async entity", + "pathfinding to use. When set to 0, 1/4 of available", + "CPU cores are used. Recommended to set to 1/3, of", + "cores depending on server load and core count." + ), + (Boolean) values.get("async.async-pathfinding.enabled").getValue(), + 0, + 100, + null, + plugin + )); + + values.put("async.async-pathfinding.keepalive", new IntegerConfigItem( + file, + "async.async-pathfinding.keepalive", + "Async Pathfinding Keepalive", + List.of("Thread keepalive time. Threads with no tasks", + "will be terminated if they remain idle for", + "this duration. Measured in seconds."), + (Boolean) values.get("async.async-pathfinding.enabled").getValue(), + 1, + 120, + "50-70", + plugin + )); + + values.put("async.async-pathfinding.queue-size", new IntegerConfigItem( + file, + "async.async-pathfinding.queue-size", + "Async Entity Tracker Queue Size", + List.of("Maximum size of the queue for pending", + "pathfinding tasks. If set to 0, the queue size", + "dynamically calculated as max-threads * 256."), + (Boolean) values.get("async.async-pathfinding.enabled").getValue(), + 0, + 500, + null, + plugin + )); + + values.put("async.async-pathfinding.reject-policy", new StringConfigItem( + file, + "async.async-pathfinding.reject-policy", + "Async Entity Tracker Queue Size", + List.of("The policy to use when the pathfinding task queue", + "is full (only relevant if queue-size is > 0) and a", + "new task is submitted"), + (Boolean) values.get("async.async-pathfinding.enabled").getValue(), + Arrays.asList("FLUSH_ALL", "CALLER_RUNS"), + List.of("CALLER_RUNS"), + plugin + )); + + values.put("async.async-mob-spawning.enabled", new BooleanConfigItem( + file, + "async.async-mob-spawning.enabled", + "Async Pathfinding", + List.of( + "Whether asynchronous mob spawning calculations should", + "be enabled. On servers with many entities, this can", + "improve performance by offloading some expensive", + "calculations required for mob spawning to other threads.", + "You must have Paper's per-player-mob-spawns config set", + "to true in paper-world-defaults.yml for this to work", + "effectively."), + true, + true, + plugin + )); } } \ No newline at end of file From c8dedd14db0bd695fcd19dd9fdf775e3ef27142c Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 20 Nov 2025 12:20:03 +0000 Subject: [PATCH 15/21] Include Metrics using maven --- .../java/net/lewmc/kryptonite/Kryptonite.java | 1 + .../java/net/lewmc/kryptonite/Metrics.java | 884 ------------------ 2 files changed, 1 insertion(+), 884 deletions(-) delete mode 100644 src/main/java/net/lewmc/kryptonite/Metrics.java diff --git a/src/main/java/net/lewmc/kryptonite/Kryptonite.java b/src/main/java/net/lewmc/kryptonite/Kryptonite.java index c22eb05..e11d4b1 100644 --- a/src/main/java/net/lewmc/kryptonite/Kryptonite.java +++ b/src/main/java/net/lewmc/kryptonite/Kryptonite.java @@ -9,6 +9,7 @@ import net.lewmc.kryptonite.event.JoinEvent; import net.lewmc.kryptonite.utils.CompatablityUtil; import net.lewmc.kryptonite.utils.UpdateUtil; +import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; diff --git a/src/main/java/net/lewmc/kryptonite/Metrics.java b/src/main/java/net/lewmc/kryptonite/Metrics.java deleted file mode 100644 index 2fcc409..0000000 --- a/src/main/java/net/lewmc/kryptonite/Metrics.java +++ /dev/null @@ -1,884 +0,0 @@ -/* - * This Metrics class was auto-generated and can be copied into your project if you are - * not using a build tool like Gradle or Maven for dependency management. - * - * IMPORTANT: You are not allowed to modify this class, except changing the package. - * - * Disallowed modifications include but are not limited to: - * - Remove the option for users to opt-out - * - Change the frequency for data submission - * - Obfuscate the code (every obfuscator should allow you to make an exception for specific files) - * - Reformat the code (if you use a linter, add an exception) - * - * Violations will result in a ban of your plugin and account from bStats. - */ -package net.lewmc.kryptonite; - -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.lang.reflect.Method; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.Callable; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.function.Supplier; -import java.util.logging.Level; -import java.util.stream.Collectors; -import java.util.zip.GZIPOutputStream; -import javax.net.ssl.HttpsURLConnection; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; -/** - * @deprecated - */ -@Deprecated -public class Metrics { - - private final Plugin plugin; - - private final MetricsBase metricsBase; - - /** - * Creates a new Metrics instance. - * - * @param plugin Your plugin instance. - * @param serviceId The id of the service. It can be found at What is my plugin id? - */ - public Metrics(JavaPlugin plugin, int serviceId) { - this.plugin = plugin; - // Get the config file - File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); - File configFile = new File(bStatsFolder, "config.yml"); - YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); - if (!config.isSet("serverUuid")) { - config.addDefault("enabled", true); - config.addDefault("serverUuid", UUID.randomUUID().toString()); - config.addDefault("logFailedRequests", false); - config.addDefault("logSentData", false); - config.addDefault("logResponseStatusText", false); - // Inform the server owners about bStats - config - .options() - .header( - "bStats (https://bStats.org) collects some basic information for plugin authors, like how\n" - + "many people use their plugin and their total player count. It's recommended to keep bStats\n" - + "enabled, but if you're not comfortable with this, you can turn this setting off. There is no\n" - + "performance penalty associated with having metrics enabled, and data sent to bStats is fully\n" - + "anonymous.") - .copyDefaults(true); - try { - config.save(configFile); - } catch (IOException ignored) { - } - } - // Load the data - boolean enabled = config.getBoolean("enabled", true); - String serverUUID = config.getString("serverUuid"); - boolean logErrors = config.getBoolean("logFailedRequests", false); - boolean logSentData = config.getBoolean("logSentData", false); - boolean logResponseStatusText = config.getBoolean("logResponseStatusText", false); - metricsBase = - new MetricsBase( - "bukkit", - serverUUID, - serviceId, - enabled, - this::appendPlatformData, - this::appendServiceData, - submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask), - plugin::isEnabled, - (message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error), - (message) -> this.plugin.getLogger().log(Level.INFO, message), - logErrors, - logSentData, - logResponseStatusText); - } - - /** Shuts down the underlying scheduler service. */ - public void shutdown() { - metricsBase.shutdown(); - } - - /** - * Adds a custom chart. - * - * @param chart The chart to add. - */ - public void addCustomChart(CustomChart chart) { - metricsBase.addCustomChart(chart); - } - - private void appendPlatformData(JsonObjectBuilder builder) { - builder.appendField("playerAmount", getPlayerAmount()); - builder.appendField("onlineMode", Bukkit.getOnlineMode() ? 1 : 0); - builder.appendField("bukkitVersion", Bukkit.getVersion()); - builder.appendField("bukkitName", Bukkit.getName()); - builder.appendField("javaVersion", System.getProperty("java.version")); - builder.appendField("osName", System.getProperty("os.name")); - builder.appendField("osArch", System.getProperty("os.arch")); - builder.appendField("osVersion", System.getProperty("os.version")); - builder.appendField("coreCount", Runtime.getRuntime().availableProcessors()); - } - - private void appendServiceData(JsonObjectBuilder builder) { - builder.appendField("pluginVersion", plugin.getDescription().getVersion()); - } - - private int getPlayerAmount() { - try { - // Around MC 1.8 the return type was changed from an array to a collection, - // This fixes java.lang.NoSuchMethodError: - // org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; - Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); - return onlinePlayersMethod.getReturnType().equals(Collection.class) - ? ((Collection) onlinePlayersMethod.invoke(Bukkit.getServer())).size() - : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length; - } catch (Exception e) { - // Just use the new method if the reflection failed - return Bukkit.getOnlinePlayers().size(); - } - } - - public static class MetricsBase { - - /** The version of the Metrics class. */ - public static final String METRICS_VERSION = "3.0.2"; - - private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s"; - - private final ScheduledExecutorService scheduler; - - private final String platform; - - private final String serverUuid; - - private final int serviceId; - - private final Consumer appendPlatformDataConsumer; - - private final Consumer appendServiceDataConsumer; - - private final Consumer submitTaskConsumer; - - private final Supplier checkServiceEnabledSupplier; - - private final BiConsumer errorLogger; - - private final Consumer infoLogger; - - private final boolean logErrors; - - private final boolean logSentData; - - private final boolean logResponseStatusText; - - private final Set customCharts = new HashSet<>(); - - private final boolean enabled; - - /** - * Creates a new MetricsBase class instance. - * - * @param platform The platform of the service. - * @param serviceId The id of the service. - * @param serverUuid The server uuid. - * @param enabled Whether or not data sending is enabled. - * @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and - * appends all platform-specific data. - * @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and - * appends all service-specific data. - * @param submitTaskConsumer A consumer that takes a runnable with the submit task. This can be - * used to delegate the data collection to a another thread to prevent errors caused by - * concurrency. Can be {@code null}. - * @param checkServiceEnabledSupplier A supplier to check if the service is still enabled. - * @param errorLogger A consumer that accepts log message and an error. - * @param infoLogger A consumer that accepts info log messages. - * @param logErrors Whether or not errors should be logged. - * @param logSentData Whether or not the sent data should be logged. - * @param logResponseStatusText Whether or not the response status text should be logged. - */ - public MetricsBase( - String platform, - String serverUuid, - int serviceId, - boolean enabled, - Consumer appendPlatformDataConsumer, - Consumer appendServiceDataConsumer, - Consumer submitTaskConsumer, - Supplier checkServiceEnabledSupplier, - BiConsumer errorLogger, - Consumer infoLogger, - boolean logErrors, - boolean logSentData, - boolean logResponseStatusText) { - ScheduledThreadPoolExecutor scheduler = - new ScheduledThreadPoolExecutor(1, task -> new Thread(task, "bStats-Metrics")); - // We want delayed tasks (non-periodic) that will execute in the future to be - // cancelled when the scheduler is shutdown. - // Otherwise, we risk preventing the server from shutting down even when - // MetricsBase#shutdown() is called - scheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); - this.scheduler = scheduler; - this.platform = platform; - this.serverUuid = serverUuid; - this.serviceId = serviceId; - this.enabled = enabled; - this.appendPlatformDataConsumer = appendPlatformDataConsumer; - this.appendServiceDataConsumer = appendServiceDataConsumer; - this.submitTaskConsumer = submitTaskConsumer; - this.checkServiceEnabledSupplier = checkServiceEnabledSupplier; - this.errorLogger = errorLogger; - this.infoLogger = infoLogger; - this.logErrors = logErrors; - this.logSentData = logSentData; - this.logResponseStatusText = logResponseStatusText; - checkRelocation(); - if (enabled) { - // WARNING: Removing the option to opt-out will get your plugin banned from - // bStats - startSubmitting(); - } - } - - public void addCustomChart(CustomChart chart) { - this.customCharts.add(chart); - } - - public void shutdown() { - scheduler.shutdown(); - } - - private void startSubmitting() { - final Runnable submitTask = - () -> { - if (!enabled || !checkServiceEnabledSupplier.get()) { - // Submitting data or service is disabled - scheduler.shutdown(); - return; - } - if (submitTaskConsumer != null) { - submitTaskConsumer.accept(this::submitData); - } else { - this.submitData(); - } - }; - // Many servers tend to restart at a fixed time at xx:00 which causes an uneven - // distribution of requests on the - // bStats backend. To circumvent this problem, we introduce some randomness into - // the initial and second delay. - // WARNING: You must not modify and part of this Metrics class, including the - // submit delay or frequency! - // WARNING: Modifying this code will get your plugin banned on bStats. Just - // don't do it! - long initialDelay = (long) (1000 * 60 * (3 + Math.random() * 3)); - long secondDelay = (long) (1000 * 60 * (Math.random() * 30)); - scheduler.schedule(submitTask, initialDelay, TimeUnit.MILLISECONDS); - scheduler.scheduleAtFixedRate( - submitTask, initialDelay + secondDelay, 1000 * 60 * 30, TimeUnit.MILLISECONDS); - } - - private void submitData() { - final JsonObjectBuilder baseJsonBuilder = new JsonObjectBuilder(); - appendPlatformDataConsumer.accept(baseJsonBuilder); - final JsonObjectBuilder serviceJsonBuilder = new JsonObjectBuilder(); - appendServiceDataConsumer.accept(serviceJsonBuilder); - JsonObjectBuilder.JsonObject[] chartData = - customCharts.stream() - .map(customChart -> customChart.getRequestJsonObject(errorLogger, logErrors)) - .filter(Objects::nonNull) - .toArray(JsonObjectBuilder.JsonObject[]::new); - serviceJsonBuilder.appendField("id", serviceId); - serviceJsonBuilder.appendField("customCharts", chartData); - baseJsonBuilder.appendField("service", serviceJsonBuilder.build()); - baseJsonBuilder.appendField("serverUUID", serverUuid); - baseJsonBuilder.appendField("metricsVersion", METRICS_VERSION); - JsonObjectBuilder.JsonObject data = baseJsonBuilder.build(); - scheduler.execute( - () -> { - try { - // Send the data - sendData(data); - } catch (Exception e) { - // Something went wrong! :( - if (logErrors) { - errorLogger.accept("Could not submit bStats metrics data", e); - } - } - }); - } - - private void sendData(JsonObjectBuilder.JsonObject data) throws Exception { - if (logSentData) { - infoLogger.accept("Sent bStats metrics data: " + data.toString()); - } - String url = String.format(REPORT_URL, platform); - HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection(); - // Compress the data to save bandwidth - byte[] compressedData = compress(data.toString()); - connection.setRequestMethod("POST"); - connection.addRequestProperty("Accept", "application/json"); - connection.addRequestProperty("Connection", "close"); - connection.addRequestProperty("Content-Encoding", "gzip"); - connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); - connection.setRequestProperty("Content-Type", "application/json"); - connection.setRequestProperty("User-Agent", "Metrics-Service/1"); - connection.setDoOutput(true); - try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { - outputStream.write(compressedData); - } - StringBuilder builder = new StringBuilder(); - try (BufferedReader bufferedReader = - new BufferedReader(new InputStreamReader(connection.getInputStream()))) { - String line; - while ((line = bufferedReader.readLine()) != null) { - builder.append(line); - } - } - if (logResponseStatusText) { - infoLogger.accept("Sent data to bStats and received response: " + builder); - } - } - - /** Checks that the class was properly relocated. */ - private void checkRelocation() { - // You can use the property to disable the check in your test environment - if (System.getProperty("bstats.relocatecheck") == null - || !System.getProperty("bstats.relocatecheck").equals("false")) { - // Maven's Relocate is clever and changes strings, too. So we have to use this - // little "trick" ... :D - final String defaultPackage = - new String(new byte[] {'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'}); - final String examplePackage = - new String(new byte[] {'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); - // We want to make sure no one just copy & pastes the example and uses the wrong - // package names - if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage) - || MetricsBase.class.getPackage().getName().startsWith(examplePackage)) { - throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); - } - } - } - - /** - * Gzips the given string. - * - * @param str The string to gzip. - * @return The gzipped string. - */ - private static byte[] compress(final String str) throws IOException { - if (str == null) { - return null; - } - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { - gzip.write(str.getBytes(StandardCharsets.UTF_8)); - } - return outputStream.toByteArray(); - } - } - - public static class SimplePie extends CustomChart { - - private final Callable callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SimplePie(String chartId, Callable callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObjectBuilder.JsonObject getChartData() throws Exception { - String value = callable.call(); - if (value == null || value.isEmpty()) { - // Null = skip the chart - return null; - } - return new JsonObjectBuilder().appendField("value", value).build(); - } - } - - public static class MultiLineChart extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public MultiLineChart(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObjectBuilder.JsonObject getChartData() throws Exception { - JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() == 0) { - // Skip this invalid - continue; - } - allSkipped = false; - valuesBuilder.appendField(entry.getKey(), entry.getValue()); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); - } - } - - public static class AdvancedPie extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public AdvancedPie(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObjectBuilder.JsonObject getChartData() throws Exception { - JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() == 0) { - // Skip this invalid - continue; - } - allSkipped = false; - valuesBuilder.appendField(entry.getKey(), entry.getValue()); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); - } - } - - public static class SimpleBarChart extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SimpleBarChart(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObjectBuilder.JsonObject getChartData() throws Exception { - JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - for (Map.Entry entry : map.entrySet()) { - valuesBuilder.appendField(entry.getKey(), new int[] {entry.getValue()}); - } - return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); - } - } - - public static class AdvancedBarChart extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public AdvancedBarChart(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObjectBuilder.JsonObject getChartData() throws Exception { - JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue().length == 0) { - // Skip this invalid - continue; - } - allSkipped = false; - valuesBuilder.appendField(entry.getKey(), entry.getValue()); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); - } - } - - public static class DrilldownPie extends CustomChart { - - private final Callable>> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public DrilldownPie(String chartId, Callable>> callable) { - super(chartId); - this.callable = callable; - } - - @Override - public JsonObjectBuilder.JsonObject getChartData() throws Exception { - JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); - Map> map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean reallyAllSkipped = true; - for (Map.Entry> entryValues : map.entrySet()) { - JsonObjectBuilder valueBuilder = new JsonObjectBuilder(); - boolean allSkipped = true; - for (Map.Entry valueEntry : map.get(entryValues.getKey()).entrySet()) { - valueBuilder.appendField(valueEntry.getKey(), valueEntry.getValue()); - allSkipped = false; - } - if (!allSkipped) { - reallyAllSkipped = false; - valuesBuilder.appendField(entryValues.getKey(), valueBuilder.build()); - } - } - if (reallyAllSkipped) { - // Null = skip the chart - return null; - } - return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); - } - } - - public abstract static class CustomChart { - - private final String chartId; - - protected CustomChart(String chartId) { - if (chartId == null) { - throw new IllegalArgumentException("chartId must not be null"); - } - this.chartId = chartId; - } - - public JsonObjectBuilder.JsonObject getRequestJsonObject( - BiConsumer errorLogger, boolean logErrors) { - JsonObjectBuilder builder = new JsonObjectBuilder(); - builder.appendField("chartId", chartId); - try { - JsonObjectBuilder.JsonObject data = getChartData(); - if (data == null) { - // If the data is null we don't send the chart. - return null; - } - builder.appendField("data", data); - } catch (Throwable t) { - if (logErrors) { - errorLogger.accept("Failed to get data for custom chart with id " + chartId, t); - } - return null; - } - return builder.build(); - } - - protected abstract JsonObjectBuilder.JsonObject getChartData() throws Exception; - } - - public static class SingleLineChart extends CustomChart { - - private final Callable callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SingleLineChart(String chartId, Callable callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObjectBuilder.JsonObject getChartData() throws Exception { - int value = callable.call(); - if (value == 0) { - // Null = skip the chart - return null; - } - return new JsonObjectBuilder().appendField("value", value).build(); - } - } - - /** - * An extremely simple JSON builder. - * - *

While this class is neither feature-rich nor the most performant one, it's sufficient enough - * for its use-case. - */ - public static class JsonObjectBuilder { - - private StringBuilder builder = new StringBuilder(); - - private boolean hasAtLeastOneField = false; - - public JsonObjectBuilder() { - builder.append("{"); - } - - /** - * Appends a null field to the JSON. - * - * @param key The key of the field. - * @return A reference to this object. - */ - public JsonObjectBuilder appendNull(String key) { - appendFieldUnescaped(key, "null"); - return this; - } - - /** - * Appends a string field to the JSON. - * - * @param key The key of the field. - * @param value The value of the field. - * @return A reference to this object. - */ - public JsonObjectBuilder appendField(String key, String value) { - if (value == null) { - throw new IllegalArgumentException("JSON value must not be null"); - } - appendFieldUnescaped(key, "\"" + escape(value) + "\""); - return this; - } - - /** - * Appends an integer field to the JSON. - * - * @param key The key of the field. - * @param value The value of the field. - * @return A reference to this object. - */ - public JsonObjectBuilder appendField(String key, int value) { - appendFieldUnescaped(key, String.valueOf(value)); - return this; - } - - /** - * Appends an object to the JSON. - * - * @param key The key of the field. - * @param object The object. - * @return A reference to this object. - */ - public JsonObjectBuilder appendField(String key, JsonObject object) { - if (object == null) { - throw new IllegalArgumentException("JSON object must not be null"); - } - appendFieldUnescaped(key, object.toString()); - return this; - } - - /** - * Appends a string array to the JSON. - * - * @param key The key of the field. - * @param values The string array. - * @return A reference to this object. - */ - public JsonObjectBuilder appendField(String key, String[] values) { - if (values == null) { - throw new IllegalArgumentException("JSON values must not be null"); - } - String escapedValues = - Arrays.stream(values) - .map(value -> "\"" + escape(value) + "\"") - .collect(Collectors.joining(",")); - appendFieldUnescaped(key, "[" + escapedValues + "]"); - return this; - } - - /** - * Appends an integer array to the JSON. - * - * @param key The key of the field. - * @param values The integer array. - * @return A reference to this object. - */ - public JsonObjectBuilder appendField(String key, int[] values) { - if (values == null) { - throw new IllegalArgumentException("JSON values must not be null"); - } - String escapedValues = - Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining(",")); - appendFieldUnescaped(key, "[" + escapedValues + "]"); - return this; - } - - /** - * Appends an object array to the JSON. - * - * @param key The key of the field. - * @param values The integer array. - * @return A reference to this object. - */ - public JsonObjectBuilder appendField(String key, JsonObject[] values) { - if (values == null) { - throw new IllegalArgumentException("JSON values must not be null"); - } - String escapedValues = - Arrays.stream(values).map(JsonObject::toString).collect(Collectors.joining(",")); - appendFieldUnescaped(key, "[" + escapedValues + "]"); - return this; - } - - /** - * Appends a field to the object. - * - * @param key The key of the field. - * @param escapedValue The escaped value of the field. - */ - private void appendFieldUnescaped(String key, String escapedValue) { - if (builder == null) { - throw new IllegalStateException("JSON has already been built"); - } - if (key == null) { - throw new IllegalArgumentException("JSON key must not be null"); - } - if (hasAtLeastOneField) { - builder.append(","); - } - builder.append("\"").append(escape(key)).append("\":").append(escapedValue); - hasAtLeastOneField = true; - } - - /** - * Builds the JSON string and invalidates this builder. - * - * @return The built JSON string. - */ - public JsonObject build() { - if (builder == null) { - throw new IllegalStateException("JSON has already been built"); - } - JsonObject object = new JsonObject(builder.append("}").toString()); - builder = null; - return object; - } - - /** - * Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt. - * - *

This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'. - * Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n"). - * - * @param value The value to escape. - * @return The escaped value. - */ - private static String escape(String value) { - final StringBuilder builder = new StringBuilder(); - for (int i = 0; i < value.length(); i++) { - char c = value.charAt(i); - if (c == '"') { - builder.append("\\\""); - } else if (c == '\\') { - builder.append("\\\\"); - } else if (c <= '\u000F') { - builder.append("\\u000").append(Integer.toHexString(c)); - } else if (c <= '\u001F') { - builder.append("\\u00").append(Integer.toHexString(c)); - } else { - builder.append(c); - } - } - return builder.toString(); - } - - /** - * A super simple representation of a JSON object. - * - *

This class only exists to make methods of the {@link JsonObjectBuilder} type-safe and not - * allow a raw string inputs for methods like {@link JsonObjectBuilder#appendField(String, - * JsonObject)}. - */ - public static class JsonObject { - - private final String value; - - private JsonObject(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } - } - } -} \ No newline at end of file From 81190cf38c642bbaa4cc9c8d9c84b5826e30e01e Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 20 Nov 2025 12:56:11 +0000 Subject: [PATCH 16/21] FIX IT! --- dependency-reduced-pom.xml | 4 +++ pom.xml | 4 +++ .../lewmc/kryptonite/config/LeafConfig.java | 8 ++---- .../kryptonite/config/MinecraftConfig.java | 6 ----- .../kryptonite/kos/gui/KOS_ConfigItemGui.java | 27 ++++++++++--------- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 1589604..0670489 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -44,6 +44,10 @@ net.lewmc.foundry net.lewmc.kryptonite.lib.foundry + + org.bstats + net.lewmc.kryptonite.lib.bstats + diff --git a/pom.xml b/pom.xml index fe73615..02ed00b 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,10 @@ net.lewmc.foundry net.lewmc.kryptonite.lib.foundry + + org.bstats + net.lewmc.kryptonite.lib.bstats + diff --git a/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java index 5a065c1..0956c18 100644 --- a/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java +++ b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java @@ -5,7 +5,6 @@ import java.io.File; import java.util.Arrays; -import java.util.HashMap; import java.util.List; /** @@ -13,11 +12,6 @@ * @since 2.1.0 */ public class LeafConfig extends ConfigCollection { - /** - * Holds configuration data for the leaf-global.yml file. - */ - public HashMap values = new HashMap<>(); - /** * Constructs the leaf-global.yml data. * @param plugin Kryptonite - Reference to the main Kryptonite class. @@ -281,5 +275,7 @@ public LeafConfig(Kryptonite plugin) { true, plugin )); + + plugin.getLogger().info("LeafConfig values size = " + values.size()); } } \ No newline at end of file diff --git a/src/main/java/net/lewmc/kryptonite/config/MinecraftConfig.java b/src/main/java/net/lewmc/kryptonite/config/MinecraftConfig.java index 4821ae9..02a56c2 100644 --- a/src/main/java/net/lewmc/kryptonite/config/MinecraftConfig.java +++ b/src/main/java/net/lewmc/kryptonite/config/MinecraftConfig.java @@ -3,7 +3,6 @@ import net.lewmc.kryptonite.Kryptonite; import net.lewmc.kryptonite.utils.config.BooleanConfigItem; import net.lewmc.kryptonite.utils.config.ConfigCollection; -import net.lewmc.kryptonite.utils.config.GenericConfigItem; import net.lewmc.kryptonite.utils.config.IntegerConfigItem; import java.util.*; @@ -13,11 +12,6 @@ * @since 2.1.0 */ public class MinecraftConfig extends ConfigCollection { - /** - * Holds configuration data for the server.properties file. - */ - public HashMap values = new HashMap<>(); - /** * Constructs the server.properties data. * @param plugin Kryptonite - Reference to the main Kryptonite class. diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java index ab13f2b..22feb91 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java @@ -12,11 +12,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -52,8 +52,7 @@ public KOS_ConfigItemGui(Kryptonite plugin, CommandSender user, Kryptonite.Confi * Shows the KOS Server Properties GUI */ public void show() { - InventoryHolder holder = this.user.getServer().getPlayer(this.user.getName()); - this.gui = new InventoryGui(this.plugin, holder, "KOS - Server Configuration", this.getElements()); + this.gui = new InventoryGui(this.plugin, (Player) this.user, "KOS - Server Configuration", this.getElements()); this.addElements(); this.gui.build(); @@ -69,6 +68,7 @@ private void addElements() { for (Map.Entry entry : this.config.values.entrySet()) { GenericConfigItem config = entry.getValue(); char id = (char) ('a' + index); + plugin.getLogger().info("Adding config element: id=" + id + " index=" + index + " name=" + config.getName()); ItemStack display = buildDisplayItem(config); @@ -91,13 +91,10 @@ private void addElements() { } private ItemStack buildDisplayItem(GenericConfigItem config) { - boolean ideal = config.isIdeal(); - boolean dependencyIsEnabled = config.dependencyIsEnabled(); - Material material; if (config.isValid()) { - material = (ideal) ? Material.LIME_CONCRETE : Material.RED_CONCRETE; + material = (config.isIdeal()) ? Material.LIME_CONCRETE : Material.RED_CONCRETE; } else { material = Material.BLACK_CONCRETE; } @@ -108,11 +105,11 @@ private ItemStack buildDisplayItem(GenericConfigItem config) { String idealValue = config.getIdealValue(); if (config.isValid()) { - meta.setDisplayName(((ideal) ? ChatColor.DARK_GREEN : ChatColor.DARK_RED) + config.getName()); - lore.add(((ideal) ? ChatColor.DARK_GREEN : ChatColor.DARK_RED) + String.valueOf(config.getValue())); + meta.setDisplayName(((config.isIdeal()) ? ChatColor.DARK_GREEN : ChatColor.DARK_RED) + config.getName()); + lore.add(((config.isIdeal()) ? ChatColor.DARK_GREEN : ChatColor.DARK_RED) + String.valueOf(config.getValue())); if (config.getDescription() != null) { lore.addAll(config.getDescription().stream() - .map(line -> ((ideal) ? ChatColor.GREEN : ChatColor.RED) + line) + .map(line -> ((config.isIdeal()) ? ChatColor.GREEN : ChatColor.RED) + line) .toList()); } lore.add(ChatColor.WHITE + "Ideal value: " + ((idealValue != null) ? idealValue : "Any")); @@ -200,8 +197,7 @@ private void handleClick(GenericConfigItem config, GuiElement.Click click) { */ private String[] getElements() { if (this.config != null && this.config.values != null) { - int size = this.config.values.size(); - int rows = (int) Math.ceil(size / 9.0); + int rows = (int) Math.ceil(this.config.values.size() / 9.0); // +1 row for the constant footer row String[] layout = new String[rows + 1]; @@ -209,7 +205,7 @@ private String[] getElements() { int index = 0; for (int r = 0; r < rows; r++) { StringBuilder row = new StringBuilder(" "); - for (int c = 0; c < 9 && index < size; c++) { + for (int c = 0; c < 9 && index < this.config.values.size(); c++) { char id = (char) ('a' + index); row.setCharAt(c, id); index++; @@ -218,9 +214,14 @@ private String[] getElements() { } layout[rows] = " t u v "; + this.plugin.getLogger().info(Arrays.toString(layout)); + for (int r = 0; r < layout.length; r++) { + plugin.getLogger().info("Layout row " + r + ": '" + layout[r] + "'"); + } return layout; } else { + this.plugin.getLogger().severe("Unable to return elements: config is null."); return new String[] {"",""," t u v "}; } } From e37cfb862fd497a4d1dec55ba224e46a723c32c4 Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 20 Nov 2025 13:09:38 +0000 Subject: [PATCH 17/21] PermissionUtil -> Foundry --- pom.xml | 2 +- .../kryptonite/commands/ExploitDBCommand.java | 5 ++--- .../kryptonite/commands/OptimiseCommand.java | 5 ++--- .../kryptonite/utils/PermissionUtil.java | 22 ------------------- 4 files changed, 5 insertions(+), 29 deletions(-) delete mode 100644 src/main/java/net/lewmc/kryptonite/utils/PermissionUtil.java diff --git a/pom.xml b/pom.xml index 02ed00b..b56e594 100644 --- a/pom.xml +++ b/pom.xml @@ -114,7 +114,7 @@ com.tchristofferson ConfigUpdater - 2.1-SNAPSHOT + 2.2 de.themoep diff --git a/src/main/java/net/lewmc/kryptonite/commands/ExploitDBCommand.java b/src/main/java/net/lewmc/kryptonite/commands/ExploitDBCommand.java index f44555b..79f0466 100644 --- a/src/main/java/net/lewmc/kryptonite/commands/ExploitDBCommand.java +++ b/src/main/java/net/lewmc/kryptonite/commands/ExploitDBCommand.java @@ -1,11 +1,11 @@ package net.lewmc.kryptonite.commands; +import net.lewmc.foundry.Permissions; import net.lewmc.kryptonite.Kryptonite; import net.lewmc.kryptonite.edb.Check; import net.lewmc.kryptonite.edb.Patch; import net.lewmc.kryptonite.edb.gui.EDB_MainGui; import net.lewmc.kryptonite.utils.MessageUtil; -import net.lewmc.kryptonite.utils.PermissionUtil; import net.lewmc.kryptonite.utils.SoftwareUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -42,9 +42,8 @@ public boolean onCommand( String[] args ) { this.message = new MessageUtil(commandSender); - PermissionUtil perm = new PermissionUtil(); - if (perm.isOperator(commandSender)) { + if (new Permissions(commandSender).isOp()) { if (args.length >= 1) { Check check = new Check(plugin, commandSender); if (Objects.equals(args[0].toLowerCase(), "check")) { diff --git a/src/main/java/net/lewmc/kryptonite/commands/OptimiseCommand.java b/src/main/java/net/lewmc/kryptonite/commands/OptimiseCommand.java index 53ae618..1df8c41 100644 --- a/src/main/java/net/lewmc/kryptonite/commands/OptimiseCommand.java +++ b/src/main/java/net/lewmc/kryptonite/commands/OptimiseCommand.java @@ -1,10 +1,10 @@ package net.lewmc.kryptonite.commands; +import net.lewmc.foundry.Permissions; import net.lewmc.kryptonite.Kryptonite; import net.lewmc.kryptonite.kos.AutoKOS; import net.lewmc.kryptonite.kos.gui.KOS_MainGui; import net.lewmc.kryptonite.utils.MessageUtil; -import net.lewmc.kryptonite.utils.PermissionUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -34,9 +34,8 @@ public OptimiseCommand(Kryptonite plugin) { @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { MessageUtil message = new MessageUtil(commandSender); - PermissionUtil perm = new PermissionUtil(); - if (perm.isOperator(commandSender)) { + if (new Permissions(commandSender).isOp()) { if (commandSender instanceof Player) { KOS_MainGui gui = new KOS_MainGui(this.plugin, commandSender); gui.show(); diff --git a/src/main/java/net/lewmc/kryptonite/utils/PermissionUtil.java b/src/main/java/net/lewmc/kryptonite/utils/PermissionUtil.java deleted file mode 100644 index 560bb80..0000000 --- a/src/main/java/net/lewmc/kryptonite/utils/PermissionUtil.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.lewmc.kryptonite.utils; - -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.Objects; - -/** - * @deprecated - */ -@Deprecated -public class PermissionUtil { - public boolean isOperator(CommandSender commandSender) { - if (commandSender instanceof Player) { - String player = commandSender.getName(); - return Objects.requireNonNull(Bukkit.getServer().getPlayer(player)).isOp(); - } else { - return true; - } - } -} From 6a3e3d2bd313a37858f65470ca1e006b712ba5e3 Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Thu, 20 Nov 2025 23:36:14 +0000 Subject: [PATCH 18/21] Update system. --- .../lewmc/kryptonite/config/BukkitConfig.java | 285 ++++++++ .../lewmc/kryptonite/config/LeafConfig.java | 5 +- .../kryptonite/config/MinecraftConfig.java | 46 +- .../kryptonite/config/PufferfishConfig.java | 161 +++++ .../lewmc/kryptonite/config/PurpurConfig.java | 187 ++++++ .../lewmc/kryptonite/config/SpigotConfig.java | 116 ++++ .../net/lewmc/kryptonite/kos/AutoKOS.java | 99 +-- .../lewmc/kryptonite/kos/config/Bukkit.java | 118 ---- .../kryptonite/kos/config/Pufferfish.java | 132 ---- .../lewmc/kryptonite/kos/config/Purpur.java | 136 ---- .../kryptonite/kos/gui/KOS_BukkitGui.java | 629 ------------------ .../kryptonite/kos/gui/KOS_ConfigItemGui.java | 25 +- .../kryptonite/kos/gui/KOS_ManualGUI.java | 15 +- .../kryptonite/kos/gui/KOS_PaperWorld_1.java | 11 + .../kryptonite/kos/gui/KOS_PaperWorld_3.java | 2 +- .../kryptonite/kos/gui/KOS_PufferfishGui.java | 388 ----------- .../kryptonite/kos/gui/KOS_PurpurGui.java | 465 ------------- .../net/lewmc/kryptonite/report/Report.java | 9 +- .../lewmc/kryptonite/utils/SoftwareUtil.java | 9 +- .../utils/config/ConfigCollection.java | 4 +- .../utils/config/GenericConfigItem.java | 4 + 21 files changed, 884 insertions(+), 1962 deletions(-) create mode 100644 src/main/java/net/lewmc/kryptonite/config/BukkitConfig.java create mode 100644 src/main/java/net/lewmc/kryptonite/config/PufferfishConfig.java create mode 100644 src/main/java/net/lewmc/kryptonite/config/PurpurConfig.java create mode 100644 src/main/java/net/lewmc/kryptonite/config/SpigotConfig.java delete mode 100644 src/main/java/net/lewmc/kryptonite/kos/config/Bukkit.java delete mode 100644 src/main/java/net/lewmc/kryptonite/kos/config/Pufferfish.java delete mode 100644 src/main/java/net/lewmc/kryptonite/kos/config/Purpur.java delete mode 100644 src/main/java/net/lewmc/kryptonite/kos/gui/KOS_BukkitGui.java delete mode 100644 src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PufferfishGui.java delete mode 100644 src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PurpurGui.java diff --git a/src/main/java/net/lewmc/kryptonite/config/BukkitConfig.java b/src/main/java/net/lewmc/kryptonite/config/BukkitConfig.java new file mode 100644 index 0000000..6b88d39 --- /dev/null +++ b/src/main/java/net/lewmc/kryptonite/config/BukkitConfig.java @@ -0,0 +1,285 @@ +package net.lewmc.kryptonite.config; + +import net.lewmc.kryptonite.Kryptonite; +import net.lewmc.kryptonite.utils.config.ConfigCollection; +import net.lewmc.kryptonite.utils.config.IntegerConfigItem; + +import java.util.List; + +/** + * Configuration data for bukkit.yml + * @since 2.1.0 + */ +public class BukkitConfig extends ConfigCollection { + /** + * Constructs the bukkit.yml data. + * @param plugin Kryptonite - Reference to the main Kryptonite class. + */ + public BukkitConfig(Kryptonite plugin) { + String file = "bukkit.yml"; + + values.put("spawn-limits.monsters", new IntegerConfigItem( + file, + "spawn-limits.monsters", + "Spawn Limit (Monsters)", + List.of( + "A limit for how many mobs should spawn in the world.", + "The server has less work to do with lower numbers,", + "but survival worlds may be less realistic."), + true, + 1, + 200, + "20-50", + plugin + )); + + values.put("spawn-limits.animals", new IntegerConfigItem( + file, + "spawn-limits.animals", + "Spawn Limit (Animals)", + List.of( + "A limit for how many animals should spawn in the", + "world. The server has less work to do with lower", + "numbers, but survival worlds may be less realistic."), + true, + 1, + 200, + "5-10", + plugin + )); + + values.put("spawn-limits.water-animals", new IntegerConfigItem( + file, + "spawn-limits.water-animals", + "Spawn Limit (Water Animals)", + List.of( + "A limit for how many water animals should spawn in", + "the world. The server has less work to do with lower", + "numbers, but survival worlds may be less realistic."), + true, + 1, + 200, + "2-5", + plugin + )); + + values.put("spawn-limits.water-ambient", new IntegerConfigItem( + file, + "spawn-limits.water-ambient", + "Spawn Limit (Water Ambient)", + List.of( + "A limit for how many water ambient should spawn in", + "the world. The server has less work to do with lower", + "numbers, but survival worlds may be less realistic."), + true, + 1, + 200, + "2-10", + plugin + )); + + values.put("spawn-limits.water-underground-creature", new IntegerConfigItem( + file, + "spawn-limits.water-underground-creature", + "Spawn Limit (Water Underground Creature)", + List.of( + "A limit for how many water underground creatures", + "should spawn in the world. The server has less work", + "to do with lower numbers, but survival worlds may be", + "less realistic."), + true, + 1, + 200, + "2-5", + plugin + )); + + values.put("spawn-limits.axolotls", new IntegerConfigItem( + file, + "spawn-limits.axolotls", + "Spawn Limit (Axolotls)", + List.of( + "A limit for how many axolotls should spawn in the", + "world. The server has less work to do with lower", + "numbers, but survival worlds may be less realistic."), + true, + 1, + 200, + "2-4", + plugin + )); + + values.put("ticks-per.monster-spawns", new IntegerConfigItem( + file, + "ticks-per.monster-spawns", + "Ticks Per Monster Spawns", + List.of( + "How often (in ticks) the server attempts to spawn", + "monsters. The server has less work to do with lower", + "numbers, but survival worlds may be less realistic."), + true, + 1, + 1000, + "5-10", + plugin + )); + + values.put("ticks-per.animal-spawns", new IntegerConfigItem( + file, + "ticks-per.animal-spawns", + "Ticks Per Animal Spawns", + List.of( + "How often (in ticks) the server attempts to spawn", + "animals. The server has less work to do with lower", + "numbers, but survival worlds may be less realistic."), + true, + 1, + 1000, + "400", + plugin + )); + + values.put("ticks-per.water-spawns", new IntegerConfigItem( + file, + "ticks-per.water-spawns", + "Ticks Per Water Spawns", + List.of( + "How often (in ticks) the server attempts to spawn", + "water creatures. The server has less work to do with", + "lower numbers, but survival worlds may be less", + "realistic."), + true, + 1, + 1000, + "400", + plugin + )); + + values.put("ticks-per.water-ambient-spawns", new IntegerConfigItem( + file, + "ticks-per.water-ambient-spawns", + "Ticks Per Water Ambient Spawns", + List.of( + "How often (in ticks) the server attempts to spawn", + "water ambient creatures. The server has less work", + "to do with lower numbers, but survival worlds may", + "be less realistic."), + true, + 1, + 1000, + "400", + plugin + )); + + values.put("ticks-per.axolotl-spawns", new IntegerConfigItem( + file, + "ticks-per.axolotl-spawns", + "Ticks Per Axolotl Spawns", + List.of( + "How often (in ticks) the server attempts to spawn", + "axolotls. The server has less work to do with lower", + "numbers, but survival worlds may be less realistic."), + true, + 1, + 1000, + "400", + plugin + )); + + values.put("ticks-per.ambient-spawns", new IntegerConfigItem( + file, + "ticks-per.ambient-spawns", + "Ticks Per Ambient Spawns", + List.of( + "How often (in ticks) the server attempts to spawn", + "ambient creatures. The server has less work to do", + "with lower numbers, but survival worlds may be less.", + "realistic"), + true, + 1, + 1000, + "400", + plugin + )); + + values.put("chunk-gc.period-in-ticks", new IntegerConfigItem( + file, + "chunk-gc.period-in-ticks", + "Chunk GC Period in Ticks", + List.of( + "The ticks between each chunk garbage collection", + "consideration."), + true, + 1, + 1000, + "400-600", + plugin + )); + } + + /** + * Configuration values supported by this format. + */ + public enum Key { + SPAWN_LIMITS_MONSTERS { + @Override + public String toString() { return "spawn-limits.monsters"; } + }, + SPAWN_LIMITS_ANIMALS { + @Override + public String toString() { return "spawn-limits.animals"; } + }, + SPAWN_LIMITS_WATER_ANIMALS { + @Override + public String toString() { return "spawn-limits.water-animals"; } + }, + SPAWN_LIMITS_WATER_AMBIENT { + @Override + public String toString() { return "spawn-limits.water-ambient"; } + }, + SPAWN_LIMITS_WATER_UNDERGROUND_CREATURE { + @Override + public String toString() { return "spawn-limits.water-underground-creature"; } + }, + SPAWN_LIMITS_AXOLOTLS { + @Override + public String toString() { return "spawn-limits.axolotls"; } + }, + SPAWN_LIMITS_AMBIENT { + @Override + public String toString() { return "spawn-limits.ambient"; } + }, + TICKS_PER_MONSTER_SPAWNS { + @Override + public String toString() { return "ticks-per.monster-spawns"; } + }, + TICKS_PER_ANIMAL_SPAWNS { + @Override + public String toString() { return "ticks-per.animal-spawns"; } + }, + TICKS_PER_WATER_SPAWNS { + @Override + public String toString() { return "ticks-per.water-spawns"; } + }, + TICKS_PER_WATER_AMBIENT_SPAWNS { + @Override + public String toString() { return "ticks-per.water-ambient-spawns"; } + }, + TICKS_PER_WATER_UNDERGROUND_CREATURE_SPAWNS { + @Override + public String toString() { return "ticks-per.water-underground-creature-spawns"; } + }, + TICKS_PER_AXOLOTL_SPAWNS { + @Override + public String toString() { return "ticks-per.axolotl-spawns"; } + }, + TICKS_PER_AMBIENT_SPAWNS { + @Override + public String toString() { return "ticks-per.ambient-spawns"; } + }, + CHUNK_GC_PERIOD_IN_TICKS { + @Override + public String toString() { return "chunk-gc.period-in-ticks"; } + } + } +} \ No newline at end of file diff --git a/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java index 0956c18..7f8f5fd 100644 --- a/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java +++ b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java @@ -4,7 +4,6 @@ import net.lewmc.kryptonite.utils.config.*; import java.io.File; -import java.util.Arrays; import java.util.List; /** @@ -254,7 +253,7 @@ public LeafConfig(Kryptonite plugin) { "is full (only relevant if queue-size is > 0) and a", "new task is submitted"), (Boolean) values.get("async.async-pathfinding.enabled").getValue(), - Arrays.asList("FLUSH_ALL", "CALLER_RUNS"), + List.of("FLUSH_ALL", "CALLER_RUNS"), List.of("CALLER_RUNS"), plugin )); @@ -275,7 +274,5 @@ public LeafConfig(Kryptonite plugin) { true, plugin )); - - plugin.getLogger().info("LeafConfig values size = " + values.size()); } } \ No newline at end of file diff --git a/src/main/java/net/lewmc/kryptonite/config/MinecraftConfig.java b/src/main/java/net/lewmc/kryptonite/config/MinecraftConfig.java index 02a56c2..f52919e 100644 --- a/src/main/java/net/lewmc/kryptonite/config/MinecraftConfig.java +++ b/src/main/java/net/lewmc/kryptonite/config/MinecraftConfig.java @@ -19,9 +19,9 @@ public class MinecraftConfig extends ConfigCollection { public MinecraftConfig(Kryptonite plugin) { String file = "server.properties"; - values.put("network-compression-threshold", new IntegerConfigItem( + values.put(Key.NETWORK_COMPRESSION_THRESHOLD.toString(), new IntegerConfigItem( file, - "network-compression-threshold", + Key.NETWORK_COMPRESSION_THRESHOLD.toString(), "Network Compression Threshold", List.of( "The cap for the size of a packet before the", @@ -33,9 +33,9 @@ public MinecraftConfig(Kryptonite plugin) { plugin )); - values.put("view-distance", new IntegerConfigItem( + values.put(Key.VIEW_DISTANCE.toString(), new IntegerConfigItem( file, - "view-distance", + Key.VIEW_DISTANCE.toString(), "View Distance", List.of("The distance players can see. Using client mods", "such as Distant Horizons or Bobby allow players", @@ -49,9 +49,9 @@ public MinecraftConfig(Kryptonite plugin) { plugin )); - values.put("simulation-distance", new IntegerConfigItem( + values.put(Key.SIMULATION_DISTANCE.toString(), new IntegerConfigItem( file, - "simulation-distance", + Key.SIMULATION_DISTANCE.toString(), "Simulation Distance", List.of("The distance mobs will be simulated."), true, @@ -61,9 +61,9 @@ public MinecraftConfig(Kryptonite plugin) { plugin )); - values.put("sync-chunk-writes", new BooleanConfigItem( + values.put(Key.SYNC_CHUNK_WRITES.toString(), new BooleanConfigItem( file, - "sync-chunk-writes", + Key.SYNC_CHUNK_WRITES.toString(), "Sync Chunk Writes", List.of("Forces the server to write chunks on the main", "thread which impacts performance." @@ -73,9 +73,9 @@ public MinecraftConfig(Kryptonite plugin) { plugin )); - values.put("allow-flight", new BooleanConfigItem( + values.put(Key.ALLOW_FLIGHT.toString(), new BooleanConfigItem( file, - "allow-flight", + Key.ALLOW_FLIGHT.toString(), "Allow Flight", List.of("This prevents players from getting kicked by the", "server for 'flying' while riding a horse or", @@ -87,4 +87,30 @@ public MinecraftConfig(Kryptonite plugin) { plugin )); } + + /** + * Configuration values supported by this format. + */ + public enum Key { + NETWORK_COMPRESSION_THRESHOLD { + @Override + public String toString() { return "network-compression-threshold";} + }, + VIEW_DISTANCE { + @Override + public String toString() { return "view-distance";} + }, + SIMULATION_DISTANCE { + @Override + public String toString() { return "simulation-distance";} + }, + SYNC_CHUNK_WRITES { + @Override + public String toString() { return "sync-chunk-writes";} + }, + ALLOW_FLIGHT { + @Override + public String toString() { return "allow-flight";} + } + } } \ No newline at end of file diff --git a/src/main/java/net/lewmc/kryptonite/config/PufferfishConfig.java b/src/main/java/net/lewmc/kryptonite/config/PufferfishConfig.java new file mode 100644 index 0000000..f2fbcd4 --- /dev/null +++ b/src/main/java/net/lewmc/kryptonite/config/PufferfishConfig.java @@ -0,0 +1,161 @@ +package net.lewmc.kryptonite.config; + +import net.lewmc.kryptonite.Kryptonite; +import net.lewmc.kryptonite.utils.config.BooleanConfigItem; +import net.lewmc.kryptonite.utils.config.ConfigCollection; +import net.lewmc.kryptonite.utils.config.IntegerConfigItem; + +import java.util.List; + +/** + * Configuration data for pufferfish.yml + * @since 2.1.0 + */ +public class PufferfishConfig extends ConfigCollection { + /** + * Constructs the pufferfish.yml data. + * @param plugin Kryptonite - Reference to the main Kryptonite class. + */ + public PufferfishConfig(Kryptonite plugin) { + String file = "pufferfish.yml"; + + values.put(Key.MAX_LOADS_PER_PROJECTILE.toString(), new IntegerConfigItem( + file, + Key.MAX_LOADS_PER_PROJECTILE.toString(), + "Max Loads per Projectile", + List.of("Specifies the maximum amount of chunks a projectile", + "can load in its lifetime. Decreasing will reduce chunk", + "loads caused by entity projectiles, but could cause", + "issues with tridents, enderpearls, etc."), + true, + 1, + 100, + "8-12", + plugin + )); + + values.put(Key.DAB_ENABLED.toString(), new BooleanConfigItem( + file, + Key.DAB_ENABLED.toString(), + "DAB Enabled", + List.of("Dynamic Activation of Brain - decreases how frequently", + "complex AI ticks. May impact mob farms, you may want to", + "consider increasing the activation-dist-mod parameter", + "or disabling DAB altogether if it is causing issues."), + true, + true, + plugin + )); + + values.put(Key.DAB_MAX_TICK_FREQ.toString(), new IntegerConfigItem( + file, + Key.DAB_MAX_TICK_FREQ.toString(), + "DAB Max Tick Frequency", + List.of("No matter what the result of the Activation Distance Modifier", + "calculation is, entities will never be ticked less frequently", + "than this often (in ticks)."), + true, + 0, + 100, + "20", + plugin + )); + + values.put(Key.DAB_ACTIVATION_DIST_MOD.toString(), new IntegerConfigItem( + file, + Key.DAB_ACTIVATION_DIST_MOD.toString(), + "DAB Activation Distance Modifier", + List.of("Controls how quickly the effects of DAB wear off with distance.", + "The default value of 8 is sufficient for most servers. Servers", + "with large amounts of villagers may benefit from decreasing", + "this value to 7, but the value should never be decreased below", + "6. If you have a small server, you may want to either increase", + "this value to 10, or simply disable DAB."), + true, + 6, + 50, + "8", + plugin + )); + + values.put(Key.ENABLE_ASYNC_MOB_SPAWNING.toString(), new BooleanConfigItem( + file, + Key.ENABLE_ASYNC_MOB_SPAWNING.toString(), + "Enable Async Mob Spawning", + List.of("Enables asynchronous mob spawning."), + true, + true, + plugin + )); + + values.put(Key.ENABLE_SUFFOCATION_OPTIMIZATION.toString(), new BooleanConfigItem( + file, + Key.ENABLE_SUFFOCATION_OPTIMIZATION.toString(), + "Enable Suffocation Optimization", + List.of("Enables suffocation optimization."), + true, + true, + plugin + )); + + values.put(Key.INACTIVE_GOAL_SELECTOR_THROTTLE.toString(), new BooleanConfigItem( + file, + Key.INACTIVE_GOAL_SELECTOR_THROTTLE.toString(), + "Inactive Goal Selector Throttle", + List.of("Improves performance. May have minor gameplay implications"), + true, + true, + plugin + )); + + values.put(Key.DISABLE_METHOD_PROFILER.toString(), new BooleanConfigItem( + file, + Key.DISABLE_METHOD_PROFILER.toString(), + "Disable Method Profiler", + List.of("Disables some additional profiling done by the game. This", + "profiling is not necessary to run in production and can cause", + "additional lag."), + true, + true, + plugin + )); + } + + /** + * Configuration values supported by this format. + */ + public enum Key { + MAX_LOADS_PER_PROJECTILE { + @Override + public String toString() { return "projectile.max-loads-per-projectile"; } + }, + DAB_ENABLED { + @Override + public String toString() { return "dab.enabled"; } + }, + DAB_MAX_TICK_FREQ { + @Override + public String toString() { return "dab.max-tick-freq"; } + }, + DAB_ACTIVATION_DIST_MOD { + @Override + public String toString() { return "dab.activation-dist-mod"; } + }, + ENABLE_ASYNC_MOB_SPAWNING { + @Override + public String toString() { return "enable-async-mob-spawning"; } + }, + ENABLE_SUFFOCATION_OPTIMIZATION { + @Override + public String toString() { return "enable-suffocation-optimization"; } + }, + INACTIVE_GOAL_SELECTOR_THROTTLE { + @Override + public String toString() { return "inactive-goal-selector-throttle"; } + }, + DISABLE_METHOD_PROFILER { + @Override + public String toString() { return "misc.disable-method-profiler"; } + } + } +} \ No newline at end of file diff --git a/src/main/java/net/lewmc/kryptonite/config/PurpurConfig.java b/src/main/java/net/lewmc/kryptonite/config/PurpurConfig.java new file mode 100644 index 0000000..862f31b --- /dev/null +++ b/src/main/java/net/lewmc/kryptonite/config/PurpurConfig.java @@ -0,0 +1,187 @@ +package net.lewmc.kryptonite.config; + +import net.lewmc.kryptonite.Kryptonite; +import net.lewmc.kryptonite.utils.config.BooleanConfigItem; +import net.lewmc.kryptonite.utils.config.ConfigCollection; +import net.lewmc.kryptonite.utils.config.IntegerConfigItem; + +import java.util.List; + +/** + * Configuration data for purpur.yml + * @since 2.1.0 + */ +public class PurpurConfig extends ConfigCollection { + /** + * Constructs the purpur.yml data. + * @param plugin Kryptonite - Reference to the main Kryptonite class. + */ + public PurpurConfig(Kryptonite plugin) { + String file = "purpur.yml"; + + values.put(Key.USE_ALTERNATE_KEEPALIVE.toString(), new BooleanConfigItem( + file, + Key.USE_ALTERNATE_KEEPALIVE.toString(), + "Use Alternate Keepalive", + List.of( + "Uses a different approach to keepalive ping timeouts.", + "Enabling this sends a keepalive packet once per", + "second to a player, and only kicks for timeout if", + "none of them were responded to in 30 seconds. Cannot", + "enable if using TCPShield."), + !plugin.getConfig().getBoolean("using-tcpshield"), + true, + plugin + )); + + values.put(Key.ZOMBIE_AGGRESSIVE_TOWARDS_VILLAGER_WHEN_LAGGING.toString(), new BooleanConfigItem( + file, + Key.ZOMBIE_AGGRESSIVE_TOWARDS_VILLAGER_WHEN_LAGGING.toString(), + "Zombie Aggressive Towards Villager when Lagging", + List.of( + "Set to false to stop zombie aggressiveness towards", + "villagers when lagging. May impact vanilla behaviour", + "when lagging, but may reduce overall lag."), + true, + true, + plugin + )); + + values.put(Key.ENTITIES_CAN_USE_PORTALS.toString(), new BooleanConfigItem( + file, + Key.ENTITIES_CAN_USE_PORTALS.toString(), + "Entities can use Portals", + List.of( + "Set to false to stop entities from being able to use", + "portals reduces lag but impacts vanilla behaviour."), + true, + false, + plugin + )); + + values.put(Key.VILLAGER_IS_LOBOTOMIZED.toString(), new BooleanConfigItem( + file, + Key.VILLAGER_IS_LOBOTOMIZED.toString(), + "Villagers Lobotomize", + List.of( + "Lobotomizes the villager if it cannot move (Does not", + "disable trading, but some trades may not refill). May", + "impact vanilla behaviour, only enable if you have done", + "ABSOLUTELY EVERYTHING ELSE to try and reduce lag. May", + "break iron golem farms."), + true, + false, + plugin + )); + + values.put(Key.VILLAGER_SEARCH_RADIUS_ACQUIRE_POI.toString(), new IntegerConfigItem( + file, + Key.VILLAGER_SEARCH_RADIUS_ACQUIRE_POI.toString(), + "Villager Search Radius (Acquire POI)", + List.of( + "Radius within which villagers search to acquire POI.", + "Below 48 may break iron golem farms."), + true, + 1, + 100, + "16-32", + plugin + )); + + values.put(Key.VILLAGER_SEARCH_RADIUS_NEAREST_BED_SENSOR.toString(), new IntegerConfigItem( + file, + Key.VILLAGER_SEARCH_RADIUS_NEAREST_BED_SENSOR.toString(), + "Villager Search Radius (Nearest Bed Sensor)", + List.of( + "Radius within which villagers search to detect the", + "nearest bed. Below 48 may break iron golem farms."), + true, + 1, + 100, + "16-32", + plugin + )); + + values.put(Key.DOLPHIN_DISABLE_TREASURE_SEARCHING.toString(), new BooleanConfigItem( + file, + Key.DOLPHIN_DISABLE_TREASURE_SEARCHING.toString(), + "Villager Search Radius (Nearest Bed Sensor)", + List.of( + "Stops the dolphin from treasure hunting. Will impact", + "vanilla behaviour."), + true, + true, + plugin + )); + + values.put(Key.TELEPORT_IF_OUTSIDE_BORDER.toString(), new BooleanConfigItem( + file, + Key.TELEPORT_IF_OUTSIDE_BORDER.toString(), + "Teleport if Outside Border", + List.of( + "Teleports you to spawn if you somehow get outside the", + "world border."), + true, + true, + plugin + )); + + values.put(Key.LAGGING_THRESHOLD.toString(), new IntegerConfigItem( + file, + Key.LAGGING_THRESHOLD.toString(), + "Lagging Threshold", + List.of( + "Purpur keeps track of when it is lagging in order to", + "have the ability to change behaviors accordingly. If", + "vanilla behaviour is being impacted too much, consider", + "reducing this. 19 is a good starting point."), + true, + 1, + 19, + "15-19", + plugin + )); + } + + /** + * Configuration values supported by this format. + */ + public enum Key { + USE_ALTERNATE_KEEPALIVE { + @Override + public String toString() { return "settings.use-alternate-keepalive"; } + }, + ZOMBIE_AGGRESSIVE_TOWARDS_VILLAGER_WHEN_LAGGING { + @Override + public String toString() { return "world-settings.default.mobs.zombie.aggressive-towards-villager-when-lagging"; } + }, + ENTITIES_CAN_USE_PORTALS { + @Override + public String toString() { return "world-settings.default.gameplay-mechanics.entities-can-use-portals"; } + }, + VILLAGER_IS_LOBOTOMIZED { + @Override + public String toString() { return "world-settings.default.mobs.villager.lobotomize.enabled"; } + }, + VILLAGER_SEARCH_RADIUS_ACQUIRE_POI { + @Override + public String toString() { return "world-settings.default.mobs.villager.search-radius.acquire-poi"; } + }, + VILLAGER_SEARCH_RADIUS_NEAREST_BED_SENSOR { + @Override + public String toString() { return "world-settings.default.mobs.villager.search-radius.nearest-bed-sensor"; } + }, + DOLPHIN_DISABLE_TREASURE_SEARCHING { + @Override + public String toString() { return "world-settings.default.mobs.dolphin.disable-treasure-searching"; } + }, + TELEPORT_IF_OUTSIDE_BORDER { + @Override + public String toString() { return "world-settings.default.gameplay-mechanics.player.teleport-if-outside-border"; } + }, + LAGGING_THRESHOLD { + @Override + public String toString() { return "settings.lagging-threshold"; } + } + } +} \ No newline at end of file diff --git a/src/main/java/net/lewmc/kryptonite/config/SpigotConfig.java b/src/main/java/net/lewmc/kryptonite/config/SpigotConfig.java new file mode 100644 index 0000000..80efed3 --- /dev/null +++ b/src/main/java/net/lewmc/kryptonite/config/SpigotConfig.java @@ -0,0 +1,116 @@ +package net.lewmc.kryptonite.config; + +import net.lewmc.kryptonite.Kryptonite; +import net.lewmc.kryptonite.utils.config.ConfigCollection; +import net.lewmc.kryptonite.utils.config.StringConfigItem; + +import java.util.List; + +/** + * Configuration data for purpur.yml + * @since 2.1.0 + */ +public class SpigotConfig extends ConfigCollection { + /** + * Constructs the purpur.yml data. + * @param plugin Kryptonite - Reference to the main Kryptonite class. + */ + public SpigotConfig(Kryptonite plugin) { + String file = "spigot.yml"; + + values.put(Key.VIEW_DISTANCE.toString(), new StringConfigItem( + file, + Key.VIEW_DISTANCE.toString(), + "View Distance", + List.of( + "The distance the server will send to the client.", + "Recommended value: 'default' (click to zero)"), + true, + List.of("default","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32"), + List.of("default"), + plugin + )); + } + + /** + * 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"; } + }, + ENTITY_TRACKING_RANGE_DISPLAY { + @Override + public String toString() { return "world-settings.default.entity-tracking-range.display"; } + }, + 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"; } + }, + 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"; } + } + } +} \ No newline at end of file diff --git a/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java b/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java index d0dcab5..7675acf 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java +++ b/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java @@ -2,11 +2,16 @@ import net.lewmc.foundry.Logger; import net.lewmc.kryptonite.Kryptonite; +import net.lewmc.kryptonite.config.BukkitConfig; import net.lewmc.kryptonite.config.MinecraftConfig; +import net.lewmc.kryptonite.config.PufferfishConfig; +import net.lewmc.kryptonite.config.PurpurConfig; import net.lewmc.kryptonite.kos.config.*; import net.lewmc.kryptonite.utils.ConfigurationUtil; import net.lewmc.kryptonite.utils.MessageUtil; import net.lewmc.kryptonite.utils.SoftwareUtil; +import net.lewmc.kryptonite.utils.config.BooleanConfigItem; +import net.lewmc.kryptonite.utils.config.IntegerConfigItem; import org.bukkit.command.CommandSender; import java.io.File; @@ -85,11 +90,11 @@ private void runVanilla() { MinecraftConfig m = new MinecraftConfig(this.plugin); - m.values.get("network-compression-threshold").setValue(this.patches.getInt("server.network-compression-threshold")); - m.values.get("simulation-distance").setValue(this.patches.getInt("server.distance.simulation")); - m.values.get("view-distance").setValue(this.patches.getInt("server.distance.view")); - m.values.get("sync-chunk-writes").setValue(this.patches.getBoolean("server.sync-chunk-writes")); - m.values.get("allow-flight").setValue(this.patches.getBoolean("server.allow-flight")); + ((IntegerConfigItem)m.values.get(MinecraftConfig.Key.NETWORK_COMPRESSION_THRESHOLD.toString())).setValue(this.patches.getInt("server.network-compression-threshold")); + ((IntegerConfigItem)m.values.get(MinecraftConfig.Key.SIMULATION_DISTANCE.toString())).setValue(this.patches.getInt("server.distance.simulation")); + ((IntegerConfigItem)m.values.get(MinecraftConfig.Key.VIEW_DISTANCE.toString())).setValue(this.patches.getInt("server.distance.view")); + ((BooleanConfigItem)m.values.get(MinecraftConfig.Key.SYNC_CHUNK_WRITES.toString())).setValue(this.patches.getBoolean("server.sync-chunk-writes")); + ((BooleanConfigItem)m.values.get(MinecraftConfig.Key.ALLOW_FLIGHT.toString())).setValue(this.patches.getBoolean("server.allow-flight")); } else { this.log.info("[KOS] 1/6 - Server does not support Server Properties, skipping..."); this.log.warn("[KOS] 1/6 - This shouldn't happen, please contact LewMC for help at lewmc.net/help"); @@ -100,25 +105,24 @@ private void runCraftBukkit() { if (this.softwareUtil.supportsCraftBukkit()) { this.log.info("[KOS] 2/6 - Running CraftBukkit optimisations"); - Bukkit bukkit = new Bukkit(this.plugin, user); - - bukkit.setInt(Bukkit.Key.SPAWN_LIMITS_MONSTERS, this.patches.getInt("craftbukkit.spawn-limits.monsters")); - bukkit.setInt(Bukkit.Key.SPAWN_LIMITS_ANIMALS, this.patches.getInt("craftbukkit.spawn-limits.animals")); - bukkit.setInt(Bukkit.Key.SPAWN_LIMITS_WATER_ANIMALS, this.patches.getInt("craftbukkit.spawn-limits.water.animals")); - bukkit.setInt(Bukkit.Key.SPAWN_LIMITS_WATER_AMBIENT, this.patches.getInt("craftbukkit.spawn-limits.water.ambient")); - bukkit.setInt(Bukkit.Key.SPAWN_LIMITS_WATER_UNDERGROUND_CREATURE, this.patches.getInt("craftbukkit.spawn-limits.water.underground.creature")); - bukkit.setInt(Bukkit.Key.SPAWN_LIMITS_AXOLOTLS, this.patches.getInt("craftbukkit.spawn-limits.axolotls")); - bukkit.setInt(Bukkit.Key.SPAWN_LIMITS_AMBIENT, this.patches.getInt("craftbukkit.spawn-limits.ambient")); - - bukkit.setInt(Bukkit.Key.TICKS_PER_MONSTER_SPAWNS, this.patches.getInt("craftbukkit.ticks-per.monsters")); - bukkit.setInt(Bukkit.Key.TICKS_PER_ANIMAL_SPAWNS, this.patches.getInt("craftbukkit.ticks-per.animals")); - bukkit.setInt(Bukkit.Key.TICKS_PER_WATER_SPAWNS, this.patches.getInt("craftbukkit.ticks-per.water.animals")); - bukkit.setInt(Bukkit.Key.TICKS_PER_WATER_AMBIENT_SPAWNS, this.patches.getInt("craftbukkit.ticks-per.water.ambient")); - bukkit.setInt(Bukkit.Key.TICKS_PER_WATER_UNDERGROUND_CREATURE_SPAWNS, this.patches.getInt("craftbukkit.ticks-per.water.underground-creature")); - bukkit.setInt(Bukkit.Key.TICKS_PER_AXOLOTL_SPAWNS, this.patches.getInt("craftbukkit.ticks-per.axolotls")); - bukkit.setInt(Bukkit.Key.TICKS_PER_AMBIENT_SPAWNS, this.patches.getInt("craftbukkit.ticks-per.ambient")); - - bukkit.setInt(Bukkit.Key.CHUNK_GC_PERIOD_IN_TICKS, this.patches.getInt("craftbukkit.chunk-gc-period-in-ticks")); + BukkitConfig bukkit = new BukkitConfig(this.plugin); + + ((IntegerConfigItem)bukkit.values.get(BukkitConfig.Key.SPAWN_LIMITS_MONSTERS.toString())).setValue(this.patches.getInt("craftbukkit.spawn-limits.monsters")); + ((IntegerConfigItem)bukkit.values.get(BukkitConfig.Key.SPAWN_LIMITS_ANIMALS.toString())).setValue(this.patches.getInt("craftbukkit.spawn-limits.animals")); + ((IntegerConfigItem)bukkit.values.get(BukkitConfig.Key.SPAWN_LIMITS_WATER_AMBIENT.toString())).setValue(this.patches.getInt("craftbukkit.spawn-limits.water.ambient")); + ((IntegerConfigItem)bukkit.values.get(BukkitConfig.Key.SPAWN_LIMITS_WATER_UNDERGROUND_CREATURE.toString())).setValue(this.patches.getInt("craftbukkit.spawn-limits.water.underground.creature")); + ((IntegerConfigItem)bukkit.values.get(BukkitConfig.Key.SPAWN_LIMITS_AXOLOTLS.toString())).setValue(this.patches.getInt("craftbukkit.spawn-limits.axolotls")); + ((IntegerConfigItem)bukkit.values.get(BukkitConfig.Key.SPAWN_LIMITS_AMBIENT.toString())).setValue(this.patches.getInt("craftbukkit.spawn-limits.ambient")); + + ((IntegerConfigItem)bukkit.values.get(BukkitConfig.Key.TICKS_PER_MONSTER_SPAWNS.toString())).setValue(this.patches.getInt("craftbukkit.ticks-per.monsters")); + ((IntegerConfigItem)bukkit.values.get(BukkitConfig.Key.TICKS_PER_ANIMAL_SPAWNS.toString())).setValue(this.patches.getInt("craftbukkit.ticks-per.animals")); + ((IntegerConfigItem)bukkit.values.get(BukkitConfig.Key.TICKS_PER_WATER_SPAWNS.toString())).setValue(this.patches.getInt("craftbukkit.ticks-per.water.animals")); + ((IntegerConfigItem)bukkit.values.get(BukkitConfig.Key.TICKS_PER_WATER_AMBIENT_SPAWNS.toString())).setValue(this.patches.getInt("craftbukkit.ticks-per.water.ambient")); + ((IntegerConfigItem)bukkit.values.get(BukkitConfig.Key.TICKS_PER_WATER_UNDERGROUND_CREATURE_SPAWNS.toString())).setValue(this.patches.getInt("craftbukkit.ticks-per.water.underground-creature")); + ((IntegerConfigItem)bukkit.values.get(BukkitConfig.Key.TICKS_PER_AXOLOTL_SPAWNS.toString())).setValue(this.patches.getInt("craftbukkit.ticks-per.axolotls")); + ((IntegerConfigItem)bukkit.values.get(BukkitConfig.Key.TICKS_PER_AMBIENT_SPAWNS.toString())).setValue(this.patches.getInt("craftbukkit.ticks-per.ambient")); + + ((IntegerConfigItem)bukkit.values.get(BukkitConfig.Key.CHUNK_GC_PERIOD_IN_TICKS.toString())).setValue(this.patches.getInt("craftbukkit.chunk-gc-period-in-ticks")); } else { this.log.info("[KOS] 2/6 - Server does not support CraftBukkit configurations, skipping..."); this.log.warn("[KOS] 2/6 - This shouldn't happen, please open an issue at github.com/lewmc/kryptonite"); @@ -295,37 +299,36 @@ private void runPurpur(boolean pregeneratedWorld) { if (this.softwareUtil.supportsPurpur()) { this.log.info("[KOS] 5/6 - Running Purpur optimisations"); - Purpur purpur = new Purpur(this.plugin, this.user); + PurpurConfig purpur = new PurpurConfig(this.plugin); if (this.plugin.getConfig().getBoolean("kos.using-tcpshield")) { this.log.info("[KOS] 5/6 - You're using TCPShield, disabling use-alternative-keepalive."); - purpur.setBoolean(Purpur.Key.USE_ALTERNATE_KEEPALIVE, false); + ((BooleanConfigItem)purpur.values.get(PurpurConfig.Key.USE_ALTERNATE_KEEPALIVE.toString())).setValue(false); } else { - purpur.setBoolean(Purpur.Key.USE_ALTERNATE_KEEPALIVE, this.patches.getBoolean("purpur.use-alternative-keepalive")); + ((BooleanConfigItem)purpur.values.get(PurpurConfig.Key.USE_ALTERNATE_KEEPALIVE.toString())).setValue(this.patches.getBoolean("purpur.use-alternative-keepalive")); } - purpur.setBoolean(Purpur.Key.ZOMBIE_AGGRESSIVE_TOWARDS_VILLAGER_WHEN_LAGGING, this.patches.getBoolean("purpur.entities.zombie.aggressive-towards-villager-when-lagging")); - purpur.setBoolean(Purpur.Key.ENTITIES_CAN_USE_PORTALS, this.patches.getBoolean("purpur.entities.all.can-use-portals")); - purpur.setBoolean(Purpur.Key.VILLAGER_IS_LOBOTOMIZED, this.patches.getBoolean("purpur.entities.villager.lobotomized")); - purpur.setInt(Purpur.Key.VILLAGER_SEARCH_RADIUS_ACQUIRE_POI, this.patches.getInt("purpur.entities.villager.search-radius.acquire-poi")); - purpur.setInt(Purpur.Key.VILLAGER_SEARCH_RADIUS_NEAREST_BED_SENSOR, this.patches.getInt("purpur.entities.villager.search-radius.nearest-bed-sensor")); + ((BooleanConfigItem)purpur.values.get(PurpurConfig.Key.ZOMBIE_AGGRESSIVE_TOWARDS_VILLAGER_WHEN_LAGGING.toString())).setValue(this.patches.getBoolean("purpur.entities.zombie.aggressive-towards-villager-when-lagging")); + ((BooleanConfigItem)purpur.values.get(PurpurConfig.Key.ENTITIES_CAN_USE_PORTALS.toString())).setValue(this.patches.getBoolean("purpur.entities.all.can-use-portals")); + ((BooleanConfigItem)purpur.values.get(PurpurConfig.Key.VILLAGER_IS_LOBOTOMIZED.toString())).setValue(this.patches.getBoolean("purpur.entities.villager.lobotomized")); + ((IntegerConfigItem)purpur.values.get(PurpurConfig.Key.VILLAGER_SEARCH_RADIUS_ACQUIRE_POI.toString())).setValue(this.patches.getInt("purpur.entities.villager.search-radius.acquire-poi")); + ((IntegerConfigItem)purpur.values.get(PurpurConfig.Key.VILLAGER_SEARCH_RADIUS_NEAREST_BED_SENSOR.toString())).setValue(this.patches.getInt("purpur.entities.villager.search-radius.nearest-bed-sensor")); if (pregeneratedWorld) { this.log.info("[KOS][4/6] World is pregenerated, enabling dolphin treasure searching..."); - purpur.setBoolean(Purpur.Key.DOLPHIN_DISABLE_TREASURE_SEARCHING, false); + ((BooleanConfigItem)purpur.values.get(PurpurConfig.Key.DOLPHIN_DISABLE_TREASURE_SEARCHING.toString())).setValue(false); } else { if (this.plugin.getConfig().getBoolean("kos.override-pregenerated-world-protections")) { - purpur.setBoolean(Purpur.Key.DOLPHIN_DISABLE_TREASURE_SEARCHING, false); + ((BooleanConfigItem)purpur.values.get(PurpurConfig.Key.DOLPHIN_DISABLE_TREASURE_SEARCHING.toString())).setValue(false); this.log.warn("[KOS][4/6] override-pregenerated-world-protections is TRUE, enabling dolphin treasure searching. This may cause lag."); } else { - purpur.setBoolean(Purpur.Key.DOLPHIN_DISABLE_TREASURE_SEARCHING, true); + ((BooleanConfigItem)purpur.values.get(PurpurConfig.Key.DOLPHIN_DISABLE_TREASURE_SEARCHING.toString())).setValue(true); this.log.info("[KOS][4/6] World not pregenerated, disabling dolphin treasure searching..."); this.message.Warning("Dolphin treasure searching has been disabled, please pre-generate your world to re-enable this."); } } - purpur.setBoolean(Purpur.Key.TELEPORT_IF_OUTSIDE_BORDER, this.patches.getBoolean("purpur.teleport-if-outside-worldborder")); - purpur.setInt(Purpur.Key.LAGGING_THRESHOLD, this.patches.getInt("purpur.lagging-tps-threshold")); - + ((BooleanConfigItem)purpur.values.get(PurpurConfig.Key.TELEPORT_IF_OUTSIDE_BORDER.toString())).setValue(this.patches.getBoolean("purpur.teleport-if-outside-worldborder")); + ((IntegerConfigItem)purpur.values.get(PurpurConfig.Key.LAGGING_THRESHOLD.toString())).setValue(this.patches.getInt("purpur.lagging-tps-threshold")); } else { this.log.info("[KOS] 5/6 - Server does not support Purpur configurations, skipping..."); } @@ -334,16 +337,16 @@ private void runPurpur(boolean pregeneratedWorld) { private void runPufferfish() { if (this.softwareUtil.supportsPufferfish()) { this.log.info("[KOS] 6/6 - Running Pufferfish optimisations"); - Pufferfish pufferfish = new Pufferfish(this.plugin, this.user); - - pufferfish.setInt(Pufferfish.Key.MAX_LOADS_PER_PROJECTILE, this.patches.getInt("pufferfish.max-loads-per-projectile")); - pufferfish.setBoolean(Pufferfish.Key.DAB_ENABLED, this.patches.getBoolean("pufferfish.entities.dynamic-activation-of-brain.enabled")); - pufferfish.setInt(Pufferfish.Key.DAB_MAX_TICK_FREQ, this.patches.getInt("pufferfish.entities.dynamic-activation-of-brain.max-tick-freq")); - pufferfish.setInt(Pufferfish.Key.DAB_ACTIVATION_DIST_MOD, this.patches.getInt("pufferfish.entities.dynamic-activation-of-brain.activation-distance-modifier")); - pufferfish.setBoolean(Pufferfish.Key.ENABLE_ASYNC_MOB_SPAWNING, this.patches.getBoolean("pufferfish.entities.async-mob-spawning")); - pufferfish.setBoolean(Pufferfish.Key.ENABLE_SUFFOCATION_OPTIMIZATION, this.patches.getBoolean("pufferfish.entities.suffocation-optimisation")); - pufferfish.setBoolean(Pufferfish.Key.INACTIVE_GOAL_SELECTOR_THROTTLE, this.patches.getBoolean("pufferfish.entities.inactive-goal-selector-throttle")); - pufferfish.setBoolean(Pufferfish.Key.DISABLE_METHOD_PROFILER, this.patches.getBoolean("pufferfish.disable-method-profiler")); + PufferfishConfig pufferfish = new PufferfishConfig(this.plugin); + + ((IntegerConfigItem)pufferfish.values.get(PufferfishConfig.Key.MAX_LOADS_PER_PROJECTILE.toString())).setValue(this.patches.getInt("pufferfish.max-loads-per-projectile")); + ((BooleanConfigItem)pufferfish.values.get(PufferfishConfig.Key.DAB_ENABLED.toString())).setValue(this.patches.getBoolean("pufferfish.entities.dynamic-activation-of-brain.enabled")); + ((IntegerConfigItem)pufferfish.values.get(PufferfishConfig.Key.DAB_MAX_TICK_FREQ.toString())).setValue(this.patches.getInt("pufferfish.entities.dynamic-activation-of-brain.max-tick-freq")); + ((IntegerConfigItem)pufferfish.values.get(PufferfishConfig.Key.DAB_ACTIVATION_DIST_MOD.toString())).setValue(this.patches.getInt("pufferfish.entities.dynamic-activation-of-brain.activation-distance-modifier")); + ((BooleanConfigItem)pufferfish.values.get(PufferfishConfig.Key.ENABLE_ASYNC_MOB_SPAWNING.toString())).setValue(this.patches.getBoolean("pufferfish.entities.async-mob-spawning")); + ((BooleanConfigItem)pufferfish.values.get(PufferfishConfig.Key.ENABLE_SUFFOCATION_OPTIMIZATION.toString())).setValue(this.patches.getBoolean("pufferfish.entities.suffocation-optimisation")); + ((BooleanConfigItem)pufferfish.values.get(PufferfishConfig.Key.INACTIVE_GOAL_SELECTOR_THROTTLE.toString())).setValue(this.patches.getBoolean("pufferfish.entities.inactive-goal-selector-throttle")); + ((BooleanConfigItem)pufferfish.values.get(PufferfishConfig.Key.DISABLE_METHOD_PROFILER.toString())).setValue(this.patches.getBoolean("pufferfish.disable-method-profiler")); } else { this.log.info("[KOS] 6/6 - Server does not support Pufferfish configurations, skipping..."); } diff --git a/src/main/java/net/lewmc/kryptonite/kos/config/Bukkit.java b/src/main/java/net/lewmc/kryptonite/kos/config/Bukkit.java deleted file mode 100644 index c068ef3..0000000 --- a/src/main/java/net/lewmc/kryptonite/kos/config/Bukkit.java +++ /dev/null @@ -1,118 +0,0 @@ -package net.lewmc.kryptonite.kos.config; - -import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.utils.ConfigurationUtil; -import net.lewmc.kryptonite.utils.LogUtil; -import org.bukkit.command.CommandSender; - -/** - * The Bukkit class manages the bukkit.yml configuration file. - * @deprecated - */ -@Deprecated -public class Bukkit { - private final Kryptonite plugin; - private final CommandSender user; - - /** - * Constructor for the Bukkit class. - * @param plugin Kryptonite - Reference to the main plugin class. - * @param user CommandSender - The user who sent the command. - */ - public Bukkit(Kryptonite plugin, CommandSender user) { - this.plugin = plugin; - this.user = user; - } - - /** - * Configuration values supported by this format. - */ - public enum Key { - SPAWN_LIMITS_MONSTERS { - @Override - public String toString() { return "spawn-limits.monsters"; } - }, - SPAWN_LIMITS_ANIMALS { - @Override - public String toString() { return "spawn-limits.animals"; } - }, - SPAWN_LIMITS_WATER_ANIMALS { - @Override - public String toString() { return "spawn-limits.water-animals"; } - }, - SPAWN_LIMITS_WATER_AMBIENT { - @Override - public String toString() { return "spawn-limits.water-ambient"; } - }, - SPAWN_LIMITS_WATER_UNDERGROUND_CREATURE { - @Override - public String toString() { return "spawn-limits.water-underground-creature"; } - }, - SPAWN_LIMITS_AXOLOTLS { - @Override - public String toString() { return "spawn-limits.axolotls"; } - }, - SPAWN_LIMITS_AMBIENT { - @Override - public String toString() { return "spawn-limits.ambient"; } - }, - TICKS_PER_MONSTER_SPAWNS { - @Override - public String toString() { return "ticks-per.monster-spawns"; } - }, - TICKS_PER_ANIMAL_SPAWNS { - @Override - public String toString() { return "ticks-per.animal-spawns"; } - }, - TICKS_PER_WATER_SPAWNS { - @Override - public String toString() { return "ticks-per.water-spawns"; } - }, - TICKS_PER_WATER_AMBIENT_SPAWNS { - @Override - public String toString() { return "ticks-per.water-ambient-spawns"; } - }, - TICKS_PER_WATER_UNDERGROUND_CREATURE_SPAWNS { - @Override - public String toString() { return "ticks-per.water-underground-creature-spawns"; } - }, - TICKS_PER_AXOLOTL_SPAWNS { - @Override - public String toString() { return "ticks-per.axolotl-spawns"; } - }, - TICKS_PER_AMBIENT_SPAWNS { - @Override - public String toString() { return "ticks-per.ambient-spawns"; } - }, - CHUNK_GC_PERIOD_IN_TICKS { - @Override - public String toString() { return "chunk-gc.period-in-ticks"; } - } - } - - /** - * Sets a requested key to a requested value. - * @param key Key - The requested key. - * @param value int - The requested value. - */ - public void setInt(Key key, int value) { - this.plugin.restartRequired = true; - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("bukkit.yml"); - cfg.set(key.toString(), value); - cfg.save(); - - LogUtil log = new LogUtil(this.plugin); - log.veboseInfo("KOS>bukkit.yml set '" + key + "' to '" + value + "'"); - } - - /** - * Gets a requested key's value. - * @param key Key - The requested key. - */ - public int getInt(Key key) { - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("bukkit.yml"); - return cfg.getInt(key.toString()); - } -} diff --git a/src/main/java/net/lewmc/kryptonite/kos/config/Pufferfish.java b/src/main/java/net/lewmc/kryptonite/kos/config/Pufferfish.java deleted file mode 100644 index f5584cc..0000000 --- a/src/main/java/net/lewmc/kryptonite/kos/config/Pufferfish.java +++ /dev/null @@ -1,132 +0,0 @@ -package net.lewmc.kryptonite.kos.config; - -import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.utils.ConfigurationUtil; -import net.lewmc.kryptonite.utils.LogUtil; -import org.bukkit.command.CommandSender; - -/** - * The Pufferfish class manages the pufferfish.yml configuration file. - * @deprecated - */ -@Deprecated -public class Pufferfish { - private final Kryptonite plugin; - private final CommandSender user; - - /** - * Constructor for the Pufferfish class. - * @param plugin Kryptonite - Reference to the main plugin class. - * @param user CommandSender - The user who sent the command. - */ - public Pufferfish(Kryptonite plugin, CommandSender user) { - this.plugin = plugin; - this.user = user; - } - - /** - * Configuration values supported by this format. - */ - public enum Key { - MAX_LOADS_PER_PROJECTILE { - @Override - public String toString() { return "projectile.max-loads-per-projectile"; } - }, - DAB_ENABLED { - @Override - public String toString() { return "dab.enabled"; } - }, - DAB_MAX_TICK_FREQ { - @Override - public String toString() { return "dab.max-tick-freq"; } - }, - DAB_ACTIVATION_DIST_MOD { - @Override - public String toString() { return "dab.activation-dist-mod"; } - }, - ENABLE_ASYNC_MOB_SPAWNING { - @Override - public String toString() { return "enable-async-mob-spawning"; } - }, - ENABLE_SUFFOCATION_OPTIMIZATION { - @Override - public String toString() { return "enable-suffocation-optimization"; } - }, - INACTIVE_GOAL_SELECTOR_THROTTLE { - @Override - public String toString() { return "inactive-goal-selector-throttle"; } - }, - DISABLE_METHOD_PROFILER { - @Override - public String toString() { return "misc.disable-method-profiler"; } - } - } - - /** - * Sets a requested key to a requested value. - * @param key Key - The requested key. - * @param value int - The requested value. - */ - public void setInt(Key key, int value) { - this.plugin.restartRequired = true; - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("pufferfish.yml"); - cfg.set(key.toString(), value); - cfg.save(); - - LogUtil log = new LogUtil(this.plugin); - log.veboseInfo("KOS>pufferfish.yml set '" + key + "' to '" + value + "'"); - } - - /** - * Gets a requested key's value. - * @param key Key - The requested key. - */ - public int getInt(Key key) { - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("pufferfish.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(Key key, boolean value) { - this.plugin.restartRequired = true; - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("pufferfish.yml"); - cfg.set(key.toString(), value); - cfg.save(); - - LogUtil log = new LogUtil(this.plugin); - log.veboseInfo("KOS>pufferfish.yml set '" + key + "' to '" + value + "'"); - } - - /** - * Gets a requested key's value. - * @param key Key - The requested key. - */ - public boolean getBoolean(Key key) { - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("pufferfish.yml"); - return cfg.getBoolean(key.toString()); - } - - /** - * Sets a requested key to a requested value. - * @param key Key - The requested key. - * @param value int - The requested value. - */ - public void setString(Key key, String value) { - this.plugin.restartRequired = true; - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("pufferfish.yml"); - cfg.set(key.toString(), value); - cfg.save(); - - LogUtil log = new LogUtil(this.plugin); - log.veboseInfo("KOS>pufferfish.yml set '" + key + "' to '" + value + "'"); - } -} diff --git a/src/main/java/net/lewmc/kryptonite/kos/config/Purpur.java b/src/main/java/net/lewmc/kryptonite/kos/config/Purpur.java deleted file mode 100644 index 0b81852..0000000 --- a/src/main/java/net/lewmc/kryptonite/kos/config/Purpur.java +++ /dev/null @@ -1,136 +0,0 @@ -package net.lewmc.kryptonite.kos.config; - -import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.utils.ConfigurationUtil; -import net.lewmc.kryptonite.utils.LogUtil; -import org.bukkit.command.CommandSender; - -/** - * The Purpur class manages the purpur.yml configuration file. - * @deprecated - */ -@Deprecated -public class Purpur { - private final Kryptonite plugin; - private final CommandSender user; - - /** - * Constructor for the Purpur class. - * @param plugin Kryptonite - Reference to the main plugin class. - * @param user CommandSender - The user who sent the command. - */ - public Purpur(Kryptonite plugin, CommandSender user) { - this.plugin = plugin; - this.user = user; - } - - /** - * Configuration values supported by this format. - */ - public enum Key { - USE_ALTERNATE_KEEPALIVE { - @Override - public String toString() { return "settings.use-alternate-keepalive"; } - }, - ZOMBIE_AGGRESSIVE_TOWARDS_VILLAGER_WHEN_LAGGING { - @Override - public String toString() { return "world-settings.default.mobs.zombie.aggressive-towards-villager-when-lagging"; } - }, - ENTITIES_CAN_USE_PORTALS { - @Override - public String toString() { return "world-settings.default.gameplay-mechanics.entities-can-use-portals"; } - }, - VILLAGER_IS_LOBOTOMIZED { - @Override - public String toString() { return "world-settings.default.mobs.villager.lobotomize.enabled"; } - }, - VILLAGER_SEARCH_RADIUS_ACQUIRE_POI { - @Override - public String toString() { return "world-settings.default.mobs.villager.search-radius.acquire-poi"; } - }, - VILLAGER_SEARCH_RADIUS_NEAREST_BED_SENSOR { - @Override - public String toString() { return "world-settings.default.mobs.villager.search-radius.nearest-bed-sensor"; } - }, - DOLPHIN_DISABLE_TREASURE_SEARCHING { - @Override - public String toString() { return "world-settings.default.mobs.dolphin.disable-treasure-searching"; } - }, - TELEPORT_IF_OUTSIDE_BORDER { - @Override - public String toString() { return "world-settings.default.gameplay-mechanics.player.teleport-if-outside-border"; } - }, - LAGGING_THRESHOLD { - @Override - public String toString() { return "settings.lagging-threshold"; } - } - } - - /** - * Sets a requested key to a requested value. - * @param key Key - The requested key. - * @param value int - The requested value. - */ - public void setInt(Key key, int value) { - this.plugin.restartRequired = true; - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("purpur.yml"); - cfg.set(key.toString(), value); - cfg.save(); - - LogUtil log = new LogUtil(this.plugin); - log.veboseInfo("KOS>purpur.yml set '" + key + "' to '" + value + "'"); - } - - /** - * Gets a requested key's value. - * @param key Key - The requested key. - */ - public int getInt(Key key) { - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("purpur.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(Key key, boolean value) { - this.plugin.restartRequired = true; - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("purpur.yml"); - cfg.set(key.toString(), value); - cfg.save(); - - LogUtil log = new LogUtil(this.plugin); - log.veboseInfo("KOS>purpur.yml set '" + key + "' to '" + value + "'"); - } - - /** - * Gets a requested key's value. - * @param key Key - The requested key. - */ - public boolean getBoolean(Key key) { - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("purpur.yml"); - return cfg.getBoolean(key.toString()); - } - - /** - * Sets a requested key to a requested value. - * @param key Key - The requested key. - * @param value int - The requested value. - */ - public void setString(Key key, String value) { - this.plugin.restartRequired = true; - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("purpur.yml"); - cfg.set(key.toString(), value); - cfg.save(); - - LogUtil log = new LogUtil(this.plugin); - log.veboseInfo("KOS>purpur.yml set '" + key + "' to '" + value + "'"); - } -} diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_BukkitGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_BukkitGui.java deleted file mode 100644 index 9be5f96..0000000 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_BukkitGui.java +++ /dev/null @@ -1,629 +0,0 @@ -package net.lewmc.kryptonite.kos.gui; - -import de.themoep.inventorygui.GuiElement; -import de.themoep.inventorygui.InventoryGui; -import de.themoep.inventorygui.StaticGuiElement; -import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.kos.config.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; - -/** - * KOS Bukkit GUI - * @deprecated - */ -@Deprecated -public class KOS_BukkitGui { - private final Kryptonite plugin; - private final CommandSender user; - private InventoryGui gui; - private Bukkit bukkit; - - /** - * Constructor for the KOS Bukkit GUI - * @param plugin Kryptonite - Reference to the main plugin class. - * @param user CommandSender - The user who sent the command. - */ - public KOS_BukkitGui(Kryptonite plugin, CommandSender user) { - this.plugin = plugin; - this.user = user; - - this.bukkit = new Bukkit(plugin, user); - } - - /** - * Shows the KOS Bukkit GUI - */ - public void show() { - InventoryHolder holder = this.user.getServer().getPlayer(this.user.getName()); - this.gui = new InventoryGui(this.plugin, holder, "KOS - Bukkit Configuration", this.getElements()); - this.addElements(); - - this.gui.build(); - this.gui.show((Player) this.user); - } - - /** - * Adds pre-programmed elements to the GUI - */ - private void addElements() { - this.spawnLimitMonsters('a'); - this.spawnLimitAnimals('b'); - this.spawnLimitWaterAnimals('c'); - this.spawnLimitWaterAmbient('d'); - this.spawnLimitWaterUndergroundCreature('e'); - this.spawnLimitAxolotls('f'); - this.spawnLimitAmbient('g'); - this.ticksPerMonsterSpawns('h'); - this.ticksPerAnimalSpawns('i'); - - this.ticksPerWaterSpawns('j'); - this.ticksPerWaterAmbientSpawns('k'); - this.ticksPerWaterUndergroundCreatureSpawns('l'); - this.ticksPerAxolotlSpawns('m'); - this.ticksPerAmbientSpawns('n'); - this.chunkGcPeriodInTicks('o'); - - KOS_GuiConstants consts = new KOS_GuiConstants(this.plugin, this.gui); - consts.addConstants(); - } - - /** - * Determines where the elements should be positioned. - * @return String[] - The position of the elements. - */ - private String[] getElements() { - - return new String[]{ - "abcdefghi", - "jklmno ", - " w x y " - }; - } - - private void spawnLimitMonsters(char id) { - int value = this.bukkit.getInt(Bukkit.Key.SPAWN_LIMITS_MONSTERS); - if (value >= 20 && value <= 60) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_MONSTERS, click, value), - ChatColor.DARK_GREEN + "Spawn Limit (Monsters)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 20) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_MONSTERS, click, value), - ChatColor.GOLD + "Spawn Limit (Monsters)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_MONSTERS, click, value), - ChatColor.DARK_RED + "Spawn Limit (Monsters)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void spawnLimitAnimals(char id) { - int value = this.bukkit.getInt(Bukkit.Key.SPAWN_LIMITS_ANIMALS); - if (value >= 5 && value <= 10) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_ANIMALS, click, value), - ChatColor.DARK_GREEN + "Spawn Limit (Animals)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 5) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_ANIMALS, click, value), - ChatColor.GOLD + "Spawn Limit (Animals)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_ANIMALS, click, value), - ChatColor.DARK_RED + "Spawn Limit (Animals)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void spawnLimitWaterAnimals(char id) { - int value = this.bukkit.getInt(Bukkit.Key.SPAWN_LIMITS_WATER_ANIMALS); - if (value >= 2 && value <= 5) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_WATER_ANIMALS, click, value), - ChatColor.DARK_GREEN + "Spawn Limit (Water Animals)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 2) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_WATER_ANIMALS, click, value), - ChatColor.GOLD + "Spawn Limit (Water Animals)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_WATER_ANIMALS, click, value), - ChatColor.DARK_RED + "Spawn Limit (Water Animals)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void spawnLimitWaterAmbient(char id) { - int value = this.bukkit.getInt(Bukkit.Key.SPAWN_LIMITS_WATER_AMBIENT); - if (value >= 2 && value <= 10) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_WATER_AMBIENT, click, value), - ChatColor.DARK_GREEN + "Spawn Limit (Water Ambient)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 2) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_WATER_AMBIENT, click, value), - ChatColor.GOLD + "Spawn Limit (Water Ambient)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_WATER_AMBIENT, click, value), - ChatColor.DARK_RED + "Spawn Limit (Water Ambient)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void spawnLimitWaterUndergroundCreature(char id) { - int value = this.bukkit.getInt(Bukkit.Key.SPAWN_LIMITS_WATER_UNDERGROUND_CREATURE); - if (value >= 3 && value <= 5) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_WATER_UNDERGROUND_CREATURE, click, value), - ChatColor.DARK_GREEN + "Spawn Limit (Water Ambient)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 3) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_WATER_UNDERGROUND_CREATURE, click, value), - ChatColor.GOLD + "Spawn Limit (Water Ambient)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_WATER_UNDERGROUND_CREATURE, click, value), - ChatColor.DARK_RED + "Spawn Limit (Water Ambient)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void spawnLimitAxolotls(char id) { - int value = this.bukkit.getInt(Bukkit.Key.SPAWN_LIMITS_AXOLOTLS); - if (value >= 3 && value <= 5) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_AXOLOTLS, click, value), - ChatColor.DARK_GREEN + "Spawn Limit (Axolotls)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 3) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_AXOLOTLS, click, value), - ChatColor.GOLD + "Spawn Limit (Axolotls)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_AXOLOTLS, click, value), - ChatColor.DARK_RED + "Spawn Limit (Axolotls)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void spawnLimitAmbient(char id) { - int value = this.bukkit.getInt(Bukkit.Key.SPAWN_LIMITS_AMBIENT); - if (value >= 1 && value <= 10) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_AMBIENT, click, value), - ChatColor.DARK_GREEN + "Spawn Limit (Ambient)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 1) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_AMBIENT, click, value), - ChatColor.GOLD + "Spawn Limit (Ambient)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.SPAWN_LIMITS_AMBIENT, click, value), - ChatColor.DARK_RED + "Spawn Limit (Ambient)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void ticksPerMonsterSpawns(char id) { - int value = this.bukkit.getInt(Bukkit.Key.TICKS_PER_MONSTER_SPAWNS); - if (value >= 5 && value <= 15) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_MONSTER_SPAWNS, click, value), - ChatColor.DARK_GREEN + "Ticks Per Monster Spawns", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 5) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_MONSTER_SPAWNS, click, value), - ChatColor.DARK_RED + "Ticks Per Monster Spawns", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too low - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_MONSTER_SPAWNS, click, value), - ChatColor.GOLD + "Ticks Per Monster Spawns", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too high - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void ticksPerAnimalSpawns(char id) { - int value = this.bukkit.getInt(Bukkit.Key.TICKS_PER_ANIMAL_SPAWNS); - if (value == 400) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_ANIMAL_SPAWNS, click, value), - ChatColor.DARK_GREEN + "Ticks Per Monster Spawns", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 400) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_ANIMAL_SPAWNS, click, value), - ChatColor.DARK_RED + "Ticks Per Monster Spawns", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too low - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_ANIMAL_SPAWNS, click, value), - ChatColor.GOLD + "Ticks Per Monster Spawns", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too high - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void ticksPerWaterSpawns(char id) { - int value = this.bukkit.getInt(Bukkit.Key.TICKS_PER_WATER_SPAWNS); - if (value >= 100 && value <= 400) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_WATER_SPAWNS, click, value), - ChatColor.DARK_GREEN + "Ticks Per Water Spawns", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 5) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_WATER_SPAWNS, click, value), - ChatColor.DARK_RED + "Ticks Per Water Spawns", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too low - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_WATER_SPAWNS, click, value), - ChatColor.GOLD + "Ticks Per Water Spawns", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too high - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void ticksPerWaterAmbientSpawns(char id) { - int value = this.bukkit.getInt(Bukkit.Key.TICKS_PER_WATER_AMBIENT_SPAWNS); - if (value >= 100 && value <= 400) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_WATER_AMBIENT_SPAWNS, click, value), - ChatColor.DARK_GREEN + "Ticks Per Water Ambient Spawns", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 5) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_WATER_AMBIENT_SPAWNS, click, value), - ChatColor.DARK_RED + "Ticks Per Water Ambient Spawns", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too low - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_WATER_AMBIENT_SPAWNS, click, value), - ChatColor.GOLD + "Ticks Per Water Ambient Spawns", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too high - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void ticksPerWaterUndergroundCreatureSpawns(char id) { - int value = this.bukkit.getInt(Bukkit.Key.TICKS_PER_WATER_UNDERGROUND_CREATURE_SPAWNS); - if (value >= 100 && value <= 400) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_WATER_UNDERGROUND_CREATURE_SPAWNS, click, value), - ChatColor.DARK_GREEN + "Ticks Per Water Ambient Spawns", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 5) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_WATER_UNDERGROUND_CREATURE_SPAWNS, click, value), - ChatColor.DARK_RED + "Ticks Per Water Ambient Spawns", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too low - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_WATER_UNDERGROUND_CREATURE_SPAWNS, click, value), - ChatColor.GOLD + "Ticks Per Water Ambient Spawns", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too high - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void ticksPerAxolotlSpawns(char id) { - int value = this.bukkit.getInt(Bukkit.Key.TICKS_PER_AXOLOTL_SPAWNS); - if (value >= 100 && value <= 400) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_AXOLOTL_SPAWNS, click, value), - ChatColor.DARK_GREEN + "Ticks Per Axolotl Spawns", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 5) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_AXOLOTL_SPAWNS, click, value), - ChatColor.DARK_RED + "Ticks Per Axolotl Spawns", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too low - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_AXOLOTL_SPAWNS, click, value), - ChatColor.GOLD + "Ticks Per Axolotl Spawns", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too high - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void ticksPerAmbientSpawns(char id) { - int value = this.bukkit.getInt(Bukkit.Key.TICKS_PER_AMBIENT_SPAWNS); - if (value >= 100 && value <= 400) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_AMBIENT_SPAWNS, click, value), - ChatColor.DARK_GREEN + "Ticks Per Ambient Spawns", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 5) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_AMBIENT_SPAWNS, click, value), - ChatColor.DARK_RED + "Ticks Per Ambient Spawns", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too low - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.TICKS_PER_AMBIENT_SPAWNS, click, value), - ChatColor.GOLD + "Ticks Per Ambient Spawns", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too high - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void chunkGcPeriodInTicks(char id) { - int value = this.bukkit.getInt(Bukkit.Key.CHUNK_GC_PERIOD_IN_TICKS); - if (value >= 400 && value <= 600) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.CHUNK_GC_PERIOD_IN_TICKS, click, value), - ChatColor.DARK_GREEN + "Chunk GC Period (In Ticks)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 5) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.CHUNK_GC_PERIOD_IN_TICKS, click, value), - ChatColor.DARK_RED + "Chunk GC Period (In Ticks)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Bukkit.Key.CHUNK_GC_PERIOD_IN_TICKS, click, value), - ChatColor.DARK_RED + "Chunk GC Period (In Ticks)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private boolean setInt(Bukkit.Key key, GuiElement.Click click, int value) { - click.getGui().close(); - if (click.getType() == ClickType.RIGHT) { - this.bukkit.setInt(key, value + 1); - } else if (click.getType() == ClickType.SHIFT_RIGHT) { - this.bukkit.setInt(key, value + 10); - } else if (click.getType() == ClickType.LEFT && value != 0) { - this.bukkit.setInt(key, value - 1); - } else if (click.getType() == ClickType.SHIFT_LEFT && value >= 10) { - this.bukkit.setInt(key, value - 10); - } - - this.show(); - return true; - } -} diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java index 22feb91..38f2be9 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java @@ -4,8 +4,7 @@ import de.themoep.inventorygui.InventoryGui; import de.themoep.inventorygui.StaticGuiElement; import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.config.LeafConfig; -import net.lewmc.kryptonite.config.MinecraftConfig; +import net.lewmc.kryptonite.config.*; import net.lewmc.kryptonite.utils.config.*; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -26,7 +25,8 @@ public class KOS_ConfigItemGui { private final Kryptonite plugin; private final CommandSender user; - private final ConfigCollection config; + private final Kryptonite.ConfigurationOptions type; + private ConfigCollection config; private InventoryGui gui; /** @@ -38,20 +38,29 @@ public class KOS_ConfigItemGui { public KOS_ConfigItemGui(Kryptonite plugin, CommandSender user, Kryptonite.ConfigurationOptions type) { this.plugin = plugin; this.user = user; + this.type = type; + } + /** + * Shows the KOS Server Properties GUI + */ + public void show() { if (type == Kryptonite.ConfigurationOptions.MINECRAFT) { this.config = new MinecraftConfig(plugin); + } else if (type == Kryptonite.ConfigurationOptions.BUKKIT) { + this.config = new BukkitConfig(plugin); + } else if (type == Kryptonite.ConfigurationOptions.SPIGOT) { + this.config = new SpigotConfig(plugin); + } else if (type == Kryptonite.ConfigurationOptions.PURPUR) { + this.config = new PurpurConfig(plugin); + } else if (type == Kryptonite.ConfigurationOptions.PUFFERFISH) { + this.config = new PufferfishConfig(plugin); } else if (type == Kryptonite.ConfigurationOptions.LEAF) { this.config = new LeafConfig(plugin); } else { this.config = null; } - } - /** - * Shows the KOS Server Properties GUI - */ - public void show() { this.gui = new InventoryGui(this.plugin, (Player) this.user, "KOS - Server Configuration", this.getElements()); this.addElements(); diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java index 1ef23ea..f7ed643 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ManualGUI.java @@ -75,8 +75,7 @@ private void addElements() { 1, click -> { click.getGui().close(); - KOS_BukkitGui bGui = new KOS_BukkitGui(this.plugin, this.user); - bGui.show(); + new KOS_ConfigItemGui(this.plugin, this.user, Kryptonite.ConfigurationOptions.BUKKIT).show(); return true; }, ChatColor.BLUE + "Bukkit", @@ -99,8 +98,7 @@ private void addElements() { 1, click -> { click.getGui().close(); - KOS_SpigotGui_1 spigGui = new KOS_SpigotGui_1(this.plugin, this.user); - spigGui.show(); + new KOS_ConfigItemGui(this.plugin, this.user, Kryptonite.ConfigurationOptions.SPIGOT).show(); return true; }, ChatColor.BLUE + "Spigot", @@ -145,8 +143,7 @@ private void addElements() { 1, click -> { click.getGui().close(); - KOS_PaperWorld_1 paperWorldGui = new KOS_PaperWorld_1(this.plugin, this.user); - paperWorldGui.show(); + new KOS_ConfigItemGui(this.plugin, this.user, Kryptonite.ConfigurationOptions.PAPER_WORLD).show(); return true; }, ChatColor.BLUE + "Paper World", @@ -169,8 +166,7 @@ private void addElements() { 1, click -> { click.getGui().close(); - KOS_PurpurGui purpurGui = new KOS_PurpurGui(this.plugin, this.user); - purpurGui.show(); + new KOS_ConfigItemGui(this.plugin, this.user, Kryptonite.ConfigurationOptions.PURPUR).show(); return true; }, ChatColor.BLUE + "Purpur", @@ -193,8 +189,7 @@ private void addElements() { 1, click -> { click.getGui().close(); - KOS_PufferfishGui pufferfishGui = new KOS_PufferfishGui(this.plugin, this.user); - pufferfishGui.show(); + new KOS_ConfigItemGui(this.plugin, this.user, Kryptonite.ConfigurationOptions.PUFFERFISH).show(); return true; }, ChatColor.BLUE + "Pufferfish", diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_1.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_1.java index c217e12..8c16b99 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_1.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_1.java @@ -13,6 +13,17 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; + + + +/* + * tick-rates - don't change with DAB + * https://shop.layten.net/how-to-optimize-your-minecraft-server/ + */ + + + + /** * KOS Paper World GUI (Page 1/5) * @deprecated diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_3.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_3.java index 3b35495..eb3983b 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_3.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_3.java @@ -38,7 +38,7 @@ public KOS_PaperWorld_3(Kryptonite plugin, CommandSender user) { this.paperWorld = new PaperWorld(plugin, user); SoftwareUtil sw = new SoftwareUtil(this.plugin); - this.dabEnabled = sw.dabEnabled(this.user); + this.dabEnabled = sw.dabEnabled(); this.isAltItemDespawnRateEnabled = this.paperWorld.getBoolean(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_ENABLED); } diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PufferfishGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PufferfishGui.java deleted file mode 100644 index 766be6b..0000000 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PufferfishGui.java +++ /dev/null @@ -1,388 +0,0 @@ -package net.lewmc.kryptonite.kos.gui; - -import de.themoep.inventorygui.GuiElement; -import de.themoep.inventorygui.InventoryGui; -import de.themoep.inventorygui.StaticGuiElement; -import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.kos.config.Pufferfish; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; - -/** - * KOS Pufferfish GUI - * @deprecated - */ -@Deprecated -public class KOS_PufferfishGui { - private final Kryptonite plugin; - private final CommandSender user; - private InventoryGui gui; - private Pufferfish pufferfish; - - /** - * Constructor for the KOS Pufferfish GUI - * @param plugin Kryptonite - Reference to the main plugin class. - * @param user CommandSender - The user who sent the command. - */ - public KOS_PufferfishGui(Kryptonite plugin, CommandSender user) { - this.plugin = plugin; - this.user = user; - - this.pufferfish = new Pufferfish(plugin, user); - } - - /** - * Shows the KOS Pufferfish GUI - */ - public void show() { - InventoryHolder holder = this.user.getServer().getPlayer(this.user.getName()); - this.gui = new InventoryGui(this.plugin, holder, "KOS - Pufferfish Configuration", this.getElements()); - this.addElements(); - - this.gui.build(); - this.gui.show((Player) this.user); - } - - /** - * Adds pre-programmed elements to the GUI - */ - private void addElements() { - this.maxLoadsPerProjectile('a'); - this.dabEnabled('b'); - this.dabMaxTickFreq('c'); - this.dabActivationDistMod('d'); - this.enableAsyncMobSpawning('e'); - this.enableSuffocationOptimization('f'); - this.inactiveGoalSelectorThrottle('g'); - this.disableMethodProfiler('h'); - - KOS_GuiConstants consts = new KOS_GuiConstants(this.plugin, this.gui); - consts.addConstants(); - } - - /** - * Determines where the elements should be positioned. - * @return String[] - The position of the elements. - */ - private String[] getElements() { - - return new String[]{ - "abcdefgh ", - " ", - " w x y " - }; - } - - private void maxLoadsPerProjectile(char id) { - int value = this.pufferfish.getInt(Pufferfish.Key.MAX_LOADS_PER_PROJECTILE); - if (value >= 8 && value <= 12) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Pufferfish.Key.MAX_LOADS_PER_PROJECTILE, click, value, false), - ChatColor.DARK_GREEN + "Max Loads per Projectile", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 8) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Pufferfish.Key.MAX_LOADS_PER_PROJECTILE, click, value, false), - ChatColor.GOLD + "Max Loads per Projectile", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.YELLOW + "May cause issues with tridents and ender pearls.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Pufferfish.Key.MAX_LOADS_PER_PROJECTILE, click, value, false), - ChatColor.DARK_RED + "Max Loads per Projectile", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.RED + "Hopper-based clocks and item sorting systems may also break.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void dabEnabled(char id) { - boolean value = this.pufferfish.getBoolean(Pufferfish.Key.DAB_ENABLED); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.pufferfish.setBoolean(Pufferfish.Key.DAB_ENABLED, true); - this.show(); - return true; - }, - ChatColor.DARK_GREEN + "DAB Enabled", - ChatColor.GREEN + "true", - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.pufferfish.setBoolean(Pufferfish.Key.DAB_ENABLED, true); - this.show(); - return true; - }, - ChatColor.DARK_RED + "Max Loads per Projectile", - ChatColor.RED + "false", - ChatColor.RED + "Impact to performance.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void dabMaxTickFreq(char id) { - int value = this.pufferfish.getInt(Pufferfish.Key.DAB_MAX_TICK_FREQ); - if (value == 20) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Pufferfish.Key.DAB_MAX_TICK_FREQ, click, value, false), - ChatColor.DARK_GREEN + "DAB Max Tick Frequency", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 20) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Pufferfish.Key.DAB_MAX_TICK_FREQ, click, value, false), - ChatColor.DARK_RED + "DAB Max Tick Frequency", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too low - impact to performance.", - ChatColor.RED + "If DAB is breaking mob farms, having this decreased will", - ChatColor.RED + "improve your player experience, but may cost performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Pufferfish.Key.DAB_MAX_TICK_FREQ, click, value, false), - ChatColor.GOLD + "DAB Max Tick Frequency", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too high - impact to player experience.", - ChatColor.YELLOW + "May break mob farms or nerf mob behaviour.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void dabActivationDistMod(char id) { - int value = this.pufferfish.getInt(Pufferfish.Key.DAB_ACTIVATION_DIST_MOD); - if (value == 8 || value == 7) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Pufferfish.Key.DAB_ACTIVATION_DIST_MOD, click, value, false), - ChatColor.DARK_GREEN + "DAB Activation Distance Modifier", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value > 8) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Pufferfish.Key.DAB_ACTIVATION_DIST_MOD, click, value, false), - ChatColor.DARK_RED + "DAB Activation Distance Modifier", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.RED + "If DAB is breaking mob farms, having this increased will", - ChatColor.RED + "improve your player experience, but may cost performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Pufferfish.Key.DAB_ACTIVATION_DIST_MOD, click, value, false), - ChatColor.GOLD + "DAB Activation Distance Modifier", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.YELLOW + "May break mob farms or nerf mob behaviour.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void enableAsyncMobSpawning(char id) { - boolean value = this.pufferfish.getBoolean(Pufferfish.Key.ENABLE_ASYNC_MOB_SPAWNING); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.pufferfish.setBoolean(Pufferfish.Key.ENABLE_ASYNC_MOB_SPAWNING, true); - this.show(); - return true; - }, - ChatColor.DARK_GREEN + "Enable Async Mob Spawning", - ChatColor.GREEN + "true", - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.pufferfish.setBoolean(Pufferfish.Key.ENABLE_ASYNC_MOB_SPAWNING, true); - this.show(); - return true; - }, - ChatColor.DARK_RED + "Enable Async Mob Spawning", - ChatColor.RED + "false", - ChatColor.RED + "Impact to performance.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void enableSuffocationOptimization(char id) { - boolean value = this.pufferfish.getBoolean(Pufferfish.Key.ENABLE_SUFFOCATION_OPTIMIZATION); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.pufferfish.setBoolean(Pufferfish.Key.ENABLE_SUFFOCATION_OPTIMIZATION, true); - this.show(); - return true; - }, - ChatColor.DARK_GREEN + "Enable Suffocation Optimization", - ChatColor.GREEN + "true", - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.pufferfish.setBoolean(Pufferfish.Key.ENABLE_SUFFOCATION_OPTIMIZATION, true); - this.show(); - return true; - }, - ChatColor.DARK_RED + "Enable Suffocation Optimization", - ChatColor.RED + "false", - ChatColor.RED + "Impact to performance.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void inactiveGoalSelectorThrottle(char id) { - boolean value = this.pufferfish.getBoolean(Pufferfish.Key.INACTIVE_GOAL_SELECTOR_THROTTLE); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.pufferfish.setBoolean(Pufferfish.Key.INACTIVE_GOAL_SELECTOR_THROTTLE, true); - this.show(); - return true; - }, - ChatColor.GOLD + "Inactive Goal Selector Throttle", - ChatColor.YELLOW + "true", - ChatColor.YELLOW + "Impact to player experience.", - ChatColor.YELLOW + "May have minor gameplay implications.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.pufferfish.setBoolean(Pufferfish.Key.INACTIVE_GOAL_SELECTOR_THROTTLE, true); - this.show(); - return true; - }, - ChatColor.DARK_RED + "Inactive Goal Selector Throttle", - ChatColor.RED + "false", - ChatColor.RED + "Impact to performance.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void disableMethodProfiler(char id) { - boolean value = this.pufferfish.getBoolean(Pufferfish.Key.DISABLE_METHOD_PROFILER); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.pufferfish.setBoolean(Pufferfish.Key.DISABLE_METHOD_PROFILER, true); - this.show(); - return true; - }, - ChatColor.DARK_GREEN + "Disable Method Profiler", - ChatColor.GREEN + "true", - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.pufferfish.setBoolean(Pufferfish.Key.DISABLE_METHOD_PROFILER, true); - this.show(); - return true; - }, - ChatColor.DARK_RED + "Disable Method Profiler", - ChatColor.RED + "false", - ChatColor.RED + "Impact to performance - this is not necessary in", - ChatColor.RED + "production environments.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private boolean setInt(Pufferfish.Key key, GuiElement.Click click, int value, boolean canBeDefault) { - click.getGui().close(); - if (click.getType() == ClickType.RIGHT) { - this.pufferfish.setInt(key, value + 1); - } else if (click.getType() == ClickType.SHIFT_RIGHT) { - this.pufferfish.setInt(key, value + 10); - } else if (click.getType() == ClickType.LEFT && value != 0) { - this.pufferfish.setInt(key, value - 1); - } else if (click.getType() == ClickType.SHIFT_LEFT && value >= 10) { - this.pufferfish.setInt(key, value - 10); - } else if ((click.getType() == ClickType.LEFT || click.getType() == ClickType.SHIFT_LEFT) && value == 0 && canBeDefault) { - this.pufferfish.setString(key, "default"); - } - - this.show(); - return true; - } -} diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PurpurGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PurpurGui.java deleted file mode 100644 index 7bff096..0000000 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PurpurGui.java +++ /dev/null @@ -1,465 +0,0 @@ -package net.lewmc.kryptonite.kos.gui; - -import de.themoep.inventorygui.GuiElement; -import de.themoep.inventorygui.InventoryGui; -import de.themoep.inventorygui.StaticGuiElement; -import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.kos.config.Purpur; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; - -/** - * KOS Purpur GUI - * @deprecated - */ -@Deprecated -public class KOS_PurpurGui { - private final Kryptonite plugin; - private final CommandSender user; - private final Purpur purpur; - private InventoryGui gui; - - /** - * Constructor for the KOS Purpur GUI - * @param plugin Kryptonite - Reference to the main plugin class. - * @param user CommandSender - The user who sent the command. - */ - public KOS_PurpurGui(Kryptonite plugin, CommandSender user) { - this.plugin = plugin; - this.user = user; - - this.purpur = new Purpur(plugin, user); - } - - /** - * Shows the KOS Purpur GUI - */ - public void show() { - InventoryHolder holder = this.user.getServer().getPlayer(this.user.getName()); - this.gui = new InventoryGui(this.plugin, holder, "KOS - Purpur Configuration", this.getElements()); - this.addElements(); - - this.gui.build(); - this.gui.show((Player) this.user); - } - - /** - * Adds pre-programmed elements to the GUI - */ - private void addElements() { - this.useAlternateKeepalive('a'); - this.zombieAggressiveTowardsVillagerWhenLagging('b'); - this.entitiesCanUsePortals('c'); - this.villagerIsLobotomized('d'); - this.villagerSearchRadiusAcquirePoi('e'); - this.villagerSearchRadiusNearestBedSensor('f'); - this.dolphinDisableTreasureSearching('g'); - this.teleportIfOutsideBorder('h'); - this.laggingThreshold('i'); - - KOS_GuiConstants consts = new KOS_GuiConstants(this.plugin, this.gui); - consts.addConstants(); - } - - /** - * Determines where the elements should be positioned. - * @return String[] - The position of the elements. - */ - private String[] getElements() { - - return new String[]{ - "abcdefghi", - " ", - " w x y " - }; - } - - private void useAlternateKeepalive(char id) { - boolean value = this.purpur.getBoolean(Purpur.Key.USE_ALTERNATE_KEEPALIVE); - if (value) { - if (this.plugin.getConfig().getBoolean("using-tcpshield")) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.purpur.setBoolean(Purpur.Key.USE_ALTERNATE_KEEPALIVE, false); - this.show(); - return true; - }, - ChatColor.GOLD + "Use Alternate Keepalive", - ChatColor.YELLOW + "true", - ChatColor.YELLOW + "You've indicated that you're using TCPShield, this feature", - ChatColor.YELLOW + "has a known compatability issue and may not work correctly.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.purpur.setBoolean(Purpur.Key.USE_ALTERNATE_KEEPALIVE, false); - this.show(); - return true; - }, - ChatColor.DARK_GREEN + "Use Alternate Keepalive", - ChatColor.GREEN + "true", - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } else { - if (this.plugin.getConfig().getBoolean("using-tcpshield")) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.purpur.setBoolean(Purpur.Key.USE_ALTERNATE_KEEPALIVE, true); - this.show(); - return true; - }, - ChatColor.DARK_GREEN + "Use Alternate Keepalive", - ChatColor.GREEN + "false", - ChatColor.GREEN + "Ideal value.", - ChatColor.GREEN + "You've indicated that you're using TCPShield, this feature", - ChatColor.GREEN + "has a known compatability issue and may not work correctly.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.purpur.setBoolean(Purpur.Key.USE_ALTERNATE_KEEPALIVE, true); - this.show(); - return true; - }, - ChatColor.GOLD + "Use Alternate Keepalive", - ChatColor.YELLOW + "false", - ChatColor.YELLOW + "Impact to player experience.", - ChatColor.YELLOW + "Enabling this prevents players from timing out as often.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - } - - private void zombieAggressiveTowardsVillagerWhenLagging(char id) { - boolean value = this.purpur.getBoolean(Purpur.Key.ZOMBIE_AGGRESSIVE_TOWARDS_VILLAGER_WHEN_LAGGING); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.purpur.setBoolean(Purpur.Key.ZOMBIE_AGGRESSIVE_TOWARDS_VILLAGER_WHEN_LAGGING, false); - this.show(); - return true; - }, - ChatColor.GOLD + "Zombie Aggressive Towards Villager When Lagging", - ChatColor.YELLOW + "true", - ChatColor.YELLOW + "Impact to player experience - vanilla behaviour will be", - ChatColor.YELLOW + "lost if the server's TPS is below the lag threshold.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.purpur.setBoolean(Purpur.Key.ZOMBIE_AGGRESSIVE_TOWARDS_VILLAGER_WHEN_LAGGING, true); - this.show(); - return true; - }, - ChatColor.DARK_RED + "Zombie Aggressive Towards Villager When Lagging", - ChatColor.RED + "false", - ChatColor.RED + "Impact to performance.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void entitiesCanUsePortals(char id) { - boolean value = this.purpur.getBoolean(Purpur.Key.ENTITIES_CAN_USE_PORTALS); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.purpur.setBoolean(Purpur.Key.ENTITIES_CAN_USE_PORTALS, false); - this.show(); - return true; - }, - ChatColor.DARK_RED + "Entities can use Portals", - ChatColor.RED + "true", - ChatColor.RED + "Impact to performance.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.purpur.setBoolean(Purpur.Key.ENTITIES_CAN_USE_PORTALS, true); - this.show(); - return true; - }, - ChatColor.GOLD + "Entities can use Portals", - ChatColor.YELLOW + "false", - ChatColor.YELLOW + "Impact to player experience - entities can", - ChatColor.YELLOW + "not use portals.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void villagerIsLobotomized(char id) { - boolean value = this.purpur.getBoolean(Purpur.Key.VILLAGER_IS_LOBOTOMIZED); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.purpur.setBoolean(Purpur.Key.VILLAGER_IS_LOBOTOMIZED, false); - this.show(); - return true; - }, - ChatColor.DARK_RED + "Villagers are Lobotomized", - ChatColor.RED + "true", - ChatColor.RED + "Impact to performance - ONLY ENABLE THIS IF", - ChatColor.RED + "YOU'VE TRIED EVERYTHING ELSE TO REDUCE LAG.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.purpur.setBoolean(Purpur.Key.VILLAGER_IS_LOBOTOMIZED, true); - this.show(); - return true; - }, - ChatColor.GOLD + "Villagers are Lobotomized", - ChatColor.YELLOW + "false", - ChatColor.YELLOW + "Impact to player experience - villagers will have", - ChatColor.YELLOW + "no AI and not work as expected. ONLY ENABLE THIS", - ChatColor.YELLOW + "IF YOU'VE TRIED EVERYTHING ELSE TO REDUCE LAG.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void villagerSearchRadiusAcquirePoi(char id) { - int value = this.purpur.getInt(Purpur.Key.VILLAGER_SEARCH_RADIUS_ACQUIRE_POI); - if (value >= 16 && value <= 32) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Purpur.Key.VILLAGER_SEARCH_RADIUS_ACQUIRE_POI, click, value, false), - ChatColor.DARK_GREEN + "Villager Search Radius (Acquire POI)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 16) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Purpur.Key.VILLAGER_SEARCH_RADIUS_ACQUIRE_POI, click, value, false), - ChatColor.GOLD + "Villager Search Radius (Acquire POI)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Impact to player experience - villagers may", - ChatColor.YELLOW + "struggle to detect job sites or beds.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Purpur.Key.VILLAGER_SEARCH_RADIUS_ACQUIRE_POI, click, value, false), - ChatColor.DARK_RED + "Villager Search Radius (Acquire POI)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void villagerSearchRadiusNearestBedSensor(char id) { - int value = this.purpur.getInt(Purpur.Key.VILLAGER_SEARCH_RADIUS_NEAREST_BED_SENSOR); - if (value >= 16 && value <= 32) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Purpur.Key.VILLAGER_SEARCH_RADIUS_NEAREST_BED_SENSOR, click, value, false), - ChatColor.DARK_GREEN + "Villager Search Radius (Nearest Bed Sensor)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 16) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Purpur.Key.VILLAGER_SEARCH_RADIUS_NEAREST_BED_SENSOR, click, value, false), - ChatColor.GOLD + "Villager Search Radius (Nearest Bed Sensor)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Impact to player experience - villagers may", - ChatColor.YELLOW + "struggle to detect beds.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Purpur.Key.VILLAGER_SEARCH_RADIUS_NEAREST_BED_SENSOR, click, value, false), - ChatColor.DARK_RED + "Villager Search Radius (Nearest Bed Sensor)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void dolphinDisableTreasureSearching(char id) { - boolean value = this.purpur.getBoolean(Purpur.Key.DOLPHIN_DISABLE_TREASURE_SEARCHING); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.purpur.setBoolean(Purpur.Key.DOLPHIN_DISABLE_TREASURE_SEARCHING, false); - this.show(); - return true; - }, - ChatColor.GOLD + "Dolphin Disable Treasure Searching", - ChatColor.YELLOW + "true", - ChatColor.YELLOW + "Impact to player experience - dolphins won't", - ChatColor.YELLOW + "perform structure searches.", - ChatColor.YELLOW + "Only enable if you have pre-generated your world.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.purpur.setBoolean(Purpur.Key.DOLPHIN_DISABLE_TREASURE_SEARCHING, true); - this.show(); - return true; - }, - ChatColor.DARK_RED + "Dolphin Disable Treasure Searching", - ChatColor.RED + "false", - ChatColor.RED + "Impact to performance.", - ChatColor.RED + "Only enable if you have pre-generated your world.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void teleportIfOutsideBorder(char id) { - boolean value = this.purpur.getBoolean(Purpur.Key.TELEPORT_IF_OUTSIDE_BORDER); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.purpur.setBoolean(Purpur.Key.TELEPORT_IF_OUTSIDE_BORDER, false); - this.show(); - return true; - }, - ChatColor.DARK_GREEN + "Teleport if Outside Border", - ChatColor.GREEN + "true", - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.purpur.setBoolean(Purpur.Key.TELEPORT_IF_OUTSIDE_BORDER, true); - this.show(); - return true; - }, - ChatColor.GOLD + "Teleport if Outside Border", - ChatColor.YELLOW + "false", - ChatColor.YELLOW + "Impact to player experience - may allow for exploits.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void laggingThreshold(char id) { - int value = this.purpur.getInt(Purpur.Key.LAGGING_THRESHOLD); - if (value > 15 && value < 20) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Purpur.Key.LAGGING_THRESHOLD, click, value, false), - ChatColor.DARK_GREEN + "Lagging Threshold", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range - If player experience is", - ChatColor.GREEN + "being impacted you may wish to lower this.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value == 20) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Purpur.Key.LAGGING_THRESHOLD, click, value, false), - ChatColor.GOLD + "Lagging Threshold", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Impact to player experience - this may break a", - ChatColor.YELLOW + "number of in-game functions.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Purpur.Key.LAGGING_THRESHOLD, click, value, false), - ChatColor.DARK_RED + "Lagging Threshold", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too low - may cause more lag. If player experience is", - ChatColor.RED + "being impacted you may wish to lower this", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private boolean setInt(Purpur.Key key, GuiElement.Click click, int value, boolean canBeDefault) { - click.getGui().close(); - if (click.getType() == ClickType.RIGHT) { - this.purpur.setInt(key, value + 1); - } else if (click.getType() == ClickType.SHIFT_RIGHT) { - this.purpur.setInt(key, value + 10); - } else if (click.getType() == ClickType.LEFT && value != 0) { - this.purpur.setInt(key, value - 1); - } else if (click.getType() == ClickType.SHIFT_LEFT && value >= 10) { - this.purpur.setInt(key, value - 10); - } else if ((click.getType() == ClickType.LEFT || click.getType() == ClickType.SHIFT_LEFT) && value == 0 && canBeDefault) { - this.purpur.setString(key, "default"); - } - - this.show(); - return true; - } -} diff --git a/src/main/java/net/lewmc/kryptonite/report/Report.java b/src/main/java/net/lewmc/kryptonite/report/Report.java index 9bd7dd9..380393b 100644 --- a/src/main/java/net/lewmc/kryptonite/report/Report.java +++ b/src/main/java/net/lewmc/kryptonite/report/Report.java @@ -1,20 +1,17 @@ package net.lewmc.kryptonite.report; import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.kos.config.Bukkit; import net.lewmc.kryptonite.utils.MessageUtil; import net.lewmc.kryptonite.utils.SoftwareUtil; import org.bukkit.command.CommandSender; public class Report { private Kryptonite plugin; - private CommandSender user; private MessageUtil message; private SoftwareUtil softwareUtil; public void runReport(Kryptonite plugin, CommandSender user) { this.plugin = plugin; - this.user = user; this.message = new MessageUtil(user); this.softwareUtil = new SoftwareUtil(this.plugin); } @@ -28,10 +25,10 @@ private void runKOSReport() { if (this.softwareUtil.supportsCraftBukkit()) { message.Info("Reporting [2/7] Gathering Bukkit configuration."); - Bukkit bukkit = new Bukkit(this.plugin, this.user); - for (Bukkit.Key item : Bukkit.Key.values()) { + //Bukkit bukkit = new Bukkit(this.plugin, this.user); + //for (Bukkit.Key item : Bukkit.Key.values()) { - } + //} } else { message.Info("Reporting [2/7] Bukkit not supported, skipping..."); } diff --git a/src/main/java/net/lewmc/kryptonite/utils/SoftwareUtil.java b/src/main/java/net/lewmc/kryptonite/utils/SoftwareUtil.java index 1f840c8..51c3c95 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/SoftwareUtil.java +++ b/src/main/java/net/lewmc/kryptonite/utils/SoftwareUtil.java @@ -1,8 +1,8 @@ package net.lewmc.kryptonite.utils; import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.kos.config.Pufferfish; -import org.bukkit.command.CommandSender; +import net.lewmc.kryptonite.config.PufferfishConfig; +import net.lewmc.kryptonite.utils.config.BooleanConfigItem; public class SoftwareUtil { private final Kryptonite plugin; @@ -35,10 +35,9 @@ public boolean supportsPufferfish() { return this.plugin.SupportedConfigurations.contains(Kryptonite.ConfigurationOptions.PUFFERFISH); } - public boolean dabEnabled(CommandSender cs) { + public boolean dabEnabled() { if (this.supportsPufferfish()) { - Pufferfish pf = new Pufferfish(this.plugin, cs); - return pf.getBoolean(Pufferfish.Key.DAB_ENABLED); + return ((BooleanConfigItem)new PufferfishConfig(this.plugin).values.get(PufferfishConfig.Key.DAB_ENABLED.toString())).getValue(); } else { return false; } diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/ConfigCollection.java b/src/main/java/net/lewmc/kryptonite/utils/config/ConfigCollection.java index 6a54957..1f593dc 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/ConfigCollection.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/ConfigCollection.java @@ -1,6 +1,6 @@ package net.lewmc.kryptonite.utils.config; -import java.util.HashMap; +import java.util.LinkedHashMap; /** * Configuration data template for config files. @@ -10,5 +10,5 @@ public abstract class ConfigCollection { /** * Holds configuration data for the relevant file. */ - public HashMap values = new HashMap<>(); + public LinkedHashMap values = new LinkedHashMap<>(); } \ No newline at end of file diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java index d11466f..5831cc6 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java @@ -64,6 +64,10 @@ public abstract class GenericConfigItem { * @param plugin Kryptonite - Reference to the main Kryptonite class. */ public GenericConfigItem(String file, String key, String name, List description, Boolean dependencyIsEnabled, Kryptonite plugin) { + new Logger(plugin.foundryConfig).info("--------- "+name+" ---------"); + new Logger(plugin.foundryConfig).info("key: '"+key); + new Logger(plugin.foundryConfig).info("description: '"+description); + new Logger(plugin.foundryConfig).info("dependencyIsEnabled: '"+dependencyIsEnabled); this.file = file; this.key = key; this.name = name; From 229c7f984432d0317e49b3d81a2a2c9e46de43a3 Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Fri, 21 Nov 2025 12:49:30 +0000 Subject: [PATCH 19/21] Update system. --- .../java/net/lewmc/kryptonite/Kryptonite.java | 9 +- .../lewmc/kryptonite/config/BukkitConfig.java | 52 +- .../lewmc/kryptonite/config/SpigotConfig.java | 255 ++++++ .../net/lewmc/kryptonite/kos/AutoKOS.java | 46 +- .../lewmc/kryptonite/kos/config/Spigot.java | 186 ----- .../lewmc/kryptonite/kos/gui/KOS_AutoGUI.java | 4 +- .../kryptonite/kos/gui/KOS_SpigotGui_1.java | 757 ------------------ .../kryptonite/kos/gui/KOS_SpigotGui_2.java | 140 ---- .../kryptonite/utils/CompatablityUtil.java | 8 +- .../kryptonite/utils/ConfigurationUtil.java | 5 +- .../utils/config/GenericConfigItem.java | 4 - 11 files changed, 318 insertions(+), 1148 deletions(-) delete mode 100644 src/main/java/net/lewmc/kryptonite/kos/config/Spigot.java delete mode 100644 src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_1.java delete mode 100644 src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_2.java diff --git a/src/main/java/net/lewmc/kryptonite/Kryptonite.java b/src/main/java/net/lewmc/kryptonite/Kryptonite.java index e11d4b1..ab317ee 100644 --- a/src/main/java/net/lewmc/kryptonite/Kryptonite.java +++ b/src/main/java/net/lewmc/kryptonite/Kryptonite.java @@ -53,8 +53,7 @@ public void onEnable() { this.log.info("Beginning startup..."); this.log.info(""); - int pluginId = 21962; - new Metrics(this, pluginId); + new Metrics(this, 21962); this.initFilesystem(); this.loadCommands(); @@ -110,8 +109,7 @@ private void initFilesystem() { @Override public void onDisable() { - FoliaLib foliaLib = new FoliaLib(this); - foliaLib.getScheduler().cancelAllTasks(); + new FoliaLib(this).getScheduler().cancelAllTasks(); } /** @@ -179,8 +177,7 @@ private void checkSoftware() { } private void detectBadPlugins() { - CompatablityUtil compat = new CompatablityUtil(this); - List badPlugins = new java.util.ArrayList<>(compat.badPlugins()); + List badPlugins = new java.util.ArrayList<>(new CompatablityUtil(this).badPlugins()); for (String badPlugin : badPlugins) { this.log.severe(""); diff --git a/src/main/java/net/lewmc/kryptonite/config/BukkitConfig.java b/src/main/java/net/lewmc/kryptonite/config/BukkitConfig.java index 6b88d39..43f5ed4 100644 --- a/src/main/java/net/lewmc/kryptonite/config/BukkitConfig.java +++ b/src/main/java/net/lewmc/kryptonite/config/BukkitConfig.java @@ -18,9 +18,9 @@ public class BukkitConfig extends ConfigCollection { public BukkitConfig(Kryptonite plugin) { String file = "bukkit.yml"; - values.put("spawn-limits.monsters", new IntegerConfigItem( + values.put(Key.SPAWN_LIMITS_MONSTERS.toString(), new IntegerConfigItem( file, - "spawn-limits.monsters", + Key.SPAWN_LIMITS_MONSTERS.toString(), "Spawn Limit (Monsters)", List.of( "A limit for how many mobs should spawn in the world.", @@ -33,9 +33,9 @@ public BukkitConfig(Kryptonite plugin) { plugin )); - values.put("spawn-limits.animals", new IntegerConfigItem( + values.put(Key.SPAWN_LIMITS_ANIMALS.toString(), new IntegerConfigItem( file, - "spawn-limits.animals", + Key.SPAWN_LIMITS_ANIMALS.toString(), "Spawn Limit (Animals)", List.of( "A limit for how many animals should spawn in the", @@ -48,9 +48,9 @@ public BukkitConfig(Kryptonite plugin) { plugin )); - values.put("spawn-limits.water-animals", new IntegerConfigItem( + values.put(Key.SPAWN_LIMITS_WATER_ANIMALS.toString(), new IntegerConfigItem( file, - "spawn-limits.water-animals", + Key.SPAWN_LIMITS_WATER_ANIMALS.toString(), "Spawn Limit (Water Animals)", List.of( "A limit for how many water animals should spawn in", @@ -63,9 +63,9 @@ public BukkitConfig(Kryptonite plugin) { plugin )); - values.put("spawn-limits.water-ambient", new IntegerConfigItem( + values.put(Key.SPAWN_LIMITS_WATER_AMBIENT.toString(), new IntegerConfigItem( file, - "spawn-limits.water-ambient", + Key.SPAWN_LIMITS_WATER_AMBIENT.toString(), "Spawn Limit (Water Ambient)", List.of( "A limit for how many water ambient should spawn in", @@ -78,9 +78,9 @@ public BukkitConfig(Kryptonite plugin) { plugin )); - values.put("spawn-limits.water-underground-creature", new IntegerConfigItem( + values.put(Key.SPAWN_LIMITS_WATER_UNDERGROUND_CREATURE.toString(), new IntegerConfigItem( file, - "spawn-limits.water-underground-creature", + Key.SPAWN_LIMITS_WATER_UNDERGROUND_CREATURE.toString(), "Spawn Limit (Water Underground Creature)", List.of( "A limit for how many water underground creatures", @@ -94,9 +94,9 @@ public BukkitConfig(Kryptonite plugin) { plugin )); - values.put("spawn-limits.axolotls", new IntegerConfigItem( + values.put(Key.SPAWN_LIMITS_AXOLOTLS.toString(), new IntegerConfigItem( file, - "spawn-limits.axolotls", + Key.SPAWN_LIMITS_AXOLOTLS.toString(), "Spawn Limit (Axolotls)", List.of( "A limit for how many axolotls should spawn in the", @@ -109,9 +109,9 @@ public BukkitConfig(Kryptonite plugin) { plugin )); - values.put("ticks-per.monster-spawns", new IntegerConfigItem( + values.put(Key.TICKS_PER_MONSTER_SPAWNS.toString(), new IntegerConfigItem( file, - "ticks-per.monster-spawns", + Key.TICKS_PER_MONSTER_SPAWNS.toString(), "Ticks Per Monster Spawns", List.of( "How often (in ticks) the server attempts to spawn", @@ -124,9 +124,9 @@ public BukkitConfig(Kryptonite plugin) { plugin )); - values.put("ticks-per.animal-spawns", new IntegerConfigItem( + values.put(Key.TICKS_PER_ANIMAL_SPAWNS.toString(), new IntegerConfigItem( file, - "ticks-per.animal-spawns", + Key.TICKS_PER_ANIMAL_SPAWNS.toString(), "Ticks Per Animal Spawns", List.of( "How often (in ticks) the server attempts to spawn", @@ -139,9 +139,9 @@ public BukkitConfig(Kryptonite plugin) { plugin )); - values.put("ticks-per.water-spawns", new IntegerConfigItem( + values.put(Key.TICKS_PER_WATER_SPAWNS.toString(), new IntegerConfigItem( file, - "ticks-per.water-spawns", + Key.TICKS_PER_WATER_SPAWNS.toString(), "Ticks Per Water Spawns", List.of( "How often (in ticks) the server attempts to spawn", @@ -155,9 +155,9 @@ public BukkitConfig(Kryptonite plugin) { plugin )); - values.put("ticks-per.water-ambient-spawns", new IntegerConfigItem( + values.put(Key.TICKS_PER_WATER_AMBIENT_SPAWNS.toString(), new IntegerConfigItem( file, - "ticks-per.water-ambient-spawns", + Key.TICKS_PER_WATER_AMBIENT_SPAWNS.toString(), "Ticks Per Water Ambient Spawns", List.of( "How often (in ticks) the server attempts to spawn", @@ -171,9 +171,9 @@ public BukkitConfig(Kryptonite plugin) { plugin )); - values.put("ticks-per.axolotl-spawns", new IntegerConfigItem( + values.put(Key.TICKS_PER_AXOLOTL_SPAWNS.toString(), new IntegerConfigItem( file, - "ticks-per.axolotl-spawns", + Key.TICKS_PER_AXOLOTL_SPAWNS.toString(), "Ticks Per Axolotl Spawns", List.of( "How often (in ticks) the server attempts to spawn", @@ -186,9 +186,9 @@ public BukkitConfig(Kryptonite plugin) { plugin )); - values.put("ticks-per.ambient-spawns", new IntegerConfigItem( + values.put(Key.TICKS_PER_AMBIENT_SPAWNS.toString(), new IntegerConfigItem( file, - "ticks-per.ambient-spawns", + Key.TICKS_PER_AMBIENT_SPAWNS.toString(), "Ticks Per Ambient Spawns", List.of( "How often (in ticks) the server attempts to spawn", @@ -202,9 +202,9 @@ public BukkitConfig(Kryptonite plugin) { plugin )); - values.put("chunk-gc.period-in-ticks", new IntegerConfigItem( + values.put(Key.CHUNK_GC_PERIOD_IN_TICKS.toString(), new IntegerConfigItem( file, - "chunk-gc.period-in-ticks", + Key.CHUNK_GC_PERIOD_IN_TICKS.toString(), "Chunk GC Period in Ticks", List.of( "The ticks between each chunk garbage collection", diff --git a/src/main/java/net/lewmc/kryptonite/config/SpigotConfig.java b/src/main/java/net/lewmc/kryptonite/config/SpigotConfig.java index 80efed3..95432ad 100644 --- a/src/main/java/net/lewmc/kryptonite/config/SpigotConfig.java +++ b/src/main/java/net/lewmc/kryptonite/config/SpigotConfig.java @@ -1,7 +1,9 @@ package net.lewmc.kryptonite.config; import net.lewmc.kryptonite.Kryptonite; +import net.lewmc.kryptonite.utils.config.BooleanConfigItem; import net.lewmc.kryptonite.utils.config.ConfigCollection; +import net.lewmc.kryptonite.utils.config.IntegerConfigItem; import net.lewmc.kryptonite.utils.config.StringConfigItem; import java.util.List; @@ -18,6 +20,8 @@ public class SpigotConfig extends ConfigCollection { public SpigotConfig(Kryptonite plugin) { String file = "spigot.yml"; + int simulationDistance = ((int) new MinecraftConfig(plugin).values.get("simulation-distance").getValue() -1)*16; + values.put(Key.VIEW_DISTANCE.toString(), new StringConfigItem( file, Key.VIEW_DISTANCE.toString(), @@ -30,6 +34,257 @@ public SpigotConfig(Kryptonite plugin) { List.of("default"), plugin )); + + values.put(Key.MOB_SPAWN_RANGE.toString(), new IntegerConfigItem( + file, + Key.MOB_SPAWN_RANGE.toString(), + "Mob Spawn Range", + List.of("The distance the server will spawn mobs."), + true, + 1, + 100, + "3-8", + plugin + )); + + values.put(Key.MOB_SPAWN_RANGE.toString(), new IntegerConfigItem( + file, + Key.MOB_SPAWN_RANGE.toString(), + "Entity Activation Range (Mobs)", + List.of("The distance the server will 'activate' mob", + "entities."), + true, + 1, + 100, + "16-"+simulationDistance, + plugin + )); + + values.put(Key.ENTITY_ACTIVATION_RANGE_ANIMALS.toString(), new IntegerConfigItem( + file, + Key.ENTITY_ACTIVATION_RANGE_ANIMALS.toString(), + "Entity Activation Range (Animals)", + List.of("The distance the server will 'activate'", + "animal entities."), + true, + 1, + 100, + "16-"+simulationDistance, + plugin + )); + + values.put(Key.ENTITY_ACTIVATION_RANGE_MONSTERS.toString(), new IntegerConfigItem( + file, + Key.ENTITY_ACTIVATION_RANGE_MONSTERS.toString(), + "Entity Activation Range (Monsters)", + List.of("The distance the server will 'activate'", + "monster entities."), + true, + 1, + 100, + "16-"+simulationDistance, + plugin + )); + + values.put(Key.ENTITY_ACTIVATION_RANGE_RAIDERS.toString(), new IntegerConfigItem( + file, + Key.ENTITY_ACTIVATION_RANGE_RAIDERS.toString(), + "Entity Activation Range (Raiders)", + List.of("The distance the server will 'activate'", + "raider entities."), + true, + 1, + 100, + "16-"+simulationDistance, + plugin + )); + + values.put(Key.ENTITY_ACTIVATION_RANGE_MISC.toString(), new IntegerConfigItem( + file, + Key.ENTITY_ACTIVATION_RANGE_MISC.toString(), + "Entity Activation Range (Misc)", + List.of("The distance the server will 'activate'", + "miscellaneous entities."), + true, + 1, + 100, + "16-"+simulationDistance, + plugin + )); + + values.put(Key.ENTITY_ACTIVATION_RANGE_WATER.toString(), new IntegerConfigItem( + file, + Key.ENTITY_ACTIVATION_RANGE_WATER.toString(), + "Entity Activation Range (Water)", + List.of("The distance the server will 'activate'", + "water entities."), + true, + 1, + 100, + "16-"+simulationDistance, + plugin + )); + + values.put(Key.ENTITY_ACTIVATION_RANGE_VILLAGERS.toString(), new IntegerConfigItem( + file, + Key.ENTITY_ACTIVATION_RANGE_VILLAGERS.toString(), + "Entity Activation Range (Villagers)", + List.of("The distance the server will 'activate'", + "villager entities."), + true, + 1, + 100, + "16-"+simulationDistance, + plugin + )); + + values.put(Key.ENTITY_ACTIVATION_RANGE_FLYING_MONSTERS.toString(), new IntegerConfigItem( + file, + Key.ENTITY_ACTIVATION_RANGE_FLYING_MONSTERS.toString(), + "Entity Activation Range (Flying Monsters)", + List.of("The distance the server will 'activate' flying", + "monster entities."), + true, + 1, + 100, + "16-"+simulationDistance, + plugin + )); + + values.put(Key.ENTITY_TRACKING_RANGE_PLAYERS.toString(), new IntegerConfigItem( + file, + Key.ENTITY_TRACKING_RANGE_PLAYERS.toString(), + "Entity Tracking Range (Players)", + List.of("Controls how far in blocks players are tracked", + "(sent to) the player."), + true, + 1, + 100, + "6-"+simulationDistance, + plugin + )); + + values.put(Key.ENTITY_TRACKING_RANGE_ANIMALS.toString(), new IntegerConfigItem( + file, + Key.ENTITY_TRACKING_RANGE_ANIMALS.toString(), + "Entity Tracking Range (Animals)", + List.of("Controls how far in blocks animals are tracked", + "(sent to) the player."), + true, + 1, + 100, + "6-"+simulationDistance, + plugin + )); + + values.put(Key.ENTITY_TRACKING_RANGE_MONSTERS.toString(), new IntegerConfigItem( + file, + Key.ENTITY_TRACKING_RANGE_MONSTERS.toString(), + "Entity Tracking Range (Monsters)", + List.of("Controls how far in blocks monsters are tracked", + "(sent to) the player."), + true, + 1, + 100, + "6-"+simulationDistance, + plugin + )); + + values.put(Key.ENTITY_TRACKING_RANGE_MISC.toString(), new IntegerConfigItem( + file, + Key.ENTITY_TRACKING_RANGE_MISC.toString(), + "Entity Tracking Range (Miscellaneous)", + List.of("Controls how far in blocks miscellaneous entities", + "are tracked (sent to) the player."), + true, + 1, + 100, + "6-"+simulationDistance, + plugin + )); + + values.put(Key.ENTITY_TRACKING_RANGE_OTHER.toString(), new IntegerConfigItem( + file, + Key.ENTITY_TRACKING_RANGE_OTHER.toString(), + "Entity Tracking Range (Other)", + List.of("Controls how far in blocks other entities are", + "tracked (sent to) the player."), + true, + 1, + 100, + "6-"+simulationDistance, + plugin + )); + + values.put(Key.ENTITY_TRACKING_RANGE_DISPLAY.toString(), new IntegerConfigItem( + file, + Key.ENTITY_TRACKING_RANGE_DISPLAY.toString(), + "Entity Tracking Range (Display)", + List.of("Controls how far in blocks display entities are", + "tracked (sent to) the player."), + true, + 1, + 100, + "6-"+simulationDistance, + plugin + )); + + values.put(Key.TICK_INACTIVE_VILLAGERS.toString(), new BooleanConfigItem( + file, + Key.TICK_INACTIVE_VILLAGERS.toString(), + "Tick Inactive Villagers", + List.of("This allows you to control whether villagers should", + "be ticked outside of the activation range. This will", + "make villagers proceed as normal and ignore the", + "activation range. Disabling this will help performance,", + "but might be confusing for players in certain situations.", + "May cause issues with iron farms and trade restocking."), + true, + false, + plugin + )); + + values.put(Key.NERF_SPAWNER_MOBS.toString(), new BooleanConfigItem( + file, + Key.NERF_SPAWNER_MOBS.toString(), + "Nerf Spawner Mobs", + List.of("Removes AI from mobs created by spawners. Helps server", + "performance but greatly impacts vanilla experience."), + true, + true, + plugin + )); + + values.put(Key.TICKS_PER_HOPPER_TRANSFER.toString(), new IntegerConfigItem( + file, + Key.TICKS_PER_HOPPER_TRANSFER.toString(), + "Ticks per Hopper Transfer", + List.of("Time in ticks that hoppers will wait to move an item.", + "Increasing this improves performance if there are a lot", + "of hoppers on your server, but will break hopper-based", + "clocks and possibly item sorting systems if set too high."), + true, + 1, + 32, + "8", + plugin + )); + + values.put(Key.TICKS_PER_HOPPER_CHECK.toString(), new IntegerConfigItem( + file, + Key.TICKS_PER_HOPPER_CHECK.toString(), + "Ticks per Hopper Check", + List.of("Time in ticks between hoppers checking for an item above", + "them or in the inventory above them. Increasing this improves", + "performance if there are a lot of hoppers on your server, but", + "will break hopper-based clocks and possibly sorting systems", + "if set too high."), + true, + 1, + 32, + "8", + plugin + )); } /** diff --git a/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java b/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java index 7675acf..6d61d9d 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java +++ b/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java @@ -2,16 +2,14 @@ import net.lewmc.foundry.Logger; import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.config.BukkitConfig; -import net.lewmc.kryptonite.config.MinecraftConfig; -import net.lewmc.kryptonite.config.PufferfishConfig; -import net.lewmc.kryptonite.config.PurpurConfig; +import net.lewmc.kryptonite.config.*; import net.lewmc.kryptonite.kos.config.*; import net.lewmc.kryptonite.utils.ConfigurationUtil; import net.lewmc.kryptonite.utils.MessageUtil; import net.lewmc.kryptonite.utils.SoftwareUtil; import net.lewmc.kryptonite.utils.config.BooleanConfigItem; import net.lewmc.kryptonite.utils.config.IntegerConfigItem; +import net.lewmc.kryptonite.utils.config.StringConfigItem; import org.bukkit.command.CommandSender; import java.io.File; @@ -133,26 +131,26 @@ private void runSpigot() { if (this.softwareUtil.supportsSpigot()) { this.log.info("[KOS] 3/6 - Running Spigot optimisations"); - Spigot spigot = new Spigot(this.plugin, this.user); - - spigot.setString(Spigot.Key.VIEW_DISTANCE, this.patches.getString("spigot.view-distance")); - spigot.setInt(Spigot.Key.MOB_SPAWN_RANGE, this.patches.getInt("spigot.mob-spawn-range")); - spigot.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_ANIMALS, this.patches.getInt("spigot.entities.activation-range.animals")); - spigot.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_MONSTERS, this.patches.getInt("spigot.entities.activation-range.monsters")); - spigot.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_RAIDERS, this.patches.getInt("spigot.entities.activation-range.raiders")); - spigot.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_MISC, this.patches.getInt("spigot.entities.activation-range.misc")); - spigot.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_WATER, this.patches.getInt("spigot.entities.activation-range.water")); - spigot.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_VILLAGERS, this.patches.getInt("spigot.entities.activation-range.villagers")); - spigot.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_FLYING_MONSTERS, this.patches.getInt("spigot.entities.activation-range.flying")); - spigot.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_PLAYERS, this.patches.getInt("spigot.entities.tracking-range.players")); - spigot.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_ANIMALS, this.patches.getInt("spigot.entities.tracking-range.animals")); - spigot.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_MONSTERS, this.patches.getInt("spigot.entities.tracking-range.monsters")); - spigot.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_MISC, this.patches.getInt("spigot.entities.tracking-range.misc")); - spigot.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_OTHER, this.patches.getInt("spigot.entities.tracking-range.other")); - spigot.setBoolean(Spigot.Key.TICK_INACTIVE_VILLAGERS, this.patches.getBoolean("spigot.entities.tick-inactive-villagers")); - spigot.setBoolean(Spigot.Key.NERF_SPAWNER_MOBS, this.patches.getBoolean("spigot.entities.spawner-mobs-nerfed")); - spigot.setInt(Spigot.Key.TICKS_PER_HOPPER_TRANSFER, this.patches.getInt("spigot.hopper.transfer")); - spigot.setInt(Spigot.Key.TICKS_PER_HOPPER_CHECK, this.patches.getInt("spigot.hopper.check")); + SpigotConfig spigot = new SpigotConfig(this.plugin); + + ((StringConfigItem)spigot.values.get(SpigotConfig.Key.VIEW_DISTANCE.toString())).setValue(this.patches.getString("spigot.view-distance")); + ((IntegerConfigItem)spigot.values.get(SpigotConfig.Key.MOB_SPAWN_RANGE.toString())).setValue(this.patches.getInt("spigot.mob-spawn-range")); + ((IntegerConfigItem)spigot.values.get(SpigotConfig.Key.ENTITY_ACTIVATION_RANGE_ANIMALS.toString())).setValue(this.patches.getInt("spigot.entities.activation-range.animals")); + ((IntegerConfigItem)spigot.values.get(SpigotConfig.Key.ENTITY_ACTIVATION_RANGE_MONSTERS.toString())).setValue(this.patches.getInt("spigot.entities.activation-range.monsters")); + ((IntegerConfigItem)spigot.values.get(SpigotConfig.Key.ENTITY_ACTIVATION_RANGE_RAIDERS.toString())).setValue(this.patches.getInt("spigot.entities.activation-range.raiders")); + ((IntegerConfigItem)spigot.values.get(SpigotConfig.Key.ENTITY_ACTIVATION_RANGE_MISC.toString())).setValue(this.patches.getInt("spigot.entities.activation-range.misc")); + ((IntegerConfigItem)spigot.values.get(SpigotConfig.Key.ENTITY_ACTIVATION_RANGE_WATER.toString())).setValue(this.patches.getInt("spigot.entities.activation-range.water")); + ((IntegerConfigItem)spigot.values.get(SpigotConfig.Key.ENTITY_ACTIVATION_RANGE_VILLAGERS.toString())).setValue(this.patches.getInt("spigot.entities.activation-range.villagers")); + ((IntegerConfigItem)spigot.values.get(SpigotConfig.Key.ENTITY_ACTIVATION_RANGE_FLYING_MONSTERS.toString())).setValue(this.patches.getInt("spigot.entities.activation-range.flying")); + ((IntegerConfigItem)spigot.values.get(SpigotConfig.Key.ENTITY_TRACKING_RANGE_PLAYERS.toString())).setValue(this.patches.getInt("spigot.entities.tracking-range.players")); + ((IntegerConfigItem)spigot.values.get(SpigotConfig.Key.ENTITY_TRACKING_RANGE_ANIMALS.toString())).setValue(this.patches.getInt("spigot.entities.tracking-range.animals")); + ((IntegerConfigItem)spigot.values.get(SpigotConfig.Key.ENTITY_TRACKING_RANGE_MONSTERS.toString())).setValue(this.patches.getInt("spigot.entities.tracking-range.monsters")); + ((IntegerConfigItem)spigot.values.get(SpigotConfig.Key.ENTITY_TRACKING_RANGE_MISC.toString())).setValue(this.patches.getInt("spigot.entities.tracking-range.misc")); + ((IntegerConfigItem)spigot.values.get(SpigotConfig.Key.ENTITY_TRACKING_RANGE_OTHER.toString())).setValue(this.patches.getInt("spigot.entities.tracking-range.other")); + ((BooleanConfigItem)spigot.values.get(SpigotConfig.Key.TICK_INACTIVE_VILLAGERS.toString())).setValue(this.patches.getBoolean("spigot.entities.tick-inactive-villagers")); + ((BooleanConfigItem)spigot.values.get(SpigotConfig.Key.NERF_SPAWNER_MOBS.toString())).setValue(this.patches.getBoolean("spigot.entities.spawner-mobs-nerfed")); + ((IntegerConfigItem)spigot.values.get(SpigotConfig.Key.TICKS_PER_HOPPER_TRANSFER.toString())).setValue(this.patches.getInt("spigot.hopper.transfer")); + ((IntegerConfigItem)spigot.values.get(SpigotConfig.Key.TICKS_PER_HOPPER_CHECK.toString())).setValue(this.patches.getInt("spigot.hopper.check")); } else { log.info("[KOS] 3/6 - Server does not support Spigot configurations, skipping..."); } diff --git a/src/main/java/net/lewmc/kryptonite/kos/config/Spigot.java b/src/main/java/net/lewmc/kryptonite/kos/config/Spigot.java deleted file mode 100644 index b622c95..0000000 --- a/src/main/java/net/lewmc/kryptonite/kos/config/Spigot.java +++ /dev/null @@ -1,186 +0,0 @@ -package net.lewmc.kryptonite.kos.config; - -import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.utils.ConfigurationUtil; -import net.lewmc.kryptonite.utils.LogUtil; -import org.bukkit.command.CommandSender; - -/** - * The Spigot class manages the spigot.yml configuration file. - * @deprecated - */ -@Deprecated -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"; } - }, - ENTITY_TRACKING_RANGE_DISPLAY { - @Override - public String toString() { return "world-settings.default.entity-tracking-range.display"; } - }, - 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"; } - }, - 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(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(); - - LogUtil log = new LogUtil(this.plugin); - log.veboseInfo("KOS>spigot.yml set '" + key + "' to '" + value + "'"); - } - - /** - * Gets a requested key's value. - * @param key Key - The requested key. - */ - public int getInt(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(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(); - - LogUtil log = new LogUtil(this.plugin); - log.veboseInfo("KOS>spigot.yml set '" + key + "' to '" + value + "'"); - } - - /** - * Gets a requested key's value. - * @param key Key - The requested key. - */ - public boolean getBoolean(Key key) { - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("spigot.yml"); - return cfg.getBoolean(key.toString()); - } - - /** - * Sets a requested key to a requested value. - * @param key Key - The requested key. - * @param value int - The requested value. - */ - public void setString(Key key, String value) { - this.plugin.restartRequired = true; - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("spigot.yml"); - cfg.set(key.toString(), value); - cfg.save(); - - LogUtil log = new LogUtil(this.plugin); - log.veboseInfo("KOS>spigot.yml set '" + key + "' to '" + value + "'"); - } - - /** - * Gets a requested key's value. - * @param key Key - The requested key. - */ - public Object getObject(Key key) { - ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, this.user); - cfg.load("spigot.yml"); - return cfg.get(key.toString()); - } -} diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_AutoGUI.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_AutoGUI.java index 70bb98e..b26cecd 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_AutoGUI.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_AutoGUI.java @@ -2,10 +2,10 @@ import de.themoep.inventorygui.InventoryGui; import de.themoep.inventorygui.StaticGuiElement; +import net.lewmc.foundry.Logger; import net.lewmc.kryptonite.Kryptonite; import net.lewmc.kryptonite.kos.AutoKOS; import net.lewmc.kryptonite.utils.ConfigurationUtil; -import net.lewmc.kryptonite.utils.LogUtil; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.CommandSender; @@ -50,7 +50,7 @@ public void show() { * Adds pre-programmed elements to the GUI */ private void addElements() { - LogUtil log = new LogUtil(this.plugin); + Logger log = new Logger(this.plugin.foundryConfig); File folder = new File(this.plugin.getDataFolder(), "profiles"); diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_1.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_1.java deleted file mode 100644 index 9675b4f..0000000 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_1.java +++ /dev/null @@ -1,757 +0,0 @@ -package net.lewmc.kryptonite.kos.gui; - -import de.themoep.inventorygui.GuiElement; -import de.themoep.inventorygui.InventoryGui; -import de.themoep.inventorygui.StaticGuiElement; -import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.config.MinecraftConfig; -import net.lewmc.kryptonite.kos.config.Spigot; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; - -/** - * KOS Spigot GUI (Page 1/2) - * @deprecated - */ -@Deprecated -public class KOS_SpigotGui_1 { - private final Kryptonite plugin; - private final CommandSender user; - private final int simulationDistance; - private InventoryGui gui; - private final Spigot spigot; - - /** - * Constructor for the KOS Spigot GUI (Page 1/2) - * @param plugin Kryptonite - Reference to the main plugin class. - * @param user CommandSender - The user who sent the command. - */ - public KOS_SpigotGui_1(Kryptonite plugin, CommandSender user) { - this.plugin = plugin; - this.user = user; - this.simulationDistance = ((int) new MinecraftConfig(plugin).values.get("simulation-distance").getValue() -1)*16; - - this.spigot = new Spigot(plugin, user); - } - - /** - * Shows the KOS Spigot GUI (Page 1/2) - */ - public void show() { - InventoryHolder holder = this.user.getServer().getPlayer(this.user.getName()); - this.gui = new InventoryGui(this.plugin, holder, "KOS - Spigot Configuration (1/2)", this.getElements()); - this.addElements(); - - this.gui.build(); - this.gui.show((Player) this.user); - } - - /** - * Adds pre-programmed elements to the GUI - */ - private void addElements() { - this.viewDistance('a'); - this.mobSpawnRange('b'); - this.entityActivationRangeAnimals('c'); - this.entityActivationRangeMonsters('d'); - this.entityActivationRangeRaiders('e'); - this.entityActivationRangeMisc('f'); - this.entityActivationRangeWater('g'); - this.entityActivationRangeVillagers('h'); - this.entityActivationRangeFlyingMonsters('i'); - this.entityTrackingRangePlayers('j'); - this.entityTrackingRangeAnimals('k'); - this.entityTrackingRangeMonsters('l'); - this.entityTrackingRangeMisc('m'); - this.entityTrackingRangeOther('n'); - this.entityTrackingRangeDisplay('o'); - this.tickInactiveVillagers('p'); - this.nerfSpawnerMobs('q'); - this.ticksPerHopperTransfer('r'); - - KOS_GuiConstants consts = new KOS_GuiConstants(this.plugin, this.gui); - consts.addConstants(); - - this.gui.addElement(new StaticGuiElement('z', - new ItemStack(Material.OAK_SIGN), - 1, - click -> { - click.getGui().close(); - KOS_SpigotGui_2 spigotGui2 = new KOS_SpigotGui_2(this.plugin, this.user); - spigotGui2.show(); - return true; - }, - ChatColor.WHITE + "Next page" - )); - } - - /** - * Determines where the elements should be positioned. - * @return String[] - The position of the elements. - */ - private String[] getElements() { - - return new String[]{ - "abcdefghi", - "jklmnopqr", - " w x y z" - }; - } - - private void viewDistance(char id) { - Object value = this.spigot.getObject(Spigot.Key.VIEW_DISTANCE); - if (value instanceof String) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.VIEW_DISTANCE, click, 0, true), - ChatColor.DARK_GREEN + "View Distance", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Ideal.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value instanceof Integer) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.WHITE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.VIEW_DISTANCE, click, (int) value, true), - ChatColor.WHITE + "View Distance", - ChatColor.GRAY + String.valueOf(value), - ChatColor.GRAY + "This value is ambiguous with other configuration options.", - ChatColor.GRAY + "Recommended value is default (lowest value), and manage.", - ChatColor.GRAY + "through the Server configuration menu instead.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.BARRIER), - 1, - click -> true, - ChatColor.DARK_RED + "Spawn Limit (Monsters)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Kryptonite cannot recognise this value, and therefore cannot edit it.", - ChatColor.RED + "Please send a screenshot of this error to github.com/lewmc/kryptonite" - )); - } - } - - private void mobSpawnRange(char id) { - int value = this.spigot.getInt(Spigot.Key.MOB_SPAWN_RANGE); - if (value >= 3 && value <= 8) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.MOB_SPAWN_RANGE, click, value, false), - ChatColor.DARK_GREEN + "Mob Spawn Range", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 3) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.MOB_SPAWN_RANGE, click, value, false), - ChatColor.GOLD + "Mob Spawn Range", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.MOB_SPAWN_RANGE, click, value, false), - ChatColor.DARK_RED + "Mob Spawn Range", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityActivationRangeAnimals(char id) { - int value = this.spigot.getInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_ANIMALS); - if (value >= 16 && value <= simulationDistance) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_ANIMALS, click, value, false), - ChatColor.DARK_GREEN + "Entity Activation Range (Animals)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 16) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_ANIMALS, click, value, false), - ChatColor.GOLD + "Entity Activation Range (Animals)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_ANIMALS, click, value, false), - ChatColor.DARK_RED + "Entity Activation Range (Animals)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityActivationRangeMonsters(char id) { - int value = this.spigot.getInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_MONSTERS); - if (value >= 16 && value <= simulationDistance) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_MONSTERS, click, value, false), - ChatColor.DARK_GREEN + "Entity Activation Range (Monsters)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 16) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_MONSTERS, click, value, false), - ChatColor.GOLD + "Entity Activation Range (Monsters)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_MONSTERS, click, value, false), - ChatColor.DARK_RED + "Entity Activation Range (Monsters)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityActivationRangeRaiders(char id) { - int value = this.spigot.getInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_RAIDERS); - if (value >= 16 && value <= simulationDistance) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_RAIDERS, click, value, false), - ChatColor.DARK_GREEN + "Entity Activation Range (Raiders)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 16) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_RAIDERS, click, value, false), - ChatColor.GOLD + "Entity Activation Range (Raiders)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_RAIDERS, click, value, false), - ChatColor.DARK_RED + "Entity Activation Range (Raiders)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityActivationRangeMisc(char id) { - int value = this.spigot.getInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_MISC); - if (value >= 16 && value <= simulationDistance) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_MISC, click, value, false), - ChatColor.DARK_GREEN + "Entity Activation Range (Misc)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 16) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_MISC, click, value, false), - ChatColor.GOLD + "Entity Activation Range (Misc)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_MISC, click, value, false), - ChatColor.DARK_RED + "Entity Activation Range (Misc)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityActivationRangeWater(char id) { - int value = this.spigot.getInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_WATER); - if (value >= 16 && value <= simulationDistance) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_WATER, click, value, false), - ChatColor.DARK_GREEN + "Entity Activation Range (Water)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 16) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_WATER, click, value, false), - ChatColor.GOLD + "Entity Activation Range (Water)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_WATER, click, value, false), - ChatColor.DARK_RED + "Entity Activation Range (Water)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityActivationRangeVillagers(char id) { - int value = this.spigot.getInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_VILLAGERS); - if (value >= 16 && value <= simulationDistance) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_VILLAGERS, click, value, false), - ChatColor.DARK_GREEN + "Entity Activation Range (Villagers)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 16) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_VILLAGERS, click, value, false), - ChatColor.GOLD + "Entity Activation Range (Villagers)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_VILLAGERS, click, value, false), - ChatColor.DARK_RED + "Entity Activation Range (Villagers)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityActivationRangeFlyingMonsters(char id) { - int value = this.spigot.getInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_FLYING_MONSTERS); - if (value >= 16 && value <= simulationDistance) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_FLYING_MONSTERS, click, value, false), - ChatColor.DARK_GREEN + "Entity Activation Range (Flying Monsters)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 16) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_FLYING_MONSTERS, click, value, false), - ChatColor.GOLD + "Entity Activation Range (Flying Monsters)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_ACTIVATION_RANGE_FLYING_MONSTERS, click, value, false), - ChatColor.DARK_RED + "Entity Activation Range (Flying Monsters)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityTrackingRangePlayers(char id) { - int value = this.spigot.getInt(Spigot.Key.ENTITY_TRACKING_RANGE_PLAYERS); - if (value >= 6 && value <= simulationDistance) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_PLAYERS, click, value, false), - ChatColor.DARK_GREEN + "Entity Tracking Range (Players)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 6) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_PLAYERS, click, value, false), - ChatColor.GOLD + "Entity Tracking Range (Players)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_PLAYERS, click, value, false), - ChatColor.DARK_RED + "Entity Tracking Range (Players)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityTrackingRangeAnimals(char id) { - int value = this.spigot.getInt(Spigot.Key.ENTITY_TRACKING_RANGE_ANIMALS); - if (value >= 6 && value <= simulationDistance) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_ANIMALS, click, value, false), - ChatColor.DARK_GREEN + "Entity Tracking Range (Animals)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 6) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_ANIMALS, click, value, false), - ChatColor.GOLD + "Entity Tracking Range (Animals)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_ANIMALS, click, value, false), - ChatColor.DARK_RED + "Entity Tracking Range (Animals)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityTrackingRangeMonsters(char id) { - int value = this.spigot.getInt(Spigot.Key.ENTITY_TRACKING_RANGE_MONSTERS); - if (value >= 6 && value <= simulationDistance) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_MONSTERS, click, value, false), - ChatColor.DARK_GREEN + "Entity Tracking Range (Monsters)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 6) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_MONSTERS, click, value, false), - ChatColor.GOLD + "Entity Tracking Range (Monsters)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_MONSTERS, click, value, false), - ChatColor.DARK_RED + "Entity Tracking Range (Monsters)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityTrackingRangeMisc(char id) { - int value = this.spigot.getInt(Spigot.Key.ENTITY_TRACKING_RANGE_MISC); - if (value >= 6 && value <= simulationDistance) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_MISC, click, value, false), - ChatColor.DARK_GREEN + "Entity Tracking Range (Misc)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 6) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_MISC, click, value, false), - ChatColor.GOLD + "Entity Tracking Range (Misc)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_MISC, click, value, false), - ChatColor.DARK_RED + "Entity Tracking Range (Misc)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityTrackingRangeOther(char id) { - int value = this.spigot.getInt(Spigot.Key.ENTITY_TRACKING_RANGE_OTHER); - if (value >= 6 && value <= simulationDistance) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_OTHER, click, value, false), - ChatColor.DARK_GREEN + "Entity Tracking Range (Other)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 6) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_OTHER, click, value, false), - ChatColor.GOLD + "Entity Tracking Range (Other)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_OTHER, click, value, false), - ChatColor.DARK_RED + "Entity Tracking Range (Other)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityTrackingRangeDisplay(char id) { - int value = this.spigot.getInt(Spigot.Key.ENTITY_TRACKING_RANGE_DISPLAY); - if (value >= 6 && value <= simulationDistance) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_DISPLAY, click, value, false), - ChatColor.DARK_GREEN + "Entity Tracking Range (Display)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value < 6) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_DISPLAY, click, value, false), - ChatColor.GOLD + "Entity Tracking Range (Display)", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too low - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_DISPLAY, click, value, false), - ChatColor.DARK_RED + "Entity Tracking Range (Display)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void tickInactiveVillagers(char id) { - boolean value = this.spigot.getBoolean(Spigot.Key.TICK_INACTIVE_VILLAGERS); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.spigot.setBoolean(Spigot.Key.TICK_INACTIVE_VILLAGERS, false); - this.show(); - return true; - }, - ChatColor.DARK_RED + "Tick Inactive Villagers", - ChatColor.RED + "true", - ChatColor.RED + "Impact to performance.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.spigot.setBoolean(Spigot.Key.TICK_INACTIVE_VILLAGERS, true); - this.show(); - return true; - }, - ChatColor.GOLD + "Tick Inactive Villagers", - ChatColor.YELLOW + "false", - ChatColor.YELLOW + "Impact to player experience - villagers and iron farms", - ChatColor.YELLOW + "may not work as expected without players nearby.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void nerfSpawnerMobs(char id) { - boolean value = this.spigot.getBoolean(Spigot.Key.NERF_SPAWNER_MOBS); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.spigot.setBoolean(Spigot.Key.NERF_SPAWNER_MOBS, false); - this.show(); - return true; - }, - ChatColor.GOLD + "Nerf Spawner Mobs", - ChatColor.YELLOW + "false", - ChatColor.YELLOW + "Impact to player experience - mobs spawned by", - ChatColor.YELLOW + "spawners will have no AI and do nothing.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.spigot.setBoolean(Spigot.Key.NERF_SPAWNER_MOBS, true); - this.show(); - return true; - }, - ChatColor.DARK_RED + "Nerf Spawner Mobs", - ChatColor.RED + "true", - ChatColor.RED + "Impact to performance if players can move spawners.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void ticksPerHopperTransfer(char id) { - int value = this.spigot.getInt(Spigot.Key.TICKS_PER_HOPPER_TRANSFER); - if (value == 8) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.TICKS_PER_HOPPER_TRANSFER, click, value, false), - ChatColor.DARK_GREEN + "Ticks per Hopper Transfer", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value > 8) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.TICKS_PER_HOPPER_TRANSFER, click, value, false), - ChatColor.GOLD + "Ticks per Hopper Transfer", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too high - impact to player experience.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.ENTITY_TRACKING_RANGE_DISPLAY, click, value, false), - ChatColor.DARK_RED + "Ticks per Hopper Transfer", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too low - impact to performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private boolean setInt(Spigot.Key key, GuiElement.Click click, int value, boolean canBeDefault) { - click.getGui().close(); - if (click.getType() == ClickType.RIGHT) { - this.spigot.setInt(key, value + 1); - } else if (click.getType() == ClickType.SHIFT_RIGHT) { - this.spigot.setInt(key, value + 10); - } else if (click.getType() == ClickType.LEFT && value != 0) { - this.spigot.setInt(key, value - 1); - } else if (click.getType() == ClickType.SHIFT_LEFT && value >= 10) { - this.spigot.setInt(key, value - 10); - } else if ((click.getType() == ClickType.LEFT || click.getType() == ClickType.SHIFT_LEFT) && value == 0 && canBeDefault) { - this.spigot.setString(key, "default"); - } - - this.show(); - return true; - } -} diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_2.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_2.java deleted file mode 100644 index 08d1c9b..0000000 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_SpigotGui_2.java +++ /dev/null @@ -1,140 +0,0 @@ -package net.lewmc.kryptonite.kos.gui; - -import de.themoep.inventorygui.GuiElement; -import de.themoep.inventorygui.InventoryGui; -import de.themoep.inventorygui.StaticGuiElement; -import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.kos.config.Spigot; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; - -/** - * KOS Spigot GUI (Page 2/2) - * @deprecated - */ -@Deprecated -public class KOS_SpigotGui_2 { - private final Kryptonite plugin; - private final CommandSender user; - private InventoryGui gui; - private final Spigot spigot; - - /** - * Constructor for the KOS Spigot GUI (Page 2/2) - * @param plugin Kryptonite - Reference to the main plugin class. - * @param user CommandSender - The user who sent the command. - */ - public KOS_SpigotGui_2(Kryptonite plugin, CommandSender user) { - this.plugin = plugin; - this.user = user; - - this.spigot = new Spigot(plugin, user); - } - - /** - * Shows the KOS Spigot GUI (Page 2/2) - */ - public void show() { - InventoryHolder holder = this.user.getServer().getPlayer(this.user.getName()); - this.gui = new InventoryGui(this.plugin, holder, "KOS - Spigot Configuration (2/2)", this.getElements()); - this.addElements(); - - this.gui.build(); - this.gui.show((Player) this.user); - } - - /** - * Adds pre-programmed elements to the GUI - */ - private void addElements() { - this.ticksPerHopperCheck('a'); - - KOS_GuiConstants consts = new KOS_GuiConstants(this.plugin, this.gui); - consts.addConstants(); - - this.gui.addElement(new StaticGuiElement('v', - new ItemStack(Material.OAK_SIGN), - 1, - click -> { - click.getGui().close(); - KOS_SpigotGui_1 spigotGui1 = new KOS_SpigotGui_1(this.plugin, this.user); - spigotGui1.show(); - return true; - }, - ChatColor.WHITE + "Previous page" - )); - } - - /** - * Determines where the elements should be positioned. - * @return String[] - The position of the elements. - */ - private String[] getElements() { - - return new String[]{ - "a ", - " ", - "v w x y " - }; - } - - private void ticksPerHopperCheck(char id) { - int value = this.spigot.getInt(Spigot.Key.TICKS_PER_HOPPER_CHECK); - if (value == 8) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.TICKS_PER_HOPPER_CHECK, click, value, false), - ChatColor.DARK_GREEN + "Ticks per Hopper Check", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value > 8) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.ORANGE_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.TICKS_PER_HOPPER_CHECK, click, value, false), - ChatColor.GOLD + "Ticks per Hopper Check", - ChatColor.YELLOW + String.valueOf(value), - ChatColor.YELLOW + "Too high - impact to player experience.", - ChatColor.YELLOW + "Hopper-based clocks and item sorting systems may break.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(Spigot.Key.TICKS_PER_HOPPER_CHECK, click, value, false), - ChatColor.DARK_RED + "Ticks per Hopper Check", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too low - impact to performance.", - ChatColor.RED + "Hopper-based clocks and item sorting systems may also break.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private boolean setInt(Spigot.Key key, GuiElement.Click click, int value, boolean canBeDefault) { - click.getGui().close(); - if (click.getType() == ClickType.RIGHT) { - this.spigot.setInt(key, value + 1); - } else if (click.getType() == ClickType.SHIFT_RIGHT) { - this.spigot.setInt(key, value + 10); - } else if (click.getType() == ClickType.LEFT && value != 0) { - this.spigot.setInt(key, value - 1); - } else if (click.getType() == ClickType.SHIFT_LEFT && value >= 10) { - this.spigot.setInt(key, value - 10); - } else if ((click.getType() == ClickType.LEFT || click.getType() == ClickType.SHIFT_LEFT) && value == 0 && canBeDefault) { - this.spigot.setString(key, "default"); - } - - this.show(); - return true; - } -} diff --git a/src/main/java/net/lewmc/kryptonite/utils/CompatablityUtil.java b/src/main/java/net/lewmc/kryptonite/utils/CompatablityUtil.java index 240865d..98e3cd6 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/CompatablityUtil.java +++ b/src/main/java/net/lewmc/kryptonite/utils/CompatablityUtil.java @@ -26,7 +26,13 @@ public List badPlugins() { p.getName().equalsIgnoreCase("PluginManager") || p.getName().equalsIgnoreCase("AutoPluginLoader") || p.getName().equalsIgnoreCase("PlugMan") || - p.getName().equalsIgnoreCase("PlugManX") + p.getName().equalsIgnoreCase("PlugManX") || + p.getName().equalsIgnoreCase("WildStacker") || + p.getName().equalsIgnoreCase("FarmLimiter") || + p.getName().equalsIgnoreCase("ChunkSpawnerLimiter") || + p.getName().equalsIgnoreCase("AntiLagX") || + p.getName().equalsIgnoreCase("WildTools") || + p.getName().equalsIgnoreCase("AutoClear") ) { badPlugins.add(p.getName()); } diff --git a/src/main/java/net/lewmc/kryptonite/utils/ConfigurationUtil.java b/src/main/java/net/lewmc/kryptonite/utils/ConfigurationUtil.java index 423ec6f..ba6417d 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/ConfigurationUtil.java +++ b/src/main/java/net/lewmc/kryptonite/utils/ConfigurationUtil.java @@ -1,5 +1,6 @@ package net.lewmc.kryptonite.utils; +import net.lewmc.foundry.Logger; import net.lewmc.kryptonite.Kryptonite; import org.bukkit.command.CommandSender; import org.bukkit.configuration.InvalidConfigurationException; @@ -12,7 +13,7 @@ */ public class ConfigurationUtil { private final MessageUtil message; - private final LogUtil log; + private final Logger log; private YamlConfiguration config; private String path; @@ -23,7 +24,7 @@ public class ConfigurationUtil { */ public ConfigurationUtil(Kryptonite plugin, CommandSender user) { this.message = new MessageUtil(user); - this.log = new LogUtil(plugin); + this.log = new Logger(plugin.foundryConfig); } /** diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java index 5831cc6..d11466f 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/GenericConfigItem.java @@ -64,10 +64,6 @@ public abstract class GenericConfigItem { * @param plugin Kryptonite - Reference to the main Kryptonite class. */ public GenericConfigItem(String file, String key, String name, List description, Boolean dependencyIsEnabled, Kryptonite plugin) { - new Logger(plugin.foundryConfig).info("--------- "+name+" ---------"); - new Logger(plugin.foundryConfig).info("key: '"+key); - new Logger(plugin.foundryConfig).info("description: '"+description); - new Logger(plugin.foundryConfig).info("dependencyIsEnabled: '"+dependencyIsEnabled); this.file = file; this.key = key; this.name = name; From 822222179ac7c8b3dc1a497e13b91aec05051939 Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Fri, 21 Nov 2025 13:05:03 +0000 Subject: [PATCH 20/21] +leaf support --- .../lewmc/kryptonite/config/LeafConfig.java | 150 +++++++++++++----- 1 file changed, 114 insertions(+), 36 deletions(-) diff --git a/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java index 7f8f5fd..e53a98f 100644 --- a/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java +++ b/src/main/java/net/lewmc/kryptonite/config/LeafConfig.java @@ -18,9 +18,9 @@ public class LeafConfig extends ConfigCollection { public LeafConfig(Kryptonite plugin) { String file = "config" + File.separator + "leaf-global.yml"; - values.put("async.parallel-world-ticking.enabled", new BooleanConfigItem( + values.put(Key.ASYNC_PARALLEL_WORLD_TICKING_ENABLED.toString(), new BooleanConfigItem( file, - "async.parallel-world-ticking.enabled", + Key.ASYNC_PARALLEL_WORLD_TICKING_ENABLED.toString(), "Parallel World Tracing", List.of( "Parallel processing different worlds in separate", @@ -32,9 +32,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.parallel-world-ticking.threads", new IntegerConfigItem( + values.put(Key.ASYNC_PARALLEL_WORLD_TICKING_THREADS.toString(), new IntegerConfigItem( file, - "async.parallel-world-ticking.threads", + Key.ASYNC_PARALLEL_WORLD_TICKING_THREADS.toString(), "Parallel World Tracing Threads", List.of("Number of threads dedicated to parallel world", "ticking. Consider setting based on amount of worlds", @@ -47,9 +47,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.parallel-world-ticking.log-container-creation-stacktraces", new BooleanConfigItem( + values.put(Key.ASYNC_PARALLEL_WORLD_TICKING_LOG_CONTAINER_CREATION_STACKTRACES.toString(), new BooleanConfigItem( file, - "async.parallel-world-ticking.log-container-creation-stacktraces", + Key.ASYNC_PARALLEL_WORLD_TICKING_LOG_CONTAINER_CREATION_STACKTRACES.toString(), "Parallel World Tracing Log Container Creation Stacktraces", List.of( "Log stacktraces when containers (like Tile Entities", @@ -60,9 +60,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.parallel-world-ticking.disable-hard-throw", new BooleanConfigItem( + values.put(Key.ASYNC_PARALLEL_WORLD_TICKING_DISABLE_HARD_THROW.toString(), new BooleanConfigItem( file, - "async.parallel-world-ticking.disable-hard-throw", + Key.ASYNC_PARALLEL_WORLD_TICKING_DISABLE_HARD_THROW.toString(), "Parallel World Tracing Disable Hard Throw", List.of( "Disable hard throws (which usually stop the server)", @@ -74,9 +74,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.parallel-world-ticking.run-async-tasks-sync", new BooleanConfigItem( + values.put(Key.ASYNC_PARALLEL_WORLD_TICKING_RUN_ASYNC_TASKS_SYNC.toString(), new BooleanConfigItem( file, - "async.parallel-world-ticking.run-async-tasks-sync", + Key.ASYNC_PARALLEL_WORLD_TICKING_RUN_ASYNC_TASKS_SYNC.toString(), "Parallel World Tracing Run Async Tasks Sync", List.of( "Run asynchronous tasks synchronously within the", @@ -88,9 +88,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.async-entity-tracker.enabled", new BooleanConfigItem( + values.put(Key.ASYNC_ENTITY_TRACKER_ENABLED.toString(), new BooleanConfigItem( file, - "async.async-entity-tracker.enabled", + Key.ASYNC_ENTITY_TRACKER_ENABLED.toString(), "Async Entity Tracker", List.of( "Make entity tracking asynchronous, can improve", @@ -102,9 +102,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.async-entity-tracker.compat-mode", new BooleanConfigItem( + values.put(Key.ASYNC_ENTITY_TRACKER_COMPAT_MODE.toString(), new BooleanConfigItem( file, - "async.async-entity-tracker.compat-mode", + Key.ASYNC_ENTITY_TRACKER_COMPAT_MODE.toString(), "Async Entity Tracker Compat Mode", List.of( "Enable compatibility mode for plugins like", @@ -117,9 +117,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.async-entity-tracker.max-threads", new IntegerConfigItem( + values.put(Key.ASYNC_ENTITY_TRACKER_MAX_THREADS.toString(), new IntegerConfigItem( file, - "async.async-entity-tracker.max-threads", + Key.ASYNC_ENTITY_TRACKER_MAX_THREADS.toString(), "Async Entity Tracker Max Threads", List.of("Maximum number of threads for the async entity", "tracker to use. When set to 0, 1/4 of available", @@ -133,9 +133,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.async-entity-tracker.keepalive", new IntegerConfigItem( + values.put(Key.ASYNC_ENTITY_TRACKER_KEEPALIVE.toString(), new IntegerConfigItem( file, - "async.async-entity-tracker.keepalive", + Key.ASYNC_ENTITY_TRACKER_KEEPALIVE.toString(), "Async Entity Tracker Keepalive", List.of("Thread keepalive time. Threads with no tasks", "will be terminated if they remain idle for", @@ -147,9 +147,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.async-entity-tracker.queue-size", new IntegerConfigItem( + values.put(Key.ASYNC_ENTITY_TRACKER_QUEUE_SIZE.toString(), new IntegerConfigItem( file, - "async.async-entity-tracker.queue-size", + Key.ASYNC_ENTITY_TRACKER_QUEUE_SIZE.toString(), "Async Entity Tracker Queue Size", List.of("Maximum size of the queue for pending entity", "tracking tasks. If set to 0, the queue size is", @@ -164,9 +164,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.async-target-finding", new BooleanConfigItem( + values.put(Key.ASYNC_TARGET_FINDING.toString(), new BooleanConfigItem( file, - "async.async-target-finding", + Key.ASYNC_TARGET_FINDING.toString(), "Async Target Finding", List.of( "Moves the expensive entity target search", @@ -177,9 +177,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.async-playerdata-save", new BooleanConfigItem( + values.put(Key.ASYNC_PLAYERDATA_SAVE.toString(), new BooleanConfigItem( file, - "async.async-playerdata-save", + Key.ASYNC_PLAYERDATA_SAVE.toString(), "Async Playerdata Save", List.of( "Make playerdata saving aynchronous. Warning: might", @@ -190,9 +190,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.async-pathfinding.enabled", new BooleanConfigItem( + values.put(Key.ASYNC_PATHFINDING_ENABLED.toString(), new BooleanConfigItem( file, - "async.async-pathfinding.enabled", + Key.ASYNC_PATHFINDING_ENABLED.toString(), "Async Pathfinding", List.of( "Make mob pathfinding calculations asynchronous."), @@ -201,9 +201,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.async-pathfinding.max-threads", new IntegerConfigItem( + values.put(Key.ASYNC_PATHFINDING_MAX_THREADS.toString(), new IntegerConfigItem( file, - "async.async-pathfinding.max-threads", + Key.ASYNC_PATHFINDING_MAX_THREADS.toString(), "Async Pathfinding Max Threads", List.of("Maximum number of threads for async entity", "pathfinding to use. When set to 0, 1/4 of available", @@ -217,9 +217,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.async-pathfinding.keepalive", new IntegerConfigItem( + values.put(Key.ASYNC_PATHFINDING_KEEPALIVE.toString(), new IntegerConfigItem( file, - "async.async-pathfinding.keepalive", + Key.ASYNC_PATHFINDING_KEEPALIVE.toString(), "Async Pathfinding Keepalive", List.of("Thread keepalive time. Threads with no tasks", "will be terminated if they remain idle for", @@ -231,9 +231,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.async-pathfinding.queue-size", new IntegerConfigItem( + values.put(Key.ASYNC_PATHFINDING_QUEUE_SIZE.toString(), new IntegerConfigItem( file, - "async.async-pathfinding.queue-size", + Key.ASYNC_PATHFINDING_QUEUE_SIZE.toString(), "Async Entity Tracker Queue Size", List.of("Maximum size of the queue for pending", "pathfinding tasks. If set to 0, the queue size", @@ -245,9 +245,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.async-pathfinding.reject-policy", new StringConfigItem( + values.put(Key.ASYNC_PATHFINDING_REJECT_POLICY.toString(), new StringConfigItem( file, - "async.async-pathfinding.reject-policy", + Key.ASYNC_PATHFINDING_REJECT_POLICY.toString(), "Async Entity Tracker Queue Size", List.of("The policy to use when the pathfinding task queue", "is full (only relevant if queue-size is > 0) and a", @@ -258,9 +258,9 @@ public LeafConfig(Kryptonite plugin) { plugin )); - values.put("async.async-mob-spawning.enabled", new BooleanConfigItem( + values.put(Key.ASYNC_MOB_SPAWNING_ENABLED.toString(), new BooleanConfigItem( file, - "async.async-mob-spawning.enabled", + Key.ASYNC_MOB_SPAWNING_ENABLED.toString(), "Async Pathfinding", List.of( "Whether asynchronous mob spawning calculations should", @@ -275,4 +275,82 @@ public LeafConfig(Kryptonite plugin) { plugin )); } + + /** + * Configuration values supported by this format. + */ + public enum Key { + ASYNC_PARALLEL_WORLD_TICKING_ENABLED { + @Override + public String toString() { return "async.parallel-world-ticking.enabled"; } + }, + ASYNC_PARALLEL_WORLD_TICKING_THREADS { + @Override + public String toString() { return "async.parallel-world-ticking.threads"; } + }, + ASYNC_PARALLEL_WORLD_TICKING_LOG_CONTAINER_CREATION_STACKTRACES { + @Override + public String toString() { return "async.parallel-world-ticking.log-container-creation-stacktraces"; } + }, + ASYNC_PARALLEL_WORLD_TICKING_DISABLE_HARD_THROW { + @Override + public String toString() { return "async.parallel-world-ticking.disable-hard-throw"; } + }, + ASYNC_PARALLEL_WORLD_TICKING_RUN_ASYNC_TASKS_SYNC { + @Override + public String toString() { return "async.parallel-world-ticking.run-async-tasks-sync"; } + }, + ASYNC_ENTITY_TRACKER_ENABLED { + @Override + public String toString() { return "async.async-entity-tracker.enabled"; } + }, + ASYNC_ENTITY_TRACKER_COMPAT_MODE { + @Override + public String toString() { return "async.async-entity-tracker.compat-mode"; } + }, + ASYNC_ENTITY_TRACKER_MAX_THREADS { + @Override + public String toString() { return "async.async-entity-tracker.max-threads"; } + }, + ASYNC_ENTITY_TRACKER_KEEPALIVE { + @Override + public String toString() { return "async.async-entity-tracker.keepalive"; } + }, + ASYNC_ENTITY_TRACKER_QUEUE_SIZE { + @Override + public String toString() { return "async.async-entity-tracker.queue-size"; } + }, + ASYNC_TARGET_FINDING { + @Override + public String toString() { return "async.async-target-finding"; } + }, + ASYNC_PLAYERDATA_SAVE { + @Override + public String toString() { return "async.async-playerdata-save"; } + }, + ASYNC_PATHFINDING_ENABLED { + @Override + public String toString() { return "async.async-pathfinding.enabled"; } + }, + ASYNC_PATHFINDING_MAX_THREADS { + @Override + public String toString() { return "async.async-pathfinding.max-threads"; } + }, + ASYNC_PATHFINDING_KEEPALIVE { + @Override + public String toString() { return "async.async-pathfinding.keepalive"; } + }, + ASYNC_PATHFINDING_QUEUE_SIZE { + @Override + public String toString() { return "async.async-pathfinding.queue-size"; } + }, + ASYNC_PATHFINDING_REJECT_POLICY { + @Override + public String toString() { return "async.async-pathfinding.reject-policy"; } + }, + ASYNC_MOB_SPAWNING_ENABLED { + @Override + public String toString() { return "async.async-mob-spawning.enabled"; } + } + } } \ No newline at end of file From f8459f0abdd10dc60958df4f059197740175f252 Mon Sep 17 00:00:00 2001 From: Lewis Milburn Date: Sat, 22 Nov 2025 11:47:59 +0000 Subject: [PATCH 21/21] Update system. --- .../kryptonite/config/PaperWorldConfig.java | 572 ++++++++++++++++ .../net/lewmc/kryptonite/kos/AutoKOS.java | 216 +++---- .../kryptonite/kos/gui/KOS_ConfigItemGui.java | 2 + .../kryptonite/kos/gui/KOS_PaperWorld_1.java | 610 ------------------ .../utils/config/DoubleConfigItem.java | 31 +- .../utils/config/IntegerConfigItem.java | 26 +- 6 files changed, 724 insertions(+), 733 deletions(-) create mode 100644 src/main/java/net/lewmc/kryptonite/config/PaperWorldConfig.java delete mode 100644 src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_1.java diff --git a/src/main/java/net/lewmc/kryptonite/config/PaperWorldConfig.java b/src/main/java/net/lewmc/kryptonite/config/PaperWorldConfig.java new file mode 100644 index 0000000..399766f --- /dev/null +++ b/src/main/java/net/lewmc/kryptonite/config/PaperWorldConfig.java @@ -0,0 +1,572 @@ +package net.lewmc.kryptonite.config; + +import net.lewmc.kryptonite.Kryptonite; +import net.lewmc.kryptonite.utils.config.BooleanConfigItem; +import net.lewmc.kryptonite.utils.config.ConfigCollection; +import net.lewmc.kryptonite.utils.config.IntegerConfigItem; +import net.lewmc.kryptonite.utils.config.StringConfigItem; + +import java.util.List; + +/** + * Configuration data for config/paper-world-defaults.yml + * @since 2.1.0 + */ +public class PaperWorldConfig extends ConfigCollection { + /** + * Constructs the config/paper-world-defaults data. + * @param plugin Kryptonite - Reference to the main Kryptonite class. + */ + public PaperWorldConfig(Kryptonite plugin) { + String file = "config/paper-world-defaults"; + + values.put(Key.DELAY_CHUNK_UNLOADS_BY.toString(), new StringConfigItem( + file, + Key.DELAY_CHUNK_UNLOADS_BY.toString(), + "Delay Chunk Unloads By", + List.of("Delays chunk unloads by the specified time.", + "Recommended value: 'default' (click to lowest)"), + true, + List.of("default","1s","2s","3s","4s","5s","6s","7s","8s","9s","10s","11s","12s","13s","14s","15s","16s","17s","18s","19s","20s","21s","22s","23s","24s","25s","26s","27s","28s","29s","30s","1m","5m","10m","30m","1h","3h","6h","12h","1d"), + List.of("default"), + plugin + )); + + values.put(Key.MAX_AUTOSAVE_CHUNKS_PER_TICK.toString(), new IntegerConfigItem( + file, + Key.MAX_AUTOSAVE_CHUNKS_PER_TICK.toString(), + "Max Autosave Chunks Per Tick", + List.of("The maximum number of chunks the auto-save system", + "will save in a single tick."), + true, + 0, + 100, + "24", + plugin + )); + + values.put(Key.PREVENT_MOVING_INTO_UNLOADED_CHUNKS.toString(), new BooleanConfigItem( + file, + Key.PREVENT_MOVING_INTO_UNLOADED_CHUNKS.toString(), + "Prevent Moving into Unloaded Chunks", + List.of("Sets whether the server will prevent players from", + "moving into unloaded chunks or not. Can reduce", + "server lag, but players may stutter when travelling,", + "especially at high speeds."), + true, + true, + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_AREA_EFFECT_CLOUD.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_AREA_EFFECT_CLOUD.toString(), + "Entity Per Chunk Save Limit (Area Effect Cloud)", + List.of("Limits the number of area effect cloud entities that", + "will be saved and loaded per chunk. A value of -1 ", + "disables the limit."), + true, + 0, + 255, + "<12", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_ARROW.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_ARROW.toString(), + "Entity Per Chunk Save Limit (Arrow)", + List.of("Limits the number of arrows that will be saved and", + "loaded per chunk. A value of -1 disables the limit."), + true, + -1, + 256, + "16-20", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_DRAGON_FIREBALL.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_DRAGON_FIREBALL.toString(), + "Entity Per Chunk Save Limit (Dragon Fireball)", + List.of("Limits the number of dragon fireball entities that", + "will be saved and loaded per chunk. A value of -1 ", + "disables the limit."), + true, + -1, + 256, + "3-5", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EGG.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EGG.toString(), + "Entity Per Chunk Save Limit (Egg)", + List.of("Limits the number of eggs that will be saved and", + "loaded per chunk. A value of -1 disables the limit."), + true, + -1, + 256, + "8-20", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_ENDER_PEARL.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_ENDER_PEARL.toString(), + "Entity Per Chunk Save Limit (Ender Pearl)", + List.of("Limits the number of ender pearls that will be", + "saved and loaded per chunk. A value of -1 disables", + "the limit."), + true, + -1, + 256, + "8-20", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_BOTTLE.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_BOTTLE.toString(), + "Entity Per Chunk Save Limit (Experience Bottle)", + List.of("Limits the number of experience bottles that will be", + "saved and loaded per chunk. A value of -1 disables", + "the limit."), + true, + -1, + 256, + "3-5", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_ORB.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_ORB.toString(), + "Entity Per Chunk Save Limit (Experience Orb)", + List.of("Limits the number of experience orbs that will be", + "saved and loaded per chunk. A value of -1 disables", + "the limit."), + true, + -1, + 256, + "16-50", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EYE_OF_ENDER.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EYE_OF_ENDER.toString(), + "Entity Per Chunk Save Limit (Eye of Ender)", + List.of("Limits the number of eyes of ender that will be", + "saved and loaded per chunk. A value of -1 disables", + "the limit."), + true, + -1, + 256, + "8-20", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_FIREBALL.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_FIREBALL.toString(), + "Entity Per Chunk Save Limit (Fireball)", + List.of("Limits the number of fireballs that will be saved and", + "loaded per chunk. A value of -1 disables the limit."), + true, + -1, + 256, + "8-10", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_LLAMA_SPIT.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_LLAMA_SPIT.toString(), + "Entity Per Chunk Save Limit (Llama Spit)", + List.of("Limits the number of llama spit entities that will", + "be saved and loaded per chunk. A value of -1", + "disables the limit."), + true, + -1, + 256, + "3-5", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_POTION.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_POTION.toString(), + "Entity Per Chunk Save Limit (Splash Potion)", + List.of("Limits the number of splash potion clouds that", + "will be saved and loaded per chunk. A value of", + "-1 disables the limit."), + true, + -1, + 256, + "8-10", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SHULKER_BULLET.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SHULKER_BULLET.toString(), + "Entity Per Chunk Save Limit (Shulker Bullet)", + List.of("Limits the number of shulker bullets that will", + "be saved and loaded per chunk. A value of -1", + "disables the limit."), + true, + -1, + 256, + "8", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SMALL_FIREBALL.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SMALL_FIREBALL.toString(), + "Entity Per Chunk Save Limit (Small Fireball)", + List.of("Limits the number of small fireballs that will", + "be saved and loaded per chunk. A value of -1", + "disables the limit."), + true, + -1, + 256, + "8", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SNOWBALL.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SNOWBALL.toString(), + "Entity Per Chunk Save Limit (Snowball)", + List.of("Limits the number of snowball entities that will", + "be saved and loaded per chunk. A value of -1", + "disables the limit."), + true, + -1, + 256, + "8-20", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SPECTRAL_ARROW.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SPECTRAL_ARROW.toString(), + "Entity Per Chunk Save Limit (Spectral Arrow)", + List.of("Limits the number of spectral arrows that will", + "be saved and loaded per chunk. A value of -1", + "disables the limit."), + true, + -1, + 256, + "5-16", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_TRIDENT.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_TRIDENT.toString(), + "Entity Per Chunk Save Limit (Trident)", + List.of("Limits the number of trident entities that will", + "be saved and loaded per chunk. A value of -1", + "disables the limit."), + true, + -1, + 256, + "10-16", + plugin + )); + + values.put(Key.ENTITY_PER_CHUNK_SAVE_LIMIT_WITHER_SKULL.toString(), new IntegerConfigItem( + file, + Key.ENTITY_PER_CHUNK_SAVE_LIMIT_WITHER_SKULL.toString(), + "Entity Per Chunk Save Limit (Wither Skull)", + List.of("Limits the number of wither skulls that will", + "be saved and loaded per chunk. A value of -1", + "disables the limit."), + true, + -1, + 256, + "72", + plugin + )); + } + + /** + * Configuration values supported by this format. + */ + public enum Key { + DELAY_CHUNK_UNLOADS_BY { + @Override public String toString() { return "chunks.delay-chunk-unloads-by"; } + }, + MAX_AUTOSAVE_CHUNKS_PER_TICK { + @Override public String toString() { return "chunks.max-auto-save-chunks-per-tick"; } + }, + PREVENT_MOVING_INTO_UNLOADED_CHUNKS { + @Override public String toString() { return "chunks.prevent-moving-into-unloaded-chunks"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_AREA_EFFECT_CLOUD { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.area_effect_cloud"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_ARROW { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.arrow"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_DRAGON_FIREBALL { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.dragon_fireball"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_EGG { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.egg"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_ENDER_PEARL { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.ender_pearl"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_BOTTLE { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.experience_bottle"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_ORB { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.experience_orb"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_EYE_OF_ENDER { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.eye_of_ender"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_FIREBALL { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.fireball"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_LLAMA_SPIT { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.llama_spit"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_POTION { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.splash_potion"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_SHULKER_BULLET { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.shulker_bullet"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_SMALL_FIREBALL { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.small_fireball"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_SNOWBALL { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.snowball"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_SPECTRAL_ARROW { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.spectral_arrow"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_TRIDENT { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.trident"; } + }, + ENTITY_PER_CHUNK_SAVE_LIMIT_WITHER_SKULL { + @Override public String toString() { return "chunks.entity-per-chunk-save-limit.wither_skull"; } + }, + ENTITY_DESPAWN_RANGES_AMBIENT_HARD { + @Override public String toString() { return "entities.spawning.despawn-ranges.ambient.hard"; } + }, + ENTITY_DESPAWN_RANGES_AMBIENT_SOFT { + @Override public String toString() { return "entities.spawning.despawn-ranges.ambient.soft"; } + }, + ENTITY_DESPAWN_RANGES_AXOLOTLS_HARD { + @Override public String toString() { return "entities.spawning.despawn-ranges.axolotls.hard"; } + }, + ENTITY_DESPAWN_RANGES_AXOLOTLS_SOFT { + @Override public String toString() { return "entities.spawning.despawn-ranges.axolotls.soft"; } + }, + ENTITY_DESPAWN_RANGES_CREATURE_HARD { + @Override public String toString() { return "entities.spawning.despawn-ranges.creature.hard"; } + }, + ENTITY_DESPAWN_RANGES_CREATURE_SOFT { + @Override public String toString() { return "entities.spawning.despawn-ranges.creature.soft"; } + }, + ENTITY_DESPAWN_RANGES_MISC_HARD { + @Override public String toString() { return "entities.spawning.despawn-ranges.misc.hard"; } + }, + ENTITY_DESPAWN_RANGES_MISC_SOFT { + @Override public String toString() { return "entities.spawning.despawn-ranges.misc.soft"; } + }, + ENTITY_DESPAWN_RANGES_MONSTER_HARD { + @Override public String toString() { return "entities.spawning.despawn-ranges.monster.hard"; } + }, + ENTITY_DESPAWN_RANGES_MONSTER_SOFT { + @Override public String toString() { return "entities.spawning.despawn-ranges.monster.soft"; } + }, + ENTITY_DESPAWN_RANGES_UNDERGROUND_WATER_CREATURE_HARD { + @Override public String toString() { return "entities.spawning.despawn-ranges.underground_water_creature.hard"; } + }, + ENTITY_DESPAWN_RANGES_UNDERGROUND_WATER_CREATURE_SOFT { + @Override public String toString() { return "entities.spawning.despawn-ranges.underground_water_creature.soft"; } + }, + ENTITY_DESPAWN_RANGES_WATER_AMBIENT_HARD { + @Override public String toString() { return "entities.spawning.despawn-ranges.water_ambient.hard"; } + }, + ENTITY_DESPAWN_RANGES_WATER_AMBIENT_SOFT { + @Override public String toString() { return "entities.spawning.despawn-ranges.water_ambient.soft"; } + }, + ENTITY_DESPAWN_RANGES_WATER_CREATURE_HARD { + @Override public String toString() { return "entities.spawning.despawn-ranges.water_creature.hard"; } + }, + ENTITY_DESPAWN_RANGES_WATER_CREATURE_SOFT { + @Override public String toString() { return "entities.spawning.despawn-ranges.water_creature.soft"; } + }, + PER_PLAYER_MOB_SPAWNS { + @Override public String toString() { return "entities.spawning.per-player-mob-spawns"; } + }, + MAX_ENTITY_COLLISIONS { + @Override public String toString() { return "collisions.max-entity-collisions"; } + }, + UPDATE_PATHFINDING_ON_BLOCK_UPDATE { + @Override public String toString() { return "misc.update-pathfinding-on-block-update"; } + }, + FIX_CLIMBING_BYPASSING_CRAMMING_RULE { + @Override public String toString() { return "collisions.fix-climbing-bypassing-cramming-rule"; } + }, + ARMOR_STANDS_TICK { + @Override public String toString() { return "entities.armor-stands.tick"; } + }, + ARMOR_STANDS_DO_COLLISION_ENTITY_LOOKUPS { + @Override public String toString() { return "entities.armor-stands.do-collision-entity-lookups"; } + }, + TICK_RATE_VILLAGER_VALIDATES_NEARBY_POI { + @Override public String toString() { return "tick-rates.behavior.villager.validatenearbypoi"; } + }, + TICK_RATE_VILLAGER_ACQUIRE_POI { + @Override public String toString() { return "tick-rates.behavior.villager.acquirepoi"; } + }, + TICK_RATE_VILLAGER_SENSOR_NEAREST_BED { + @Override public String toString() { return "tick-rates.sensor.villager.nearestbedsensor"; } + }, + TICK_RATE_VILLAGER_SENSOR_SECONDARY_POI { + @Override public String toString() { return "tick-rates.sensor.villager.secondarypoisensor"; } + }, + TICK_RATE_VILLAGER_SENSOR_VILLAGER_BABIES { + @Override public String toString() { return "tick-rates.sensor.villager.villagerbabiessensor"; } + }, + TICK_RATE_VILLAGER_SENSOR_PLAYER { + @Override public String toString() { return "tick-rates.sensor.villager.playersensor"; } + }, + TICK_RATE_VILLAGER_SENSOR_NEAREST_LIVING_ENTITY { + @Override public String toString() { return "tick-rates.sensor.villager.nearestlivingentitysensor"; } + }, + ALT_ITEM_DESPAWN_RATE_ENABLED { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.enabled"; } + }, + ALT_ITEM_DESPAWN_RATE_COBBLESTONE { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.cobblestone"; } + }, + ALT_ITEM_DESPAWN_RATE_NETHERRACK { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.netherrack"; } + }, + ALT_ITEM_DESPAWN_RATE_SAND { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.sand"; } + }, + ALT_ITEM_DESPAWN_RATE_RED_SAND { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.red_sand"; } + }, + ALT_ITEM_DESPAWN_RATE_GRAVEL { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.gravel"; } + }, + ALT_ITEM_DESPAWN_RATE_DIRT { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.dirt"; } + }, + ALT_ITEM_DESPAWN_RATE_SHORT_GRASS { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.short_grass"; } + }, + ALT_ITEM_DESPAWN_RATE_PUMPKIN { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.pumpkin"; } + }, + ALT_ITEM_DESPAWN_RATE_MELON_SLICE { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.melon_slice"; } + }, + ALT_ITEM_DESPAWN_RATE_KELP { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.kelp"; } + }, + ALT_ITEM_DESPAWN_RATE_BAMBOO { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.bamboo"; } + }, + ALT_ITEM_DESPAWN_RATE_SUGAR_CANE { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.sugar_cane"; } + }, + ALT_ITEM_DESPAWN_RATE_TWISTING_VINES { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.twisting_vines"; } + }, + ALT_ITEM_DESPAWN_RATE_WEEPING_VINES { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.weeping_vines"; } + }, + ALT_ITEM_DESPAWN_RATE_OAK_LEAVES { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.oak_leaves"; } + }, + ALT_ITEM_DESPAWN_RATE_SPRUCE_LEAVES { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.spruce_leaves"; } + }, + ALT_ITEM_DESPAWN_RATE_BIRCH_LEAVES { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.birch_leaves"; } + }, + ALT_ITEM_DESPAWN_RATE_JUNGLE_LEAVES { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.jungle_leaves"; } + }, + ALT_ITEM_DESPAWN_RATE_ACACIA_LEAVES { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.acacia_leaves"; } + }, + ALT_ITEM_DESPAWN_RATE_DARK_OAK_LEAVES { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.dark_oak_leaves"; } + }, + ALT_ITEM_DESPAWN_RATE_MANGROVE_LEAVES { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.mangrove_leaves"; } + }, + ALT_ITEM_DESPAWN_RATE_CACTUS { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.cactus"; } + }, + ALT_ITEM_DESPAWN_RATE_DIORITE { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.diorite"; } + }, + ALT_ITEM_DESPAWN_RATE_GRANITE { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.granite"; } + }, + ALT_ITEM_DESPAWN_RATE_ANDESITE { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.andesite"; } + }, + ALT_ITEM_DESPAWN_RATE_SCAFFOLDING { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.scaffolding"; } + }, + ALT_ITEM_DESPAWN_RATE_EGG { + @Override public String toString() { return "entities.spawning.alt-item-despawn-rate.items.egg"; } + }, + REDSTONE_IMPLEMENTATION { + @Override public String toString() { return "misc.redstone-implementation"; } + }, + HOPPER_DISABLE_MOVE_EVENT { + @Override public String toString() { return "hopper.disable-move-event"; } + }, + HOPPER_IGNORE_OCCLUDING_BLOCKS { + @Override public String toString() { return "hopper.ignore-occluding-blocks"; } + }, + TICK_RATE_MOB_SPAWNER { + @Override public String toString() { return "tick-rates.mob-spawner"; } + }, + OPTIMIZE_EXPLOSIONS { + @Override public String toString() { return "environment.optimize-explosions"; } + }, + TREASURE_MAPS_ENABLED { + @Override public String toString() { return "environment.treasure-maps.enabled"; } + }, + TREASURE_MAPS_FIND_ALREADY_DISCOVERED_LOOT_TABLES { + @Override public String toString() { return "environment.treasure-maps.find-already-discovered.loot-tables"; } + }, + TREASURE_MAPS_FIND_ALREADY_DISCOVERED_VILLAGER_TRADE { + @Override public String toString() { return "environment.treasure-maps.find-already-discovered.villager-trade"; } + }, + TICK_RATE_GRASS_SPREAD { + @Override public String toString() { return "tick-rates.grass-spread"; } + }, + TICK_RATE_CONTAINER_UPDATE { + @Override public String toString() { return "tick-rates.container-update"; } + }, + ARROW_DESPAWN_RATE_NON_PLAYER { + @Override public String toString() { return "entities.spawning.non-player-arrow-despawn-rate"; } + }, + ARROW_DESPAWN_RATE_CREATIVE { + @Override public String toString() { return "entities.spawning.creative-arrow-despawn-rate"; } + }, + NERFED_SPAWNER_MOBS_SHOULD_JUMP { + @Override public String toString() { return "spawner-nerfed-mobs-should-jump"; } + } + } +} \ No newline at end of file diff --git a/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java b/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java index 6d61d9d..cd38a75 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java +++ b/src/main/java/net/lewmc/kryptonite/kos/AutoKOS.java @@ -160,134 +160,130 @@ private void runPaper(boolean pregeneratedWorld) { if (this.softwareUtil.supportsPaperWorld()) { this.log.info("[KOS] 4/6 - Running Paper optimisations"); - PaperWorld pw = new PaperWorld(this.plugin, this.user); - - pw.setInt(PaperWorld.Key.DELAY_CHUNK_UNLOADS_BY, this.patches.getInt("paper.chunks.delay-unloads")); - pw.setInt(PaperWorld.Key.MAX_AUTOSAVE_CHUNKS_PER_TICK, this.patches.getInt("paper.chunks.max-autosave-per-tick")); - pw.setBoolean(PaperWorld.Key.PREVENT_MOVING_INTO_UNLOADED_CHUNKS, this.patches.getBoolean("paper.chunks.prevent-moving-into-unloaded")); - - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_AREA_EFFECT_CLOUD, this.patches.getInt("paper.chunks.entity-save-limit.area-effect-cloud")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_ARROW, this.patches.getInt("paper.chunks.entity-save-limit.arrow")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_DRAGON_FIREBALL, this.patches.getInt("paper.chunks.entity-save-limit.dragon-fireball")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EGG, this.patches.getInt("paper.chunks.entity-save-limit.egg")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_ENDER_PEARL, this.patches.getInt("paper.chunks.entity-save-limit.ender-pearl")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_BOTTLE, this.patches.getInt("paper.chunks.entity-save-limit.experience-bottle")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_ORB, this.patches.getInt("paper.chunks.entity-save-limit.experience-orb")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EYE_OF_ENDER, this.patches.getInt("paper.chunks.entity-save-limit.eye-of-ender")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_FIREBALL, this.patches.getInt("paper.chunks.entity-save-limit.fireball")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_LLAMA_SPIT, this.patches.getInt("paper.chunks.entity-save-limit.llama-spit")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_POTION, this.patches.getInt("paper.chunks.entity-save-limit.potion")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SHULKER_BULLET, this.patches.getInt("paper.chunks.entity-save-limit.shulker-bullet")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SMALL_FIREBALL, this.patches.getInt("paper.chunks.entity-save-limit.small-fireball")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SNOWBALL, this.patches.getInt("paper.chunks.entity-save-limit.snowball")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SPECTRAL_ARROW, this.patches.getInt("paper.chunks.entity-save-limit.spectral-arrow")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_TRIDENT, this.patches.getInt("paper.chunks.entity-save-limit.trident")); - pw.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_WITHER_SKULL, this.patches.getInt("paper.chunks.entity-save-limit.wither-skull")); - - - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_AMBIENT_HARD, this.patches.getString("paper.despawn-ranges.ambient.hard")); - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_AMBIENT_SOFT, this.patches.getString("paper.despawn-ranges.ambient.soft")); - - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_AXOLOTLS_HARD, this.patches.getString("paper.despawn-ranges.axolotl.hard")); - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_AXOLOTLS_SOFT, this.patches.getString("paper.despawn-ranges.axolotl.soft")); - - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_CREATURE_HARD, this.patches.getString("paper.despawn-ranges.creature.hard")); - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_CREATURE_SOFT, this.patches.getString("paper.despawn-ranges.creature.soft")); - - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_MISC_HARD, this.patches.getString("paper.despawn-ranges.misc.hard")); - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_MISC_SOFT, this.patches.getString("paper.despawn-ranges.misc.soft")); - - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_MONSTER_HARD, this.patches.getString("paper.despawn-ranges.monster.hard")); - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_MONSTER_SOFT, this.patches.getString("paper.despawn-ranges.monster.soft")); - - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_UNDERGROUND_WATER_CREATURE_HARD, this.patches.getString("paper.despawn-ranges.water.underground-creature.hard")); - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_UNDERGROUND_WATER_CREATURE_SOFT, this.patches.getString("paper.despawn-ranges.water.underground-creature.soft")); - - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_WATER_AMBIENT_HARD, this.patches.getString("paper.despawn-ranges.water.ambient.hard")); - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_WATER_AMBIENT_SOFT, this.patches.getString("paper.despawn-ranges.water.ambient.soft")); - - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_WATER_CREATURE_HARD, this.patches.getString("paper.despawn-ranges.water.creature.hard")); - pw.setString(PaperWorld.Key.ENTITY_DESPAWN_RANGES_WATER_CREATURE_SOFT, this.patches.getString("paper.despawn-ranges.water.creature.soft")); - - - pw.setBoolean(PaperWorld.Key.PER_PLAYER_MOB_SPAWNS, this.patches.getBoolean("paper.per-player-mob-spawns")); - pw.setInt(PaperWorld.Key.MAX_ENTITY_COLLISIONS, this.patches.getInt("paper.max-entity-collisions")); - pw.setBoolean(PaperWorld.Key.UPDATE_PATHFINDING_ON_BLOCK_UPDATE, this.patches.getBoolean("paper.update-pathfinding-on-block-update")); - pw.setBoolean(PaperWorld.Key.FIX_CLIMBING_BYPASSING_CRAMMING_RULE, this.patches.getBoolean("paper.fix-climbing-bypass-cramming-rule")); - pw.setBoolean(PaperWorld.Key.ARMOR_STANDS_TICK, this.patches.getBoolean("paper.armor-stands.tick")); - pw.setBoolean(PaperWorld.Key.ARMOR_STANDS_DO_COLLISION_ENTITY_LOOKUPS, this.patches.getBoolean("paper.armor-stands.do-collision-entity-lookups")); - pw.setBoolean(PaperWorld.Key.NERFED_SPAWNER_MOBS_SHOULD_JUMP, this.patches.getBoolean("paper.nerfed-spawner-mobs-can-jump")); + PaperWorldConfig pw = new PaperWorldConfig(this.plugin); + + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.DELAY_CHUNK_UNLOADS_BY.toString())).setValue(this.patches.getInt("paper.chunks.delay-unloads")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.MAX_AUTOSAVE_CHUNKS_PER_TICK.toString())).setValue(this.patches.getInt("paper.chunks.max-autosave-per-tick")); + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.PREVENT_MOVING_INTO_UNLOADED_CHUNKS.toString())).setValue(this.patches.getBoolean("paper.chunks.prevent-moving-into-unloaded")); + + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_AREA_EFFECT_CLOUD.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.area-effect-cloud")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_ARROW.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.arrow")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_DRAGON_FIREBALL.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.dragon-fireball")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EGG.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.egg")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_ENDER_PEARL.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.ender-pearl")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_BOTTLE.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.experience-bottle")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_ORB.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.experience-orb")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EYE_OF_ENDER.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.eye-of-ender")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_FIREBALL.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.fireball")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_LLAMA_SPIT.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.llama-spit")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_POTION.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.potion")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SHULKER_BULLET.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.shulker-bullet")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SMALL_FIREBALL.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.small-fireball")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SNOWBALL.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.snowball")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SPECTRAL_ARROW.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.spectral-arrow")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_TRIDENT.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.trident")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_WITHER_SKULL.toString())).setValue(this.patches.getInt("paper.chunks.entity-save-limit.wither-skull")); + + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_AMBIENT_HARD.toString())).setValue(this.patches.getString("paper.despawn-ranges.ambient.hard")); + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_AMBIENT_SOFT.toString())).setValue(this.patches.getString("paper.despawn-ranges.ambient.soft")); + + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_AXOLOTLS_HARD.toString())).setValue(this.patches.getString("paper.despawn-ranges.axolotl.hard")); + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_AXOLOTLS_SOFT.toString())).setValue(this.patches.getString("paper.despawn-ranges.axolotl.soft")); + + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_CREATURE_HARD.toString())).setValue(this.patches.getString("paper.despawn-ranges.creature.hard")); + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_CREATURE_SOFT.toString())).setValue(this.patches.getString("paper.despawn-ranges.creature.soft")); + + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_MISC_HARD.toString())).setValue(this.patches.getString("paper.despawn-ranges.misc.hard")); + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_MISC_SOFT.toString())).setValue(this.patches.getString("paper.despawn-ranges.misc.soft")); + + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_MONSTER_HARD.toString())).setValue(this.patches.getString("paper.despawn-ranges.monster.hard")); + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_MONSTER_SOFT.toString())).setValue(this.patches.getString("paper.despawn-ranges.monster.soft")); + + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_UNDERGROUND_WATER_CREATURE_HARD.toString())).setValue(this.patches.getString("paper.despawn-ranges.water.underground-creature.hard")); + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_UNDERGROUND_WATER_CREATURE_SOFT.toString())).setValue(this.patches.getString("paper.despawn-ranges.water.underground-creature.soft")); + + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_WATER_AMBIENT_HARD.toString())).setValue(this.patches.getString("paper.despawn-ranges.water.ambient.hard")); + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_WATER_AMBIENT_SOFT.toString())).setValue(this.patches.getString("paper.despawn-ranges.water.ambient.soft")); + + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_WATER_CREATURE_HARD.toString())).setValue(this.patches.getString("paper.despawn-ranges.water.creature.hard")); + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.ENTITY_DESPAWN_RANGES_WATER_CREATURE_SOFT.toString())).setValue(this.patches.getString("paper.despawn-ranges.water.creature.soft")); + + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.PER_PLAYER_MOB_SPAWNS.toString())).setValue(this.patches.getBoolean("paper.per-player-mob-spawns")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.MAX_ENTITY_COLLISIONS.toString())).setValue(this.patches.getInt("paper.max-entity-collisions")); + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.UPDATE_PATHFINDING_ON_BLOCK_UPDATE.toString())).setValue(this.patches.getBoolean("paper.update-pathfinding-on-block-update")); + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.FIX_CLIMBING_BYPASSING_CRAMMING_RULE.toString())).setValue(this.patches.getBoolean("paper.fix-climbing-bypass-cramming-rule")); + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.ARMOR_STANDS_TICK.toString())).setValue(this.patches.getBoolean("paper.armor-stands.tick")); + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.ARMOR_STANDS_DO_COLLISION_ENTITY_LOOKUPS.toString())).setValue(this.patches.getBoolean("paper.armor-stands.do-collision-entity-lookups")); + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.NERFED_SPAWNER_MOBS_SHOULD_JUMP.toString())).setValue(this.patches.getBoolean("paper.nerfed-spawner-mobs-can-jump")); if (!this.softwareUtil.supportsPufferfish()) { - pw.setInt(PaperWorld.Key.TICK_RATE_VILLAGER_VALIDATES_NEARBY_POI, this.patches.getInt("paper.tick-rates.villager.behaviour.nearby-poi")); - pw.setInt(PaperWorld.Key.TICK_RATE_VILLAGER_ACQUIRE_POI, this.patches.getInt("paper.tick-rates.villager.behaviour.acquire-poi")); - - pw.setInt(PaperWorld.Key.TICK_RATE_VILLAGER_SENSOR_SECONDARY_POI, this.patches.getInt("paper.tick-rates.villager.sensor.secondary-poi")); - pw.setInt(PaperWorld.Key.TICK_RATE_VILLAGER_SENSOR_NEAREST_BED, this.patches.getInt("paper.tick-rates.villager.sensor.nearest-bed")); - pw.setInt(PaperWorld.Key.TICK_RATE_VILLAGER_SENSOR_VILLAGER_BABIES, this.patches.getInt("paper.tick-rates.villager.sensor.villager-babies")); - pw.setInt(PaperWorld.Key.TICK_RATE_VILLAGER_SENSOR_PLAYER, this.patches.getInt("paper.tick-rates.villager.sensor.player")); - pw.setInt(PaperWorld.Key.TICK_RATE_VILLAGER_SENSOR_NEAREST_LIVING_ENTITY, this.patches.getInt("paper.tick-rates.villager.sensor.nearest-living-entity")); - + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.TICK_RATE_VILLAGER_VALIDATES_NEARBY_POI.toString())).setValue(this.patches.getInt("paper.tick-rates.villager.behaviour.nearby-poi")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.TICK_RATE_VILLAGER_ACQUIRE_POI.toString())).setValue(this.patches.getInt("paper.tick-rates.villager.behaviour.acquire-poi")); + + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.TICK_RATE_VILLAGER_SENSOR_SECONDARY_POI.toString())).setValue(this.patches.getInt("paper.tick-rates.villager.sensor.secondary-poi")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.TICK_RATE_VILLAGER_SENSOR_NEAREST_BED.toString())).setValue(this.patches.getInt("paper.tick-rates.villager.sensor.nearest-bed")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.TICK_RATE_VILLAGER_SENSOR_VILLAGER_BABIES.toString())).setValue(this.patches.getInt("paper.tick-rates.villager.sensor.villager-babies")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.TICK_RATE_VILLAGER_SENSOR_PLAYER.toString())).setValue(this.patches.getInt("paper.tick-rates.villager.sensor.player")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.TICK_RATE_VILLAGER_SENSOR_NEAREST_LIVING_ENTITY.toString())).setValue(this.patches.getInt("paper.tick-rates.villager.sensor.nearest-living-entity")); } else { this.log.info("[KOS][4/6] You're running Pufferfish, skipping some steps due to incompatibility..."); } - pw.setBoolean(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_ENABLED, this.patches.getBoolean("paper.optimised-despawn.enabled")); - - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_COBBLESTONE, this.patches.getInt("paper.optimised-despawn.cobblestone")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_NETHERRACK, this.patches.getInt("paper.optimised-despawn.netherrack")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_SAND, this.patches.getInt("paper.optimised-despawn.sand")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_RED_SAND, this.patches.getInt("paper.optimised-despawn.red-sand")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_GRAVEL, this.patches.getInt("paper.optimised-despawn.gravel")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_DIRT, this.patches.getInt("paper.optimised-despawn.dirt")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_SHORT_GRASS, this.patches.getInt("paper.optimised-despawn.short-grass")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_PUMPKIN, this.patches.getInt("paper.optimised-despawn.pumpkin")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_MELON_SLICE, this.patches.getInt("paper.optimised-despawn.melon-slice")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_KELP, this.patches.getInt("paper.optimised-despawn.kelp")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_BAMBOO, this.patches.getInt("paper.optimised-despawn.bamboo")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_SUGAR_CANE, this.patches.getInt("paper.optimised-despawn.sugar-cane")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_TWISTING_VINES, this.patches.getInt("paper.optimised-despawn.twisting-vines")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_WEEPING_VINES, this.patches.getInt("paper.optimised-despawn.weeping-vines")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_OAK_LEAVES, this.patches.getInt("paper.optimised-despawn.oak-leaves")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_SPRUCE_LEAVES, this.patches.getInt("paper.optimised-despawn.spruce-leaves")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_BIRCH_LEAVES, this.patches.getInt("paper.optimised-despawn.birch-leaves")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_JUNGLE_LEAVES, this.patches.getInt("paper.optimised-despawn.jungle-leaves")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_ACACIA_LEAVES, this.patches.getInt("paper.optimised-despawn.acacia-leaves")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_DARK_OAK_LEAVES, this.patches.getInt("paper.optimised-despawn.dark-oak-leaves")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_MANGROVE_LEAVES, this.patches.getInt("paper.optimised-despawn.mangrove-leaves")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_CACTUS, this.patches.getInt("paper.optimised-despawn.cactus")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_DIORITE, this.patches.getInt("paper.optimised-despawn.diorite")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_GRANITE, this.patches.getInt("paper.optimised-despawn.granite")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_ANDESITE, this.patches.getInt("paper.optimised-despawn.andesite")); - pw.setInt(PaperWorld.Key.ALT_ITEM_DESPAWN_RATE_SCAFFOLDING, this.patches.getInt("paper.optimised-despawn.scaffolding")); - - - pw.setString(PaperWorld.Key.REDSTONE_IMPLEMENTATION, this.patches.getString("paper.redstone-implementation")); - pw.setBoolean(PaperWorld.Key.HOPPER_DISABLE_MOVE_EVENT, this.patches.getBoolean("paper.hoppers.disable-move-event")); - pw.setBoolean(PaperWorld.Key.HOPPER_IGNORE_OCCLUDING_BLOCKS, this.patches.getBoolean("paper.hoppers.ignore-occluding-blocks")); - pw.setInt(PaperWorld.Key.TICK_RATE_MOB_SPAWNER, this.patches.getInt("paper.tick-rates.mob-spawner")); - pw.setBoolean(PaperWorld.Key.OPTIMIZE_EXPLOSIONS, this.patches.getBoolean("paper.optimise-explosions")); + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_ENABLED.toString())).setValue(this.patches.getBoolean("paper.optimised-despawn.enabled")); + + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_COBBLESTONE.toString())).setValue(this.patches.getInt("paper.optimised-despawn.cobblestone")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_NETHERRACK.toString())).setValue(this.patches.getInt("paper.optimised-despawn.netherrack")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_SAND.toString())).setValue(this.patches.getInt("paper.optimised-despawn.sand")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_RED_SAND.toString())).setValue(this.patches.getInt("paper.optimised-despawn.red-sand")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_GRAVEL.toString())).setValue(this.patches.getInt("paper.optimised-despawn.gravel")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_DIRT.toString())).setValue(this.patches.getInt("paper.optimised-despawn.dirt")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_SHORT_GRASS.toString())).setValue(this.patches.getInt("paper.optimised-despawn.short-grass")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_PUMPKIN.toString())).setValue(this.patches.getInt("paper.optimised-despawn.pumpkin")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_MELON_SLICE.toString())).setValue(this.patches.getInt("paper.optimised-despawn.melon-slice")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_KELP.toString())).setValue(this.patches.getInt("paper.optimised-despawn.kelp")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_BAMBOO.toString())).setValue(this.patches.getInt("paper.optimised-despawn.bamboo")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_SUGAR_CANE.toString())).setValue(this.patches.getInt("paper.optimised-despawn.sugar-cane")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_TWISTING_VINES.toString())).setValue(this.patches.getInt("paper.optimised-despawn.twisting-vines")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_WEEPING_VINES.toString())).setValue(this.patches.getInt("paper.optimised-despawn.weeping-vines")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_OAK_LEAVES.toString())).setValue(this.patches.getInt("paper.optimised-despawn.oak-leaves")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_SPRUCE_LEAVES.toString())).setValue(this.patches.getInt("paper.optimised-despawn.spruce-leaves")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_BIRCH_LEAVES.toString())).setValue(this.patches.getInt("paper.optimised-despawn.birch-leaves")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_JUNGLE_LEAVES.toString())).setValue(this.patches.getInt("paper.optimised-despawn.jungle-leaves")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_ACACIA_LEAVES.toString())).setValue(this.patches.getInt("paper.optimised-despawn.acacia-leaves")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_DARK_OAK_LEAVES.toString())).setValue(this.patches.getInt("paper.optimised-despawn.dark-oak-leaves")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_MANGROVE_LEAVES.toString())).setValue(this.patches.getInt("paper.optimised-despawn.mangrove-leaves")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_CACTUS.toString())).setValue(this.patches.getInt("paper.optimised-despawn.cactus")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_DIORITE.toString())).setValue(this.patches.getInt("paper.optimised-despawn.diorite")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_GRANITE.toString())).setValue(this.patches.getInt("paper.optimised-despawn.granite")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_ANDESITE.toString())).setValue(this.patches.getInt("paper.optimised-despawn.andesite")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ALT_ITEM_DESPAWN_RATE_SCAFFOLDING.toString())).setValue(this.patches.getInt("paper.optimised-despawn.scaffolding")); + + ((StringConfigItem)pw.values.get(PaperWorldConfig.Key.REDSTONE_IMPLEMENTATION.toString())).setValue(this.patches.getString("paper.redstone-implementation")); + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.HOPPER_DISABLE_MOVE_EVENT.toString())).setValue(this.patches.getBoolean("paper.hoppers.disable-move-event")); + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.HOPPER_IGNORE_OCCLUDING_BLOCKS.toString())).setValue(this.patches.getBoolean("paper.hoppers.ignore-occluding-blocks")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.TICK_RATE_MOB_SPAWNER.toString())).setValue(this.patches.getInt("paper.tick-rates.mob-spawner")); + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.OPTIMIZE_EXPLOSIONS.toString())).setValue(this.patches.getBoolean("paper.optimise-explosions")); if (pregeneratedWorld) { this.log.info("[KOS][4/6] World is pregenerated, enabling treasure maps..."); - pw.setBoolean(PaperWorld.Key.TREASURE_MAPS_ENABLED, true); + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.TREASURE_MAPS_ENABLED.toString())).setValue(true); } else { if (this.plugin.getConfig().getBoolean("kos.override-pregenerated-world-protections")) { - pw.setBoolean(PaperWorld.Key.TREASURE_MAPS_ENABLED, true); + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.TREASURE_MAPS_ENABLED.toString())).setValue(true); this.log.warn("[KOS][4/6] override-pregenerated-world-protections is TRUE, enabling treasure maps. This may cause lag."); } else { - pw.setBoolean(PaperWorld.Key.TREASURE_MAPS_ENABLED, false); + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.TREASURE_MAPS_ENABLED.toString())).setValue(false); this.log.info("[KOS][4/6] World not pregenerated, disabling treasure maps..."); this.message.Warning("Treasure maps have been disabled, please pre-generate your world to re-enable them."); } } - pw.setBoolean(PaperWorld.Key.TREASURE_MAPS_FIND_ALREADY_DISCOVERED_LOOT_TABLES, this.patches.getBoolean("paper.find-already-discovered-loot-tables")); - pw.setBoolean(PaperWorld.Key.TREASURE_MAPS_FIND_ALREADY_DISCOVERED_VILLAGER_TRADE, this.patches.getBoolean("paper.find-already-discovered-villager-trade")); - pw.setInt(PaperWorld.Key.TICK_RATE_GRASS_SPREAD, this.patches.getInt("paper.tick-rates.grass-spread")); - pw.setInt(PaperWorld.Key.TICK_RATE_CONTAINER_UPDATE, this.patches.getInt("paper.tick-rates.container-update")); - pw.setInt(PaperWorld.Key.ARROW_DESPAWN_RATE_NON_PLAYER, this.patches.getInt("paper.optimised-despawn.arrow.non-player")); - pw.setInt(PaperWorld.Key.ARROW_DESPAWN_RATE_CREATIVE, this.patches.getInt("paper.optimised-despawn.arrow.creative")); + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.TREASURE_MAPS_FIND_ALREADY_DISCOVERED_LOOT_TABLES.toString())).setValue(this.patches.getBoolean("paper.find-already-discovered-loot-tables")); + ((BooleanConfigItem)pw.values.get(PaperWorldConfig.Key.TREASURE_MAPS_FIND_ALREADY_DISCOVERED_VILLAGER_TRADE.toString())).setValue(this.patches.getBoolean("paper.find-already-discovered-villager-trade")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.TICK_RATE_GRASS_SPREAD.toString())).setValue(this.patches.getInt("paper.tick-rates.grass-spread")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.TICK_RATE_CONTAINER_UPDATE.toString())).setValue(this.patches.getInt("paper.tick-rates.container-update")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ARROW_DESPAWN_RATE_NON_PLAYER.toString())).setValue(this.patches.getInt("paper.optimised-despawn.arrow.non-player")); + ((IntegerConfigItem)pw.values.get(PaperWorldConfig.Key.ARROW_DESPAWN_RATE_CREATIVE.toString())).setValue(this.patches.getInt("paper.optimised-despawn.arrow.creative")); } else { log.info("[KOS] 4/6 - Server does not support Paper World configurations, skipping..."); } diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java index 38f2be9..9223a08 100644 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java +++ b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_ConfigItemGui.java @@ -51,6 +51,8 @@ public void show() { this.config = new BukkitConfig(plugin); } else if (type == Kryptonite.ConfigurationOptions.SPIGOT) { this.config = new SpigotConfig(plugin); + } else if (type == Kryptonite.ConfigurationOptions.PAPER_WORLD) { + this.config = new PaperWorldConfig(plugin); } else if (type == Kryptonite.ConfigurationOptions.PURPUR) { this.config = new PurpurConfig(plugin); } else if (type == Kryptonite.ConfigurationOptions.PUFFERFISH) { diff --git a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_1.java b/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_1.java deleted file mode 100644 index 8c16b99..0000000 --- a/src/main/java/net/lewmc/kryptonite/kos/gui/KOS_PaperWorld_1.java +++ /dev/null @@ -1,610 +0,0 @@ -package net.lewmc.kryptonite.kos.gui; - -import de.themoep.inventorygui.GuiElement; -import de.themoep.inventorygui.InventoryGui; -import de.themoep.inventorygui.StaticGuiElement; -import net.lewmc.kryptonite.Kryptonite; -import net.lewmc.kryptonite.kos.config.PaperWorld; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; - - - - -/* - * tick-rates - don't change with DAB - * https://shop.layten.net/how-to-optimize-your-minecraft-server/ - */ - - - - -/** - * KOS Paper World GUI (Page 1/5) - * @deprecated - */ -@Deprecated -public class KOS_PaperWorld_1 { - private final Kryptonite plugin; - private final CommandSender user; - private final PaperWorld paperWorld; - private InventoryGui gui; - - /** - * Constructor for the KOS Paper World GUI (Page 1/5) - * @param plugin Kryptonite - Reference to the main plugin class. - * @param user CommandSender - The user who sent the command. - */ - public KOS_PaperWorld_1(Kryptonite plugin, CommandSender user) { - this.plugin = plugin; - this.user = user; - this.paperWorld = new PaperWorld(plugin, user); - } - - /** - * Shows the KOS Paper World GUI (Page 1/5) - */ - public void show() { - InventoryHolder holder = this.user.getServer().getPlayer(this.user.getName()); - this.gui = new InventoryGui(this.plugin, holder, "KOS - Paper World Configuration (1/5)", this.getElements()); - this.addElements(); - - this.gui.build(); - this.gui.show((Player) this.user); - } - - /** - * Adds pre-programmed elements to the GUI - */ - private void addElements() { - this.delayChunkUnloadsBy('a'); - this.maxAutosaveChunksPerTick('b'); - this.preventMovingIntoUnloadedChucks('c'); - this.entityPerChunkSaveLimitAreaEffectCloud('d'); - this.entityPerChunkSaveLimitArrow('e'); - this.entityPerChunkSaveLimitDragonFireball('f'); - this.entityPerChunkSaveLimitEgg('g'); - this.entityPerChunkSaveLimitEnderPearl('h'); - this.entityPerChunkSaveLimitExperienceBottle('i'); - this.entityPerChunkSaveLimitExperienceOrb('j'); - this.entityPerChunkSaveLimitEyeOfEnder('k'); - this.entityPerChunkSaveLimitFireball('l'); - this.entityPerChunkSaveLimitLlamaSpit('m'); - this.entityPerChunkSaveLimitPotion('n'); - this.entityPerChunkSaveLimitShulkerBullet('o'); - this.entityPerChunkSaveLimitSmallFireball('p'); - this.entityPerChunkSaveLimitSnowball('q'); - this.entityPerChunkSaveLimitSpectralArrow('r'); - - KOS_GuiConstants consts = new KOS_GuiConstants(this.plugin, this.gui); - consts.addConstants(); - - this.gui.addElement(new StaticGuiElement('z', - new ItemStack(Material.OAK_SIGN), - 1, - click -> { - click.getGui().close(); - KOS_PaperWorld_2 nextGui = new KOS_PaperWorld_2(this.plugin, this.user); - nextGui.show(); - return true; - }, - ChatColor.WHITE + "Next page" - )); - } - - /** - * Determines where the elements should be positioned. - * @return String[] - The position of the elements. - */ - private String[] getElements() { - - return new String[]{ - "abcdefghi", - "jklmnopqr", - " w x y z" - }; - } - - private void delayChunkUnloadsBy(char id) { - Object value = this.paperWorld.getObject(PaperWorld.Key.DELAY_CHUNK_UNLOADS_BY); - if (value instanceof String && value == "default") { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.DELAY_CHUNK_UNLOADS_BY, click, 0, true), - ChatColor.DARK_GREEN + "Delay Chunk Unloads By", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value instanceof String && value != "default") { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.WHITE_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.DELAY_CHUNK_UNLOADS_BY, click, (int) value, true), - ChatColor.WHITE + "Delay Chunk Unloads By", - ChatColor.GRAY + String.valueOf(value), - ChatColor.GRAY + "'default' (lowest value) is ideal for most servers.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else if (value instanceof Integer) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.WHITE_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.DELAY_CHUNK_UNLOADS_BY, click, (int) value, true), - ChatColor.WHITE + "Delay Chunk Unloads By", - ChatColor.GRAY + String.valueOf(value), - ChatColor.GRAY + "'default' (lowest value) is ideal for most servers.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.BARRIER), - 1, - click -> true, - ChatColor.DARK_RED + "Delay Chunk Unloads By", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Kryptonite cannot recognise this value, and therefore cannot edit it.", - ChatColor.RED + "Please send a screenshot of this error to github.com/lewmc/kryptonite" - )); - } - } - - private void maxAutosaveChunksPerTick(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.MAX_AUTOSAVE_CHUNKS_PER_TICK); - if (value == 24) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.MAX_AUTOSAVE_CHUNKS_PER_TICK, click, value, false), - ChatColor.DARK_GREEN + "Max Autosave Chunks Per Tick", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.MAX_AUTOSAVE_CHUNKS_PER_TICK, click, value, false), - ChatColor.DARK_RED + "Max Autosave Chunks Per Tick", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Advanced players only - may cause performance issues if set incorrectly.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void preventMovingIntoUnloadedChucks(char id) { - boolean value = this.paperWorld.getBoolean(PaperWorld.Key.PREVENT_MOVING_INTO_UNLOADED_CHUNKS); - if (value) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.paperWorld.setBoolean(PaperWorld.Key.PREVENT_MOVING_INTO_UNLOADED_CHUNKS, false); - this.show(); - return true; - }, - ChatColor.DARK_GREEN + "Prevent Moving into Unloaded Chunks", - ChatColor.GREEN + "true", - ChatColor.GREEN + "Ideal value.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> { - click.getGui().close(); - this.paperWorld.setBoolean(PaperWorld.Key.PREVENT_MOVING_INTO_UNLOADED_CHUNKS, true); - this.show(); - return true; - }, - ChatColor.DARK_RED + "Prevent Moving into Unloaded Chunks", - ChatColor.RED + "false", - ChatColor.RED + "Heavy impact to performance.", - ChatColor.BLUE + "Click to toggle true/false." - )); - } - } - - private void entityPerChunkSaveLimitAreaEffectCloud(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_AREA_EFFECT_CLOUD); - if (value < 11) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_AREA_EFFECT_CLOUD, click, value, false), - ChatColor.DARK_GREEN + "Entity Per Chunk Save Limit (Area Effect Cloud)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_AREA_EFFECT_CLOUD, click, value, false), - ChatColor.DARK_RED + "Entity Per Chunk Save Limit (Area Effect Cloud)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to chunk loading performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityPerChunkSaveLimitArrow(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_ARROW); - if (value < 20) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_ARROW, click, value, false), - ChatColor.DARK_GREEN + "Entity Per Chunk Save Limit (Arrow)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_ARROW, click, value, false), - ChatColor.DARK_RED + "Entity Per Chunk Save Limit (Arrow)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to chunk loading performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityPerChunkSaveLimitDragonFireball(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_DRAGON_FIREBALL); - if (value < 6) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_DRAGON_FIREBALL, click, value, false), - ChatColor.DARK_GREEN + "Entity Per Chunk Save Limit (Dragon Fireball)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_DRAGON_FIREBALL, click, value, false), - ChatColor.DARK_RED + "Entity Per Chunk Save Limit (Dragon Fireball)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to chunk loading performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityPerChunkSaveLimitEgg(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EGG); - if (value < 9) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EGG, click, value, false), - ChatColor.DARK_GREEN + "Entity Per Chunk Save Limit (Egg)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EGG, click, value, false), - ChatColor.DARK_RED + "Entity Per Chunk Save Limit (Egg)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to chunk loading performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityPerChunkSaveLimitEnderPearl(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_ENDER_PEARL); - if (value < 9) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_ENDER_PEARL, click, value, false), - ChatColor.DARK_GREEN + "Entity Per Chunk Save Limit (Ender Pearl)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_ENDER_PEARL, click, value, false), - ChatColor.DARK_RED + "Entity Per Chunk Save Limit (Ender Pearl)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to chunk loading performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityPerChunkSaveLimitExperienceBottle(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_BOTTLE); - if (value < 4) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_BOTTLE, click, value, false), - ChatColor.DARK_GREEN + "Entity Per Chunk Save Limit (Experience Bottle)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_BOTTLE, click, value, false), - ChatColor.DARK_RED + "Entity Per Chunk Save Limit (Experience Bottle)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to chunk loading performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityPerChunkSaveLimitExperienceOrb(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_ORB); - if (value < 21) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_ORB, click, value, false), - ChatColor.DARK_GREEN + "Entity Per Chunk Save Limit (Experience Orb)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EXPERIENCE_ORB, click, value, false), - ChatColor.DARK_RED + "Entity Per Chunk Save Limit (Experience Orb)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to chunk loading performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityPerChunkSaveLimitEyeOfEnder(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EYE_OF_ENDER); - if (value < 11) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EYE_OF_ENDER, click, value, false), - ChatColor.DARK_GREEN + "Entity Per Chunk Save Limit (Eye of Ender)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_EYE_OF_ENDER, click, value, false), - ChatColor.DARK_RED + "Entity Per Chunk Save Limit (Eye of Ender)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to chunk loading performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityPerChunkSaveLimitFireball(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_FIREBALL); - if (value < 11) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_FIREBALL, click, value, false), - ChatColor.DARK_GREEN + "Entity Per Chunk Save Limit (Fireball)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_FIREBALL, click, value, false), - ChatColor.DARK_RED + "Entity Per Chunk Save Limit (Fireball)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to chunk loading performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityPerChunkSaveLimitLlamaSpit(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_LLAMA_SPIT); - if (value < 6) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_LLAMA_SPIT, click, value, false), - ChatColor.DARK_GREEN + "Entity Per Chunk Save Limit (Llama Spit)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_LLAMA_SPIT, click, value, false), - ChatColor.DARK_RED + "Entity Per Chunk Save Limit (Llama Spit)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to chunk loading performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityPerChunkSaveLimitPotion(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_POTION); - if (value < 6) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_POTION, click, value, false), - ChatColor.DARK_GREEN + "Entity Per Chunk Save Limit (Potion)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_POTION, click, value, false), - ChatColor.DARK_RED + "Entity Per Chunk Save Limit (Potion)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to chunk loading performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityPerChunkSaveLimitShulkerBullet(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SHULKER_BULLET); - if (value < 9) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SHULKER_BULLET, click, value, false), - ChatColor.DARK_GREEN + "Entity Per Chunk Save Limit (Shulker Bullet)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SHULKER_BULLET, click, value, false), - ChatColor.DARK_RED + "Entity Per Chunk Save Limit (Shulker Bullet)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to chunk loading performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityPerChunkSaveLimitSmallFireball(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SMALL_FIREBALL); - if (value < 11) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SMALL_FIREBALL, click, value, false), - ChatColor.DARK_GREEN + "Entity Per Chunk Save Limit (Small Fireball)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SMALL_FIREBALL, click, value, false), - ChatColor.DARK_RED + "Entity Per Chunk Save Limit (Small Fireball)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to chunk loading performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityPerChunkSaveLimitSnowball(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SNOWBALL); - if (value < 21) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SNOWBALL, click, value, false), - ChatColor.DARK_GREEN + "Entity Per Chunk Save Limit (Snowball)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SNOWBALL, click, value, false), - ChatColor.DARK_RED + "Entity Per Chunk Save Limit (Snowball)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to chunk loading performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private void entityPerChunkSaveLimitSpectralArrow(char id) { - int value = this.paperWorld.getInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SPECTRAL_ARROW); - if (value < 6) { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.LIME_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SPECTRAL_ARROW, click, value, false), - ChatColor.DARK_GREEN + "Entity Per Chunk Save Limit (Spectral Arrow)", - ChatColor.GREEN + String.valueOf(value), - ChatColor.GREEN + "Within ideal range.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } else { - this.gui.addElement(new StaticGuiElement(id, - new ItemStack(Material.RED_CONCRETE), - 1, - click -> this.setInt(PaperWorld.Key.ENTITY_PER_CHUNK_SAVE_LIMIT_SPECTRAL_ARROW, click, value, false), - ChatColor.DARK_RED + "Entity Per Chunk Save Limit (Spectral Arrow)", - ChatColor.RED + String.valueOf(value), - ChatColor.RED + "Too high - impact to chunk loading performance.", - ChatColor.BLUE + "Right click to increase - left click to decrease." - )); - } - } - - private boolean setInt(PaperWorld.Key key, GuiElement.Click click, int value, boolean canBeDefault) { - click.getGui().close(); - if (click.getType() == ClickType.RIGHT) { - this.paperWorld.setInt(key, value + 1); - } else if (click.getType() == ClickType.SHIFT_RIGHT) { - this.paperWorld.setInt(key, value + 10); - } else if (click.getType() == ClickType.LEFT && value != 0) { - this.paperWorld.setInt(key, value - 1); - } else if (click.getType() == ClickType.SHIFT_LEFT && value >= 10) { - this.paperWorld.setInt(key, value - 10); - } else if ((click.getType() == ClickType.LEFT || click.getType() == ClickType.SHIFT_LEFT) && value == 0 && canBeDefault) { - this.paperWorld.setString(key, "default"); - } - - this.show(); - return true; - } -} diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java index 2059fc4..5a05a60 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/DoubleConfigItem.java @@ -102,16 +102,31 @@ public boolean willBeValid(Double value) { */ @Override public boolean isIdeal() { - if (idealValue == null) { return true; } - Double current = this.getValue(); - if (idealValue.contains("-")) { - String[] parts = idealValue.split("-"); - double minIdeal = Double.parseDouble(parts[0]); - double maxIdeal = Double.parseDouble(parts[1]); + if (idealValue == null) { + return true; + } + + double current = this.getValue(); + String trimmed = idealValue.trim(); + + if (trimmed.contains("-")) { + String[] parts = trimmed.split("-"); + double minIdeal = Double.parseDouble(parts[0].trim()); + double maxIdeal = Double.parseDouble(parts[1].trim()); return current >= minIdeal && current <= maxIdeal; - } else { - return current == Double.parseDouble(idealValue); } + + if (trimmed.startsWith(">")) { + double threshold = Double.parseDouble(trimmed.substring(1).trim()); + return current > threshold; + } + + if (trimmed.startsWith("<")) { + double threshold = Double.parseDouble(trimmed.substring(1).trim()); + return current < threshold; + } + + return current == Double.parseDouble(trimmed); } /** diff --git a/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java b/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java index 2bed188..10c4776 100644 --- a/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java +++ b/src/main/java/net/lewmc/kryptonite/utils/config/IntegerConfigItem.java @@ -102,18 +102,34 @@ public boolean willBeValid(Integer value) { */ @Override public boolean isIdeal() { - if (idealValue == null) { return true; } + if (idealValue == null) { + return true; + } + int current = this.getValue(); - if (idealValue.contains("-")) { - String[] parts = idealValue.split("-"); + String trimmed = idealValue.trim(); + + if (trimmed.contains("-")) { + String[] parts = trimmed.split("-"); int minIdeal = Integer.parseInt(parts[0].trim()); int maxIdeal = Integer.parseInt(parts[1].trim()); return current >= minIdeal && current <= maxIdeal; - } else { - return current == Integer.parseInt(idealValue); } + + if (trimmed.startsWith(">")) { + int threshold = Integer.parseInt(trimmed.substring(1).trim()); + return current > threshold; + } + + if (trimmed.startsWith("<")) { + int threshold = Integer.parseInt(trimmed.substring(1).trim()); + return current < threshold; + } + + return current == Integer.parseInt(trimmed); } + /** * Returns the ideal value in human-readable, string format. * @return String - The ideal value.