mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-07-01 13:14:44 +02:00
child.yml was a mistake
This commit is contained in:
@ -1,60 +0,0 @@
|
||||
package com.gmail.nossr50.skills.child;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class ChildConfig extends AutoUpdateConfigLoader {
|
||||
public ChildConfig() {
|
||||
super("child.yml");
|
||||
loadKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadKeys() {
|
||||
config.setDefaults(YamlConfiguration.loadConfiguration(plugin.getResourceAsReader("child.yml")));
|
||||
|
||||
FamilyTree.clearRegistrations(); // when reloading, need to clear statics
|
||||
|
||||
for (PrimarySkillType skill : PrimarySkillType.CHILD_SKILLS) {
|
||||
plugin.debug("Finding parents of " + skill.name());
|
||||
|
||||
EnumSet<PrimarySkillType> parentSkills = EnumSet.noneOf(PrimarySkillType.class);
|
||||
boolean useDefaults = false; // If we had an error we back out and use defaults
|
||||
|
||||
for (String name : config.getStringList(StringUtils.getCapitalized(skill.name()))) {
|
||||
try {
|
||||
PrimarySkillType parentSkill = PrimarySkillType.valueOf(name.toUpperCase());
|
||||
FamilyTree.enforceNotChildSkill(parentSkill);
|
||||
parentSkills.add(parentSkill);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
plugin.getLogger().warning(name + " is not a valid skill type, or is a child skill!");
|
||||
useDefaults = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (useDefaults) {
|
||||
parentSkills.clear();
|
||||
for (String name : config.getDefaults().getStringList(StringUtils.getCapitalized(skill.name()))) {
|
||||
/* We do less checks in here because it's from inside our jar.
|
||||
* If they're dedicated enough to have modified it, they can have the errors it may produce.
|
||||
* Alternatively, this can be used to allow child skills to be parent skills, provided there are no circular dependencies this is an advanced sort of configuration.
|
||||
*/
|
||||
parentSkills.add(PrimarySkillType.valueOf(name.toUpperCase()));
|
||||
}
|
||||
}
|
||||
|
||||
// Register them
|
||||
for (PrimarySkillType parentSkill : parentSkills) {
|
||||
plugin.debug("Registering " + parentSkill.name() + " as parent of " + skill.name());
|
||||
FamilyTree.registerParent(skill, parentSkill);
|
||||
}
|
||||
}
|
||||
|
||||
FamilyTree.closeRegistration();
|
||||
}
|
||||
}
|
@ -1,53 +1,33 @@
|
||||
package com.gmail.nossr50.skills.child;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class FamilyTree {
|
||||
private static HashMap<PrimarySkillType, Set<PrimarySkillType>> tree = new HashMap<PrimarySkillType, Set<PrimarySkillType>>();
|
||||
static final ImmutableSet<PrimarySkillType> salvageTree;
|
||||
static final ImmutableSet<PrimarySkillType> smeltingTree;
|
||||
|
||||
static {
|
||||
ArrayList<PrimarySkillType> salvageParentsList = new ArrayList<>();
|
||||
ArrayList<PrimarySkillType> smeltingParentsList = new ArrayList<>();
|
||||
|
||||
salvageParentsList.add(PrimarySkillType.FISHING);
|
||||
salvageParentsList.add(PrimarySkillType.REPAIR);
|
||||
|
||||
smeltingParentsList.add(PrimarySkillType.MINING);
|
||||
smeltingParentsList.add(PrimarySkillType.REPAIR);
|
||||
|
||||
salvageTree = ImmutableSet.copyOf(salvageParentsList);
|
||||
smeltingTree = ImmutableSet.copyOf(smeltingParentsList);
|
||||
}
|
||||
|
||||
public static Set<PrimarySkillType> getParents(PrimarySkillType childSkill) {
|
||||
enforceChildSkill(childSkill);
|
||||
|
||||
// We do not check if we have the child skill in question, as not having it would mean we did something wrong, and an NPE is desired.
|
||||
return tree.get(childSkill);
|
||||
}
|
||||
|
||||
protected static void registerParent(PrimarySkillType childSkill, PrimarySkillType parentSkill) {
|
||||
enforceChildSkill(childSkill);
|
||||
enforceNotChildSkill(parentSkill);
|
||||
|
||||
if (!tree.containsKey(childSkill)) {
|
||||
tree.put(childSkill, EnumSet.noneOf(PrimarySkillType.class));
|
||||
}
|
||||
|
||||
tree.get(childSkill).add(parentSkill);
|
||||
}
|
||||
|
||||
protected static void closeRegistration() {
|
||||
for (PrimarySkillType childSkill : tree.keySet()) {
|
||||
Set<PrimarySkillType> immutableSet = Collections.unmodifiableSet(tree.get(childSkill));
|
||||
tree.put(childSkill, immutableSet);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void clearRegistrations() {
|
||||
tree.clear();
|
||||
}
|
||||
|
||||
protected static void enforceChildSkill(PrimarySkillType skill) {
|
||||
if (!skill.isChildSkill()) {
|
||||
throw new IllegalArgumentException(skill.name() + " is not a child skill!");
|
||||
}
|
||||
}
|
||||
|
||||
protected static void enforceNotChildSkill(PrimarySkillType skill) {
|
||||
if (skill.isChildSkill()) {
|
||||
throw new IllegalArgumentException(skill.name() + " is a child skill!");
|
||||
}
|
||||
if(childSkill == PrimarySkillType.SALVAGE)
|
||||
return salvageTree;
|
||||
else
|
||||
return smeltingTree;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user