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..71d9179 --- /dev/null +++ b/src/main/java/xyz/quickbasic/tieredrepairkits/RepairKitManager.java @@ -0,0 +1,53 @@ +package xyz.quickbasic.tieredrepairkits; + +import xyz.quickbasic.tieredrepairkits.config.RepairTier; + +import java.util.Map; + +// Manages repair-kit data for the plugin +public class RepairKitManager { + + // Reference to the main plugin class + private final TieredRepairKits plugin; + + // Cached tiers map for easy access + private Map tiers; + + // Constructor + public RepairKitManager(TieredRepairKits plugin) { + this.plugin = plugin; + + // Load the config into local variables + loadConfig(); + } + + // Load config from TRKConfig + public void loadConfig() { + TRKConfig config = plugin.getConfig().get(); + + // Get all tiers from TRKConfig + tiers = config.getTiers(); + + // Log loaded tiers + for (var entry : tiers.entrySet()) { + String tierName = entry.getKey(); + RepairTier tier = entry.getValue(); + + TieredRepairKits.LOGGER.atInfo().log("Loaded tier: " + tierName); + TieredRepairKits.LOGGER.atInfo().log("Enabled: " + tier.isEnabled()); + TieredRepairKits.LOGGER.atInfo().log("RepairPenalty: " + tier.getRepairPenalty()); + TieredRepairKits.LOGGER.atInfo().log("FieldcraftingEnabled: " + tier.isFieldcraftingEnabled()); + TieredRepairKits.LOGGER.atInfo().log("Recipe size: " + tier.getRecipe().size()); + } + } + + // Getter for all tiers + public Map getTiers() { + return tiers; + } + + // Optional: getter for a single tier + public RepairTier getTier(String name) { + return tiers.get(name); + } +} \ 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..566343e --- /dev/null +++ b/src/main/java/xyz/quickbasic/tieredrepairkits/TRKConfig.java @@ -0,0 +1,115 @@ +package xyz.quickbasic.tieredrepairkits; + +import com.hypixel.hytale.codec.KeyedCodec; +import com.hypixel.hytale.codec.builder.BuilderCodec; +import xyz.quickbasic.tieredrepairkits.config.RepairTier; + +import java.util.LinkedHashMap; +import java.util.Map; + +// Main config class for TieredRepairKits +public class TRKConfig { + + public static final BuilderCodec CODEC = BuilderCodec.builder(TRKConfig.class, TRKConfig::new) + + .append(new KeyedCodec("TierCopper", RepairTier.CODEC), + (cfg, val) -> cfg.tierCopper = val, + cfg -> cfg.tierCopper).add() + + .append(new KeyedCodec("TierIron", RepairTier.CODEC), + (cfg, val) -> cfg.tierIron = val, + cfg -> cfg.tierIron).add() + + .append(new KeyedCodec("TierSilver", RepairTier.CODEC), + (cfg, val) -> cfg.tierSilver = val, + cfg -> cfg.tierSilver).add() + + .append(new KeyedCodec("TierGold", RepairTier.CODEC), + (cfg, val) -> cfg.tierGold = val, + cfg -> cfg.tierGold).add() + + .append(new KeyedCodec("TierThorium", RepairTier.CODEC), + (cfg, val) -> cfg.tierThorium = val, + cfg -> cfg.tierThorium).add() + + .append(new KeyedCodec("TierCobalt", RepairTier.CODEC), + (cfg, val) -> cfg.tierCobalt = val, + cfg -> cfg.tierCobalt).add() + + .append(new KeyedCodec("TierAdamantite", RepairTier.CODEC), + (cfg, val) -> cfg.tierAdamantite = val, + cfg -> cfg.tierAdamantite).add() + + .append(new KeyedCodec("TierMithril", RepairTier.CODEC), + (cfg, val) -> cfg.tierMithril = val, + cfg -> cfg.tierMithril).add() + + .append(new KeyedCodec("TierOnyxium", RepairTier.CODEC), + (cfg, val) -> cfg.tierOnyxium = val, + cfg -> cfg.tierOnyxium).add() + + .append(new KeyedCodec("TierPrisma", RepairTier.CODEC), + (cfg, val) -> cfg.tierPrisma = val, + cfg -> cfg.tierPrisma).add() + + .build(); + + // --- Tier fields --- + private RepairTier tierCopper = new RepairTier(); + private RepairTier tierIron = new RepairTier(); + private RepairTier tierSilver = new RepairTier(); + private RepairTier tierGold = new RepairTier(); + private RepairTier tierThorium = new RepairTier(); + private RepairTier tierCobalt = new RepairTier(); + private RepairTier tierAdamantite = new RepairTier(); + private RepairTier tierMithril = new RepairTier(); + private RepairTier tierOnyxium = new RepairTier(); + private RepairTier tierPrisma = new RepairTier(); + + // Cached map for runtime convenience + private Map cachedMap; + + public TRKConfig() {} + + // Returns a map of tier names -> RepairTier + public Map getTiers() { + if (cachedMap == null) { + cachedMap = new LinkedHashMap<>(); + cachedMap.put("TierCopper", tierCopper); + cachedMap.put("TierIron", tierIron); + cachedMap.put("TierSilver", tierSilver); + cachedMap.put("TierGold", tierGold); + cachedMap.put("TierThorium", tierThorium); + cachedMap.put("TierCobalt", tierCobalt); + cachedMap.put("TierAdamantite", tierAdamantite); + cachedMap.put("TierMithril", tierMithril); + cachedMap.put("TierOnyxium", tierOnyxium); + cachedMap.put("TierPrisma", tierPrisma); + } + return cachedMap; + } + + // Individual tier getters + public RepairTier getTierCopper() { return tierCopper; } + public RepairTier getTierIron() { return tierIron; } + public RepairTier getTierSilver() { return tierSilver; } + public RepairTier getTierGold() { return tierGold; } + public RepairTier getTierThorium() { return tierThorium; } + public RepairTier getTierCobalt() { return tierCobalt; } + public RepairTier getTierAdamantite() { return tierAdamantite; } + public RepairTier getTierMithril() { return tierMithril; } + public RepairTier getTierOnyxium() { return tierOnyxium; } + public RepairTier getTierPrisma() { return tierPrisma; } + + // Individual tier setters (optional, also clears cached map) + public void setTierCopper(RepairTier tier) { this.tierCopper = tier; cachedMap = null; } + public void setTierIron(RepairTier tier) { this.tierIron = tier; cachedMap = null; } + public void setTierSilver(RepairTier tier) { this.tierSilver = tier; cachedMap = null; } + public void setTierGold(RepairTier tier) { this.tierGold = tier; cachedMap = null; } + public void setTierThorium(RepairTier tier) { this.tierThorium = tier; cachedMap = null; } + public void setTierCobalt(RepairTier tier) { this.tierCobalt = tier; cachedMap = null; } + public void setTierAdamantite(RepairTier tier) { this.tierAdamantite = tier; cachedMap = null; } + public void setTierMithril(RepairTier tier) { this.tierMithril = tier; cachedMap = null; } + public void setTierOnyxium(RepairTier tier) { this.tierOnyxium = tier; cachedMap = null; } + public void setTierPrisma(RepairTier tier) { this.tierPrisma = tier; cachedMap = null; } +} \ 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 diff --git a/src/main/java/xyz/quickbasic/tieredrepairkits/config/RecipeIngredient.java b/src/main/java/xyz/quickbasic/tieredrepairkits/config/RecipeIngredient.java new file mode 100644 index 0000000..3e74f08 --- /dev/null +++ b/src/main/java/xyz/quickbasic/tieredrepairkits/config/RecipeIngredient.java @@ -0,0 +1,30 @@ +package xyz.quickbasic.tieredrepairkits.config; + +import com.hypixel.hytale.codec.Codec; +import com.hypixel.hytale.codec.KeyedCodec; +import com.hypixel.hytale.codec.builder.BuilderCodec; + +public class RecipeIngredient { + + public static final BuilderCodec CODEC = + BuilderCodec.builder(RecipeIngredient.class, RecipeIngredient::new) + + .append(new KeyedCodec("ItemId", Codec.STRING), + (obj, value) -> obj.itemId = value, + (obj) -> obj.itemId).add() + + .append(new KeyedCodec("Quantity", Codec.INTEGER), + (obj, value) -> obj.quantity = value, + (obj) -> obj.quantity).add() + + .build(); + + private String itemId = "Ingredient_Fibre"; + private int quantity = 1; + + public RecipeIngredient() {} + + public String getItemId() { return itemId; } + + public int getQuantity() { return quantity; } +} \ No newline at end of file diff --git a/src/main/java/xyz/quickbasic/tieredrepairkits/config/RepairTier.java b/src/main/java/xyz/quickbasic/tieredrepairkits/config/RepairTier.java new file mode 100644 index 0000000..3fd8e3e --- /dev/null +++ b/src/main/java/xyz/quickbasic/tieredrepairkits/config/RepairTier.java @@ -0,0 +1,81 @@ +package xyz.quickbasic.tieredrepairkits.config; + +import com.hypixel.hytale.codec.Codec; +import com.hypixel.hytale.codec.KeyedCodec; +import com.hypixel.hytale.codec.builder.BuilderCodec; +import com.hypixel.hytale.codec.codecs.array.ArrayCodec; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class RepairTier { + + // In this API version, we create an ArrayCodec and then convert it to/from a List + // We use the RecipeIngredient.CODEC and a constructor for the array type. + private static final Codec> INGREDIENT_LIST_CODEC = new Codec>() { + private final ArrayCodec arrayCodec = new ArrayCodec<>(RecipeIngredient.CODEC, RecipeIngredient[]::new); + + @Override + public List decode(org.bson.BsonValue bsonValue, com.hypixel.hytale.codec.ExtraInfo extraInfo) { + RecipeIngredient[] arr = arrayCodec.decode(bsonValue, extraInfo); + return arr == null ? new ArrayList<>() : new ArrayList<>(Arrays.asList(arr)); + } + + @Override + public org.bson.BsonValue encode(List value, com.hypixel.hytale.codec.ExtraInfo extraInfo) { + return arrayCodec.encode(value.toArray(new RecipeIngredient[0]), extraInfo); + } + + @Override + public com.hypixel.hytale.codec.schema.config.Schema toSchema(com.hypixel.hytale.codec.schema.SchemaContext context) { + return arrayCodec.toSchema(context); + } + }; + + public static final BuilderCodec CODEC = + BuilderCodec.builder(RepairTier.class, RepairTier::new) + .append(new KeyedCodec<>("Enabled", Codec.BOOLEAN), + (obj, value) -> obj.enabled = value, + (obj) -> obj.enabled).add() + + .append(new KeyedCodec<>("RepairPenalty", Codec.DOUBLE), + (obj, value) -> obj.repairPenalty = value, + (obj) -> obj.repairPenalty).add() + + .append(new KeyedCodec<>("FieldcraftingEnabled", Codec.BOOLEAN), + (obj, value) -> obj.fieldcraftingEnabled = value, + (obj) -> obj.fieldcraftingEnabled).add() + + .append(new KeyedCodec<>("FieldcraftingRecipe", INGREDIENT_LIST_CODEC), + (obj, value) -> obj.fieldcraftingRecipe = value, + (obj) -> obj.fieldcraftingRecipe).add() + + .append(new KeyedCodec<>("Recipe", INGREDIENT_LIST_CODEC), + (obj, value) -> obj.recipe = value, + (obj) -> obj.recipe).add() + + .build(); + + private boolean enabled = true; + private double repairPenalty = 0.0; + private boolean fieldcraftingEnabled = false; + private List fieldcraftingRecipe = new ArrayList<>(); + private List recipe = new ArrayList<>(); + + public RepairTier() {} + + // --- Getters --- + public boolean isEnabled() { return enabled; } + public double getRepairPenalty() { return repairPenalty; } + public boolean isFieldcraftingEnabled() { return fieldcraftingEnabled; } + public List getFieldcraftingRecipe() { return fieldcraftingRecipe; } + public List getRecipe() { return recipe; } + + // --- Setters --- + public void setEnabled(boolean enabled) { this.enabled = enabled; } + public void setRepairPenalty(double repairPenalty) { this.repairPenalty = repairPenalty; } + public void setFieldcraftingEnabled(boolean fieldcraftingEnabled) { this.fieldcraftingEnabled = fieldcraftingEnabled; } + public void setFieldcraftingRecipe(List fieldcraftingRecipe) { this.fieldcraftingRecipe = fieldcraftingRecipe; } + public void setRecipe(List recipe) { this.recipe = recipe; } +} \ No newline at end of file diff --git a/src/main/resources/manifest.json b/src/main/resources/manifest.json index d05ffe3..fe27952 100644 --- a/src/main/resources/manifest.json +++ b/src/main/resources/manifest.json @@ -1,21 +1,30 @@ { - "Group": "QuickBASIC", - "Name": "QuickBASIC.TieredRepairKits", - "Version": "1.0.1", - "ServerVersion": "2026.03.26-89796e57b", - "Description": "Balanced tiered Repair Kits that can increase the maximum durability of items", - "Authors": [ - { - "Name": "QuickBASIC", - "Email": "quickbasic@quickbasic.xyz", - "Url": "https://git.quickbasic.xyz/hytale-modding" - } - ], - "Website": "https://git.quickbasic.xyz/hytale-modding/TieredRepairKits", - "Dependencies": {}, - "OptionalDependencies": {}, - "LoadBefore": {}, - "DisabledByDefault": false, - "IncludesAssetPack": false, - "SubPlugins": [] -} + "Group": "QuickBASIC", + "Name": "QuickBASIC.TieredRepairKits", + "Version": "1.1.0", + "Main": "xyz.quickbasic.tieredrepairkits.TieredRepairKits", + "ServerVersion": "2026.03.26-89796e57b", + "Description": "Balanced tiered Repair Kits that can increase the maximum durability of items", + "Authors": [ + { + "Name": "QuickBASIC", + "Email": "quickbasic@quickbasic.xyz", + "Url": "https://git.quickbasic.xyz/hytale-modding" + } + ], + "Website": "https://git.quickbasic.xyz/hytale-modding/TieredRepairKits", + "Dependencies": { + + }, + "OptionalDependencies": { + + }, + "LoadBefore": { + + }, + "DisabledByDefault": false, + "IncludesAssetPack": true, + "SubPlugins": [ + + ] +} \ No newline at end of file