From bbc84bed33dde25d181db171c46229a2506f708e Mon Sep 17 00:00:00 2001 From: Robin Date: Sat, 5 Oct 2024 14:01:39 +0100 Subject: [PATCH] Add better description handling --- src/main/java/xyz/oribuin/fishing/augment/Augment.java | 4 ++-- .../java/xyz/oribuin/fishing/manager/TierManager.java | 8 +++++--- src/main/java/xyz/oribuin/fishing/skill/Skill.java | 8 ++++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/xyz/oribuin/fishing/augment/Augment.java b/src/main/java/xyz/oribuin/fishing/augment/Augment.java index d2a80b5..ecef982 100644 --- a/src/main/java/xyz/oribuin/fishing/augment/Augment.java +++ b/src/main/java/xyz/oribuin/fishing/augment/Augment.java @@ -68,7 +68,7 @@ public void saveSettings(@NotNull CommentedConfigurationSection config) { config.set("enabled", this.enabled); config.set("max-level", this.maxLevel); config.set("required-level", this.requiredLevel); - config.set("description", this.description); + config.set("description", List.of(this.description.split("\n"))); CommentedConfigurationSection section = config.getConfigurationSection("display-item"); if (section == null) section = config.createSection("display-item"); @@ -86,7 +86,7 @@ public void loadSettings(@NotNull CommentedConfigurationSection config) { this.enabled = config.getBoolean("enabled", true); this.maxLevel = config.getInt("max-level", 1); this.requiredLevel = config.getInt("required-level", 1); - this.description = config.getString("description", this.description); + this.description = String.join("\n", config.getStringList("description")); ItemConstruct construct = ItemConstruct.deserialize(config.getConfigurationSection("display-item")); if (construct == null) { diff --git a/src/main/java/xyz/oribuin/fishing/manager/TierManager.java b/src/main/java/xyz/oribuin/fishing/manager/TierManager.java index 0ee36b3..1d1c70a 100644 --- a/src/main/java/xyz/oribuin/fishing/manager/TierManager.java +++ b/src/main/java/xyz/oribuin/fishing/manager/TierManager.java @@ -26,7 +26,7 @@ public TierManager(RosePlugin rosePlugin) { @Override public void reload() { - File tierFolder = FishUtils.createFile(this.rosePlugin, new File(this.rosePlugin.getDataFolder(), "tiers")); + File tierFolder = new File(this.rosePlugin.getDataFolder(), "tiers"); // Load all the tiers from the config files in the folder File[] content = tierFolder.listFiles(); @@ -38,11 +38,13 @@ public void reload() { if (content == null) return; for (File file : content) { - if (file.isDirectory()) return; // we're not subdirectoring + if (file.isDirectory()) return; // we're not subdirectories if (!file.getName().endsWith(".yml")) return; // it's not a yml file + CommentedFileConfiguration tierConfig = CommentedFileConfiguration.loadConfiguration(file); + Tier tier = new Tier(file.getName().replace(".yml", "")); - tier.reload(); // Load the tier settings + tier.loadSettings(tierConfig); // Load the tier settings this.tiers.put(tier.name(), tier); } diff --git a/src/main/java/xyz/oribuin/fishing/skill/Skill.java b/src/main/java/xyz/oribuin/fishing/skill/Skill.java index 1841ef7..5a126c1 100644 --- a/src/main/java/xyz/oribuin/fishing/skill/Skill.java +++ b/src/main/java/xyz/oribuin/fishing/skill/Skill.java @@ -10,8 +10,10 @@ import xyz.oribuin.fishing.api.event.FishEventHandler; import java.nio.file.Path; +import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; public abstract class Skill extends FishEventHandler implements Configurable { @@ -90,7 +92,8 @@ public String name() { */ @Override public void loadSettings(@NotNull CommentedConfigurationSection config) { - this.description = config.getString("description", "No Description"); + this.description = String.join("\n", config.getStringList("description")); + } /** @@ -100,7 +103,8 @@ public void loadSettings(@NotNull CommentedConfigurationSection config) { */ @Override public void saveSettings(@NotNull CommentedConfigurationSection config) { - config.set("description", this.description); + config.addComments(this.comments().toArray(new String[0])); + config.set("description", List.of(this.description.split("\n"))); } }