Compare commits

1 Commits

Author SHA1 Message Date
3df6b25723 add config logic 2026-03-26 14:21:52 -04:00
7 changed files with 110 additions and 347 deletions

View File

@@ -17,7 +17,7 @@ includes_pack=true
# The release channel your plugin should be built and ran against. This is # 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 # usually release or pre-release. You can verify your settings in the
# official launcher. # official launcher.
patchline=release patchline=pre-release
# Determines if the development server should also load mods from the user's # 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 # standard mods folder. This lets you test mods by installing them where a

View File

@@ -1,43 +1,63 @@
package xyz.quickbasic.tieredrepairkits; package xyz.quickbasic.tieredrepairkits;
import xyz.quickbasic.tieredrepairkits.config.RepairTier;
import java.util.Map; // 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
// Manages repair-kit data for the plugin // rest of the plugin can access easily.
public class RepairKitManager { public class RepairKitManager {
// Reference to the main plugin class.
// This allows the manager to access things like config, logging, etc.
private final TieredRepairKits plugin; private final TieredRepairKits plugin;
private Map<String, RepairTier> tiers;
// 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) { public RepairKitManager(TieredRepairKits plugin) {
// Store the reference to the plugin
this.plugin = plugin; this.plugin = plugin;
// Immediately load values from the config file into local variables
loadConfig(); loadConfig();
} }
// This method loads values from the plugin configuration
// and stores them inside this manager class.
public void loadConfig() { public void loadConfig() {
// Retrieve the TRKConfig object from the plugin's Config wrapper
TRKConfig config = plugin.getConfig().get(); TRKConfig config = plugin.getConfig().get();
tiers = config.getTiers();
// Log loaded tiers // Copy values from the config object into this manager's variables
for (var entry : tiers.entrySet()) { this.someValue = config.getSomeValue();
String tierName = entry.getKey(); this.someString = config.getSomeString();
RepairTier tier = entry.getValue();
TieredRepairKits.LOGGER.atInfo().log( // Log information to the server console to confirm the config was loaded
"Tier " + tierName TieredRepairKits.LOGGER.atInfo().log("Config Loaded");
+ ": enabled=" + tier.isEnabled()
+ " penalty=" + tier.getRepairPenalty() // Print the loaded values so you can verify them during development
+ " ingredients=" + tier.getRecipe().length TieredRepairKits.LOGGER.atInfo().log("SomeValue = " + someValue);
); TieredRepairKits.LOGGER.atInfo().log("SomeString = " + someString);
}
} }
public Map<String, RepairTier> getTiers() {
return tiers; // Getter method for someValue
// Other classes can call this to retrieve the loaded value
public int getSomeValue() {
return someValue;
} }
public RepairTier getTier(String name) {
return tiers.get(name); // Getter method for someString
// Provides read access to the stored config value
public String getSomeString() {
return someString;
} }
} }

View File

