More API migration on the DB impl

This commit is contained in:
nossr50 2020-12-23 12:00:05 -08:00
parent 843e3ace99
commit 25f7dd223d
8 changed files with 243 additions and 238 deletions

View File

@ -9,6 +9,7 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.neetgames.mcmmo.exceptions.InvalidSkillException; import com.neetgames.mcmmo.exceptions.InvalidSkillException;
import com.neetgames.mcmmo.exceptions.ProfileRetrievalException; import com.neetgames.mcmmo.exceptions.ProfileRetrievalException;
import com.neetgames.mcmmo.player.MMOPlayerData; import com.neetgames.mcmmo.player.MMOPlayerData;
import com.neetgames.mcmmo.skill.RootSkill;
import org.apache.commons.lang.NullArgumentException; import org.apache.commons.lang.NullArgumentException;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -61,12 +62,12 @@ public interface DatabaseManager {
* Retrieve leaderboard info. * Retrieve leaderboard info.
* Will never be null but it may be empty * Will never be null but it may be empty
* *
* @param skill The skill to retrieve info on * @param rootSkill The skill to retrieve info on
* @param pageNumber Which page in the leaderboards to retrieve * @param pageNumber Which page in the leaderboards to retrieve
* @param statsPerPage The number of stats per page * @param statsPerPage The number of stats per page
* @return the requested leaderboard information * @return the requested leaderboard information
*/ */
@NotNull List<PlayerStat> readLeaderboard(@Nullable PrimarySkillType skill, int pageNumber, int statsPerPage) throws InvalidSkillException; @NotNull List<PlayerStat> readLeaderboard(@NotNull RootSkill rootSkill, int pageNumber, int statsPerPage) throws InvalidSkillException;
/** /**
* Retrieve rank info into a HashMap from PrimarySkillType to the rank. * Retrieve rank info into a HashMap from PrimarySkillType to the rank.
@ -77,7 +78,7 @@ public interface DatabaseManager {
* @param playerName The name of the user to retrieve the rankings for * @param playerName The name of the user to retrieve the rankings for
* @return the requested rank information * @return the requested rank information
*/ */
@NotNull Map<PrimarySkillType, Integer> readRank(@NotNull String playerName); @NotNull Map<RootSkill, Integer> readRank(@NotNull String playerName);
/** /**
* Add a new user to the database. * Add a new user to the database.

View File

@ -35,7 +35,7 @@ import java.util.*;
public final class FlatFileDatabaseManager extends AbstractDatabaseManager { public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
public static final String FLATFILE_SPLIT_CHARACTER_REGEX = ":"; public static final String FLATFILE_SPLIT_CHARACTER_REGEX = ":";
private final HashMap<PrimarySkillType, List<PlayerStat>> playerStatHash = new HashMap<>(); private final HashMap<RootSkill, List<PlayerStat>> playerStatHash = new HashMap<>();
private final List<PlayerStat> powerLevels = new ArrayList<>(); private final List<PlayerStat> powerLevels = new ArrayList<>();
private long lastUpdate = 0; private long lastUpdate = 0;
@ -200,7 +200,7 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
mcMMO.p.getLogger().info("Purged " + removedPlayers + " users from the database."); mcMMO.p.getLogger().info("Purged " + removedPlayers + " users from the database.");
} }
public boolean removeUser(String playerName, @Nullable UUID uuid) { public boolean removeUser(@NotNull String playerName, @Nullable UUID uuid) {
//NOTE: UUID is unused for FlatFile for this interface implementation //NOTE: UUID is unused for FlatFile for this interface implementation
boolean worked = false; boolean worked = false;
@ -342,23 +342,23 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
writer.append(primarySkillExperienceValueMap.get(CoreSkills.WOODCUTTING_CS)).append(":"); writer.append(primarySkillExperienceValueMap.get(CoreSkills.WOODCUTTING_CS)).append(":");
writer.append(primarySkillLevelMap.get(CoreSkills.REPAIR_CS)).append(":"); writer.append(primarySkillLevelMap.get(CoreSkills.REPAIR_CS)).append(":");
writer.append(primarySkillLevelMap.get(CoreSkills.UNARMED_CS)).append(":"); writer.append(primarySkillLevelMap.get(CoreSkills.UNARMED_CS)).append(":");
writer.append(primarySkillLevelMap.get(PrimarySkillType.HERBALISM)).append(":"); writer.append(primarySkillLevelMap.get(CoreSkills.HERBALISM_CS)).append(":");
writer.append(primarySkillLevelMap.get(PrimarySkillType.EXCAVATION)).append(":"); writer.append(primarySkillLevelMap.get(CoreSkills.EXCAVATION_CS)).append(":");
writer.append(primarySkillLevelMap.get(CoreSkills.ARCHERY_CS)).append(":"); writer.append(primarySkillLevelMap.get(CoreSkills.ARCHERY_CS)).append(":");
writer.append(primarySkillLevelMap.get(PrimarySkillType.SWORDS)).append(":"); writer.append(primarySkillLevelMap.get(CoreSkills.SWORDS_CS)).append(":");
writer.append(primarySkillLevelMap.get(CoreSkills.AXES_CS)).append(":"); writer.append(primarySkillLevelMap.get(CoreSkills.AXES_CS)).append(":");
writer.append(primarySkillLevelMap.get(CoreSkills.ACROBATICS_CS)).append(":"); writer.append(primarySkillLevelMap.get(CoreSkills.ACROBATICS_CS)).append(":");
writer.append(primarySkillExperienceValueMap.get(CoreSkills.REPAIR_CS)).append(":"); writer.append(primarySkillExperienceValueMap.get(CoreSkills.REPAIR_CS)).append(":");
writer.append(primarySkillExperienceValueMap.get(CoreSkills.UNARMED_CS)).append(":"); writer.append(primarySkillExperienceValueMap.get(CoreSkills.UNARMED_CS)).append(":");
writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.HERBALISM)).append(":"); writer.append(primarySkillExperienceValueMap.get(CoreSkills.HERBALISM_CS)).append(":");
writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.EXCAVATION)).append(":"); writer.append(primarySkillExperienceValueMap.get(CoreSkills.EXCAVATION_CS)).append(":");
writer.append(primarySkillExperienceValueMap.get(CoreSkills.ARCHERY_CS)).append(":"); writer.append(primarySkillExperienceValueMap.get(CoreSkills.ARCHERY_CS)).append(":");
writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.SWORDS)).append(":"); writer.append(primarySkillExperienceValueMap.get(CoreSkills.SWORDS_CS)).append(":");
writer.append(primarySkillExperienceValueMap.get(CoreSkills.AXES_CS)).append(":"); writer.append(primarySkillExperienceValueMap.get(CoreSkills.AXES_CS)).append(":");
writer.append(primarySkillExperienceValueMap.get(CoreSkills.ACROBATICS_CS)).append(":"); writer.append(primarySkillExperienceValueMap.get(CoreSkills.ACROBATICS_CS)).append(":");
writer.append(":"); writer.append(":");
writer.append(primarySkillLevelMap.get(PrimarySkillType.TAMING)).append(":"); writer.append(primarySkillLevelMap.get(CoreSkills.TAMING_CS)).append(":");
writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.TAMING)).append(":"); writer.append(primarySkillExperienceValueMap.get(CoreSkills.TAMING_CS)).append(":");
writer.append((int) mmoDataSnapshot.getAbilityDATS(SuperAbilityType.BERSERK)).append(":"); writer.append((int) mmoDataSnapshot.getAbilityDATS(SuperAbilityType.BERSERK)).append(":");
writer.append((int) mmoDataSnapshot.getAbilityDATS(SuperAbilityType.GIGA_DRILL_BREAKER)).append(":"); writer.append((int) mmoDataSnapshot.getAbilityDATS(SuperAbilityType.GIGA_DRILL_BREAKER)).append(":");
writer.append((int) mmoDataSnapshot.getAbilityDATS(SuperAbilityType.TREE_FELLER)).append(":"); writer.append((int) mmoDataSnapshot.getAbilityDATS(SuperAbilityType.TREE_FELLER)).append(":");
@ -405,29 +405,29 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
public static int BARSTATE_CROSSBOWS = 64; public static int BARSTATE_CROSSBOWS = 64;
*/ */
writer.append(primarySkillLevelMap.get(PrimarySkillType.TRIDENTS)).append(":"); writer.append(primarySkillLevelMap.get(CoreSkills.TRIDENTS_CS)).append(":");
writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.TRIDENTS)).append(":"); writer.append(primarySkillExperienceValueMap.get(CoreSkills.TRIDENTS_CS)).append(":");
writer.append(primarySkillLevelMap.get(PrimarySkillType.CROSSBOWS)).append(":"); writer.append(primarySkillLevelMap.get(CoreSkills.CROSSBOWS_CS)).append(":");
writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.CROSSBOWS)).append(":"); writer.append(primarySkillExperienceValueMap.get(CoreSkills.CROSSBOWS_CS)).append(":");
//XPBar States //XPBar States
writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.ACROBATICS_CS).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.ACROBATICS_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.ALCHEMY_CS).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.ALCHEMY_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.ARCHERY_CS).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.ARCHERY_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.AXES_CS).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.AXES_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.EXCAVATION).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.EXCAVATION_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.FISHING_CS).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.FISHING_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.HERBALISM).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.HERBALISM_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.MINING_CS).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.MINING_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.REPAIR_CS).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.REPAIR_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.SALVAGE).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.SALVAGE_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.SMELTING).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.SMELTING_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.SWORDS).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.SWORDS_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.TAMING).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.TAMING_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.UNARMED_CS).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.UNARMED_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.WOODCUTTING_CS).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.WOODCUTTING_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.TRIDENTS).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.TRIDENTS_CS).toString()).append(":");
writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.CROSSBOWS).toString()).append(":"); writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.CROSSBOWS_CS).toString()).append(":");
writer.append(0).append(":"); //archery super 1 cd writer.append(0).append(":"); //archery super 1 cd
writer.append(0).append(":"); //xbow super 1 cd writer.append(0).append(":"); //xbow super 1 cd
@ -438,7 +438,8 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
writer.append("\r\n"); writer.append("\r\n");
} }
public @NotNull List<PlayerStat> readLeaderboard(@NotNull PrimarySkillType skill, int pageNumber, int statsPerPage) { @Override
public @NotNull List<PlayerStat> readLeaderboard(@NotNull RootSkill skill, int pageNumber, int statsPerPage) {
updateLeaderboards(); updateLeaderboards();
List<PlayerStat> statsList = skill == null ? powerLevels : playerStatHash.get(skill); List<PlayerStat> statsList = skill == null ? powerLevels : playerStatHash.get(skill);
int fromIndex = (Math.max(pageNumber, 1) - 1) * statsPerPage; int fromIndex = (Math.max(pageNumber, 1) - 1) * statsPerPage;
@ -446,13 +447,17 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
return statsList.subList(Math.min(fromIndex, statsList.size()), Math.min(fromIndex + statsPerPage, statsList.size())); return statsList.subList(Math.min(fromIndex, statsList.size()), Math.min(fromIndex + statsPerPage, statsList.size()));
} }
public @NotNull Map<PrimarySkillType, Integer> readRank(@NotNull String playerName) { @Override
public @NotNull Map<RootSkill, Integer> readRank(@NotNull String playerName) {
updateLeaderboards(); updateLeaderboards();
Map<PrimarySkillType, Integer> skills = new HashMap<>(); Map<RootSkill, Integer> skills = new HashMap<>();
for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) { for (RootSkill rootSkill : CoreSkills.getImmutableCoreRootSkillSet()) {
skills.put(skill, getPlayerRank(playerName, playerStatHash.get(skill))); if(CoreSkills.isChildSkill(rootSkill))
continue;
skills.put(rootSkill, getPlayerRank(playerName, playerStatHash.get(rootSkill)));
} }
skills.put(null, getPlayerRank(playerName, powerLevels)); skills.put(null, getPlayerRank(playerName, powerLevels));
@ -460,6 +465,7 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
return skills; return skills;
} }
@Override
public void insertNewUser(@NotNull String playerName, @NotNull UUID uuid) { public void insertNewUser(@NotNull String playerName, @NotNull UUID uuid) {
BufferedWriter out = null; BufferedWriter out = null;
synchronized (fileWritingLock) { synchronized (fileWritingLock) {
@ -700,12 +706,11 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
String[] stringDataSplit = line.split(":"); String[] stringDataSplit = line.split(":");
try { try {
PlayerProfile playerProfile = loadFromLine(stringDataSplit); MMOPlayerData mmoPlayerData = loadFromLine(stringDataSplit);
if(playerProfile == null) if(mmoPlayerData == null)
continue; continue;
PersistentPlayerData persistentPlayerData = playerProfile.getPersistentPlayerData(); destination.saveUser(mcMMO.getUserManager().createPlayerDataSnapshot(mmoPlayerData));
destination.saveUser(mcMMO.getUserManager().createPlayerDataSnapshot(persistentPlayerData));
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -804,23 +809,23 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
playerName = data[FlatFileMappings.USERNAME]; playerName = data[FlatFileMappings.USERNAME];
int powerLevel = 0; int powerLevel = 0;
Map<PrimarySkillType, Integer> skills = getSkillMapFromLine(data); Map<RootSkill, Integer> skills = getSkillMapFromLine(data);
powerLevel += putStat(acrobatics, playerName, skills.get(CoreSkills.ACROBATICS_CS)); powerLevel += putStat(acrobatics, playerName, skills.get(CoreSkills.ACROBATICS_CS));
powerLevel += putStat(alchemy, playerName, skills.get(CoreSkills.ALCHEMY_CS)); powerLevel += putStat(alchemy, playerName, skills.get(CoreSkills.ALCHEMY_CS));
powerLevel += putStat(archery, playerName, skills.get(CoreSkills.ARCHERY_CS)); powerLevel += putStat(archery, playerName, skills.get(CoreSkills.ARCHERY_CS));
powerLevel += putStat(axes, playerName, skills.get(CoreSkills.AXES_CS)); powerLevel += putStat(axes, playerName, skills.get(CoreSkills.AXES_CS));
powerLevel += putStat(excavation, playerName, skills.get(PrimarySkillType.EXCAVATION)); powerLevel += putStat(excavation, playerName, skills.get(CoreSkills.EXCAVATION_CS));
powerLevel += putStat(fishing, playerName, skills.get(CoreSkills.FISHING_CS)); powerLevel += putStat(fishing, playerName, skills.get(CoreSkills.FISHING_CS));
powerLevel += putStat(herbalism, playerName, skills.get(PrimarySkillType.HERBALISM)); powerLevel += putStat(herbalism, playerName, skills.get(CoreSkills.HERBALISM_CS));
powerLevel += putStat(mining, playerName, skills.get(CoreSkills.MINING_CS)); powerLevel += putStat(mining, playerName, skills.get(CoreSkills.MINING_CS));
powerLevel += putStat(repair, playerName, skills.get(CoreSkills.REPAIR_CS)); powerLevel += putStat(repair, playerName, skills.get(CoreSkills.REPAIR_CS));
powerLevel += putStat(swords, playerName, skills.get(PrimarySkillType.SWORDS)); powerLevel += putStat(swords, playerName, skills.get(CoreSkills.SWORDS_CS));
powerLevel += putStat(taming, playerName, skills.get(PrimarySkillType.TAMING)); powerLevel += putStat(taming, playerName, skills.get(CoreSkills.TAMING_CS));
powerLevel += putStat(unarmed, playerName, skills.get(CoreSkills.UNARMED_CS)); powerLevel += putStat(unarmed, playerName, skills.get(CoreSkills.UNARMED_CS));
powerLevel += putStat(woodcutting, playerName, skills.get(CoreSkills.WOODCUTTING_CS)); powerLevel += putStat(woodcutting, playerName, skills.get(CoreSkills.WOODCUTTING_CS));
powerLevel += putStat(woodcutting, playerName, skills.get(PrimarySkillType.CROSSBOWS)); powerLevel += putStat(woodcutting, playerName, skills.get(CoreSkills.CROSSBOWS_CS));
powerLevel += putStat(woodcutting, playerName, skills.get(PrimarySkillType.TRIDENTS)); powerLevel += putStat(woodcutting, playerName, skills.get(CoreSkills.TRIDENTS_CS));
putStat(powerLevels, playerName, powerLevel); putStat(powerLevels, playerName, powerLevel);
} }
@ -861,13 +866,13 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
playerStatHash.put(CoreSkills.WOODCUTTING_CS, woodcutting); playerStatHash.put(CoreSkills.WOODCUTTING_CS, woodcutting);
playerStatHash.put(CoreSkills.REPAIR_CS, repair); playerStatHash.put(CoreSkills.REPAIR_CS, repair);
playerStatHash.put(CoreSkills.UNARMED_CS, unarmed); playerStatHash.put(CoreSkills.UNARMED_CS, unarmed);
playerStatHash.put(PrimarySkillType.HERBALISM, herbalism); playerStatHash.put(CoreSkills.HERBALISM_CS, herbalism);
playerStatHash.put(PrimarySkillType.EXCAVATION, excavation); playerStatHash.put(CoreSkills.EXCAVATION_CS, excavation);
playerStatHash.put(CoreSkills.ARCHERY_CS, archery); playerStatHash.put(CoreSkills.ARCHERY_CS, archery);
playerStatHash.put(PrimarySkillType.SWORDS, swords); playerStatHash.put(CoreSkills.SWORDS_CS, swords);
playerStatHash.put(CoreSkills.AXES_CS, axes); playerStatHash.put(CoreSkills.AXES_CS, axes);
playerStatHash.put(CoreSkills.ACROBATICS_CS, acrobatics); playerStatHash.put(CoreSkills.ACROBATICS_CS, acrobatics);
playerStatHash.put(PrimarySkillType.TAMING, taming); playerStatHash.put(CoreSkills.TAMING_CS, taming);
playerStatHash.put(CoreSkills.FISHING_CS, fishing); playerStatHash.put(CoreSkills.FISHING_CS, fishing);
playerStatHash.put(CoreSkills.ALCHEMY_CS, alchemy); playerStatHash.put(CoreSkills.ALCHEMY_CS, alchemy);
} }
@ -1102,14 +1107,17 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
//TODO: If new skills are added this needs to be rewritten //TODO: If new skills are added this needs to be rewritten
if (Config.getInstance().getTruncateSkills()) { if (Config.getInstance().getTruncateSkills()) {
for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) { for (RootSkill rootSkill : CoreSkills.getImmutableCoreRootSkillSet()) {
int index = getSkillIndex(skill); if(CoreSkills.isChildSkill(rootSkill))
continue;
int index = getSkillIndex(rootSkill);
if (index >= stringDataArray.length) { if (index >= stringDataArray.length) {
continue; continue;
} }
int cap = Config.getInstance().getLevelCap(skill); int cap = Config.getInstance().getLevelCap(rootSkill);
if (Integer.parseInt(stringDataArray[index]) > cap) { if (Integer.parseInt(stringDataArray[index]) > cap) {
mcMMO.p.getLogger().warning("Truncating " + skill.getName() + " to configured max level for player " + stringDataArray[FlatFileMappings.USERNAME]); mcMMO.p.getLogger().warning("Truncating " + rootSkill.getSkillName() + " to configured max level for player " + stringDataArray[FlatFileMappings.USERNAME]);
stringDataArray[index] = cap + ""; stringDataArray[index] = cap + "";
updated = true; updated = true;
} }
@ -1167,10 +1175,10 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
updated |= oldVersion != null; updated |= oldVersion != null;
if (Config.getInstance().getTruncateSkills()) { if (Config.getInstance().getTruncateSkills()) {
Map<PrimarySkillType, Integer> skills = getSkillMapFromLine(stringDataArray); Map<RootSkill, Integer> skillsMap = getSkillMapFromLine(stringDataArray);
for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) { for (RootSkill rootSkill : CoreSkills.getNonChildSkills()) {
int cap = Config.getInstance().getLevelCap(skill); int cap = Config.getInstance().getLevelCap(rootSkill);
if (skills.get(skill) > cap) { if (skillsMap.get(rootSkill) > cap) {
updated = true; updated = true;
} }
} }
@ -1272,29 +1280,28 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
private @Nullable MMOPlayerData loadFromLine(@NotNull String[] dataStrSplit) { private @Nullable MMOPlayerData loadFromLine(@NotNull String[] dataStrSplit) {
MMODataBuilder playerDataBuilder = new MMODataBuilder(); MMODataBuilder playerDataBuilder = new MMODataBuilder();
HashMap<RootSkill, Integer> skillLevelMap = getSkillMapFromLine(dataStrSplit); // Skill levels Map<RootSkill, Integer> skillLevelMap = getSkillMapFromLine(dataStrSplit); // Skill levels
HashMap<RootSkill, Float> skillExperienceValueMap = new EnumMap<PrimarySkillType, Float>(PrimarySkillType.class); // Skill & XP Map<RootSkill, Float> skillExperienceValueMap = new HashMap<>(); // Skill & XP
HashMap<SuperSkill, Integer> skillAbilityDeactivationTimeStamp = new EnumMap<SuperAbilityType, Integer>(SuperAbilityType.class); // Ability & Cooldown Map<SuperSkill, Integer> skillAbilityDeactivationTimeStamp = new HashMap<>(); // Ability & Cooldown
EnumMap<UniqueDataType, Integer> uniquePlayerDataMap = new EnumMap<UniqueDataType, Integer>(UniqueDataType.class); Map<UniqueDataType, Integer> uniquePlayerDataMap = new EnumMap<UniqueDataType, Integer>(UniqueDataType.class);
HashMap<RootSkill, SkillBossBarState> xpBarStateMap = new EnumMap<PrimarySkillType, SkillBossBarState>(PrimarySkillType.class); Map<RootSkill, SkillBossBarState> xpBarStateMap = new HashMap<>();
// MobHealthBarType mobHealthbarType;
int scoreboardTipsShown; int scoreboardTipsShown;
skillExperienceValueMap.put(PrimarySkillType.TAMING, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_TAMING])); skillExperienceValueMap.put(CoreSkills.TAMING_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_TAMING]));
skillExperienceValueMap.put(CoreSkills.MINING_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_MINING])); skillExperienceValueMap.put(CoreSkills.MINING_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_MINING]));
skillExperienceValueMap.put(CoreSkills.REPAIR_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_REPAIR])); skillExperienceValueMap.put(CoreSkills.REPAIR_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_REPAIR]));
skillExperienceValueMap.put(CoreSkills.WOODCUTTING_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_WOODCUTTING])); skillExperienceValueMap.put(CoreSkills.WOODCUTTING_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_WOODCUTTING]));
skillExperienceValueMap.put(CoreSkills.UNARMED_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_UNARMED])); skillExperienceValueMap.put(CoreSkills.UNARMED_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_UNARMED]));
skillExperienceValueMap.put(PrimarySkillType.HERBALISM, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_HERBALISM])); skillExperienceValueMap.put(CoreSkills.HERBALISM_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_HERBALISM]));
skillExperienceValueMap.put(PrimarySkillType.EXCAVATION, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_EXCAVATION])); skillExperienceValueMap.put(CoreSkills.EXCAVATION_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_EXCAVATION]));
skillExperienceValueMap.put(CoreSkills.ARCHERY_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_ARCHERY])); skillExperienceValueMap.put(CoreSkills.ARCHERY_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_ARCHERY]));
skillExperienceValueMap.put(PrimarySkillType.SWORDS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_SWORDS])); skillExperienceValueMap.put(CoreSkills.SWORDS_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_SWORDS]));
skillExperienceValueMap.put(CoreSkills.AXES_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_AXES])); skillExperienceValueMap.put(CoreSkills.AXES_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_AXES]));
skillExperienceValueMap.put(CoreSkills.ACROBATICS_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_ACROBATICS])); skillExperienceValueMap.put(CoreSkills.ACROBATICS_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_ACROBATICS]));
skillExperienceValueMap.put(CoreSkills.FISHING_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_FISHING])); skillExperienceValueMap.put(CoreSkills.FISHING_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_FISHING]));
skillExperienceValueMap.put(CoreSkills.ALCHEMY_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_ALCHEMY])); skillExperienceValueMap.put(CoreSkills.ALCHEMY_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_ALCHEMY]));
skillExperienceValueMap.put(PrimarySkillType.TRIDENTS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_TRIDENTS])); skillExperienceValueMap.put(CoreSkills.TRIDENTS_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_TRIDENTS]));
skillExperienceValueMap.put(PrimarySkillType.CROSSBOWS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_CROSSBOWS])); skillExperienceValueMap.put(CoreSkills.CROSSBOWS_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_CROSSBOWS]));
//Set Skill XP //Set Skill XP
@ -1353,19 +1360,19 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
xpBarStateMap.put(CoreSkills.ALCHEMY_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_ALCHEMY])); xpBarStateMap.put(CoreSkills.ALCHEMY_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_ALCHEMY]));
xpBarStateMap.put(CoreSkills.ARCHERY_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_ARCHERY])); xpBarStateMap.put(CoreSkills.ARCHERY_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_ARCHERY]));
xpBarStateMap.put(CoreSkills.AXES_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_AXES])); xpBarStateMap.put(CoreSkills.AXES_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_AXES]));
xpBarStateMap.put(PrimarySkillType.EXCAVATION, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_EXCAVATION])); xpBarStateMap.put(CoreSkills.EXCAVATION_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_EXCAVATION]));
xpBarStateMap.put(CoreSkills.FISHING_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_FISHING])); xpBarStateMap.put(CoreSkills.FISHING_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_FISHING]));
xpBarStateMap.put(PrimarySkillType.HERBALISM, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_HERBALISM])); xpBarStateMap.put(CoreSkills.HERBALISM_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_HERBALISM]));
xpBarStateMap.put(CoreSkills.MINING_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_MINING])); xpBarStateMap.put(CoreSkills.MINING_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_MINING]));
xpBarStateMap.put(CoreSkills.REPAIR_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_REPAIR])); xpBarStateMap.put(CoreSkills.REPAIR_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_REPAIR]));
xpBarStateMap.put(PrimarySkillType.SALVAGE, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_SALVAGE])); xpBarStateMap.put(CoreSkills.SALVAGE_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_SALVAGE]));
xpBarStateMap.put(PrimarySkillType.SMELTING, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_SMELTING])); xpBarStateMap.put(CoreSkills.SMELTING_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_SMELTING]));
xpBarStateMap.put(PrimarySkillType.SWORDS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_SWORDS])); xpBarStateMap.put(CoreSkills.SWORDS_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_SWORDS]));
xpBarStateMap.put(PrimarySkillType.TAMING, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_TAMING])); xpBarStateMap.put(CoreSkills.TAMING_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_TAMING]));
xpBarStateMap.put(CoreSkills.UNARMED_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_UNARMED])); xpBarStateMap.put(CoreSkills.UNARMED_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_UNARMED]));
xpBarStateMap.put(CoreSkills.WOODCUTTING_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_WOODCUTTING])); xpBarStateMap.put(CoreSkills.WOODCUTTING_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_WOODCUTTING]));
xpBarStateMap.put(PrimarySkillType.TRIDENTS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_TRIDENTS])); xpBarStateMap.put(CoreSkills.TRIDENTS_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_TRIDENTS]));
xpBarStateMap.put(PrimarySkillType.CROSSBOWS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_CROSSBOWS])); xpBarStateMap.put(CoreSkills.CROSSBOWS_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_CROSSBOWS]));
} catch (Exception e) { } catch (Exception e) {
xpBarStateMap = MMOExperienceBarManager.generateDefaultBarStateMap(); xpBarStateMap = MMOExperienceBarManager.generateDefaultBarStateMap();
@ -1407,7 +1414,7 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
skillLevelsMap.put(CoreSkills.SWORDS_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_SWORDS])); skillLevelsMap.put(CoreSkills.SWORDS_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_SWORDS]));
skillLevelsMap.put(CoreSkills.AXES_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_AXES])); skillLevelsMap.put(CoreSkills.AXES_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_AXES]));
skillLevelsMap.put(CoreSkills.ACROBATICS_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_ACROBATICS])); skillLevelsMap.put(CoreSkills.ACROBATICS_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_ACROBATICS]));
skillLevelsMap.put(CoreSkills.FISHING_CS_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_FISHING])); skillLevelsMap.put(CoreSkills.FISHING_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_FISHING]));
skillLevelsMap.put(CoreSkills.ALCHEMY_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_ALCHEMY])); skillLevelsMap.put(CoreSkills.ALCHEMY_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_ALCHEMY]));
skillLevelsMap.put(CoreSkills.TRIDENTS_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_TRIDENTS])); skillLevelsMap.put(CoreSkills.TRIDENTS_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_TRIDENTS]));
skillLevelsMap.put(CoreSkills.CROSSBOWS_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_CROSSBOWS])); skillLevelsMap.put(CoreSkills.CROSSBOWS_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_CROSSBOWS]));
@ -1419,7 +1426,9 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager {
return DatabaseType.FLATFILE; return DatabaseType.FLATFILE;
} }
private int getSkillIndex(PrimarySkillType primarySkillType) { private int getSkillIndex(@NotNull RootSkill rootSkill) {
PrimarySkillType primarySkillType = CoreSkills.getSkill(rootSkill);
switch (primarySkillType) { switch (primarySkillType) {
case ACROBATICS: case ACROBATICS:
return FlatFileMappings.SKILLS_ACROBATICS; return FlatFileMappings.SKILLS_ACROBATICS;

View File

@ -16,7 +16,10 @@ import com.neetgames.mcmmo.MobHealthBarType;
import com.neetgames.mcmmo.UniqueDataType; import com.neetgames.mcmmo.UniqueDataType;
import com.neetgames.mcmmo.exceptions.InvalidSkillException; import com.neetgames.mcmmo.exceptions.InvalidSkillException;
import com.neetgames.mcmmo.exceptions.ProfileRetrievalException; import com.neetgames.mcmmo.exceptions.ProfileRetrievalException;
import com.neetgames.mcmmo.player.MMOPlayerData;
import com.neetgames.mcmmo.skill.RootSkill;
import com.neetgames.mcmmo.skill.SkillBossBarState; import com.neetgames.mcmmo.skill.SkillBossBarState;
import com.neetgames.mcmmo.skill.SuperSkill;
import org.apache.commons.lang.NullArgumentException; import org.apache.commons.lang.NullArgumentException;
import org.apache.tomcat.jdbc.pool.DataSource; import org.apache.tomcat.jdbc.pool.DataSource;
import org.apache.tomcat.jdbc.pool.PoolProperties; import org.apache.tomcat.jdbc.pool.PoolProperties;
@ -184,7 +187,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
mcMMO.p.getLogger().info("Purged " + purged + " users from the database."); mcMMO.p.getLogger().info("Purged " + purged + " users from the database.");
} }
public boolean removeUser(String playerName, @Nullable UUID uuid) { public boolean removeUser(@NotNull String playerName, @Nullable UUID uuid) {
boolean success = false; boolean success = false;
Connection connection = null; Connection connection = null;
PreparedStatement statement = null; PreparedStatement statement = null;
@ -257,24 +260,24 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
+ ", unarmed = ?, herbalism = ?, excavation = ?" + ", unarmed = ?, herbalism = ?, excavation = ?"
+ ", archery = ?, swords = ?, axes = ?, acrobatics = ?" + ", archery = ?, swords = ?, axes = ?, acrobatics = ?"
+ ", fishing = ?, alchemy = ?, tridents = ?, crossbows = ?, total = ? WHERE user_id = ?"); + ", fishing = ?, alchemy = ?, tridents = ?, crossbows = ?, total = ? WHERE user_id = ?");
statement.setInt(1, dataSnapshot.getSkillLevel(PrimarySkillType.TAMING)); statement.setInt(1, dataSnapshot.getSkillLevel(CoreSkills.TAMING_CS));
statement.setInt(2, dataSnapshot.getSkillLevel(PrimarySkillType.MINING)); statement.setInt(2, dataSnapshot.getSkillLevel(CoreSkills.MINING_CS));
statement.setInt(3, dataSnapshot.getSkillLevel(CoreSkills.REPAIR_CS)); statement.setInt(3, dataSnapshot.getSkillLevel(CoreSkills.REPAIR_CS));
statement.setInt(4, dataSnapshot.getSkillLevel(CoreSkills.WOODCUTTING_CS)); statement.setInt(4, dataSnapshot.getSkillLevel(CoreSkills.WOODCUTTING_CS));
statement.setInt(5, dataSnapshot.getSkillLevel(CoreSkills.UNARMED_CS)); statement.setInt(5, dataSnapshot.getSkillLevel(CoreSkills.UNARMED_CS));
statement.setInt(6, dataSnapshot.getSkillLevel(PrimarySkillType.HERBALISM)); statement.setInt(6, dataSnapshot.getSkillLevel(CoreSkills.HERBALISM_CS));
statement.setInt(7, dataSnapshot.getSkillLevel(PrimarySkillType.EXCAVATION)); statement.setInt(7, dataSnapshot.getSkillLevel(CoreSkills.EXCAVATION_CS));
statement.setInt(8, dataSnapshot.getSkillLevel(PrimarySkillType.ARCHERY)); statement.setInt(8, dataSnapshot.getSkillLevel(CoreSkills.ARCHERY_CS));
statement.setInt(9, dataSnapshot.getSkillLevel(PrimarySkillType.SWORDS)); statement.setInt(9, dataSnapshot.getSkillLevel(CoreSkills.SWORDS_CS));
statement.setInt(10, dataSnapshot.getSkillLevel(CoreSkills.AXES_CS)); statement.setInt(10, dataSnapshot.getSkillLevel(CoreSkills.AXES_CS));
statement.setInt(11, dataSnapshot.getSkillLevel(CoreSkills.ACROBATICS_CS)); statement.setInt(11, dataSnapshot.getSkillLevel(CoreSkills.ACROBATICS_CS));
statement.setInt(12, dataSnapshot.getSkillLevel(PrimarySkillType.FISHING)); statement.setInt(12, dataSnapshot.getSkillLevel(CoreSkills.FISHING_CS));
statement.setInt(13, dataSnapshot.getSkillLevel(CoreSkills.ALCHEMY_CS)); statement.setInt(13, dataSnapshot.getSkillLevel(CoreSkills.ALCHEMY_CS));
statement.setInt(14, dataSnapshot.getSkillLevel(PrimarySkillType.TRIDENTS)); statement.setInt(14, dataSnapshot.getSkillLevel(CoreSkills.TRIDENTS_CS));
statement.setInt(15, dataSnapshot.getSkillLevel(PrimarySkillType.CROSSBOWS)); statement.setInt(15, dataSnapshot.getSkillLevel(CoreSkills.CROSSBOWS_CS));
int total = 0; int total = 0;
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) for (RootSkill rootSkill : CoreSkills.getNonChildSkills())
total += dataSnapshot.getSkillLevel(primarySkillType); total += dataSnapshot.getSkillLevel(rootSkill);
statement.setInt(16, total); statement.setInt(16, total);
statement.setInt(17, id); statement.setInt(17, id);
success &= (statement.executeUpdate() != 0); success &= (statement.executeUpdate() != 0);
@ -289,21 +292,21 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
+ ", unarmed = ?, herbalism = ?, excavation = ?" + ", unarmed = ?, herbalism = ?, excavation = ?"
+ ", archery = ?, swords = ?, axes = ?, acrobatics = ?" + ", archery = ?, swords = ?, axes = ?, acrobatics = ?"
+ ", fishing = ?, alchemy = ?, tridents = ?, crossbows = ?, WHERE user_id = ?"); + ", fishing = ?, alchemy = ?, tridents = ?, crossbows = ?, WHERE user_id = ?");
statement.setInt(1, dataSnapshot.getSkillXpLevel(PrimarySkillType.TAMING)); statement.setInt(1, dataSnapshot.getSkillXpLevel(CoreSkills.TAMING_CS));
statement.setInt(2, dataSnapshot.getSkillXpLevel(PrimarySkillType.MINING)); statement.setInt(2, dataSnapshot.getSkillXpLevel(CoreSkills.MINING_CS));
statement.setInt(3, dataSnapshot.getSkillXpLevel(CoreSkills.REPAIR_CS)); statement.setInt(3, dataSnapshot.getSkillXpLevel(CoreSkills.REPAIR_CS));
statement.setInt(4, dataSnapshot.getSkillXpLevel(CoreSkills.WOODCUTTING_CS)); statement.setInt(4, dataSnapshot.getSkillXpLevel(CoreSkills.WOODCUTTING_CS));
statement.setInt(5, dataSnapshot.getSkillXpLevel(CoreSkills.UNARMED_CS)); statement.setInt(5, dataSnapshot.getSkillXpLevel(CoreSkills.UNARMED_CS));
statement.setInt(6, dataSnapshot.getSkillXpLevel(PrimarySkillType.HERBALISM)); statement.setInt(6, dataSnapshot.getSkillXpLevel(CoreSkills.HERBALISM_CS));
statement.setInt(7, dataSnapshot.getSkillXpLevel(PrimarySkillType.EXCAVATION)); statement.setInt(7, dataSnapshot.getSkillXpLevel(CoreSkills.EXCAVATION_CS));
statement.setInt(8, dataSnapshot.getSkillXpLevel(PrimarySkillType.ARCHERY)); statement.setInt(8, dataSnapshot.getSkillXpLevel(CoreSkills.ARCHERY_CS));
statement.setInt(9, dataSnapshot.getSkillXpLevel(PrimarySkillType.SWORDS)); statement.setInt(9, dataSnapshot.getSkillXpLevel(CoreSkills.SWORDS_CS));
statement.setInt(10, dataSnapshot.getSkillXpLevel(CoreSkills.AXES_CS)); statement.setInt(10, dataSnapshot.getSkillXpLevel(CoreSkills.AXES_CS));
statement.setInt(11, dataSnapshot.getSkillXpLevel(CoreSkills.ACROBATICS_CS)); statement.setInt(11, dataSnapshot.getSkillXpLevel(CoreSkills.ACROBATICS_CS));
statement.setInt(12, dataSnapshot.getSkillXpLevel(PrimarySkillType.FISHING)); statement.setInt(12, dataSnapshot.getSkillXpLevel(CoreSkills.FISHING_CS));
statement.setInt(13, dataSnapshot.getSkillXpLevel(CoreSkills.ALCHEMY_CS)); statement.setInt(13, dataSnapshot.getSkillXpLevel(CoreSkills.ALCHEMY_CS));
statement.setInt(14, dataSnapshot.getSkillXpLevel(PrimarySkillType.TRIDENTS)); statement.setInt(14, dataSnapshot.getSkillXpLevel(CoreSkills.TRIDENTS_CS));
statement.setInt(15, dataSnapshot.getSkillXpLevel(PrimarySkillType.CROSSBOWS)); statement.setInt(15, dataSnapshot.getSkillXpLevel(CoreSkills.CROSSBOWS_CS));
statement.setInt(16, id); statement.setInt(16, id);
success &= (statement.executeUpdate() != 0); success &= (statement.executeUpdate() != 0);
statement.close(); statement.close();
@ -337,7 +340,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
} }
statement = connection.prepareStatement("UPDATE " + tablePrefix + "huds SET mobhealthbar = ?, scoreboardtips = ? WHERE user_id = ?"); statement = connection.prepareStatement("UPDATE " + tablePrefix + "huds SET mobhealthbar = ?, scoreboardtips = ? WHERE user_id = ?");
statement.setString(1, dataSnapshot.getMobHealthBarType() == null ? Config.getInstance().getMobHealthbarDefault().name() : dataSnapshot.getMobHealthBarType().name()); statement.setString(1, Config.getInstance().getMobHealthbarDefault().name());
statement.setInt(2, dataSnapshot.getScoreboardTipsShown()); statement.setInt(2, dataSnapshot.getScoreboardTipsShown());
statement.setInt(3, id); statement.setInt(3, id);
success = (statement.executeUpdate() != 0); success = (statement.executeUpdate() != 0);
@ -354,23 +357,23 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
+ ", view_unarmed = ?, view_herbalism = ?, view_excavation = ?" + ", view_unarmed = ?, view_herbalism = ?, view_excavation = ?"
+ ", view_archery = ?, view_swords = ?, view_axes = ?, view_acrobatics = ?" + ", view_archery = ?, view_swords = ?, view_axes = ?, view_acrobatics = ?"
+ ", view_fishing = ?, view_alchemy = ?, view_salvage = ?, view_smelting = ?, view_tridents = ?, view_crossbows = ? WHERE user_id = ?"); + ", view_fishing = ?, view_alchemy = ?, view_salvage = ?, view_smelting = ?, view_tridents = ?, view_crossbows = ? WHERE user_id = ?");
statement.setString(1, dataSnapshot.getBarStateMap().get(PrimarySkillType.TAMING).toString()); statement.setString(1, dataSnapshot.getBarStateMap().get(CoreSkills.TAMING_CS).toString());
statement.setString(2, dataSnapshot.getBarStateMap().get(PrimarySkillType.MINING).toString()); statement.setString(2, dataSnapshot.getBarStateMap().get(CoreSkills.MINING_CS).toString());
statement.setString(3, dataSnapshot.getBarStateMap().get(CoreSkills.REPAIR_CS).toString()); statement.setString(3, dataSnapshot.getBarStateMap().get(CoreSkills.REPAIR_CS).toString());
statement.setString(4, dataSnapshot.getBarStateMap().get(CoreSkills.WOODCUTTING_CS).toString()); statement.setString(4, dataSnapshot.getBarStateMap().get(CoreSkills.WOODCUTTING_CS).toString());
statement.setString(5, dataSnapshot.getBarStateMap().get(CoreSkills.UNARMED_CS).toString()); statement.setString(5, dataSnapshot.getBarStateMap().get(CoreSkills.UNARMED_CS).toString());
statement.setString(6, dataSnapshot.getBarStateMap().get(PrimarySkillType.HERBALISM).toString()); statement.setString(6, dataSnapshot.getBarStateMap().get(CoreSkills.HERBALISM_CS).toString());
statement.setString(7, dataSnapshot.getBarStateMap().get(PrimarySkillType.EXCAVATION).toString()); statement.setString(7, dataSnapshot.getBarStateMap().get(CoreSkills.EXCAVATION_CS).toString());
statement.setString(8, dataSnapshot.getBarStateMap().get(PrimarySkillType.ARCHERY).toString()); statement.setString(8, dataSnapshot.getBarStateMap().get(CoreSkills.ARCHERY_CS).toString());
statement.setString(9, dataSnapshot.getBarStateMap().get(PrimarySkillType.SWORDS).toString()); statement.setString(9, dataSnapshot.getBarStateMap().get(CoreSkills.SWORDS_CS).toString());
statement.setString(10, dataSnapshot.getBarStateMap().get(CoreSkills.AXES_CS).toString()); statement.setString(10, dataSnapshot.getBarStateMap().get(CoreSkills.AXES_CS).toString());
statement.setString(11, dataSnapshot.getBarStateMap().get(CoreSkills.ACROBATICS_CS).toString()); statement.setString(11, dataSnapshot.getBarStateMap().get(CoreSkills.ACROBATICS_CS).toString());
statement.setString(12, dataSnapshot.getBarStateMap().get(PrimarySkillType.FISHING).toString()); statement.setString(12, dataSnapshot.getBarStateMap().get(CoreSkills.FISHING_CS).toString());
statement.setString(13, dataSnapshot.getBarStateMap().get(CoreSkills.ALCHEMY_CS).toString()); statement.setString(13, dataSnapshot.getBarStateMap().get(CoreSkills.ALCHEMY_CS).toString());
statement.setString(14, dataSnapshot.getBarStateMap().get(PrimarySkillType.SALVAGE).toString()); statement.setString(14, dataSnapshot.getBarStateMap().get(CoreSkills.SALVAGE_CS).toString());
statement.setString(15, dataSnapshot.getBarStateMap().get(PrimarySkillType.SMELTING).toString()); statement.setString(15, dataSnapshot.getBarStateMap().get(CoreSkills.SMELTING_CS).toString());
statement.setString(16, dataSnapshot.getBarStateMap().get(PrimarySkillType.TRIDENTS).toString()); statement.setString(16, dataSnapshot.getBarStateMap().get(CoreSkills.TRIDENTS_CS).toString());
statement.setString(17, dataSnapshot.getBarStateMap().get(PrimarySkillType.CROSSBOWS).toString()); statement.setString(17, dataSnapshot.getBarStateMap().get(CoreSkills.CROSSBOWS_CS).toString());
statement.setInt(18, id); statement.setInt(18, id);
success &= (statement.executeUpdate() != 0); success &= (statement.executeUpdate() != 0);
statement.close(); statement.close();
@ -406,17 +409,17 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
return success; return success;
} }
public @NotNull List<PlayerStat> readLeaderboard(@Nullable PrimarySkillType skill, int pageNumber, int statsPerPage) throws InvalidSkillException { public @NotNull List<PlayerStat> readLeaderboard(@Nullable RootSkill rootSkill, int pageNumber, int statsPerPage) throws InvalidSkillException {
List<PlayerStat> stats = new ArrayList<>(); List<PlayerStat> stats = new ArrayList<>();
//Fix for a plugin that people are using that is throwing SQL errors //Fix for a plugin that people are using that is throwing SQL errors
if(skill != null && skill.isChildSkill()) { if(rootSkill != null && CoreSkills.isChildSkill(rootSkill)) {
mcMMO.p.getLogger().severe("A plugin hooking into mcMMO is being naughty with our database commands, update all plugins that hook into mcMMO and contact their devs!"); mcMMO.p.getLogger().severe("A plugin hooking into mcMMO is being naughty with our database commands, update all plugins that hook into mcMMO and contact their devs!");
throw new InvalidSkillException("A plugin hooking into mcMMO that you are using is attempting to read leaderboard skills for child skills, child skills do not have leaderboards! This is NOT an mcMMO error!"); throw new InvalidSkillException("A plugin hooking into mcMMO that you are using is attempting to read leaderboard skills for child skills, child skills do not have leaderboards! This is NOT an mcMMO error!");
} }
String query = skill == null ? ALL_QUERY_VERSION : skill.name().toLowerCase(Locale.ENGLISH); String query = rootSkill == null ? ALL_QUERY_VERSION : rootSkill.getSkillName().toLowerCase(Locale.ENGLISH);
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement statement = null; PreparedStatement statement = null;
Connection connection = null; Connection connection = null;
@ -452,8 +455,8 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
return stats; return stats;
} }
public @NotNull Map<PrimarySkillType, Integer> readRank(@NotNull String playerName) { public @NotNull Map<RootSkill, Integer> readRank(@NotNull String playerName) {
Map<PrimarySkillType, Integer> skills = new HashMap<>(); Map<RootSkill, Integer> skills = new HashMap<>();
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement statement = null; PreparedStatement statement = null;
@ -461,8 +464,8 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
try { try {
connection = getConnection(PoolIdentifier.MISC); connection = getConnection(PoolIdentifier.MISC);
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) { for (RootSkill rootSkill : CoreSkills.getNonChildSkills()) {
String skillName = primarySkillType.name().toLowerCase(Locale.ENGLISH); String skillName = rootSkill.getSkillName().toLowerCase(Locale.ENGLISH);
// Get count of all users with higher skill level than player // Get count of all users with higher skill level than player
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 " +
@ -489,7 +492,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
while (resultSet.next()) { while (resultSet.next()) {
if (resultSet.getString("user").equalsIgnoreCase(playerName)) { if (resultSet.getString("user").equalsIgnoreCase(playerName)) {
skills.put(primarySkillType, rank + resultSet.getRow()); skills.put(rootSkill, rank + resultSet.getRow());
break; break;
} }
} }
@ -602,16 +605,16 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
} }
@Override @Override
public @Nullable PlayerProfile queryPlayerDataByPlayer(@NotNull Player player) throws ProfileRetrievalException, NullArgumentException { public @Nullable MMOPlayerData queryPlayerDataByPlayer(@NotNull Player player) throws ProfileRetrievalException, NullArgumentException {
return loadPlayerProfile(player, player.getName(), player.getUniqueId()); return loadPlayerProfile(player, player.getName(), player.getUniqueId());
} }
@Override @Override
public @Nullable PlayerProfile queryPlayerDataByUUID(@NotNull UUID uuid, @NotNull String playerName) throws ProfileRetrievalException, NullArgumentException { public @Nullable MMOPlayerData queryPlayerDataByUUID(@NotNull UUID uuid, @NotNull String playerName) throws ProfileRetrievalException, NullArgumentException {
return loadPlayerProfile(null, playerName, uuid); return loadPlayerProfile(null, playerName, uuid);
} }
private @Nullable PlayerProfile loadPlayerProfile(@Nullable Player player, @NotNull String playerName, @Nullable UUID playerUUID) { private @Nullable MMOPlayerData loadPlayerProfile(@Nullable Player player, @NotNull String playerName, @Nullable UUID playerUUID) {
PreparedStatement statement = null; PreparedStatement statement = null;
Connection connection = null; Connection connection = null;
ResultSet resultSet = null; ResultSet resultSet = null;
@ -641,7 +644,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
if (resultSet.next()) { if (resultSet.next()) {
try { try {
PlayerProfile profile = loadFromResult(playerName, resultSet); MMOPlayerData mmoPlayerData = loadFromResult(playerName, resultSet);
String name = resultSet.getString(42); // TODO: Magic Number, make sure it stays updated String name = resultSet.getString(42); // TODO: Magic Number, make sure it stays updated
resultSet.close(); resultSet.close();
statement.close(); statement.close();
@ -666,7 +669,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
statement.close(); statement.close();
} }
return profile; return mmoPlayerData;
} }
catch (SQLException e) { catch (SQLException e) {
printErrors(e); printErrors(e);
@ -702,14 +705,9 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
try { try {
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
resultSet.next(); resultSet.next();
PlayerProfile playerProfile = loadFromResult(playerName, resultSet); //TODO: Optimize, probably needless to make a snapshot here, brain tired
MMOPlayerData mmoPlayerData = loadFromResult(playerName, resultSet);
if(playerProfile == null) MMODataSnapshot mmoDataSnapshot = mcMMO.getUserManager().createPlayerDataSnapshot(mmoPlayerData);
continue;
PersistentPlayerData persistentPlayerData = playerProfile.getPersistentPlayerData();
MMODataSnapshot mmoDataSnapshot = mcMMO.getUserManager().createPlayerDataSnapshot(persistentPlayerData);
destination.saveUser(mmoDataSnapshot); destination.saveUser(mmoDataSnapshot);
resultSet.close(); resultSet.close();
} }
@ -752,7 +750,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
} }
public boolean saveUserUUID(String userName, UUID uuid) { public boolean saveUserUUID(@NotNull String userName, @NotNull UUID uuid) {
PreparedStatement statement = null; PreparedStatement statement = null;
Connection connection = null; Connection connection = null;
@ -1024,10 +1022,12 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
} }
if (Config.getInstance().getTruncateSkills()) { if (Config.getInstance().getTruncateSkills()) {
for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) { for (RootSkill rootSkill : CoreSkills.getNonChildSkills()) {
int cap = Config.getInstance().getLevelCap(skill); int cap = Config.getInstance().getLevelCap(rootSkill);
if (cap != Integer.MAX_VALUE) { if (cap != Integer.MAX_VALUE) {
statement = connection.prepareStatement("UPDATE `" + tablePrefix + "skills` SET `" + skill.name().toLowerCase(Locale.ENGLISH) + "` = " + cap + " WHERE `" + skill.name().toLowerCase(Locale.ENGLISH) + "` > " + cap); statement = connection.prepareStatement("UPDATE `" + tablePrefix + "skills` SET `"
+ rootSkill.getSkillName().toLowerCase(Locale.ENGLISH) + "` = " + cap + " WHERE `"
+ rootSkill.getSkillName().toLowerCase(Locale.ENGLISH) + "` > " + cap);
statement.executeUpdate(); statement.executeUpdate();
tryClose(statement); tryClose(statement);
} }
@ -1188,13 +1188,13 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
} }
} }
private @Nullable PlayerProfile loadFromResult(String playerName, ResultSet result) throws SQLException { private @Nullable MMOPlayerData loadFromResult(@NotNull String playerName, @NotNull ResultSet result) throws SQLException {
MMODataBuilder MMODataBuilder = new MMODataBuilder(); MMODataBuilder MMODataBuilder = new MMODataBuilder();
EnumMap<PrimarySkillType, Integer> skills = new EnumMap<PrimarySkillType, Integer>(PrimarySkillType.class); // Skill & Level Map<RootSkill, Integer> skills = new HashMap<>(); // Skill & Level
EnumMap<PrimarySkillType, Float> skillsXp = new EnumMap<PrimarySkillType, Float>(PrimarySkillType.class); // Skill & XP Map<RootSkill, Float> skillsXp = new HashMap<>(); // Skill & XP
EnumMap<SuperAbilityType, Integer> skillsDATS = new EnumMap<SuperAbilityType, Integer>(SuperAbilityType.class); // Ability & Cooldown Map<SuperSkill, Integer> skillsDATS = new HashMap<>(); // Ability & Cooldown
EnumMap<UniqueDataType, Integer> uniqueData = new EnumMap<UniqueDataType, Integer>(UniqueDataType.class); //Chimaera wing cooldown and other misc info Map<UniqueDataType, Integer> uniqueData = new EnumMap<UniqueDataType, Integer>(UniqueDataType.class); //Chimaera wing cooldown and other misc info
EnumMap<PrimarySkillType, SkillBossBarState> xpBarStateMap = new EnumMap<PrimarySkillType, SkillBossBarState>(PrimarySkillType.class); Map<RootSkill, SkillBossBarState> xpBarStateMap = new HashMap<RootSkill, SkillBossBarState>();
MobHealthBarType mobHealthbarType; MobHealthBarType mobHealthbarType;
UUID uuid; UUID uuid;
@ -1209,37 +1209,37 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
final int OFFSET_XPBAR = OFFSET_OTHER + otherCount; final int OFFSET_XPBAR = OFFSET_OTHER + otherCount;
final int OFFSET_TOGGLE = OFFSET_XPBAR + allSkills; final int OFFSET_TOGGLE = OFFSET_XPBAR + allSkills;
skills.put(PrimarySkillType.TAMING, result.getInt(OFFSET_SKILLS + 1)); skills.put(CoreSkills.TAMING_CS, result.getInt(OFFSET_SKILLS + 1));
skills.put(PrimarySkillType.MINING, result.getInt(OFFSET_SKILLS + 2)); skills.put(CoreSkills.MINING_CS, result.getInt(OFFSET_SKILLS + 2));
skills.put(CoreSkills.REPAIR_CS, result.getInt(OFFSET_SKILLS + 3)); skills.put(CoreSkills.REPAIR_CS, result.getInt(OFFSET_SKILLS + 3));
skills.put(CoreSkills.WOODCUTTING_CS, result.getInt(OFFSET_SKILLS + 4)); skills.put(CoreSkills.WOODCUTTING_CS, result.getInt(OFFSET_SKILLS + 4));
skills.put(CoreSkills.UNARMED_CS, result.getInt(OFFSET_SKILLS + 5)); skills.put(CoreSkills.UNARMED_CS, result.getInt(OFFSET_SKILLS + 5));
skills.put(PrimarySkillType.HERBALISM, result.getInt(OFFSET_SKILLS + 6)); skills.put(CoreSkills.HERBALISM_CS, result.getInt(OFFSET_SKILLS + 6));
skills.put(PrimarySkillType.EXCAVATION, result.getInt(OFFSET_SKILLS + 7)); skills.put(CoreSkills.EXCAVATION_CS, result.getInt(OFFSET_SKILLS + 7));
skills.put(PrimarySkillType.ARCHERY, result.getInt(OFFSET_SKILLS + 8)); skills.put(CoreSkills.ARCHERY_CS, result.getInt(OFFSET_SKILLS + 8));
skills.put(PrimarySkillType.SWORDS, result.getInt(OFFSET_SKILLS + 9)); skills.put(CoreSkills.SWORDS_CS, result.getInt(OFFSET_SKILLS + 9));
skills.put(CoreSkills.AXES_CS, result.getInt(OFFSET_SKILLS + 10)); skills.put(CoreSkills.AXES_CS, result.getInt(OFFSET_SKILLS + 10));
skills.put(CoreSkills.ACROBATICS_CS, result.getInt(OFFSET_SKILLS + 11)); skills.put(CoreSkills.ACROBATICS_CS, result.getInt(OFFSET_SKILLS + 11));
skills.put(PrimarySkillType.FISHING, result.getInt(OFFSET_SKILLS + 12)); skills.put(CoreSkills.FISHING_CS, result.getInt(OFFSET_SKILLS + 12));
skills.put(CoreSkills.ALCHEMY_CS, result.getInt(OFFSET_SKILLS + 13)); skills.put(CoreSkills.ALCHEMY_CS, result.getInt(OFFSET_SKILLS + 13));
skills.put(PrimarySkillType.TRIDENTS, result.getInt(OFFSET_SKILLS + 14)); skills.put(CoreSkills.TRIDENTS_CS, result.getInt(OFFSET_SKILLS + 14));
skills.put(PrimarySkillType.CROSSBOWS, result.getInt(OFFSET_SKILLS + 15)); skills.put(CoreSkills.CROSSBOWS_CS, result.getInt(OFFSET_SKILLS + 15));
skillsXp.put(PrimarySkillType.TAMING, result.getFloat(OFFSET_EXPERIENCE + 1)); skillsXp.put(CoreSkills.TAMING_CS, result.getFloat(OFFSET_EXPERIENCE + 1));
skillsXp.put(PrimarySkillType.MINING, result.getFloat(OFFSET_EXPERIENCE + 2)); skillsXp.put(CoreSkills.MINING_CS, result.getFloat(OFFSET_EXPERIENCE + 2));
skillsXp.put(CoreSkills.REPAIR_CS, result.getFloat(OFFSET_EXPERIENCE + 3)); skillsXp.put(CoreSkills.REPAIR_CS, result.getFloat(OFFSET_EXPERIENCE + 3));
skillsXp.put(CoreSkills.WOODCUTTING_CS, result.getFloat(OFFSET_EXPERIENCE + 4)); skillsXp.put(CoreSkills.WOODCUTTING_CS, result.getFloat(OFFSET_EXPERIENCE + 4));
skillsXp.put(CoreSkills.UNARMED_CS, result.getFloat(OFFSET_EXPERIENCE + 5)); skillsXp.put(CoreSkills.UNARMED_CS, result.getFloat(OFFSET_EXPERIENCE + 5));
skillsXp.put(PrimarySkillType.HERBALISM, result.getFloat(OFFSET_EXPERIENCE + 6)); skillsXp.put(CoreSkills.HERBALISM_CS, result.getFloat(OFFSET_EXPERIENCE + 6));
skillsXp.put(PrimarySkillType.EXCAVATION, result.getFloat(OFFSET_EXPERIENCE + 7)); skillsXp.put(CoreSkills.EXCAVATION_CS, result.getFloat(OFFSET_EXPERIENCE + 7));
skillsXp.put(PrimarySkillType.ARCHERY, result.getFloat(OFFSET_EXPERIENCE + 8)); skillsXp.put(CoreSkills.ARCHERY_CS, result.getFloat(OFFSET_EXPERIENCE + 8));
skillsXp.put(PrimarySkillType.SWORDS, result.getFloat(OFFSET_EXPERIENCE + 9)); skillsXp.put(CoreSkills.SWORDS_CS, result.getFloat(OFFSET_EXPERIENCE + 9));
skillsXp.put(CoreSkills.AXES_CS, result.getFloat(OFFSET_EXPERIENCE + 10)); skillsXp.put(CoreSkills.AXES_CS, result.getFloat(OFFSET_EXPERIENCE + 10));
skillsXp.put(CoreSkills.ACROBATICS_CS, result.getFloat(OFFSET_EXPERIENCE + 11)); skillsXp.put(CoreSkills.ACROBATICS_CS, result.getFloat(OFFSET_EXPERIENCE + 11));
skillsXp.put(PrimarySkillType.FISHING, result.getFloat(OFFSET_EXPERIENCE + 12)); skillsXp.put(CoreSkills.FISHING_CS, result.getFloat(OFFSET_EXPERIENCE + 12));
skillsXp.put(CoreSkills.ALCHEMY_CS, result.getFloat(OFFSET_EXPERIENCE + 13)); skillsXp.put(CoreSkills.ALCHEMY_CS, result.getFloat(OFFSET_EXPERIENCE + 13));
skillsXp.put(PrimarySkillType.TRIDENTS, result.getFloat(OFFSET_EXPERIENCE + 14)); skillsXp.put(CoreSkills.TRIDENTS_CS, result.getFloat(OFFSET_EXPERIENCE + 14));
skillsXp.put(PrimarySkillType.CROSSBOWS, result.getFloat(OFFSET_EXPERIENCE + 15)); skillsXp.put(CoreSkills.CROSSBOWS_CS, result.getFloat(OFFSET_EXPERIENCE + 15));
// Taming - Unused - result.getInt(OFFSET_COOLDOWNS + 1) // Taming - Unused - result.getInt(OFFSET_COOLDOWNS + 1)
skillsDATS.put(SuperAbilityType.SUPER_BREAKER, result.getInt(OFFSET_COOLDOWNS + 2)); skillsDATS.put(SuperAbilityType.SUPER_BREAKER, result.getInt(OFFSET_COOLDOWNS + 2));
@ -1282,30 +1282,31 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
} }
//XPBAR //XPBAR
xpBarStateMap.put(PrimarySkillType.TAMING, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 1))); xpBarStateMap.put(CoreSkills.TAMING_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 1)));
xpBarStateMap.put(PrimarySkillType.MINING, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 2))); xpBarStateMap.put(CoreSkills.MINING_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 2)));
xpBarStateMap.put(CoreSkills.REPAIR_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 3))); xpBarStateMap.put(CoreSkills.REPAIR_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 3)));
xpBarStateMap.put(CoreSkills.WOODCUTTING_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 4))); xpBarStateMap.put(CoreSkills.WOODCUTTING_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 4)));
xpBarStateMap.put(CoreSkills.UNARMED_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 5))); xpBarStateMap.put(CoreSkills.UNARMED_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 5)));
xpBarStateMap.put(PrimarySkillType.HERBALISM, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 6))); xpBarStateMap.put(CoreSkills.HERBALISM_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 6)));
xpBarStateMap.put(PrimarySkillType.EXCAVATION, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 7))); xpBarStateMap.put(CoreSkills.EXCAVATION_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 7)));
xpBarStateMap.put(PrimarySkillType.ARCHERY, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 8))); xpBarStateMap.put(CoreSkills.ARCHERY_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 8)));
xpBarStateMap.put(PrimarySkillType.SWORDS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 9))); xpBarStateMap.put(CoreSkills.SWORDS_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 9)));
xpBarStateMap.put(CoreSkills.AXES_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 10))); xpBarStateMap.put(CoreSkills.AXES_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 10)));
xpBarStateMap.put(CoreSkills.ACROBATICS_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 11))); xpBarStateMap.put(CoreSkills.ACROBATICS_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 11)));
xpBarStateMap.put(PrimarySkillType.FISHING, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 12))); xpBarStateMap.put(CoreSkills.FISHING_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 12)));
xpBarStateMap.put(CoreSkills.ALCHEMY_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 13))); xpBarStateMap.put(CoreSkills.ALCHEMY_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 13)));
xpBarStateMap.put(PrimarySkillType.SALVAGE, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 14))); xpBarStateMap.put(CoreSkills.SALVAGE_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 14)));
xpBarStateMap.put(PrimarySkillType.SMELTING, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 15))); xpBarStateMap.put(CoreSkills.SMELTING_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 15)));
xpBarStateMap.put(PrimarySkillType.TRIDENTS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 16))); xpBarStateMap.put(CoreSkills.TRIDENTS_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 16)));
xpBarStateMap.put(PrimarySkillType.CROSSBOWS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 17))); xpBarStateMap.put(CoreSkills.CROSSBOWS_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 17)));
//TOGGLE //TOGGLE
boolean chatSpy = result.getBoolean(OFFSET_TOGGLE+1); boolean chatSpy = result.getBoolean(OFFSET_TOGGLE+1);
boolean rankLess = result.getBoolean(OFFSET_TOGGLE+2); boolean rankLess = result.getBoolean(OFFSET_TOGGLE+2);
//Build //Build
MMODataBuilder.setSkillLevelValues(skills) MMODataBuilder mmoDataBuilder = new MMODataBuilder();
mmoDataBuilder.setSkillLevelValues(skills)
.setSkillExperienceValues(skillsXp) .setSkillExperienceValues(skillsXp)
.setAbilityDeactivationTimestamps(skillsDATS) .setAbilityDeactivationTimestamps(skillsDATS)
.setUniquePlayerData(uniqueData) .setUniquePlayerData(uniqueData)
@ -1315,14 +1316,11 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
.setPartyChatSpying(chatSpy) .setPartyChatSpying(chatSpy)
.setLastLogin(0) //TODO: Program this in properly .setLastLogin(0) //TODO: Program this in properly
.setScoreboardTipsShown(scoreboardTipsShown) .setScoreboardTipsShown(scoreboardTipsShown)
.setMobHealthBarType(mobHealthbarType)
.setLeaderBoardExemption(rankLess); .setLeaderBoardExemption(rankLess);
PersistentPlayerData persistentPlayerData;
try { try {
persistentPlayerData = MMODataBuilder.build(); return mmoDataBuilder.build();
return new PlayerProfile(persistentPlayerData);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
@ -1454,11 +1452,11 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
resultSet = statement.executeQuery("SHOW INDEX FROM `" + tablePrefix + "skills` WHERE `Key_name` LIKE 'idx\\_%'"); resultSet = statement.executeQuery("SHOW INDEX FROM `" + tablePrefix + "skills` WHERE `Key_name` LIKE 'idx\\_%'");
resultSet.last(); resultSet.last();
if (resultSet.getRow() != PrimarySkillType.NON_CHILD_SKILLS.size()) { if (resultSet.getRow() != CoreSkills.getNonChildSkills().size()) {
mcMMO.p.getLogger().info("Indexing tables, this may take a while on larger databases"); mcMMO.p.getLogger().info("Indexing tables, this may take a while on larger databases");
for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) { for (RootSkill rootSkill : CoreSkills.getNonChildSkills()) {
String skill_name = skill.name().toLowerCase(Locale.ENGLISH); String skill_name = rootSkill.getSkillName().toLowerCase(Locale.ENGLISH);
try { try {
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "skills` ADD INDEX `idx_" + skill_name + "` (`" + skill_name + "`) USING BTREE"); statement.executeUpdate("ALTER TABLE `" + tablePrefix + "skills` ADD INDEX `idx_" + skill_name + "` (`" + skill_name + "`) USING BTREE");

View File

@ -29,9 +29,6 @@ public class MMODataBuilder {
/* Records */ /* Records */
private long lastLogin; private long lastLogin;
/* HUDs */
private @Nullable MobHealthBarType mobHealthBarType;
/* Skill Data */ /* Skill Data */
private @Nullable Map<RootSkill, Integer> skillLevelValues; private @Nullable Map<RootSkill, Integer> skillLevelValues;
private @Nullable Map<RootSkill, Float> skillExperienceValues; private @Nullable Map<RootSkill, Float> skillExperienceValues;
@ -99,10 +96,6 @@ public class MMODataBuilder {
validateBarStateMapEntries(barStateMap); validateBarStateMapEntries(barStateMap);
if(mobHealthBarType == null)
throw new NullArgumentException("mobHealthBarType");
return new PersistentPlayerData(playerUUID, playerName, partyChatSpying, skillLevelValues, skillExperienceValues, abilityDeactivationTimestamps, uniquePlayerData, barStateMap, scoreboardTipsShown, lastLogin, leaderBoardExemption); return new PersistentPlayerData(playerUUID, playerName, partyChatSpying, skillLevelValues, skillExperienceValues, abilityDeactivationTimestamps, uniquePlayerData, barStateMap, scoreboardTipsShown, lastLogin, leaderBoardExemption);
} }
@ -189,7 +182,7 @@ public class MMODataBuilder {
return skillLevelValues; return skillLevelValues;
} }
public @NotNull MMODataBuilder setSkillLevelValues(@NotNull HashMap<RootSkill, Integer> skillLevelValues) { public @NotNull MMODataBuilder setSkillLevelValues(@NotNull Map<RootSkill, Integer> skillLevelValues) {
this.skillLevelValues = skillLevelValues; this.skillLevelValues = skillLevelValues;
return this; return this;
} }
@ -198,7 +191,7 @@ public class MMODataBuilder {
return skillExperienceValues; return skillExperienceValues;
} }
public @NotNull MMODataBuilder setSkillExperienceValues(@NotNull HashMap<RootSkill, Float> skillExperienceValues) { public @NotNull MMODataBuilder setSkillExperienceValues(@NotNull Map<RootSkill, Float> skillExperienceValues) {
this.skillExperienceValues = skillExperienceValues; this.skillExperienceValues = skillExperienceValues;
return this; return this;
} }
@ -207,7 +200,7 @@ public class MMODataBuilder {
return abilityDeactivationTimestamps; return abilityDeactivationTimestamps;
} }
public @NotNull MMODataBuilder setAbilityDeactivationTimestamps(@NotNull HashMap<SuperSkill, Integer> abilityDeactivationTimestamps) { public @NotNull MMODataBuilder setAbilityDeactivationTimestamps(@NotNull Map<SuperSkill, Integer> abilityDeactivationTimestamps) {
this.abilityDeactivationTimestamps = abilityDeactivationTimestamps; this.abilityDeactivationTimestamps = abilityDeactivationTimestamps;
return this; return this;
} }
@ -216,12 +209,12 @@ public class MMODataBuilder {
return uniquePlayerData; return uniquePlayerData;
} }
public @NotNull MMODataBuilder setUniquePlayerData(@NotNull EnumMap<UniqueDataType, Integer> uniquePlayerData) { public @NotNull MMODataBuilder setUniquePlayerData(@NotNull Map<UniqueDataType, Integer> uniquePlayerData) {
this.uniquePlayerData = uniquePlayerData; this.uniquePlayerData = uniquePlayerData;
return this; return this;
} }
public @Nullable Map<PrimarySkillType, SkillBossBarState> getBarStateMap() { public @Nullable Map<RootSkill, SkillBossBarState> getBarStateMap() {
return barStateMap; return barStateMap;
} }

View File

@ -5,8 +5,10 @@ import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.neetgames.mcmmo.MobHealthBarType; import com.neetgames.mcmmo.MobHealthBarType;
import com.neetgames.mcmmo.UniqueDataType; import com.neetgames.mcmmo.UniqueDataType;
import com.neetgames.mcmmo.player.MMOPlayerData;
import com.neetgames.mcmmo.skill.RootSkill; import com.neetgames.mcmmo.skill.RootSkill;
import com.neetgames.mcmmo.skill.SkillBossBarState; import com.neetgames.mcmmo.skill.SkillBossBarState;
import com.neetgames.mcmmo.skill.SuperSkill;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.UUID; import java.util.UUID;
@ -17,43 +19,38 @@ public class MMODataSnapshot {
private final @NotNull UUID playerUUID; private final @NotNull UUID playerUUID;
/* Records */ /* Records */
private final @NotNull Long lastLogin; private final long lastLogin;
/* HUDs */
private final @NotNull MobHealthBarType mobHealthBarType;
/* Skill Data */ /* Skill Data */
private final @NotNull ImmutableMap<RootSkill, Integer> skillLevelValues; private final @NotNull ImmutableMap<RootSkill, Integer> skillLevelValues;
private final @NotNull ImmutableMap<RootSkill, Float> skillExperienceValues; private final @NotNull ImmutableMap<RootSkill, Float> skillExperienceValues;
private final @NotNull ImmutableMap<SuperAbilityType, Integer> abilityDeactivationTimestamps; // Ability & Cooldown private final @NotNull ImmutableMap<SuperSkill, Integer> abilityDeactivationTimestamps; // Ability & Cooldown
private final @NotNull ImmutableMap<UniqueDataType, Integer> uniquePlayerData; //Misc data that doesn't fit into other categories (chimaera wing, etc..) private final @NotNull ImmutableMap<UniqueDataType, Integer> uniquePlayerData; //Misc data that doesn't fit into other categories (chimaera wing, etc..)
private final @NotNull ImmutableMap<PrimarySkillType, SkillBossBarState> barStateMap; private final @NotNull ImmutableMap<RootSkill, SkillBossBarState> barStateMap;
/* Special Flags */ /* Special Flags */
private final @NotNull Boolean partyChatSpying; private final boolean partyChatSpying;
private final @NotNull Boolean leaderBoardExclusion; private final boolean leaderBoardExclusion;
/* Scoreboards */ /* Scoreboards */
private final @NotNull Integer scoreboardTipsShown; private final int scoreboardTipsShown;
public MMODataSnapshot(@NotNull PersistentPlayerData persistentPlayerData) { public MMODataSnapshot(@NotNull MMOPlayerData mmoPlayerData) {
playerName = persistentPlayerData.getPlayerName(); playerName = mmoPlayerData.getPlayerName();
playerUUID = persistentPlayerData.getPlayerUUID(); playerUUID = mmoPlayerData.getPlayerUUID();
lastLogin = persistentPlayerData.getLastLogin(); lastLogin = mmoPlayerData.getLastLogin();
mobHealthBarType = persistentPlayerData.getMobHealthBarType(); skillLevelValues = ImmutableMap.copyOf(mmoPlayerData.getSkillLevelsMap());
skillExperienceValues = ImmutableMap.copyOf(mmoPlayerData.getSkillsExperienceMap());
abilityDeactivationTimestamps = ImmutableMap.copyOf(mmoPlayerData.getAbilityDeactivationTimestamps());
uniquePlayerData = ImmutableMap.copyOf(mmoPlayerData.getUniquePlayerData());
barStateMap = ImmutableMap.copyOf(mmoPlayerData.getBarStateMap());
skillLevelValues = ImmutableMap.copyOf(persistentPlayerData.getSkillLevelsMap()); partyChatSpying = mmoPlayerData.isPartyChatSpying();
skillExperienceValues = ImmutableMap.copyOf(persistentPlayerData.getSkillsExperienceMap()); leaderBoardExclusion = mmoPlayerData.isLeaderBoardExcluded();
abilityDeactivationTimestamps = ImmutableMap.copyOf(persistentPlayerData.getAbilityDeactivationTimestamps());
uniquePlayerData = ImmutableMap.copyOf(persistentPlayerData.getUniquePlayerData());
barStateMap = ImmutableMap.copyOf(persistentPlayerData.getBarStateMap());
partyChatSpying = persistentPlayerData.isPartyChatSpying(); scoreboardTipsShown = mmoPlayerData.getScoreboardTipsShown();
leaderBoardExclusion = persistentPlayerData.isLeaderBoardExcluded();
scoreboardTipsShown = persistentPlayerData.getScoreboardTipsShown();
} }
public @NotNull String getPlayerName() { public @NotNull String getPlayerName() {
@ -68,9 +65,6 @@ public class MMODataSnapshot {
return lastLogin; return lastLogin;
} }
public @NotNull MobHealthBarType getMobHealthBarType() {
return mobHealthBarType;
}
public @NotNull ImmutableMap<RootSkill, Integer> getSkillLevelValues() { public @NotNull ImmutableMap<RootSkill, Integer> getSkillLevelValues() {
return skillLevelValues; return skillLevelValues;
@ -80,7 +74,7 @@ public class MMODataSnapshot {
return skillExperienceValues; return skillExperienceValues;
} }
public @NotNull ImmutableMap<SuperAbilityType, Integer> getAbilityDeactivationTimestamps() { public @NotNull ImmutableMap<SuperSkill, Integer> getAbilityDeactivationTimestamps() {
return abilityDeactivationTimestamps; return abilityDeactivationTimestamps;
} }
@ -100,15 +94,15 @@ public class MMODataSnapshot {
return scoreboardTipsShown; return scoreboardTipsShown;
} }
public int getSkillLevel(@NotNull PrimarySkillType primarySkillType) { public int getSkillLevel(@NotNull RootSkill rootSkill) {
return skillLevelValues.getOrDefault(primarySkillType, 0); return skillLevelValues.getOrDefault(rootSkill, 0);
} }
public int getSkillXpLevel(@NotNull PrimarySkillType primarySkillType) { public int getSkillXpLevel(@NotNull RootSkill rootSkill) {
return (skillExperienceValues.getOrDefault(primarySkillType, 0F)).intValue(); return (skillExperienceValues.getOrDefault(rootSkill, 0F)).intValue();
} }
public long getAbilityDATS(@NotNull SuperAbilityType superAbilityType) { public long getAbilityDATS(@NotNull SuperSkill superAbilityType) {
return abilityDeactivationTimestamps.getOrDefault(superAbilityType, 0); return abilityDeactivationTimestamps.getOrDefault(superAbilityType, 0);
} }

View File

@ -1,30 +1,30 @@
package com.gmail.nossr50.datatypes.skills; package com.gmail.nossr50.datatypes.skills;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.neetgames.mcmmo.exceptions.InvalidSkillException;
import com.neetgames.mcmmo.skill.RootSkill; import com.neetgames.mcmmo.skill.RootSkill;
import com.neetgames.mcmmo.skill.Skill;
import com.neetgames.mcmmo.skill.SkillIdentity; import com.neetgames.mcmmo.skill.SkillIdentity;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
public class CoreSkills { public class CoreSkills {
private static final @NotNull ImmutableSet<RootSkill> CORE_ROOT_SKILLS_IMMUTABLE_SET; private static final @NotNull ImmutableSet<RootSkill> CORE_ROOT_SKILLS;
private static final @NotNull ImmutableSet<RootSkill> CORE_CHILD_SKILLS; private static final @NotNull ImmutableSet<RootSkill> CORE_CHILD_SKILLS;
private static final @NotNull ImmutableSet<RootSkill> CORE_NON_CHILD_SKILLS;
public static final @NotNull CoreRootSkill ACROBATICS_CS, ALCHEMY_CS, ARCHERY_CS, AXES_CS, EXCAVATION_CS, public static final @NotNull CoreRootSkill ACROBATICS_CS, ALCHEMY_CS, ARCHERY_CS, AXES_CS, EXCAVATION_CS,
FISHING_CS, HERBALISM_CS, MINING_CS, REPAIR_CS, SALVAGE_CS, SMELTING_CS, SWORDS_CS, TAMING_CS, UNARMED_CS, FISHING_CS, HERBALISM_CS, MINING_CS, REPAIR_CS, SALVAGE_CS, SMELTING_CS, SWORDS_CS, TAMING_CS, UNARMED_CS,
WOODCUTTING_CS, TRIDENTS_CS, CROSSBOWS_CS; WOODCUTTING_CS, TRIDENTS_CS, CROSSBOWS_CS;
public static final @NotNull SkillIdentity ACROBATICS_ID, ALCHEMY_ID, ARCHERY_ID, AXES_ID, EXCAVATION_ID, public static final @NotNull SkillIdentity ACROBATICS_ID, ALCHEMY_ID, ARCHERY_ID, AXES_ID, EXCAVATION_ID,
FISHING_ID, HERBALISM_ID, MINING_ID, REPAIR_ID, SALVAGE_ID, SMELTING_ID, SWORDS_ID, TAMING_ID, UNARMED_ID, FISHING_ID, HERBALISM_ID, MINING_ID, REPAIR_ID, SALVAGE_ID, SMELTING_ID, SWORDS_ID, TAMING_ID, UNARMED_ID,
WOODCUTTING_ID, TRIDENTS_ID, CROSSBOWS_ID; WOODCUTTING_ID, TRIDENTS_ID, CROSSBOWS_ID;
private static @NotNull private static @NotNull
final HackySkillMappings hackySkillMappings = new HackySkillMappings(); final HackySkillMappings hackySkillMappings = new HackySkillMappings();
@ -106,8 +106,9 @@ public class CoreSkills {
rootSkillSet.add(TRIDENTS_CS); rootSkillSet.add(TRIDENTS_CS);
rootSkillSet.add(CROSSBOWS_CS); rootSkillSet.add(CROSSBOWS_CS);
CORE_ROOT_SKILLS_IMMUTABLE_SET = ImmutableSet.copyOf(rootSkillSet); CORE_ROOT_SKILLS = ImmutableSet.copyOf(rootSkillSet);
CORE_CHILD_SKILLS = ImmutableSet.copyOf(childSkillSet); CORE_CHILD_SKILLS = ImmutableSet.copyOf(childSkillSet);
CORE_NON_CHILD_SKILLS = ImmutableSet.copyOf(generateNonChildSkillSet());
} }
/** /**
@ -117,7 +118,7 @@ public class CoreSkills {
* @return a set of all root skills built into mcMMO * @return a set of all root skills built into mcMMO
*/ */
public static @NotNull Set<RootSkill> getImmutableCoreRootSkillSet() { public static @NotNull Set<RootSkill> getImmutableCoreRootSkillSet() {
return CORE_ROOT_SKILLS_IMMUTABLE_SET; return CORE_ROOT_SKILLS;
} }
/** /**
@ -159,6 +160,15 @@ public class CoreSkills {
return hackySkillMappings.rootToPrimaryMap.get(rootSkill); return hackySkillMappings.rootToPrimaryMap.get(rootSkill);
} }
@Deprecated
private static @NotNull Set<RootSkill> generateNonChildSkillSet() {
return getImmutableCoreRootSkillSet().stream().filter((x) -> !isChildSkill(x)).collect(Collectors.toSet());
}
public static @NotNull Set<RootSkill> getNonChildSkills() {
return CORE_NON_CHILD_SKILLS;
}
protected static class HackySkillMappings { protected static class HackySkillMappings {
@NotNull Map<PrimarySkillType, RootSkill> primaryToRootMap = new HashMap<>(); @NotNull Map<PrimarySkillType, RootSkill> primaryToRootMap = new HashMap<>();
@NotNull Map<RootSkill, PrimarySkillType> rootToPrimaryMap = new HashMap<>(); @NotNull Map<RootSkill, PrimarySkillType> rootToPrimaryMap = new HashMap<>();

View File

@ -1,8 +1,8 @@
package com.gmail.nossr50.runnables.commands; package com.gmail.nossr50.runnables.commands;
import com.gmail.nossr50.datatypes.database.PlayerStat; import com.gmail.nossr50.datatypes.database.PlayerStat;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.neetgames.mcmmo.skill.RootSkill;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -12,11 +12,11 @@ import java.util.List;
public class MctopCommandAsyncTask extends BukkitRunnable { public class MctopCommandAsyncTask extends BukkitRunnable {
private final CommandSender sender; private final CommandSender sender;
private final PrimarySkillType skill; private final RootSkill rootSkill;
private final int page; private final int page;
private final boolean useBoard, useChat; private final boolean useBoard, useChat;
public MctopCommandAsyncTask(int page, PrimarySkillType skill, CommandSender sender, boolean useBoard, boolean useChat) { public MctopCommandAsyncTask(int page, RootSkill rootSkill, CommandSender sender, boolean useBoard, boolean useChat) {
Validate.isTrue(useBoard || useChat, "Attempted to start a rank retrieval with both board and chat off"); Validate.isTrue(useBoard || useChat, "Attempted to start a rank retrieval with both board and chat off");
Validate.notNull(sender, "Attempted to start a rank retrieval with no recipient"); Validate.notNull(sender, "Attempted to start a rank retrieval with no recipient");
@ -25,7 +25,7 @@ public class MctopCommandAsyncTask extends BukkitRunnable {
} }
this.page = page; this.page = page;
this.skill = skill; this.rootSkill = rootSkill;
this.sender = sender; this.sender = sender;
this.useBoard = useBoard; this.useBoard = useBoard;
this.useChat = useChat; this.useChat = useChat;
@ -33,8 +33,8 @@ public class MctopCommandAsyncTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
final List<PlayerStat> userStats = mcMMO.getDatabaseManager().readLeaderboard(skill, page, 10); final List<PlayerStat> userStats = mcMMO.getDatabaseManager().readLeaderboard(rootSkill, page, 10);
new MctopCommandDisplayTask(userStats, page, skill, sender, useBoard, useChat).runTaskLater(mcMMO.p, 1); new MctopCommandDisplayTask(userStats, page, rootSkill, sender, useBoard, useChat).runTaskLater(mcMMO.p, 1);
} }
} }

View File

@ -116,8 +116,8 @@ public final class UserManager {
return entity != null && entity.hasMetadata(mcMMO.playerDataKey); return entity != null && entity.hasMetadata(mcMMO.playerDataKey);
} }
public @NotNull MMODataSnapshot createPlayerDataSnapshot(@NotNull MMODataSnapshot mmoDataSnapshot) { public @NotNull MMODataSnapshot createPlayerDataSnapshot(@NotNull MMOPlayerData mmoPlayerData) {
return new MMODataSnapshot(mmoDataSnapshot); return new MMODataSnapshot(mmoPlayerData);
} }
public void saveUserImmediately(@NotNull MMOPlayerData mmoPlayerData, boolean useSync) { public void saveUserImmediately(@NotNull MMOPlayerData mmoPlayerData, boolean useSync) {