From 25f7dd223d6a70d1d9b6f402961c85c7652380c6 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 23 Dec 2020 12:00:05 -0800 Subject: [PATCH] More API migration on the DB impl --- .../nossr50/database/DatabaseManager.java | 7 +- .../database/FlatFileDatabaseManager.java | 153 +++++++------- .../nossr50/database/SQLDatabaseManager.java | 200 +++++++++--------- .../datatypes/player/MMODataBuilder.java | 17 +- .../datatypes/player/MMODataSnapshot.java | 58 +++-- .../nossr50/datatypes/skills/CoreSkills.java | 30 ++- .../commands/MctopCommandAsyncTask.java | 12 +- .../nossr50/util/player/UserManager.java | 4 +- 8 files changed, 243 insertions(+), 238 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/database/DatabaseManager.java b/src/main/java/com/gmail/nossr50/database/DatabaseManager.java index a4b883c36..e9fb27a74 100644 --- a/src/main/java/com/gmail/nossr50/database/DatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/DatabaseManager.java @@ -9,6 +9,7 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.neetgames.mcmmo.exceptions.InvalidSkillException; import com.neetgames.mcmmo.exceptions.ProfileRetrievalException; import com.neetgames.mcmmo.player.MMOPlayerData; +import com.neetgames.mcmmo.skill.RootSkill; import org.apache.commons.lang.NullArgumentException; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -61,12 +62,12 @@ public interface DatabaseManager { * Retrieve leaderboard info. * 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 statsPerPage The number of stats per page * @return the requested leaderboard information */ - @NotNull List readLeaderboard(@Nullable PrimarySkillType skill, int pageNumber, int statsPerPage) throws InvalidSkillException; + @NotNull List readLeaderboard(@NotNull RootSkill rootSkill, int pageNumber, int statsPerPage) throws InvalidSkillException; /** * 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 * @return the requested rank information */ - @NotNull Map readRank(@NotNull String playerName); + @NotNull Map readRank(@NotNull String playerName); /** * Add a new user to the database. diff --git a/src/main/java/com/gmail/nossr50/database/FlatFileDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/FlatFileDatabaseManager.java index 875ca8bfd..064318651 100644 --- a/src/main/java/com/gmail/nossr50/database/FlatFileDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/FlatFileDatabaseManager.java @@ -35,7 +35,7 @@ import java.util.*; public final class FlatFileDatabaseManager extends AbstractDatabaseManager { public static final String FLATFILE_SPLIT_CHARACTER_REGEX = ":"; - private final HashMap> playerStatHash = new HashMap<>(); + private final HashMap> playerStatHash = new HashMap<>(); private final List powerLevels = new ArrayList<>(); private long lastUpdate = 0; @@ -200,7 +200,7 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { 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 boolean worked = false; @@ -342,23 +342,23 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { writer.append(primarySkillExperienceValueMap.get(CoreSkills.WOODCUTTING_CS)).append(":"); writer.append(primarySkillLevelMap.get(CoreSkills.REPAIR_CS)).append(":"); writer.append(primarySkillLevelMap.get(CoreSkills.UNARMED_CS)).append(":"); - writer.append(primarySkillLevelMap.get(PrimarySkillType.HERBALISM)).append(":"); - writer.append(primarySkillLevelMap.get(PrimarySkillType.EXCAVATION)).append(":"); + writer.append(primarySkillLevelMap.get(CoreSkills.HERBALISM_CS)).append(":"); + writer.append(primarySkillLevelMap.get(CoreSkills.EXCAVATION_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.ACROBATICS_CS)).append(":"); writer.append(primarySkillExperienceValueMap.get(CoreSkills.REPAIR_CS)).append(":"); writer.append(primarySkillExperienceValueMap.get(CoreSkills.UNARMED_CS)).append(":"); - writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.HERBALISM)).append(":"); - writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.EXCAVATION)).append(":"); + writer.append(primarySkillExperienceValueMap.get(CoreSkills.HERBALISM_CS)).append(":"); + writer.append(primarySkillExperienceValueMap.get(CoreSkills.EXCAVATION_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.ACROBATICS_CS)).append(":"); writer.append(":"); - writer.append(primarySkillLevelMap.get(PrimarySkillType.TAMING)).append(":"); - writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.TAMING)).append(":"); + writer.append(primarySkillLevelMap.get(CoreSkills.TAMING_CS)).append(":"); + writer.append(primarySkillExperienceValueMap.get(CoreSkills.TAMING_CS)).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.TREE_FELLER)).append(":"); @@ -405,29 +405,29 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { public static int BARSTATE_CROSSBOWS = 64; */ - writer.append(primarySkillLevelMap.get(PrimarySkillType.TRIDENTS)).append(":"); - writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.TRIDENTS)).append(":"); - writer.append(primarySkillLevelMap.get(PrimarySkillType.CROSSBOWS)).append(":"); - writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.CROSSBOWS)).append(":"); + writer.append(primarySkillLevelMap.get(CoreSkills.TRIDENTS_CS)).append(":"); + writer.append(primarySkillExperienceValueMap.get(CoreSkills.TRIDENTS_CS)).append(":"); + writer.append(primarySkillLevelMap.get(CoreSkills.CROSSBOWS_CS)).append(":"); + writer.append(primarySkillExperienceValueMap.get(CoreSkills.CROSSBOWS_CS)).append(":"); //XPBar States 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.ARCHERY_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(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.REPAIR_CS).toString()).append(":"); - writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.SALVAGE).toString()).append(":"); - writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.SMELTING).toString()).append(":"); - writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.SWORDS).toString()).append(":"); - writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.TAMING).toString()).append(":"); + writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.SALVAGE_CS).toString()).append(":"); + writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.SMELTING_CS).toString()).append(":"); + writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.SWORDS_CS).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.WOODCUTTING_CS).toString()).append(":"); - writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.TRIDENTS).toString()).append(":"); - writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.CROSSBOWS).toString()).append(":"); + writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.TRIDENTS_CS).toString()).append(":"); + writer.append(mmoDataSnapshot.getBarStateMap().get(CoreSkills.CROSSBOWS_CS).toString()).append(":"); writer.append(0).append(":"); //archery 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"); } - public @NotNull List readLeaderboard(@NotNull PrimarySkillType skill, int pageNumber, int statsPerPage) { + @Override + public @NotNull List readLeaderboard(@NotNull RootSkill skill, int pageNumber, int statsPerPage) { updateLeaderboards(); List statsList = skill == null ? powerLevels : playerStatHash.get(skill); 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())); } - public @NotNull Map readRank(@NotNull String playerName) { + @Override + public @NotNull Map readRank(@NotNull String playerName) { updateLeaderboards(); - Map skills = new HashMap<>(); + Map skills = new HashMap<>(); - for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) { - skills.put(skill, getPlayerRank(playerName, playerStatHash.get(skill))); + for (RootSkill rootSkill : CoreSkills.getImmutableCoreRootSkillSet()) { + if(CoreSkills.isChildSkill(rootSkill)) + continue; + + skills.put(rootSkill, getPlayerRank(playerName, playerStatHash.get(rootSkill))); } skills.put(null, getPlayerRank(playerName, powerLevels)); @@ -460,6 +465,7 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { return skills; } + @Override public void insertNewUser(@NotNull String playerName, @NotNull UUID uuid) { BufferedWriter out = null; synchronized (fileWritingLock) { @@ -700,12 +706,11 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { String[] stringDataSplit = line.split(":"); try { - PlayerProfile playerProfile = loadFromLine(stringDataSplit); - if(playerProfile == null) + MMOPlayerData mmoPlayerData = loadFromLine(stringDataSplit); + if(mmoPlayerData == null) continue; - PersistentPlayerData persistentPlayerData = playerProfile.getPersistentPlayerData(); - destination.saveUser(mcMMO.getUserManager().createPlayerDataSnapshot(persistentPlayerData)); + destination.saveUser(mcMMO.getUserManager().createPlayerDataSnapshot(mmoPlayerData)); } catch (Exception e) { e.printStackTrace(); @@ -804,23 +809,23 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { playerName = data[FlatFileMappings.USERNAME]; int powerLevel = 0; - Map skills = getSkillMapFromLine(data); + Map skills = getSkillMapFromLine(data); powerLevel += putStat(acrobatics, playerName, skills.get(CoreSkills.ACROBATICS_CS)); powerLevel += putStat(alchemy, playerName, skills.get(CoreSkills.ALCHEMY_CS)); powerLevel += putStat(archery, playerName, skills.get(CoreSkills.ARCHERY_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(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(repair, playerName, skills.get(CoreSkills.REPAIR_CS)); - powerLevel += putStat(swords, playerName, skills.get(PrimarySkillType.SWORDS)); - powerLevel += putStat(taming, playerName, skills.get(PrimarySkillType.TAMING)); + powerLevel += putStat(swords, playerName, skills.get(CoreSkills.SWORDS_CS)); + powerLevel += putStat(taming, playerName, skills.get(CoreSkills.TAMING_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(PrimarySkillType.CROSSBOWS)); - powerLevel += putStat(woodcutting, playerName, skills.get(PrimarySkillType.TRIDENTS)); + powerLevel += putStat(woodcutting, playerName, skills.get(CoreSkills.CROSSBOWS_CS)); + powerLevel += putStat(woodcutting, playerName, skills.get(CoreSkills.TRIDENTS_CS)); putStat(powerLevels, playerName, powerLevel); } @@ -861,13 +866,13 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { playerStatHash.put(CoreSkills.WOODCUTTING_CS, woodcutting); playerStatHash.put(CoreSkills.REPAIR_CS, repair); playerStatHash.put(CoreSkills.UNARMED_CS, unarmed); - playerStatHash.put(PrimarySkillType.HERBALISM, herbalism); - playerStatHash.put(PrimarySkillType.EXCAVATION, excavation); + playerStatHash.put(CoreSkills.HERBALISM_CS, herbalism); + playerStatHash.put(CoreSkills.EXCAVATION_CS, excavation); 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.ACROBATICS_CS, acrobatics); - playerStatHash.put(PrimarySkillType.TAMING, taming); + playerStatHash.put(CoreSkills.TAMING_CS, taming); playerStatHash.put(CoreSkills.FISHING_CS, fishing); 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 if (Config.getInstance().getTruncateSkills()) { - for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) { - int index = getSkillIndex(skill); + for (RootSkill rootSkill : CoreSkills.getImmutableCoreRootSkillSet()) { + if(CoreSkills.isChildSkill(rootSkill)) + continue; + + int index = getSkillIndex(rootSkill); if (index >= stringDataArray.length) { continue; } - int cap = Config.getInstance().getLevelCap(skill); + int cap = Config.getInstance().getLevelCap(rootSkill); 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 + ""; updated = true; } @@ -1167,10 +1175,10 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { updated |= oldVersion != null; if (Config.getInstance().getTruncateSkills()) { - Map skills = getSkillMapFromLine(stringDataArray); - for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) { - int cap = Config.getInstance().getLevelCap(skill); - if (skills.get(skill) > cap) { + Map skillsMap = getSkillMapFromLine(stringDataArray); + for (RootSkill rootSkill : CoreSkills.getNonChildSkills()) { + int cap = Config.getInstance().getLevelCap(rootSkill); + if (skillsMap.get(rootSkill) > cap) { updated = true; } } @@ -1272,29 +1280,28 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { private @Nullable MMOPlayerData loadFromLine(@NotNull String[] dataStrSplit) { MMODataBuilder playerDataBuilder = new MMODataBuilder(); - HashMap skillLevelMap = getSkillMapFromLine(dataStrSplit); // Skill levels - HashMap skillExperienceValueMap = new EnumMap(PrimarySkillType.class); // Skill & XP - HashMap skillAbilityDeactivationTimeStamp = new EnumMap(SuperAbilityType.class); // Ability & Cooldown - EnumMap uniquePlayerDataMap = new EnumMap(UniqueDataType.class); - HashMap xpBarStateMap = new EnumMap(PrimarySkillType.class); -// MobHealthBarType mobHealthbarType; + Map skillLevelMap = getSkillMapFromLine(dataStrSplit); // Skill levels + Map skillExperienceValueMap = new HashMap<>(); // Skill & XP + Map skillAbilityDeactivationTimeStamp = new HashMap<>(); // Ability & Cooldown + Map uniquePlayerDataMap = new EnumMap(UniqueDataType.class); + Map xpBarStateMap = new HashMap<>(); 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.REPAIR_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_REPAIR])); 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(PrimarySkillType.HERBALISM, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_HERBALISM])); - skillExperienceValueMap.put(PrimarySkillType.EXCAVATION, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_EXCAVATION])); + skillExperienceValueMap.put(CoreSkills.HERBALISM_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_HERBALISM])); + 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(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.ACROBATICS_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_ACROBATICS])); 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(PrimarySkillType.TRIDENTS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_TRIDENTS])); - skillExperienceValueMap.put(PrimarySkillType.CROSSBOWS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_CROSSBOWS])); + skillExperienceValueMap.put(CoreSkills.TRIDENTS_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_TRIDENTS])); + skillExperienceValueMap.put(CoreSkills.CROSSBOWS_CS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_CROSSBOWS])); //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.ARCHERY_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_ARCHERY])); 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(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.REPAIR_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_REPAIR])); - xpBarStateMap.put(PrimarySkillType.SALVAGE, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_SALVAGE])); - xpBarStateMap.put(PrimarySkillType.SMELTING, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_SMELTING])); - xpBarStateMap.put(PrimarySkillType.SWORDS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_SWORDS])); - xpBarStateMap.put(PrimarySkillType.TAMING, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_TAMING])); + xpBarStateMap.put(CoreSkills.SALVAGE_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_SALVAGE])); + xpBarStateMap.put(CoreSkills.SMELTING_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_SMELTING])); + xpBarStateMap.put(CoreSkills.SWORDS_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_SWORDS])); + 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.WOODCUTTING_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_WOODCUTTING])); - xpBarStateMap.put(PrimarySkillType.TRIDENTS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_TRIDENTS])); - xpBarStateMap.put(PrimarySkillType.CROSSBOWS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_CROSSBOWS])); + xpBarStateMap.put(CoreSkills.TRIDENTS_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_TRIDENTS])); + xpBarStateMap.put(CoreSkills.CROSSBOWS_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_CROSSBOWS])); } catch (Exception e) { 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.AXES_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_AXES])); 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.TRIDENTS_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_TRIDENTS])); skillLevelsMap.put(CoreSkills.CROSSBOWS_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_CROSSBOWS])); @@ -1419,7 +1426,9 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { return DatabaseType.FLATFILE; } - private int getSkillIndex(PrimarySkillType primarySkillType) { + private int getSkillIndex(@NotNull RootSkill rootSkill) { + PrimarySkillType primarySkillType = CoreSkills.getSkill(rootSkill); + switch (primarySkillType) { case ACROBATICS: return FlatFileMappings.SKILLS_ACROBATICS; diff --git a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java index e4b69d007..13ccf9175 100644 --- a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java @@ -16,7 +16,10 @@ import com.neetgames.mcmmo.MobHealthBarType; import com.neetgames.mcmmo.UniqueDataType; import com.neetgames.mcmmo.exceptions.InvalidSkillException; 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.SuperSkill; import org.apache.commons.lang.NullArgumentException; import org.apache.tomcat.jdbc.pool.DataSource; 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."); } - public boolean removeUser(String playerName, @Nullable UUID uuid) { + public boolean removeUser(@NotNull String playerName, @Nullable UUID uuid) { boolean success = false; Connection connection = null; PreparedStatement statement = null; @@ -257,24 +260,24 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { + ", unarmed = ?, herbalism = ?, excavation = ?" + ", archery = ?, swords = ?, axes = ?, acrobatics = ?" + ", fishing = ?, alchemy = ?, tridents = ?, crossbows = ?, total = ? WHERE user_id = ?"); - statement.setInt(1, dataSnapshot.getSkillLevel(PrimarySkillType.TAMING)); - statement.setInt(2, dataSnapshot.getSkillLevel(PrimarySkillType.MINING)); + statement.setInt(1, dataSnapshot.getSkillLevel(CoreSkills.TAMING_CS)); + statement.setInt(2, dataSnapshot.getSkillLevel(CoreSkills.MINING_CS)); statement.setInt(3, dataSnapshot.getSkillLevel(CoreSkills.REPAIR_CS)); statement.setInt(4, dataSnapshot.getSkillLevel(CoreSkills.WOODCUTTING_CS)); statement.setInt(5, dataSnapshot.getSkillLevel(CoreSkills.UNARMED_CS)); - statement.setInt(6, dataSnapshot.getSkillLevel(PrimarySkillType.HERBALISM)); - statement.setInt(7, dataSnapshot.getSkillLevel(PrimarySkillType.EXCAVATION)); - statement.setInt(8, dataSnapshot.getSkillLevel(PrimarySkillType.ARCHERY)); - statement.setInt(9, dataSnapshot.getSkillLevel(PrimarySkillType.SWORDS)); + statement.setInt(6, dataSnapshot.getSkillLevel(CoreSkills.HERBALISM_CS)); + statement.setInt(7, dataSnapshot.getSkillLevel(CoreSkills.EXCAVATION_CS)); + statement.setInt(8, dataSnapshot.getSkillLevel(CoreSkills.ARCHERY_CS)); + statement.setInt(9, dataSnapshot.getSkillLevel(CoreSkills.SWORDS_CS)); statement.setInt(10, dataSnapshot.getSkillLevel(CoreSkills.AXES_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(14, dataSnapshot.getSkillLevel(PrimarySkillType.TRIDENTS)); - statement.setInt(15, dataSnapshot.getSkillLevel(PrimarySkillType.CROSSBOWS)); + statement.setInt(14, dataSnapshot.getSkillLevel(CoreSkills.TRIDENTS_CS)); + statement.setInt(15, dataSnapshot.getSkillLevel(CoreSkills.CROSSBOWS_CS)); int total = 0; - for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) - total += dataSnapshot.getSkillLevel(primarySkillType); + for (RootSkill rootSkill : CoreSkills.getNonChildSkills()) + total += dataSnapshot.getSkillLevel(rootSkill); statement.setInt(16, total); statement.setInt(17, id); success &= (statement.executeUpdate() != 0); @@ -289,21 +292,21 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { + ", unarmed = ?, herbalism = ?, excavation = ?" + ", archery = ?, swords = ?, axes = ?, acrobatics = ?" + ", fishing = ?, alchemy = ?, tridents = ?, crossbows = ?, WHERE user_id = ?"); - statement.setInt(1, dataSnapshot.getSkillXpLevel(PrimarySkillType.TAMING)); - statement.setInt(2, dataSnapshot.getSkillXpLevel(PrimarySkillType.MINING)); + statement.setInt(1, dataSnapshot.getSkillXpLevel(CoreSkills.TAMING_CS)); + statement.setInt(2, dataSnapshot.getSkillXpLevel(CoreSkills.MINING_CS)); statement.setInt(3, dataSnapshot.getSkillXpLevel(CoreSkills.REPAIR_CS)); statement.setInt(4, dataSnapshot.getSkillXpLevel(CoreSkills.WOODCUTTING_CS)); statement.setInt(5, dataSnapshot.getSkillXpLevel(CoreSkills.UNARMED_CS)); - statement.setInt(6, dataSnapshot.getSkillXpLevel(PrimarySkillType.HERBALISM)); - statement.setInt(7, dataSnapshot.getSkillXpLevel(PrimarySkillType.EXCAVATION)); - statement.setInt(8, dataSnapshot.getSkillXpLevel(PrimarySkillType.ARCHERY)); - statement.setInt(9, dataSnapshot.getSkillXpLevel(PrimarySkillType.SWORDS)); + statement.setInt(6, dataSnapshot.getSkillXpLevel(CoreSkills.HERBALISM_CS)); + statement.setInt(7, dataSnapshot.getSkillXpLevel(CoreSkills.EXCAVATION_CS)); + statement.setInt(8, dataSnapshot.getSkillXpLevel(CoreSkills.ARCHERY_CS)); + statement.setInt(9, dataSnapshot.getSkillXpLevel(CoreSkills.SWORDS_CS)); statement.setInt(10, dataSnapshot.getSkillXpLevel(CoreSkills.AXES_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(14, dataSnapshot.getSkillXpLevel(PrimarySkillType.TRIDENTS)); - statement.setInt(15, dataSnapshot.getSkillXpLevel(PrimarySkillType.CROSSBOWS)); + statement.setInt(14, dataSnapshot.getSkillXpLevel(CoreSkills.TRIDENTS_CS)); + statement.setInt(15, dataSnapshot.getSkillXpLevel(CoreSkills.CROSSBOWS_CS)); statement.setInt(16, id); success &= (statement.executeUpdate() != 0); 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.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(3, id); success = (statement.executeUpdate() != 0); @@ -354,23 +357,23 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { + ", view_unarmed = ?, view_herbalism = ?, view_excavation = ?" + ", view_archery = ?, view_swords = ?, view_axes = ?, view_acrobatics = ?" + ", 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(2, dataSnapshot.getBarStateMap().get(PrimarySkillType.MINING).toString()); + statement.setString(1, dataSnapshot.getBarStateMap().get(CoreSkills.TAMING_CS).toString()); + statement.setString(2, dataSnapshot.getBarStateMap().get(CoreSkills.MINING_CS).toString()); statement.setString(3, dataSnapshot.getBarStateMap().get(CoreSkills.REPAIR_CS).toString()); statement.setString(4, dataSnapshot.getBarStateMap().get(CoreSkills.WOODCUTTING_CS).toString()); statement.setString(5, dataSnapshot.getBarStateMap().get(CoreSkills.UNARMED_CS).toString()); - statement.setString(6, dataSnapshot.getBarStateMap().get(PrimarySkillType.HERBALISM).toString()); - statement.setString(7, dataSnapshot.getBarStateMap().get(PrimarySkillType.EXCAVATION).toString()); - statement.setString(8, dataSnapshot.getBarStateMap().get(PrimarySkillType.ARCHERY).toString()); - statement.setString(9, dataSnapshot.getBarStateMap().get(PrimarySkillType.SWORDS).toString()); + statement.setString(6, dataSnapshot.getBarStateMap().get(CoreSkills.HERBALISM_CS).toString()); + statement.setString(7, dataSnapshot.getBarStateMap().get(CoreSkills.EXCAVATION_CS).toString()); + statement.setString(8, dataSnapshot.getBarStateMap().get(CoreSkills.ARCHERY_CS).toString()); + statement.setString(9, dataSnapshot.getBarStateMap().get(CoreSkills.SWORDS_CS).toString()); statement.setString(10, dataSnapshot.getBarStateMap().get(CoreSkills.AXES_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(14, dataSnapshot.getBarStateMap().get(PrimarySkillType.SALVAGE).toString()); - statement.setString(15, dataSnapshot.getBarStateMap().get(PrimarySkillType.SMELTING).toString()); - statement.setString(16, dataSnapshot.getBarStateMap().get(PrimarySkillType.TRIDENTS).toString()); - statement.setString(17, dataSnapshot.getBarStateMap().get(PrimarySkillType.CROSSBOWS).toString()); + statement.setString(14, dataSnapshot.getBarStateMap().get(CoreSkills.SALVAGE_CS).toString()); + statement.setString(15, dataSnapshot.getBarStateMap().get(CoreSkills.SMELTING_CS).toString()); + statement.setString(16, dataSnapshot.getBarStateMap().get(CoreSkills.TRIDENTS_CS).toString()); + statement.setString(17, dataSnapshot.getBarStateMap().get(CoreSkills.CROSSBOWS_CS).toString()); statement.setInt(18, id); success &= (statement.executeUpdate() != 0); statement.close(); @@ -406,17 +409,17 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { return success; } - public @NotNull List readLeaderboard(@Nullable PrimarySkillType skill, int pageNumber, int statsPerPage) throws InvalidSkillException { + public @NotNull List readLeaderboard(@Nullable RootSkill rootSkill, int pageNumber, int statsPerPage) throws InvalidSkillException { List stats = new ArrayList<>(); //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!"); 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; PreparedStatement statement = null; Connection connection = null; @@ -452,8 +455,8 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { return stats; } - public @NotNull Map readRank(@NotNull String playerName) { - Map skills = new HashMap<>(); + public @NotNull Map readRank(@NotNull String playerName) { + Map skills = new HashMap<>(); ResultSet resultSet = null; PreparedStatement statement = null; @@ -461,8 +464,8 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { try { connection = getConnection(PoolIdentifier.MISC); - for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) { - String skillName = primarySkillType.name().toLowerCase(Locale.ENGLISH); + for (RootSkill rootSkill : CoreSkills.getNonChildSkills()) { + String skillName = rootSkill.getSkillName().toLowerCase(Locale.ENGLISH); // 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 " + "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()) { if (resultSet.getString("user").equalsIgnoreCase(playerName)) { - skills.put(primarySkillType, rank + resultSet.getRow()); + skills.put(rootSkill, rank + resultSet.getRow()); break; } } @@ -602,16 +605,16 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { } @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()); } @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); } - 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; Connection connection = null; ResultSet resultSet = null; @@ -641,7 +644,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { if (resultSet.next()) { try { - PlayerProfile profile = loadFromResult(playerName, resultSet); + MMOPlayerData mmoPlayerData = loadFromResult(playerName, resultSet); String name = resultSet.getString(42); // TODO: Magic Number, make sure it stays updated resultSet.close(); statement.close(); @@ -666,7 +669,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { statement.close(); } - return profile; + return mmoPlayerData; } catch (SQLException e) { printErrors(e); @@ -702,14 +705,9 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { try { resultSet = statement.executeQuery(); resultSet.next(); - PlayerProfile playerProfile = loadFromResult(playerName, resultSet); - - if(playerProfile == null) - continue; - - PersistentPlayerData persistentPlayerData = playerProfile.getPersistentPlayerData(); - - MMODataSnapshot mmoDataSnapshot = mcMMO.getUserManager().createPlayerDataSnapshot(persistentPlayerData); + //TODO: Optimize, probably needless to make a snapshot here, brain tired + MMOPlayerData mmoPlayerData = loadFromResult(playerName, resultSet); + MMODataSnapshot mmoDataSnapshot = mcMMO.getUserManager().createPlayerDataSnapshot(mmoPlayerData); destination.saveUser(mmoDataSnapshot); 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; Connection connection = null; @@ -1024,10 +1022,12 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { } if (Config.getInstance().getTruncateSkills()) { - for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) { - int cap = Config.getInstance().getLevelCap(skill); + for (RootSkill rootSkill : CoreSkills.getNonChildSkills()) { + int cap = Config.getInstance().getLevelCap(rootSkill); 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(); 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(); - EnumMap skills = new EnumMap(PrimarySkillType.class); // Skill & Level - EnumMap skillsXp = new EnumMap(PrimarySkillType.class); // Skill & XP - EnumMap skillsDATS = new EnumMap(SuperAbilityType.class); // Ability & Cooldown - EnumMap uniqueData = new EnumMap(UniqueDataType.class); //Chimaera wing cooldown and other misc info - EnumMap xpBarStateMap = new EnumMap(PrimarySkillType.class); + Map skills = new HashMap<>(); // Skill & Level + Map skillsXp = new HashMap<>(); // Skill & XP + Map skillsDATS = new HashMap<>(); // Ability & Cooldown + Map uniqueData = new EnumMap(UniqueDataType.class); //Chimaera wing cooldown and other misc info + Map xpBarStateMap = new HashMap(); MobHealthBarType mobHealthbarType; UUID uuid; @@ -1209,37 +1209,37 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { final int OFFSET_XPBAR = OFFSET_OTHER + otherCount; final int OFFSET_TOGGLE = OFFSET_XPBAR + allSkills; - skills.put(PrimarySkillType.TAMING, result.getInt(OFFSET_SKILLS + 1)); - skills.put(PrimarySkillType.MINING, result.getInt(OFFSET_SKILLS + 2)); + skills.put(CoreSkills.TAMING_CS, result.getInt(OFFSET_SKILLS + 1)); + skills.put(CoreSkills.MINING_CS, result.getInt(OFFSET_SKILLS + 2)); skills.put(CoreSkills.REPAIR_CS, result.getInt(OFFSET_SKILLS + 3)); skills.put(CoreSkills.WOODCUTTING_CS, result.getInt(OFFSET_SKILLS + 4)); skills.put(CoreSkills.UNARMED_CS, result.getInt(OFFSET_SKILLS + 5)); - skills.put(PrimarySkillType.HERBALISM, result.getInt(OFFSET_SKILLS + 6)); - skills.put(PrimarySkillType.EXCAVATION, result.getInt(OFFSET_SKILLS + 7)); - skills.put(PrimarySkillType.ARCHERY, result.getInt(OFFSET_SKILLS + 8)); - skills.put(PrimarySkillType.SWORDS, result.getInt(OFFSET_SKILLS + 9)); + skills.put(CoreSkills.HERBALISM_CS, result.getInt(OFFSET_SKILLS + 6)); + skills.put(CoreSkills.EXCAVATION_CS, result.getInt(OFFSET_SKILLS + 7)); + skills.put(CoreSkills.ARCHERY_CS, result.getInt(OFFSET_SKILLS + 8)); + skills.put(CoreSkills.SWORDS_CS, result.getInt(OFFSET_SKILLS + 9)); skills.put(CoreSkills.AXES_CS, result.getInt(OFFSET_SKILLS + 10)); 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(PrimarySkillType.TRIDENTS, result.getInt(OFFSET_SKILLS + 14)); - skills.put(PrimarySkillType.CROSSBOWS, result.getInt(OFFSET_SKILLS + 15)); + skills.put(CoreSkills.TRIDENTS_CS, result.getInt(OFFSET_SKILLS + 14)); + skills.put(CoreSkills.CROSSBOWS_CS, result.getInt(OFFSET_SKILLS + 15)); - skillsXp.put(PrimarySkillType.TAMING, result.getFloat(OFFSET_EXPERIENCE + 1)); - skillsXp.put(PrimarySkillType.MINING, result.getFloat(OFFSET_EXPERIENCE + 2)); + skillsXp.put(CoreSkills.TAMING_CS, result.getFloat(OFFSET_EXPERIENCE + 1)); + skillsXp.put(CoreSkills.MINING_CS, result.getFloat(OFFSET_EXPERIENCE + 2)); skillsXp.put(CoreSkills.REPAIR_CS, result.getFloat(OFFSET_EXPERIENCE + 3)); skillsXp.put(CoreSkills.WOODCUTTING_CS, result.getFloat(OFFSET_EXPERIENCE + 4)); skillsXp.put(CoreSkills.UNARMED_CS, result.getFloat(OFFSET_EXPERIENCE + 5)); - skillsXp.put(PrimarySkillType.HERBALISM, result.getFloat(OFFSET_EXPERIENCE + 6)); - skillsXp.put(PrimarySkillType.EXCAVATION, result.getFloat(OFFSET_EXPERIENCE + 7)); - skillsXp.put(PrimarySkillType.ARCHERY, result.getFloat(OFFSET_EXPERIENCE + 8)); - skillsXp.put(PrimarySkillType.SWORDS, result.getFloat(OFFSET_EXPERIENCE + 9)); + skillsXp.put(CoreSkills.HERBALISM_CS, result.getFloat(OFFSET_EXPERIENCE + 6)); + skillsXp.put(CoreSkills.EXCAVATION_CS, result.getFloat(OFFSET_EXPERIENCE + 7)); + skillsXp.put(CoreSkills.ARCHERY_CS, result.getFloat(OFFSET_EXPERIENCE + 8)); + skillsXp.put(CoreSkills.SWORDS_CS, result.getFloat(OFFSET_EXPERIENCE + 9)); skillsXp.put(CoreSkills.AXES_CS, result.getFloat(OFFSET_EXPERIENCE + 10)); 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(PrimarySkillType.TRIDENTS, result.getFloat(OFFSET_EXPERIENCE + 14)); - skillsXp.put(PrimarySkillType.CROSSBOWS, result.getFloat(OFFSET_EXPERIENCE + 15)); + skillsXp.put(CoreSkills.TRIDENTS_CS, result.getFloat(OFFSET_EXPERIENCE + 14)); + skillsXp.put(CoreSkills.CROSSBOWS_CS, result.getFloat(OFFSET_EXPERIENCE + 15)); // Taming - Unused - result.getInt(OFFSET_COOLDOWNS + 1) skillsDATS.put(SuperAbilityType.SUPER_BREAKER, result.getInt(OFFSET_COOLDOWNS + 2)); @@ -1282,30 +1282,31 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { } //XPBAR - xpBarStateMap.put(PrimarySkillType.TAMING, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 1))); - xpBarStateMap.put(PrimarySkillType.MINING, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 2))); + xpBarStateMap.put(CoreSkills.TAMING_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 1))); + 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.WOODCUTTING_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 4))); 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(PrimarySkillType.EXCAVATION, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 7))); - xpBarStateMap.put(PrimarySkillType.ARCHERY, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 8))); - xpBarStateMap.put(PrimarySkillType.SWORDS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 9))); + xpBarStateMap.put(CoreSkills.HERBALISM_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 6))); + xpBarStateMap.put(CoreSkills.EXCAVATION_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 7))); + xpBarStateMap.put(CoreSkills.ARCHERY_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 8))); + 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.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(PrimarySkillType.SALVAGE, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 14))); - xpBarStateMap.put(PrimarySkillType.SMELTING, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 15))); - xpBarStateMap.put(PrimarySkillType.TRIDENTS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 16))); - xpBarStateMap.put(PrimarySkillType.CROSSBOWS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 17))); + xpBarStateMap.put(CoreSkills.SALVAGE_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 14))); + xpBarStateMap.put(CoreSkills.SMELTING_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 15))); + xpBarStateMap.put(CoreSkills.TRIDENTS_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 16))); + xpBarStateMap.put(CoreSkills.CROSSBOWS_CS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 17))); //TOGGLE boolean chatSpy = result.getBoolean(OFFSET_TOGGLE+1); boolean rankLess = result.getBoolean(OFFSET_TOGGLE+2); //Build - MMODataBuilder.setSkillLevelValues(skills) + MMODataBuilder mmoDataBuilder = new MMODataBuilder(); + mmoDataBuilder.setSkillLevelValues(skills) .setSkillExperienceValues(skillsXp) .setAbilityDeactivationTimestamps(skillsDATS) .setUniquePlayerData(uniqueData) @@ -1315,14 +1316,11 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { .setPartyChatSpying(chatSpy) .setLastLogin(0) //TODO: Program this in properly .setScoreboardTipsShown(scoreboardTipsShown) - .setMobHealthBarType(mobHealthbarType) .setLeaderBoardExemption(rankLess); - PersistentPlayerData persistentPlayerData; try { - persistentPlayerData = MMODataBuilder.build(); - return new PlayerProfile(persistentPlayerData); + return mmoDataBuilder.build(); } catch (Exception e) { e.printStackTrace(); 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.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"); - for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) { - String skill_name = skill.name().toLowerCase(Locale.ENGLISH); + for (RootSkill rootSkill : CoreSkills.getNonChildSkills()) { + String skill_name = rootSkill.getSkillName().toLowerCase(Locale.ENGLISH); try { statement.executeUpdate("ALTER TABLE `" + tablePrefix + "skills` ADD INDEX `idx_" + skill_name + "` (`" + skill_name + "`) USING BTREE"); diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/MMODataBuilder.java b/src/main/java/com/gmail/nossr50/datatypes/player/MMODataBuilder.java index 961dc7b37..bdc6e5534 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/MMODataBuilder.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/MMODataBuilder.java @@ -29,9 +29,6 @@ public class MMODataBuilder { /* Records */ private long lastLogin; - /* HUDs */ - private @Nullable MobHealthBarType mobHealthBarType; - /* Skill Data */ private @Nullable Map skillLevelValues; private @Nullable Map skillExperienceValues; @@ -99,10 +96,6 @@ public class MMODataBuilder { validateBarStateMapEntries(barStateMap); - if(mobHealthBarType == null) - throw new NullArgumentException("mobHealthBarType"); - - return new PersistentPlayerData(playerUUID, playerName, partyChatSpying, skillLevelValues, skillExperienceValues, abilityDeactivationTimestamps, uniquePlayerData, barStateMap, scoreboardTipsShown, lastLogin, leaderBoardExemption); } @@ -189,7 +182,7 @@ public class MMODataBuilder { return skillLevelValues; } - public @NotNull MMODataBuilder setSkillLevelValues(@NotNull HashMap skillLevelValues) { + public @NotNull MMODataBuilder setSkillLevelValues(@NotNull Map skillLevelValues) { this.skillLevelValues = skillLevelValues; return this; } @@ -198,7 +191,7 @@ public class MMODataBuilder { return skillExperienceValues; } - public @NotNull MMODataBuilder setSkillExperienceValues(@NotNull HashMap skillExperienceValues) { + public @NotNull MMODataBuilder setSkillExperienceValues(@NotNull Map skillExperienceValues) { this.skillExperienceValues = skillExperienceValues; return this; } @@ -207,7 +200,7 @@ public class MMODataBuilder { return abilityDeactivationTimestamps; } - public @NotNull MMODataBuilder setAbilityDeactivationTimestamps(@NotNull HashMap abilityDeactivationTimestamps) { + public @NotNull MMODataBuilder setAbilityDeactivationTimestamps(@NotNull Map abilityDeactivationTimestamps) { this.abilityDeactivationTimestamps = abilityDeactivationTimestamps; return this; } @@ -216,12 +209,12 @@ public class MMODataBuilder { return uniquePlayerData; } - public @NotNull MMODataBuilder setUniquePlayerData(@NotNull EnumMap uniquePlayerData) { + public @NotNull MMODataBuilder setUniquePlayerData(@NotNull Map uniquePlayerData) { this.uniquePlayerData = uniquePlayerData; return this; } - public @Nullable Map getBarStateMap() { + public @Nullable Map getBarStateMap() { return barStateMap; } diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/MMODataSnapshot.java b/src/main/java/com/gmail/nossr50/datatypes/player/MMODataSnapshot.java index af191cc1d..1f9aa9fd8 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/MMODataSnapshot.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/MMODataSnapshot.java @@ -5,8 +5,10 @@ import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.google.common.collect.ImmutableMap; import com.neetgames.mcmmo.MobHealthBarType; import com.neetgames.mcmmo.UniqueDataType; +import com.neetgames.mcmmo.player.MMOPlayerData; import com.neetgames.mcmmo.skill.RootSkill; import com.neetgames.mcmmo.skill.SkillBossBarState; +import com.neetgames.mcmmo.skill.SuperSkill; import org.jetbrains.annotations.NotNull; import java.util.UUID; @@ -17,43 +19,38 @@ public class MMODataSnapshot { private final @NotNull UUID playerUUID; /* Records */ - private final @NotNull Long lastLogin; - - /* HUDs */ - private final @NotNull MobHealthBarType mobHealthBarType; + private final long lastLogin; /* Skill Data */ private final @NotNull ImmutableMap skillLevelValues; private final @NotNull ImmutableMap skillExperienceValues; - private final @NotNull ImmutableMap abilityDeactivationTimestamps; // Ability & Cooldown + private final @NotNull ImmutableMap abilityDeactivationTimestamps; // Ability & Cooldown private final @NotNull ImmutableMap uniquePlayerData; //Misc data that doesn't fit into other categories (chimaera wing, etc..) - private final @NotNull ImmutableMap barStateMap; + private final @NotNull ImmutableMap barStateMap; /* Special Flags */ - private final @NotNull Boolean partyChatSpying; - private final @NotNull Boolean leaderBoardExclusion; + private final boolean partyChatSpying; + private final boolean leaderBoardExclusion; /* Scoreboards */ - private final @NotNull Integer scoreboardTipsShown; + private final int scoreboardTipsShown; - public MMODataSnapshot(@NotNull PersistentPlayerData persistentPlayerData) { - playerName = persistentPlayerData.getPlayerName(); - playerUUID = persistentPlayerData.getPlayerUUID(); - lastLogin = persistentPlayerData.getLastLogin(); + public MMODataSnapshot(@NotNull MMOPlayerData mmoPlayerData) { + playerName = mmoPlayerData.getPlayerName(); + playerUUID = mmoPlayerData.getPlayerUUID(); + 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()); - skillExperienceValues = ImmutableMap.copyOf(persistentPlayerData.getSkillsExperienceMap()); - abilityDeactivationTimestamps = ImmutableMap.copyOf(persistentPlayerData.getAbilityDeactivationTimestamps()); - uniquePlayerData = ImmutableMap.copyOf(persistentPlayerData.getUniquePlayerData()); - barStateMap = ImmutableMap.copyOf(persistentPlayerData.getBarStateMap()); + partyChatSpying = mmoPlayerData.isPartyChatSpying(); + leaderBoardExclusion = mmoPlayerData.isLeaderBoardExcluded(); - partyChatSpying = persistentPlayerData.isPartyChatSpying(); - leaderBoardExclusion = persistentPlayerData.isLeaderBoardExcluded(); - - scoreboardTipsShown = persistentPlayerData.getScoreboardTipsShown(); + scoreboardTipsShown = mmoPlayerData.getScoreboardTipsShown(); } public @NotNull String getPlayerName() { @@ -68,9 +65,6 @@ public class MMODataSnapshot { return lastLogin; } - public @NotNull MobHealthBarType getMobHealthBarType() { - return mobHealthBarType; - } public @NotNull ImmutableMap getSkillLevelValues() { return skillLevelValues; @@ -80,7 +74,7 @@ public class MMODataSnapshot { return skillExperienceValues; } - public @NotNull ImmutableMap getAbilityDeactivationTimestamps() { + public @NotNull ImmutableMap getAbilityDeactivationTimestamps() { return abilityDeactivationTimestamps; } @@ -100,15 +94,15 @@ public class MMODataSnapshot { return scoreboardTipsShown; } - public int getSkillLevel(@NotNull PrimarySkillType primarySkillType) { - return skillLevelValues.getOrDefault(primarySkillType, 0); + public int getSkillLevel(@NotNull RootSkill rootSkill) { + return skillLevelValues.getOrDefault(rootSkill, 0); } - public int getSkillXpLevel(@NotNull PrimarySkillType primarySkillType) { - return (skillExperienceValues.getOrDefault(primarySkillType, 0F)).intValue(); + public int getSkillXpLevel(@NotNull RootSkill rootSkill) { + return (skillExperienceValues.getOrDefault(rootSkill, 0F)).intValue(); } - public long getAbilityDATS(@NotNull SuperAbilityType superAbilityType) { + public long getAbilityDATS(@NotNull SuperSkill superAbilityType) { return abilityDeactivationTimestamps.getOrDefault(superAbilityType, 0); } diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/CoreSkills.java b/src/main/java/com/gmail/nossr50/datatypes/skills/CoreSkills.java index 951517a56..7218b035c 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/CoreSkills.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/CoreSkills.java @@ -1,30 +1,30 @@ package com.gmail.nossr50.datatypes.skills; import com.google.common.collect.ImmutableSet; -import com.neetgames.mcmmo.exceptions.InvalidSkillException; import com.neetgames.mcmmo.skill.RootSkill; -import com.neetgames.mcmmo.skill.Skill; import com.neetgames.mcmmo.skill.SkillIdentity; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; public class CoreSkills { - private static final @NotNull ImmutableSet CORE_ROOT_SKILLS_IMMUTABLE_SET; + private static final @NotNull ImmutableSet CORE_ROOT_SKILLS; private static final @NotNull ImmutableSet CORE_CHILD_SKILLS; + private static final @NotNull ImmutableSet CORE_NON_CHILD_SKILLS; 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, - WOODCUTTING_CS, TRIDENTS_CS, CROSSBOWS_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; 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, - WOODCUTTING_ID, TRIDENTS_ID, CROSSBOWS_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; + private static @NotNull final HackySkillMappings hackySkillMappings = new HackySkillMappings(); @@ -106,8 +106,9 @@ public class CoreSkills { rootSkillSet.add(TRIDENTS_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_NON_CHILD_SKILLS = ImmutableSet.copyOf(generateNonChildSkillSet()); } /** @@ -117,7 +118,7 @@ public class CoreSkills { * @return a set of all root skills built into mcMMO */ public static @NotNull Set getImmutableCoreRootSkillSet() { - return CORE_ROOT_SKILLS_IMMUTABLE_SET; + return CORE_ROOT_SKILLS; } /** @@ -159,6 +160,15 @@ public class CoreSkills { return hackySkillMappings.rootToPrimaryMap.get(rootSkill); } + @Deprecated + private static @NotNull Set generateNonChildSkillSet() { + return getImmutableCoreRootSkillSet().stream().filter((x) -> !isChildSkill(x)).collect(Collectors.toSet()); + } + + public static @NotNull Set getNonChildSkills() { + return CORE_NON_CHILD_SKILLS; + } + protected static class HackySkillMappings { @NotNull Map primaryToRootMap = new HashMap<>(); @NotNull Map rootToPrimaryMap = new HashMap<>(); diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandAsyncTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandAsyncTask.java index 387175cf7..fd8baf125 100644 --- a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandAsyncTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandAsyncTask.java @@ -1,8 +1,8 @@ package com.gmail.nossr50.runnables.commands; import com.gmail.nossr50.datatypes.database.PlayerStat; -import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.mcMMO; +import com.neetgames.mcmmo.skill.RootSkill; import org.apache.commons.lang.Validate; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -12,11 +12,11 @@ import java.util.List; public class MctopCommandAsyncTask extends BukkitRunnable { private final CommandSender sender; - private final PrimarySkillType skill; + private final RootSkill rootSkill; private final int page; 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.notNull(sender, "Attempted to start a rank retrieval with no recipient"); @@ -25,7 +25,7 @@ public class MctopCommandAsyncTask extends BukkitRunnable { } this.page = page; - this.skill = skill; + this.rootSkill = rootSkill; this.sender = sender; this.useBoard = useBoard; this.useChat = useChat; @@ -33,8 +33,8 @@ public class MctopCommandAsyncTask extends BukkitRunnable { @Override public void run() { - final List userStats = mcMMO.getDatabaseManager().readLeaderboard(skill, page, 10); + final List 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); } } diff --git a/src/main/java/com/gmail/nossr50/util/player/UserManager.java b/src/main/java/com/gmail/nossr50/util/player/UserManager.java index c202db754..5da4b44d3 100644 --- a/src/main/java/com/gmail/nossr50/util/player/UserManager.java +++ b/src/main/java/com/gmail/nossr50/util/player/UserManager.java @@ -116,8 +116,8 @@ public final class UserManager { return entity != null && entity.hasMetadata(mcMMO.playerDataKey); } - public @NotNull MMODataSnapshot createPlayerDataSnapshot(@NotNull MMODataSnapshot mmoDataSnapshot) { - return new MMODataSnapshot(mmoDataSnapshot); + public @NotNull MMODataSnapshot createPlayerDataSnapshot(@NotNull MMOPlayerData mmoPlayerData) { + return new MMODataSnapshot(mmoPlayerData); } public void saveUserImmediately(@NotNull MMOPlayerData mmoPlayerData, boolean useSync) {