We've got these functions, might as well use them.

This commit is contained in:
GJ 2013-05-21 10:02:09 -04:00
parent a2f80569e3
commit 0c52b3016c
10 changed files with 47 additions and 89 deletions

View File

@ -506,11 +506,7 @@ public final class ExperienceAPI {
int powerLevel = 0; int powerLevel = 0;
PlayerProfile profile = getOfflineProfile(playerName); PlayerProfile profile = getOfflineProfile(playerName);
for (SkillType type : SkillType.values()) { for (SkillType type : SkillType.nonChildSkills()) {
if (type.isChildSkill()) {
continue;
}
powerLevel += profile.getSkillLevel(type); powerLevel += profile.getSkillLevel(type);
} }

View File

@ -294,11 +294,7 @@ public final class FlatfileDatabaseManager {
Map<String, Integer> skills = new HashMap<String, Integer>(); Map<String, Integer> skills = new HashMap<String, Integer>();
for (SkillType skill : SkillType.values()) { for (SkillType skill : SkillType.nonChildSkills()) {
if (skill.isChildSkill()) {
continue;
}
skills.put(skill.name(), getPlayerRank(playerName, playerStatHash.get(skill))); skills.put(skill.name(), getPlayerRank(playerName, playerStatHash.get(skill)));
} }

View File

@ -415,11 +415,7 @@ public final class SQLDatabaseManager {
if (checkConnected()) { if (checkConnected()) {
try { try {
for (SkillType skillType : SkillType.values()) { for (SkillType skillType : SkillType.nonChildSkills()) {
if (skillType.isChildSkill()) {
continue;
}
String skillName = skillType.name().toLowerCase(); String skillName = skillType.name().toLowerCase();
String sql = "SELECT COUNT(*) AS rank FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE " + skillName + " > 0 " + String sql = "SELECT COUNT(*) AS rank FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE " + skillName + " > 0 " +
"AND " + skillName + " > (SELECT " + skillName + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id " + "AND " + skillName + " > (SELECT " + skillName + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id " +

View File

@ -441,11 +441,7 @@ public class McMMOPlayer {
public int getPowerLevel() { public int getPowerLevel() {
int powerLevel = 0; int powerLevel = 0;
for (SkillType type : SkillType.values()) { for (SkillType type : SkillType.nonChildSkills()) {
if (type.isChildSkill()) {
continue;
}
if (Permissions.skillEnabled(player, type)) { if (Permissions.skillEnabled(player, type)) {
powerLevel += profile.getSkillLevel(type); powerLevel += profile.getSkillLevel(type);
} }

View File

@ -49,11 +49,7 @@ public class PlayerProfile {
skillsDATS.put(abilityType, 0); skillsDATS.put(abilityType, 0);
} }
for (SkillType skillType : SkillType.values()) { for (SkillType skillType : SkillType.nonChildSkills()) {
if (skillType.isChildSkill()) {
continue;
}
skills.put(skillType, 0); skills.put(skillType, 0);
skillsXp.put(skillType, 0F); skillsXp.put(skillType, 0F);
} }

View File

@ -31,8 +31,8 @@ public class McrankCommandDisplayTask extends BukkitRunnable {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading")); sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading"));
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName)); sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName));
for (SkillType skill : SkillType.values()) { for (SkillType skill : SkillType.nonChildSkills()) {
if (skill.isChildSkill() || (player != null && !Permissions.skillEnabled(player, skill))) { if (player != null && !Permissions.skillEnabled(player, skill)) {
continue; continue;
} }

View File

@ -19,44 +19,42 @@ public class ChildConfig extends AutoUpdateConfigLoader {
protected void loadKeys() { protected void loadKeys() {
config.setDefaults(YamlConfiguration.loadConfiguration(plugin.getResource("child.yml"))); config.setDefaults(YamlConfiguration.loadConfiguration(plugin.getResource("child.yml")));
for (SkillType skill : SkillType.values()) { for (SkillType skill : SkillType.childSkills()) {
if (skill.isChildSkill()) { plugin.debug("Finding parents of " + skill.name());
plugin.debug("Finding parents of " + skill.name());
List<String> parentNames = config.getStringList(StringUtils.getCapitalized(skill.name())); List<String> parentNames = config.getStringList(StringUtils.getCapitalized(skill.name()));
EnumSet<SkillType> parentSkills = EnumSet.noneOf(SkillType.class); EnumSet<SkillType> parentSkills = EnumSet.noneOf(SkillType.class);
boolean useDefaults = false; // If we had an error we back out and use defaults boolean useDefaults = false; // If we had an error we back out and use defaults
for (String name : parentNames) { for (String name : parentNames) {
try { try {
SkillType parentSkill = Enum.valueOf(SkillType.class, name.toUpperCase()); SkillType parentSkill = SkillType.valueOf(name.toUpperCase());
FamilyTree.enforceNotChildSkill(parentSkill); FamilyTree.enforceNotChildSkill(parentSkill);
parentSkills.add(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;
}
} }
catch (IllegalArgumentException ex) {
if (useDefaults) { plugin.getLogger().warning(name + " is not a valid skill type, or is a child skill!");
parentSkills.clear(); useDefaults = true;
for (String name : config.getDefaults().getStringList(StringUtils.getCapitalized(skill.name()))) { break;
/* 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(SkillType.valueOf(name.toUpperCase()));
}
} }
}
// Register them if (useDefaults) {
for (SkillType parentSkill : parentSkills) { parentSkills.clear();
plugin.debug("Registering " + parentSkill.name() + " as parent of " + skill.name()); for (String name : config.getDefaults().getStringList(StringUtils.getCapitalized(skill.name()))) {
FamilyTree.registerParent(skill, parentSkill); /* 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(SkillType.valueOf(name.toUpperCase()));
} }
} }
// Register them
for (SkillType parentSkill : parentSkills) {
plugin.debug("Registering " + parentSkill.name() + " as parent of " + skill.name());
FamilyTree.registerParent(skill, parentSkill);
}
} }
FamilyTree.closeRegistration(); FamilyTree.closeRegistration();

View File

@ -21,11 +21,7 @@ public final class HardcoreManager {
PlayerProfile playerProfile = UserManager.getPlayer(player).getProfile(); PlayerProfile playerProfile = UserManager.getPlayer(player).getProfile();
int totalLost = 0; int totalLost = 0;
for (SkillType skillType : SkillType.values()) { for (SkillType skillType : SkillType.nonChildSkills()) {
if (skillType.isChildSkill()) {
continue;
}
int playerSkillLevel = playerProfile.getSkillLevel(skillType); int playerSkillLevel = playerProfile.getSkillLevel(skillType);
if (playerSkillLevel <= 0) { if (playerSkillLevel <= 0) {
@ -52,11 +48,7 @@ public final class HardcoreManager {
PlayerProfile victimProfile = UserManager.getPlayer(victim).getProfile(); PlayerProfile victimProfile = UserManager.getPlayer(victim).getProfile();
int totalStolen = 0; int totalStolen = 0;
for (SkillType skillType : SkillType.values()) { for (SkillType skillType : SkillType.nonChildSkills()) {
if (skillType.isChildSkill()) {
continue;
}
int killerSkillLevel = killerProfile.getSkillLevel(skillType); int killerSkillLevel = killerProfile.getSkillLevel(skillType);
int victimSkillLevel = victimProfile.getSkillLevel(skillType); int victimSkillLevel = victimProfile.getSkillLevel(skillType);

View File

@ -182,8 +182,8 @@ public class ScoreboardManager {
PlayerProfile profile = mcMMOPlayer.getProfile(); PlayerProfile profile = mcMMOPlayer.getProfile();
Server server = mcMMO.p.getServer(); Server server = mcMMO.p.getServer();
for (SkillType skill : SkillType.values()) { for (SkillType skill : SkillType.nonChildSkills()) {
if (skill.isChildSkill() || !Permissions.skillEnabled(player, skill)) { if (!Permissions.skillEnabled(player, skill)) {
continue; continue;
} }
@ -201,8 +201,8 @@ public class ScoreboardManager {
Map<String, Integer> skills = Config.getInstance().getUseMySQL() ? SQLDatabaseManager.readSQLRank(playerName) : FlatfileDatabaseManager.getPlayerRanks(playerName); Map<String, Integer> skills = Config.getInstance().getUseMySQL() ? SQLDatabaseManager.readSQLRank(playerName) : FlatfileDatabaseManager.getPlayerRanks(playerName);
for (SkillType skill : SkillType.values()) { for (SkillType skill : SkillType.nonChildSkills()) {
if (skill.isChildSkill() || !Permissions.skillEnabled(player, skill)) { if (!Permissions.skillEnabled(player, skill)) {
continue; continue;
} }
@ -228,11 +228,7 @@ public class ScoreboardManager {
Map<String, Integer> skills = Config.getInstance().getUseMySQL() ? SQLDatabaseManager.readSQLRank(targetName) : FlatfileDatabaseManager.getPlayerRanks(targetName); Map<String, Integer> skills = Config.getInstance().getUseMySQL() ? SQLDatabaseManager.readSQLRank(targetName) : FlatfileDatabaseManager.getPlayerRanks(targetName);
for (SkillType skill : SkillType.values()) { for (SkillType skill : SkillType.nonChildSkills()) {
if (skill.isChildSkill()) {
continue;
}
rank = skills.get(skill.name()); rank = skills.get(skill.name());
if (rank != null) { if (rank != null) {
@ -257,8 +253,8 @@ public class ScoreboardManager {
int powerLevel = 0; int powerLevel = 0;
int skillLevel; int skillLevel;
for (SkillType skill : SkillType.values()) { for (SkillType skill : SkillType.nonChildSkills()) {
if (skill.isChildSkill() || !Permissions.skillEnabled(target, skill)) { if (!Permissions.skillEnabled(target, skill)) {
continue; continue;
} }
@ -277,11 +273,7 @@ public class ScoreboardManager {
int powerLevel = 0; int powerLevel = 0;
int skillLevel; int skillLevel;
for (SkillType skill : SkillType.values()) { for (SkillType skill : SkillType.nonChildSkills()) {
if (skill.isChildSkill()) {
continue;
}
skillLevel = targetProfile.getSkillLevel(skill); skillLevel = targetProfile.getSkillLevel(skill);
objective.getScore(server.getOfflinePlayer(SkillUtils.getSkillName(skill))).setScore(skillLevel); objective.getScore(server.getOfflinePlayer(SkillUtils.getSkillName(skill))).setScore(skillLevel);
powerLevel += skillLevel; powerLevel += skillLevel;

View File

@ -204,11 +204,7 @@ public class SpoutUtils {
} }
// Standard XP Icons // Standard XP Icons
for (SkillType skillType : SkillType.values()) { for (SkillType skillType : SkillType.nonChildSkills()) {
if (skillType.isChildSkill()) {
continue;
}
String skillName = StringUtils.getCapitalized(skillType.toString()); String skillName = StringUtils.getCapitalized(skillType.toString());
files.add(writeFile(skillName + ".png", hudStandardDirectory)); files.add(writeFile(skillName + ".png", hudStandardDirectory));