From a15d736d453797f85123aa8abc74eed968e89f0b Mon Sep 17 00:00:00 2001 From: QuickBASIC Date: Fri, 27 Mar 2026 16:55:57 -0400 Subject: [PATCH] simplify config, remove fieldcrafting, implement default config --- .../tieredrepairkits/RepairKitManager.java | 12 -- .../tieredrepairkits/TRKConfig.java | 113 +++++++++++++++++- .../tieredrepairkits/TieredRepairKits.java | 4 +- .../config/RecipeIngredient.java | 38 ++++-- .../config/RecipeListCodec.java | 36 ++++++ .../tieredrepairkits/config/RepairTier.java | 79 +++++------- src/main/resources/manifest.json | 4 +- 7 files changed, 208 insertions(+), 78 deletions(-) create mode 100644 src/main/java/xyz/quickbasic/tieredrepairkits/config/RecipeListCodec.java diff --git a/src/main/java/xyz/quickbasic/tieredrepairkits/RepairKitManager.java b/src/main/java/xyz/quickbasic/tieredrepairkits/RepairKitManager.java index 71d9179..a509e00 100644 --- a/src/main/java/xyz/quickbasic/tieredrepairkits/RepairKitManager.java +++ b/src/main/java/xyz/quickbasic/tieredrepairkits/RepairKitManager.java @@ -7,25 +7,16 @@ 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 @@ -36,17 +27,14 @@ public class RepairKitManager { 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); } diff --git a/src/main/java/xyz/quickbasic/tieredrepairkits/TRKConfig.java b/src/main/java/xyz/quickbasic/tieredrepairkits/TRKConfig.java index 566343e..ae69ac8 100644 --- a/src/main/java/xyz/quickbasic/tieredrepairkits/TRKConfig.java +++ b/src/main/java/xyz/quickbasic/tieredrepairkits/TRKConfig.java @@ -3,9 +3,13 @@ package xyz.quickbasic.tieredrepairkits; import com.hypixel.hytale.codec.KeyedCodec; import com.hypixel.hytale.codec.builder.BuilderCodec; import xyz.quickbasic.tieredrepairkits.config.RepairTier; +import xyz.quickbasic.tieredrepairkits.config.RecipeIngredient; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Arrays; +import java.util.ArrayList; +import java.util.List; // Main config class for TieredRepairKits public class TRKConfig { @@ -69,9 +73,99 @@ public class TRKConfig { // Cached map for runtime convenience private Map cachedMap; - public TRKConfig() {} + public TRKConfig() { + + // TierCopper + tierCopper.setEnabled(true); + tierCopper.setRepairPenalty(0.05); + tierCopper.setRecipe(list( + ing("Ingredient_Fibre", 2), + ing("Ingredient_Bar_Copper", 4), + ing("Ingredient_Stick", 2) + )); + + // TierIron + tierIron.setEnabled(true); + tierIron.setRepairPenalty(0); + tierIron.setRecipe(list( + ing("Ingredient_Fabric_Scrap_Linen", 2), + ing("Ingredient_Bar_Iron", 8), + ing("Ingredient_Leather_Light", 2) + )); + + // TierSilver + tierSilver.setEnabled(true); + tierSilver.setRepairPenalty(-0.01); + tierSilver.setRecipe(list( + ing("Ingredient_Bolt_Wool", 4), + ing("Ingredient_Bar_Silver", 16), + ing("Ingredient_Fire_Essence", 4) + )); + + // TierGold + tierGold.setEnabled(true); + tierGold.setRepairPenalty(-0.01); + tierGold.setRecipe(list( + ing("Ingredient_Bolt_Wool", 4), + ing("Ingredient_Bar_Gold", 16), + ing("Ingredient_Fire_Essence", 4) + )); + + // TierThorium + tierThorium.setEnabled(true); + tierThorium.setRepairPenalty(-0.025); + tierThorium.setRecipe(list( + ing("Ingredient_Chitin_Sturdy", 2), + ing("Ingredient_Bar_Thorium", 16), + ing("Ingredient_Sac_Venom", 2) + )); + + // TierCobalt + tierCobalt.setEnabled(true); + tierCobalt.setRepairPenalty(-0.05); + tierCobalt.setRecipe(list( + ing("Ingredient_Fabric_Scrap_Shadoweave", 4), + ing("Ingredient_Bar_Cobalt", 16), + ing("Ingredient_Ice_Essence", 4) + )); + + // TierAdamantite + tierAdamantite.setEnabled(true); + tierAdamantite.setRepairPenalty(-0.075); + tierAdamantite.setRecipe(list( + ing("Ingredient_Crystal_Red", 4), + ing("Ingredient_Bar_Adamantite", 16), + ing("Ingredient_Fire_Essence", 4) + )); + + // TierMithril + tierMithril.setEnabled(true); + tierMithril.setRepairPenalty(-0.1); + tierMithril.setRecipe(list( + ing("Ingredient_Voidheart", 4), + ing("Ingredient_Bar_Mithril", 16), + ing("Ingredient_Leather_Storm", 4) + )); + + // TierOnyxium + tierOnyxium.setEnabled(true); + tierOnyxium.setRepairPenalty(-0.125); + tierOnyxium.setRecipe(list( + ing("Rock_Gem_Voidstone", 1), + ing("Ingredient_Bar_Onyxium", 16), + ing("Ingredient_Leather_Storm", 4) + )); + + // TierPrisma + tierPrisma.setEnabled(true); + tierPrisma.setRepairPenalty(-0.15); + tierPrisma.setRecipe(list( + ing("Rock_Gem_Diamond", 1), + ing("Ingredient_Bar_Prisma", 16), + ing("Ingredient_Leather_Storm", 4) + )); + } - // Returns a map of tier names -> RepairTier public Map getTiers() { if (cachedMap == null) { cachedMap = new LinkedHashMap<>(); @@ -101,7 +195,7 @@ public class TRKConfig { public RepairTier getTierOnyxium() { return tierOnyxium; } public RepairTier getTierPrisma() { return tierPrisma; } - // Individual tier setters (optional, also clears cached map) + // Individual tier setters (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; } @@ -112,4 +206,17 @@ public class TRKConfig { 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; } + + // --- Helper methods --- + private static RecipeIngredient ing(String id, int qty) { + RecipeIngredient r = new RecipeIngredient(); + r.setItemId(id); + r.setQuantity(qty); + return r; + } + + @SafeVarargs + private static List list(T... items) { + return new ArrayList<>(Arrays.asList(items)); + } } \ 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 5c18c11..9888feb 100644 --- a/src/main/java/xyz/quickbasic/tieredrepairkits/TieredRepairKits.java +++ b/src/main/java/xyz/quickbasic/tieredrepairkits/TieredRepairKits.java @@ -18,8 +18,8 @@ public class TieredRepairKits extends JavaPlugin { 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); + // This links the config file name ("TieredRepairKits") with the codec defined in TRKConfig. + private final Config config = this.withConfig("TieredRepairKits", TRKConfig.CODEC); // Public getter so other classes (like managers) can access the plugin config public Config getConfig() { diff --git a/src/main/java/xyz/quickbasic/tieredrepairkits/config/RecipeIngredient.java b/src/main/java/xyz/quickbasic/tieredrepairkits/config/RecipeIngredient.java index 3e74f08..96016db 100644 --- a/src/main/java/xyz/quickbasic/tieredrepairkits/config/RecipeIngredient.java +++ b/src/main/java/xyz/quickbasic/tieredrepairkits/config/RecipeIngredient.java @@ -8,23 +8,37 @@ 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(); + .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 RecipeIngredient(String itemId, int quantity) { + this.itemId = itemId; + this.quantity = quantity; + } - public int getQuantity() { return quantity; } + public String getItemId() { + return itemId; + } + + public int getQuantity() { + return quantity; + } + + public void setItemId(String itemId) { + this.itemId = itemId; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } } \ No newline at end of file diff --git a/src/main/java/xyz/quickbasic/tieredrepairkits/config/RecipeListCodec.java b/src/main/java/xyz/quickbasic/tieredrepairkits/config/RecipeListCodec.java new file mode 100644 index 0000000..dba0fbd --- /dev/null +++ b/src/main/java/xyz/quickbasic/tieredrepairkits/config/RecipeListCodec.java @@ -0,0 +1,36 @@ +package xyz.quickbasic.tieredrepairkits.config; + +import com.hypixel.hytale.codec.Codec; +import com.hypixel.hytale.codec.codecs.array.ArrayCodec; +import com.hypixel.hytale.codec.schema.SchemaContext; +import com.hypixel.hytale.codec.schema.config.Schema; +import org.bson.BsonValue; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class RecipeListCodec implements Codec> { + + private final ArrayCodec arrayCodec = new ArrayCodec<>(RecipeIngredient.CODEC, RecipeIngredient[]::new); + + @Override + public List decode(BsonValue bsonValue, com.hypixel.hytale.codec.ExtraInfo extraInfo) { + try { + RecipeIngredient[] arr = arrayCodec.decode(bsonValue, extraInfo); + return arr == null ? new ArrayList<>() : new ArrayList<>(Arrays.asList(arr)); + } catch (Exception e) { + return new ArrayList<>(); + } + } + + @Override + public BsonValue encode(List value, com.hypixel.hytale.codec.ExtraInfo extraInfo) { + return arrayCodec.encode(value.toArray(new RecipeIngredient[0]), extraInfo); + } + + @Override + public Schema toSchema(SchemaContext context) { + return arrayCodec.toSchema(context); + } +} \ 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 index 66c611f..aab2552 100644 --- a/src/main/java/xyz/quickbasic/tieredrepairkits/config/RepairTier.java +++ b/src/main/java/xyz/quickbasic/tieredrepairkits/config/RepairTier.java @@ -1,81 +1,66 @@ 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 com.hypixel.hytale.codec.KeyedCodec; +import com.hypixel.hytale.codec.Codec; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; public class RepairTier { - // 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); - } - }; + private static final Codec> INGREDIENT_LIST_CODEC = new RecipeListCodec(); 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() - + 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() - + obj -> obj.repairPenalty).add() .append(new KeyedCodec<>("Recipe", INGREDIENT_LIST_CODEC), (obj, value) -> obj.recipe = value, - (obj) -> obj.recipe).add() - + 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 --- + // 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 --- + // 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; } + + // Validation + public void validate(String tierName) { + if (repairPenalty < -1.0 || repairPenalty > 1.0) { + repairPenalty = 0; + } + validateRecipe(recipe); + } + + private void validateRecipe(List ingredients) { + if (ingredients == null) return; + int maxIngredients = 5; + if (ingredients.size() > maxIngredients) { + ingredients.subList(maxIngredients, ingredients.size()).clear(); + } + for (RecipeIngredient ing : ingredients) { + if (ing.getItemId() == null || ing.getItemId().isBlank()) { + ing.setItemId("Unknown"); + } + if (ing.getQuantity() <= 0) { + ing.setQuantity(1); + } + } + } } \ No newline at end of file diff --git a/src/main/resources/manifest.json b/src/main/resources/manifest.json index fe27952..5fe22e6 100644 --- a/src/main/resources/manifest.json +++ b/src/main/resources/manifest.json @@ -1,6 +1,6 @@ { - "Group": "QuickBASIC", - "Name": "QuickBASIC.TieredRepairKits", + "Group": "xyz.quickbasic", + "Name": "TieredRepairKits", "Version": "1.1.0", "Main": "xyz.quickbasic.tieredrepairkits.TieredRepairKits", "ServerVersion": "2026.03.26-89796e57b",