simplification

This commit is contained in:
okx-code
2019-03-21 21:57:49 +00:00
parent 7bfd407c58
commit 6e236109a7
18 changed files with 161 additions and 101 deletions
@@ -1,9 +1,8 @@
package sh.okx.rankup.requirements;
import org.bukkit.configuration.ConfigurationSection;
import java.util.HashSet;
import java.util.Map;
import java.util.List;
import java.util.Objects;
import java.util.Set;
public class RequirementRegistry {
@@ -24,18 +23,16 @@ public class RequirementRegistry {
return null;
}
public Set<Requirement> getRequirements(ConfigurationSection section) {
public Set<Requirement> getRequirements(List<String> list) {
Set<Requirement> requirements = new HashSet<>();
for (Map.Entry<String, Object> entry : section.getValues(false).entrySet()) {
String name = entry.getKey();
String value = String.valueOf(entry.getValue());
for (String req : list) {
String[] parts = req.split(" ", 2);
String name = parts[0];
String value = parts[1];
Requirement requirement = newRequirement(name, value);
if (requirement == null) {
System.err.println("Unknown requirement: " + name);
} else {
requirements.add(requirement);
}
Objects.requireNonNull(requirement, "Unknown requirement: " + name);
requirements.add(requirement);
}
return requirements;
}
@@ -9,7 +9,7 @@ import java.lang.reflect.Method;
/**
* Because mcMMO like changing the name of their skill types.
* Singleton (not thread safe!) class to access different mcMMO versions.
* Singleton class to access different mcMMO versions.
*/
public class McMMOSkillUtil {
private static McMMOSkillUtil instance;
@@ -31,19 +31,19 @@ public class McMMOSkillUtil {
try {
skillTypeClass = Class.forName(pckg + "SkillType");
} catch (ClassNotFoundException e2) {
throw new RuntimeException("mcMMO Skill Type class not found");
throw new UnsupportedOperationException("mcMMO Skill Type class not found");
}
}
}
try {
values = skillTypeClass.getMethod("values");
} catch (NoSuchMethodException e) {
throw new RuntimeException("mcMMO " + skillTypeClass + ".values() not found");
throw new UnsupportedOperationException("mcMMO " + skillTypeClass + ".values() not found");
}
try {
valueOf = skillTypeClass.getMethod("valueOf", String.class);
} catch (NoSuchMethodException e) {
throw new RuntimeException("mcMMO" + skillTypeClass + ".valueOf(String) not found");
throw new UnsupportedOperationException("mcMMO" + skillTypeClass + ".valueOf(String) not found");
}
/*try {
@@ -54,7 +54,7 @@ public class McMMOSkillUtil {
try {
getSkillLevel = McMMOPlayer.class.getMethod("getSkillLevel", skillTypeClass);
} catch (NoSuchMethodException e) {
throw new RuntimeException("mcMMO UserManager.getSkillLevel(" + skillTypeClass + ") not found");
throw new UnsupportedOperationException("mcMMO UserManager.getSkillLevel(" + skillTypeClass + ") not found");
}
}