diff --git a/gradle.properties b/gradle.properties index c216770..f36d02b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ includes_pack=true # The release channel your plugin should be built and ran against. This is # usually release or pre-release. You can verify your settings in the # official launcher. -patchline=release +patchline=pre-release # Determines if the development server should also load mods from the user's # standard mods folder. This lets you test mods by installing them where a diff --git a/src/main/java/xyz/quickbasic/tieredrepairkits/RepairKitManager.java b/src/main/java/xyz/quickbasic/tieredrepairkits/RepairKitManager.java new file mode 100644 index 0000000..fffd2b2 --- /dev/null +++ b/src/main/java/xyz/quickbasic/tieredrepairkits/RepairKitManager.java @@ -0,0 +1,63 @@ +package xyz.quickbasic.tieredrepairkits; + + +// This class is responsible for managing repair-kit related data for the plugin. +// It loads values from the configuration and stores them in variables that the +// rest of the plugin can access easily. +public class RepairKitManager { + + // Reference to the main plugin class. + // This allows the manager to access things like config, logging, etc. + private final TieredRepairKits plugin; + + // Local copies of configuration values. + // These are loaded from the config file when the manager starts. + private int someValue; + private String someString; + + + // Constructor for the manager. + // This runs when a new RepairKitManager is created in your main plugin. + public RepairKitManager(TieredRepairKits plugin) { + + // Store the reference to the plugin + this.plugin = plugin; + + // Immediately load values from the config file into local variables + loadConfig(); + } + + + // This method loads values from the plugin configuration + // and stores them inside this manager class. + public void loadConfig() { + + // Retrieve the TRKConfig object from the plugin's Config wrapper + TRKConfig config = plugin.getConfig().get(); + + // Copy values from the config object into this manager's variables + this.someValue = config.getSomeValue(); + this.someString = config.getSomeString(); + + // Log information to the server console to confirm the config was loaded + TieredRepairKits.LOGGER.atInfo().log("Config Loaded"); + + // Print the loaded values so you can verify them during development + TieredRepairKits.LOGGER.atInfo().log("SomeValue = " + someValue); + TieredRepairKits.LOGGER.atInfo().log("SomeString = " + someString); + } + + + // Getter method for someValue + // Other classes can call this to retrieve the loaded value + public int getSomeValue() { + return someValue; + } + + + // Getter method for someString + // Provides read access to the stored config value + public String getSomeString() { + return someString; + } +} \ No newline at end of file diff --git a/src/main/java/xyz/quickbasic/tieredrepairkits/TRKConfig.java b/src/main/java/xyz/quickbasic/tieredrepairkits/TRKConfig.java new file mode 100644 index 0000000..324c764 --- /dev/null +++ b/src/main/java/xyz/quickbasic/tieredrepairkits/TRKConfig.java @@ -0,0 +1,77 @@ +package xyz.quickbasic.tieredrepairkits; + +// Hytale codec system imports used to serialize/deserialize config data +import com.hypixel.hytale.codec.Codec; // Careful to not use other Codec imports +import com.hypixel.hytale.codec.KeyedCodec; +import com.hypixel.hytale.codec.builder.BuilderCodec; + + +// This class represents the structure of your plugin's configuration file. +// The fields in this class correspond to values stored in JSON. +public class TRKConfig { + + // CODEC tells the Hytale engine how to convert between: + // Java object (TRKConfig) <-> JSON file on disk + public static final BuilderCodec CODEC = BuilderCodec.builder(TRKConfig.class, TRKConfig::new) + + // Adds a config field called "SomeValue" to the JSON + // Codec.INTEGER tells Hytale the value is an integer + .append(new KeyedCodec("SomeValue", Codec.INTEGER), + + // Setter: how the JSON value gets written into this object + (config, value) -> config.someValue = value, + + // Getter: how the value is read from this object when saving JSON + (config) -> config.someValue).add() + + // Adds another config field called "SomeString" + // Codec.STRING tells Hytale the value type is a string + .append(new KeyedCodec("SomeString", Codec.STRING), + + // Setter: how JSON value updates the object field + (config, value) -> config.someString = value, + + // Getter: how the value is read when saving + (config) -> config.someString).add() + + // Finalizes the codec definition + .build(); + + + // Default value for the integer config entry + // If the config file doesn't exist yet, this value will be written + private int someValue = 12; + + // Default value for the string config entry + private String someString = "My default string"; + + + // Default constructor required by the codec system + // The codec calls this when creating a new config object + public TRKConfig() { + } + + + // Getter for SomeValue + // Allows other classes to read the value safely + public int getSomeValue() { + return someValue; + } + + // Getter for SomeString + public String getSomeString() { + return someString; + } + + + // Setter for SomeValue + // Allows code to change the value before saving the config + public void setSomeValue(int someValue) { + this.someValue = someValue; + } + + // Setter for SomeString + public void setSomeString(String someString) { + this.someString = someString; + } +} \ No newline at end of file diff --git a/src/main/java/xyz/quickbasic/tieredrepairkits/TieredRepairKits.java b/src/main/java/xyz/quickbasic/tieredrepairkits/TieredRepairKits.java index 530ef0e..5c18c11 100644 --- a/src/main/java/xyz/quickbasic/tieredrepairkits/TieredRepairKits.java +++ b/src/main/java/xyz/quickbasic/tieredrepairkits/TieredRepairKits.java @@ -3,20 +3,45 @@ package xyz.quickbasic.tieredrepairkits; import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.server.core.plugin.JavaPlugin; import com.hypixel.hytale.server.core.plugin.JavaPluginInit; +import com.hypixel.hytale.server.core.util.Config; import javax.annotation.Nonnull; + +// Main plugin class. All Hytale Java plugins extend JavaPlugin. public class TieredRepairKits extends JavaPlugin { + // Logger instance for writing messages to the server console/logs public static final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass(); + // Manager class that will contain the logic related to repair kits + private RepairKitManager repairKitManager; + + // Config wrapper provided by the Hytale server API. + // This links the config file name ("MyConfig") with the codec defined in TRKConfig. + private final Config config = this.withConfig("MyConfig", TRKConfig.CODEC); + + // Public getter so other classes (like managers) can access the plugin config + public Config getConfig() { + return config; + } + + // Constructor called by the Hytale server when the plugin is created public TieredRepairKits(@Nonnull JavaPluginInit init) { super(init); } + // Called by the server when the plugin is being set up @Override protected void setup() { - // Register event listeners here - try using the "Hytale Devtools: Add new event listener" command + + // Create the RepairKitManager and pass the plugin instance to it + // This allows the manager to access config, logger, etc. + repairKitManager = new RepairKitManager(this); + + // Save the config file if it does not exist yet + // This ensures defaults from TRKConfig are written to disk + config.save(); } } \ No newline at end of file