From fb701944daee57512898a6c4bb8b7312d543fc57 Mon Sep 17 00:00:00 2001 From: Holly P <25277367+Thatsmusic99@users.noreply.github.com> Date: Wed, 25 Oct 2023 17:01:57 +0100 Subject: [PATCH] chore: move sections to heads.yml (#113) --- .../headsplus/config/ConfigHeads.java | 2 ++ .../headsplus/config/ConfigHeadsSelector.java | 25 +++++++++++-------- .../headsplus/config/ConfigMobs.java | 1 - .../headsplus/managers/AutograbManager.java | 2 +- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/github/thatsmusic99/headsplus/config/ConfigHeads.java b/src/main/java/io/github/thatsmusic99/headsplus/config/ConfigHeads.java index 25bc806e..64ff2744 100644 --- a/src/main/java/io/github/thatsmusic99/headsplus/config/ConfigHeads.java +++ b/src/main/java/io/github/thatsmusic99/headsplus/config/ConfigHeads.java @@ -32,9 +32,11 @@ public void addDefaults() { if (isNew() || head.version > getDouble("version")) { forceExample("heads." + head.name().toLowerCase() + ".display-name", head.displayName); forceExample("heads." + head.name().toLowerCase() + ".texture", head.texture); + forceExample("heads.HP#" + head.name().toLowerCase() + ".section", head.section); } else { addExample("heads." + head.name().toLowerCase() + ".display-name", head.displayName); addExample("heads." + head.name().toLowerCase() + ".texture", head.texture); + addExample("heads.HP#" + head.name().toLowerCase() + ".section", head.section); } } } diff --git a/src/main/java/io/github/thatsmusic99/headsplus/config/ConfigHeadsSelector.java b/src/main/java/io/github/thatsmusic99/headsplus/config/ConfigHeadsSelector.java index 8a1871cb..33bd9967 100644 --- a/src/main/java/io/github/thatsmusic99/headsplus/config/ConfigHeadsSelector.java +++ b/src/main/java/io/github/thatsmusic99/headsplus/config/ConfigHeadsSelector.java @@ -44,7 +44,6 @@ public void addDefaults() { addDefault("version", 3.5); makeSectionLenient("sections"); - makeSectionLenient("heads"); if (version >= 3.5) return; if (ConfigCustomHeads.get() != null) return; for (HeadsXSections section : HeadsXSections.values()) { @@ -60,21 +59,25 @@ public void addDefaults() { addExample("sections." + section.id + ".enabled", true); } } - for (HeadsXEnums head : HeadsXEnums.values()) { - if (head.version > version) { - forceExample("heads.HP#" + head.name().toLowerCase() + ".section", head.section); - } else { - addExample("heads.HP#" + head.name().toLowerCase() + ".section", head.section); - } - } set("version", 3.5); } + @Override + public void moveToNew() { + + // Get everything in heads + if (getConfigSection("heads") == null) return; + for (String key : getConfigSection("heads").getKeys(false)) { + moveTo("heads." + key + ".section", "heads." + key + ".section", ConfigHeads.get()); + } + } + @Override public void postSave() { sections.clear(); totalHeads = 0; + // Setting up sections for (String key : getConfigSection("sections").getKeys(false)) { ConfigSection section = getConfigSection("sections." + key); @@ -87,13 +90,15 @@ public void postSave() { .withTexture(section.getString("texture"))); } // Setting up heads - for (String key : getConfigSection("heads").getKeys(false)) { - ConfigSection section = getConfigSection("heads." + key); + for (String key : ConfigHeads.get().getConfigSection("heads").getKeys(false)) { + ConfigSection section = ConfigHeads.get().getConfigSection("heads." + key); if (section == null) continue; + // If the section doesn't exist, continue if (!section.contains("section")) continue; if (!sections.containsKey(section.getString("section"))) continue; SectionInfo sectionInfo = sections.get(section.getString("section")); + // Get the head info itself if (!HeadManager.get().contains(key)) continue; BuyableHeadInfo headInfo = new BuyableHeadInfo(HeadManager.get().getHeadInfo(key), key); diff --git a/src/main/java/io/github/thatsmusic99/headsplus/config/ConfigMobs.java b/src/main/java/io/github/thatsmusic99/headsplus/config/ConfigMobs.java index e8677148..46f5cfaa 100644 --- a/src/main/java/io/github/thatsmusic99/headsplus/config/ConfigMobs.java +++ b/src/main/java/io/github/thatsmusic99/headsplus/config/ConfigMobs.java @@ -11,7 +11,6 @@ import org.bukkit.entity.Rabbit; import org.jetbrains.annotations.Nullable; -import java.io.IOException; import java.util.*; public class ConfigMobs extends FeatureConfig { diff --git a/src/main/java/io/github/thatsmusic99/headsplus/managers/AutograbManager.java b/src/main/java/io/github/thatsmusic99/headsplus/managers/AutograbManager.java index 2c2f4f5d..40611509 100644 --- a/src/main/java/io/github/thatsmusic99/headsplus/managers/AutograbManager.java +++ b/src/main/java/io/github/thatsmusic99/headsplus/managers/AutograbManager.java @@ -226,7 +226,7 @@ private static void addTexture(String texture, boolean force, CommandSender send buyableHead.withPrice(MainConfig.get().getAutograbber().PRICE); section.addHead(id, buyableHead); // Add to the actual config - ConfigHeadsSelector.get().forceExample("heads.HP#" + id + ".section", sectionStr); + ConfigHeads.get().forceExample("heads.HP#" + id + ".section", sectionStr); if (buyableHead.getPrice() != -1) { ConfigHeadsSelector.get().forceExample("heads.HP#" + id + ".price", buyableHead.getPrice()); }