Skip to content

Commit

Permalink
chore: move sections to heads.yml (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thatsmusic99 committed Oct 25, 2023
1 parent 12513dd commit fb70194
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
Expand Up @@ -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);
}
}
}
Expand Down
Expand Up @@ -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()) {
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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());
}
Expand Down

0 comments on commit fb70194

Please sign in to comment.