@@ -1,217 +1,77 @@
package xyz.quickbasic.tieredrepairkits; 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.KeyedCodec;
import com.hypixel.hytale.codec.builder.BuilderCodec; 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 // 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 { public class TRKConfig {
// CODEC tells the Hytale engine how to convert between:
// Java object (TRKConfig) <-> JSON file on disk
public static final BuilderCodec<TRKConfig> CODEC = BuilderCodec.builder(TRKConfig.class, TRKConfig::new) public static final BuilderCodec<TRKConfig> CODEC = BuilderCodec.builder(TRKConfig.class, TRKConfig::new)
.append(new KeyedCodec<RepairTier>("TierCopper", RepairTier.CODEC), // Adds a config field called "SomeValue" to the JSON
(cfg, val) -> cfg.tierCopper = val, // Codec.INTEGER tells Hytale the value is an integer
cfg -> cfg.tierCopper).add() .append(new KeyedCodec<Integer>("SomeValue", Codec.INTEGER),
.append(new KeyedCodec<RepairTier>("TierIron", RepairTier.CODEC), // Setter: how the JSON value gets written into this object
(cfg, val) -> cfg.tierIron = val, (config, value) -> config.someValue = value,
cfg -> cfg.tierIron).add()
.append(new KeyedCodec<RepairTier>("TierSilver", RepairTier.CODEC), // Getter: how the value is read from this object when saving JSON
(cfg, val) -> cfg.tierSilver = val, (config) -> config.someValue).add()
cfg -> cfg.tierSilver).add()
.append(new KeyedCodec<RepairTier>("TierGold", RepairTier.CODEC), // Adds another config field called "SomeString"
(cfg, val) -> cfg.tierGold = val, // Codec.STRING tells Hytale the value type is a string
cfg -> cfg.tierGold).add() .append(new KeyedCodec<String>("SomeString", Codec.STRING),
.append(new KeyedCodec<RepairTier>("TierThorium", RepairTier.CODEC), // Setter: how JSON value updates the object field
(cfg, val) -> cfg.tierThorium = val, (config, value) -> config.someString = value,
cfg -> cfg.tierThorium).add()
.append(new KeyedCodec<RepairTier>("TierCobalt", RepairTier.CODEC), // Getter: how the value is read when saving
(cfg, val) -> cfg.tierCobalt = val, (config) -> config.someString).add()
cfg -> cfg.tierCobalt).add()
.append(new KeyedCodec<RepairTier>("TierAdamantite", RepairTier.CODEC),
(cfg, val) -> cfg.tierAdamantite = val,
cfg -> cfg.tierAdamantite).add()
.append(new KeyedCodec<RepairTier>("TierMithril", RepairTier.CODEC),
(cfg, val) -> cfg.tierMithril = val,
cfg -> cfg.tierMithril).add()
.append(new KeyedCodec<RepairTier>("TierOnyxium", RepairTier.CODEC),
(cfg, val) -> cfg.tierOnyxium = val,
cfg -> cfg.tierOnyxium).add()
.append(new KeyedCodec<RepairTier>("TierPrisma", RepairTier.CODEC),
(cfg, val) -> cfg.tierPrisma = val,
cfg -> cfg.tierPrisma).add()
// Finalizes the codec definition
.build(); .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 // Default value for the integer config entry
private Map<String, RepairTier> cachedMap; // 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() { public TRKConfig() {
// Initialize all tiers with helper method
tierCopper.setEnabled(true);
tierCopper.setRepairPenalty(0.05);
tierCopper.setRecipe(recipe(
ing("Ingredient_Fibre", 2),
ing("Ingredient_Bar_Copper", 4),
ing("Ingredient_Stick", 2)
));
tierIron.setEnabled(true);
tierIron.setRepairPenalty(0);
tierIron.setRecipe(recipe(
ing("Ingredient_Fabric_Scrap_Linen", 2),
ing("Ingredient_Bar_Iron", 8),
ing("Ingredient_Leather_Light", 2)
));
tierSilver.setEnabled(true);
tierSilver.setRepairPenalty(-0.01);
tierSilver.setRecipe(recipe(
ing("Ingredient_Bolt_Wool", 4),
ing("Ingredient_Bar_Silver", 16),
ing("Ingredient_Fire_Essence", 4)
));
tierGold.setEnabled(true);
tierGold.setRepairPenalty(-0.01);
tierGold.setRecipe(recipe(
ing("Ingredient_Bolt_Wool", 4),
ing("Ingredient_Bar_Gold", 16),
ing("Ingredient_Fire_Essence", 4)
));
tierThorium.setEnabled(true);
tierThorium.setRepairPenalty(-0.025);
tierThorium.setRecipe(recipe(
ing("Ingredient_Chitin_Sturdy", 2),
ing("Ingredient_Bar_Thorium", 16),
ing("Ingredient_Sac_Venom", 2)
));
tierCobalt.setEnabled(true);
tierCobalt.setRepairPenalty(-0.05);
tierCobalt.setRecipe(recipe(
ing("Ingredient_Fabric_Scrap_Shadoweave", 4),
ing("Ingredient_Bar_Cobalt", 16),
ing("Ingredient_Ice_Essence", 4)
));
tierAdamantite.setEnabled(true);
tierAdamantite.setRepairPenalty(-0.075);
tierAdamantite.setRecipe(recipe(
ing("Ingredient_Crystal_Red", 4),
ing("Ingredient_Bar_Adamantite", 16),
ing("Ingredient_Fire_Essence", 4)
));
tierMithril.setEnabled(true);
tierMithril.setRepairPenalty(-0.1);
tierMithril.setRecipe(recipe(
ing("Ingredient_Voidheart", 4),
ing("Ingredient_Bar_Mithril", 16),
ing("Ingredient_Leather_Storm", 4)
));
tierOnyxium.setEnabled(true);
tierOnyxium.setRepairPenalty(-0.125);
tierOnyxium.setRecipe(recipe(
ing("Rock_Gem_Voidstone", 1),
ing("Ingredient_Bar_Onyxium", 16),
ing("Ingredient_Leather_Storm", 4)
));
tierPrisma.setEnabled(true);
tierPrisma.setRepairPenalty(-0.15);
tierPrisma.setRecipe(recipe(
ing("Rock_Gem_Diamond", 1),
ing("Ingredient_Bar_Prisma", 16),
ing("Ingredient_Leather_Storm", 4)
));
} }
public Map<String, RepairTier> getTiers() {
if (cachedMap == null) { // Getter for SomeValue
cachedMap = new LinkedHashMap<>(); // Allows other classes to read the value safely
cachedMap.put("TierCopper", tierCopper); public int getSomeValue() {
cachedMap.put("TierIron", tierIron); return someValue;
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 // Getter for SomeString
public RepairTier getTierCopper() { return tierCopper; } public String getSomeString() {
public RepairTier getTierIron() { return tierIron; } return someString;
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 (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; }
// --- 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 <T> List<T> list(T... items) { // Setter for SomeValue
return new ArrayList<>(Arrays.asList(items)); // Allows code to change the value before saving the config
public void setSomeValue(int someValue) {
this.someValue = someValue;
} }
@SafeVarargs // Setter for SomeString
private static RecipeIngredient[] recipe(RecipeIngredient... ingredients) { public void setSomeString(String someString) {
return ingredients; // Returns RecipeIngredient[] directly this.someString = someString;
} }
} }

View File

@@ -18,8 +18,8 @@ public class TieredRepairKits extends JavaPlugin {
private RepairKitManager repairKitManager; private RepairKitManager repairKitManager;
// Config wrapper provided by the Hytale server API. // Config wrapper provided by the Hytale server API.
// This links the config file name ("TieredRepairKits") with the codec defined in TRKConfig. // This links the config file name ("MyConfig") with the codec defined in TRKConfig.
private final Config<TRKConfig> config = this.withConfig("TieredRepairKits", TRKConfig.CODEC); private final Config<TRKConfig> config = this.withConfig("MyConfig", TRKConfig.CODEC);
// Public getter so other classes (like managers) can access the plugin config // Public getter so other classes (like managers) can access the plugin config
public Config<TRKConfig> getConfig() { public Config<TRKConfig> getConfig() {

View File

@@ -1,44 +0,0 @@
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<RecipeIngredient> 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 RecipeIngredient(String itemId, int quantity) {
this.itemId = itemId;
this.quantity = 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;
}
}

View File

@@ -1,64 +0,0 @@
package xyz.quickbasic.tieredrepairkits.config;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.Codec;
import com.hypixel.hytale.codec.codecs.array.ArrayCodec;
public class RepairTier {
private static final Codec<RecipeIngredient[]> INGREDIENT_ARRAY_CODEC =
new ArrayCodec<>(RecipeIngredient.CODEC, RecipeIngredient[]::new);
public static final BuilderCodec<RepairTier> 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<>("Recipe", INGREDIENT_ARRAY_CODEC),
(obj, value) -> obj.recipe = value,
obj -> obj.recipe).add()
.build();
private boolean enabled = true;
private double repairPenalty = 0.0;
private RecipeIngredient[] recipe = new RecipeIngredient[0];
public RepairTier() {}
public boolean isEnabled() { return enabled; }
public double getRepairPenalty() { return repairPenalty; }
public RecipeIngredient[] getRecipe() { return recipe; }
public void setEnabled(boolean enabled) { this.enabled = enabled; }
public void setRepairPenalty(double repairPenalty) { this.repairPenalty = repairPenalty; }
public void setRecipe(RecipeIngredient[] recipe) { this.recipe = recipe; }
public void validate(String tierName) {
if (repairPenalty < -1.0 || repairPenalty > 1.0) {
repairPenalty = 0;
}
validateRecipe(recipe);
}
private void validateRecipe(RecipeIngredient[] ingredients) {
if (ingredients == null) return;
int maxIngredients = 5;
if (ingredients.length > maxIngredients) {
RecipeIngredient[] truncated = new RecipeIngredient[maxIngredients];
System.arraycopy(ingredients, 0, truncated, 0, maxIngredients);
recipe = truncated;
}
for (RecipeIngredient ing : ingredients) {
if (ing.getItemId() == null || ing.getItemId().isBlank()) {
ing.setItemId("Unknown");
}
if (ing.getQuantity() <= 0) {
ing.setQuantity(1);
}
}
}
}

View File

@@ -1,8 +1,7 @@
{ {
"Group": "xyz.quickbasic", "Group": "QuickBASIC",
"Name": "TieredRepairKits", "Name": "QuickBASIC.TieredRepairKits",
"Version": "1.1.0", "Version": "1.0.1",
"Main": "xyz.quickbasic.tieredrepairkits.TieredRepairKits",
"ServerVersion": "2026.03.26-89796e57b", "ServerVersion": "2026.03.26-89796e57b",
"Description": "Balanced tiered Repair Kits that can increase the maximum durability of items", "Description": "Balanced tiered Repair Kits that can increase the maximum durability of items",
"Authors": [ "Authors": [
@@ -13,18 +12,10 @@
} }
], ],
"Website": "https://git.quickbasic.xyz/hytale-modding/TieredRepairKits", "Website": "https://git.quickbasic.xyz/hytale-modding/TieredRepairKits",
"Dependencies": { "Dependencies": {},
"OptionalDependencies": {},
}, "LoadBefore": {},
"OptionalDependencies": {
},
"LoadBefore": {
},
"DisabledByDefault": false, "DisabledByDefault": false,
"IncludesAssetPack": true, "IncludesAssetPack": false,
"SubPlugins": [ "SubPlugins": []
]
} }