Skip to content

Commit

Permalink
fix: heads-selector getting wiped and not being very lenient
Browse files Browse the repository at this point in the history
  • Loading branch information
Thatsmusic99 committed Jun 29, 2023
1 parent f209e6e commit 5abb1e7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 26 deletions.
Expand Up @@ -39,7 +39,10 @@ public void run() {
try {
if (cs instanceof FeatureConfig) {
FeatureConfig featureConfig = (FeatureConfig) cs;
if (!featureConfig.shouldLoad()) continue;
if (!featureConfig.shouldLoad()) {
featureConfig.setLoaded(false);
continue;
}
if (!featureConfig.isLoaded()) {
featureConfig.load();
continue;
Expand Down
Expand Up @@ -32,6 +32,9 @@ 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);
} else {
addExample("heads." + head.name().toLowerCase() + ".display-name", head.displayName);
addExample("heads." + head.name().toLowerCase() + ".texture", head.texture);
}
}
}
Expand Down
Expand Up @@ -49,15 +49,22 @@ public void addDefaults() {
if (ConfigCustomHeads.get() != null) return;
for (HeadsXSections section : HeadsXSections.values()) {
if (section.version > version) {
addDefault("sections." + section.id + ".texture", section.texture);
addDefault("sections." + section.id + ".display-name", section.displayName);
addDefault("sections." + section.id + ".permission", "headsplus.section." + section.id);
addDefault("sections." + section.id + ".enabled", true);
forceExample("sections." + section.id + ".texture", section.texture);
forceExample("sections." + section.id + ".display-name", section.displayName);
forceExample("sections." + section.id + ".permission", "headsplus.section." + section.id);
forceExample("sections." + section.id + ".enabled", true);
} else {
addExample("sections." + section.id + ".texture", section.texture);
addExample("sections." + section.id + ".display-name", section.displayName);
addExample("sections." + section.id + ".permission", "headsplus.section." + section.id);
addExample("sections." + section.id + ".enabled", true);
}
}
for (HeadsXEnums head : HeadsXEnums.values()) {
if (head.version > version) {
addDefault("heads.HP#" + head.name().toLowerCase() + ".section", head.section);
forceExample("heads.HP#" + head.name().toLowerCase() + ".section", head.section);
} else {
addExample("heads.HP#" + head.name().toLowerCase() + ".section", head.section);
}
}

Expand Down
Expand Up @@ -35,23 +35,29 @@ public void addDefaults() {
set("version", version);
for (int i = 1; i <= getDefLevels().size(); i++) {
BaseLevel l = getDefLevels().get(i);
if (l.getAddedVersion() > current) {
addExample("levels." + l.getConfigName() + ".display-name", l.getDisplayName());
addExample("levels." + l.getConfigName() + ".added-version", l.getAddedVersion());
addExample("levels." + l.getConfigName() + ".required-xp", l.getRequiredXP());
addExample("levels." + l.getConfigName() + ".hierarchy", i);
addExample("levels." + l.getConfigName() + ".rewards.enabled", false);
addExample("levels." + l.getConfigName() + ".rewards.reward-type",
HPChallengeRewardTypes.ECO.name());
addExample("levels." + l.getConfigName() + ".rewards.reward-value", 300);
addExample("levels." + l.getConfigName() + ".rewards.item-amount", 0);
addExample("levels." + l.getConfigName() + ".rewards.command-sender", "player");
}

addOrForce("levels." + l.getConfigName() + ".display-name", l.getDisplayName(), l.getAddedVersion() > current);
addOrForce("levels." + l.getConfigName() + ".added-version", l.getAddedVersion(), l.getAddedVersion() > current);
addOrForce("levels." + l.getConfigName() + ".required-xp", l.getRequiredXP(), l.getAddedVersion() > current);
addOrForce("levels." + l.getConfigName() + ".hierarchy", i, l.getAddedVersion() > current);
addOrForce("levels." + l.getConfigName() + ".rewards.enabled", false, l.getAddedVersion() > current);
addOrForce("levels." + l.getConfigName() + ".rewards.reward-type",
HPChallengeRewardTypes.ECO.name(), l.getAddedVersion() > current);
addOrForce("levels." + l.getConfigName() + ".rewards.reward-value", 300, l.getAddedVersion() > current);
addOrForce("levels." + l.getConfigName() + ".rewards.item-amount", 0, l.getAddedVersion() > current);
addOrForce("levels." + l.getConfigName() + ".rewards.command-sender", "player", l.getAddedVersion() > current);
}
}
}

private void addOrForce(String path, Object value, boolean force) {
if (force) {
forceExample(path, value);
} else {
addExample(path, value);
}
}

@Override
public void moveToNew() {

Expand Down
Expand Up @@ -10,6 +10,12 @@ public FeatureConfig(@NotNull String name) throws Exception {
super(name);
}

@Override
public void load() throws Exception {
super.load();
setLoaded(true);
}

public abstract boolean shouldLoad();

public boolean isLoaded() {
Expand Down
Expand Up @@ -13,14 +13,6 @@ public HPConfig(@NotNull String name) throws Exception {
super(getOrCreateFile(name));
}

@Override
public void reload() throws Exception {
super.reload();
moveToNew();
save();
postSave();
}

protected static File getOrCreateFile(String name) {
File file = new File(HeadsPlus.get().getDataFolder(), name);
try {
Expand Down

0 comments on commit 5abb1e7

Please sign in to comment.