Refactoring to make my life easier

This commit is contained in:
nossr50
2018-12-29 05:24:55 -08:00
parent 35368db05d
commit 0d260a74c9
126 changed files with 1471 additions and 1408 deletions

View File

@ -2,10 +2,10 @@ package com.gmail.nossr50.skills.child;
import java.util.EnumSet;
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
import org.bukkit.configuration.file.YamlConfiguration;
import com.gmail.nossr50.config.AutoUpdateConfigLoader;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.StringUtils;
public class ChildConfig extends AutoUpdateConfigLoader {
@ -20,15 +20,15 @@ public class ChildConfig extends AutoUpdateConfigLoader {
FamilyTree.clearRegistrations(); // when reloading, need to clear statics
for (SkillType skill : SkillType.CHILD_SKILLS) {
for (PrimarySkill skill : PrimarySkill.CHILD_SKILLS) {
plugin.debug("Finding parents of " + skill.name());
EnumSet<SkillType> parentSkills = EnumSet.noneOf(SkillType.class);
EnumSet<PrimarySkill> parentSkills = EnumSet.noneOf(PrimarySkill.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 {
SkillType parentSkill = SkillType.valueOf(name.toUpperCase());
PrimarySkill parentSkill = PrimarySkill.valueOf(name.toUpperCase());
FamilyTree.enforceNotChildSkill(parentSkill);
parentSkills.add(parentSkill);
}
@ -46,12 +46,12 @@ public class ChildConfig extends AutoUpdateConfigLoader {
* 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(SkillType.valueOf(name.toUpperCase()));
parentSkills.add(PrimarySkill.valueOf(name.toUpperCase()));
}
}
// Register them
for (SkillType parentSkill : parentSkills) {
for (PrimarySkill parentSkill : parentSkills) {
plugin.debug("Registering " + parentSkill.name() + " as parent of " + skill.name());
FamilyTree.registerParent(skill, parentSkill);
}

View File

@ -5,32 +5,32 @@ import java.util.EnumSet;
import java.util.HashMap;
import java.util.Set;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
public class FamilyTree {
private static HashMap<SkillType, Set<SkillType>> tree = new HashMap<SkillType, Set<SkillType>>();
private static HashMap<PrimarySkill, Set<PrimarySkill>> tree = new HashMap<PrimarySkill, Set<PrimarySkill>>();
public static Set<SkillType> getParents(SkillType childSkill) {
public static Set<PrimarySkill> getParents(PrimarySkill 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(SkillType childSkill, SkillType parentSkill) {
protected static void registerParent(PrimarySkill childSkill, PrimarySkill parentSkill) {
enforceChildSkill(childSkill);
enforceNotChildSkill(parentSkill);
if (!tree.containsKey(childSkill)) {
tree.put(childSkill, EnumSet.noneOf(SkillType.class));
tree.put(childSkill, EnumSet.noneOf(PrimarySkill.class));
}
tree.get(childSkill).add(parentSkill);
}
protected static void closeRegistration() {
for (SkillType childSkill : tree.keySet()) {
Set<SkillType> immutableSet = Collections.unmodifiableSet(tree.get(childSkill));
for (PrimarySkill childSkill : tree.keySet()) {
Set<PrimarySkill> immutableSet = Collections.unmodifiableSet(tree.get(childSkill));
tree.put(childSkill, immutableSet);
}
}
@ -39,13 +39,13 @@ public class FamilyTree {
tree.clear();
}
protected static void enforceChildSkill(SkillType skill) {
protected static void enforceChildSkill(PrimarySkill skill) {
if (!skill.isChildSkill()) {
throw new IllegalArgumentException(skill.name() + " is not a child skill!");
}
}
protected static void enforceNotChildSkill(SkillType skill) {
protected static void enforceNotChildSkill(PrimarySkill skill) {
if (skill.isChildSkill()) {
throw new IllegalArgumentException(skill.name() + " is a child skill!");
}