From 843e3ace99dd3a2ff1dbe4f1c1b716226e865534 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 23 Dec 2020 11:08:57 -0800 Subject: [PATCH] API migration on DBs --- .../database/AbstractDatabaseManager.java | 6 +- .../database/FlatFileDatabaseManager.java | 199 +++++++++--------- .../nossr50/database/SQLDatabaseManager.java | 79 +++---- ...erDataBuilder.java => MMODataBuilder.java} | 35 ++- .../player/PlayerProfileLoadingTask.java | 4 - 5 files changed, 160 insertions(+), 163 deletions(-) rename src/main/java/com/gmail/nossr50/datatypes/player/{PersistentPlayerDataBuilder.java => MMODataBuilder.java} (81%) diff --git a/src/main/java/com/gmail/nossr50/database/AbstractDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/AbstractDatabaseManager.java index 3f1bf1ca8..46bbc7254 100644 --- a/src/main/java/com/gmail/nossr50/database/AbstractDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/AbstractDatabaseManager.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.database; -import com.gmail.nossr50.datatypes.player.PersistentPlayerDataBuilder; +import com.gmail.nossr50.datatypes.player.MMODataBuilder; import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.mcMMO; import com.neetgames.mcmmo.exceptions.ProfileRetrievalException; @@ -25,9 +25,9 @@ public abstract class AbstractDatabaseManager implements DatabaseManager { //TODO: have this use the PersistentPlayerData object created below to initialize defaults insertNewUser(player.getName(), player.getUniqueId()); //Construct player data object - PersistentPlayerDataBuilder persistentPlayerDataBuilder = new PersistentPlayerDataBuilder(); + MMODataBuilder MMODataBuilder = new MMODataBuilder(); //Return player profile - return new PlayerProfile(persistentPlayerDataBuilder.buildNewPlayerData(player.getUniqueId(), player.getName())); + return new PlayerProfile(MMODataBuilder.buildNewPlayerData(player.getUniqueId(), player.getName())); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/com/gmail/nossr50/database/FlatFileDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/FlatFileDatabaseManager.java index e79152175..875ca8bfd 100644 --- a/src/main/java/com/gmail/nossr50/database/FlatFileDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/FlatFileDatabaseManager.java @@ -6,6 +6,7 @@ import com.gmail.nossr50.datatypes.database.DatabaseType; import com.gmail.nossr50.datatypes.database.PlayerStat; import com.gmail.nossr50.datatypes.database.UpgradeType; import com.gmail.nossr50.datatypes.player.*; +import com.gmail.nossr50.datatypes.skills.CoreSkills; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.mcMMO; @@ -18,7 +19,11 @@ import com.google.common.collect.ImmutableMap; import com.neetgames.mcmmo.MobHealthBarType; import com.neetgames.mcmmo.UniqueDataType; 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 it.unimi.dsi.fastutil.Hash; import org.apache.commons.lang.NullArgumentException; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -66,7 +71,7 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { while ((line = in.readLine()) != null) { String[] character = line.split(":"); - Map skills = getSkillMapFromLine(character); + Map skills = getSkillMapFromLine(character); boolean powerless = true; for (int skill : skills.values()) { @@ -325,32 +330,32 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { } private void writeUserToLine(@NotNull MMODataSnapshot mmoDataSnapshot, @NotNull String playerName, @NotNull UUID uuid, @NotNull StringBuilder writer) { - ImmutableMap primarySkillLevelMap = mmoDataSnapshot.getSkillLevelValues(); - ImmutableMap primarySkillExperienceValueMap = mmoDataSnapshot.getSkillExperienceValues(); + ImmutableMap primarySkillLevelMap = mmoDataSnapshot.getSkillLevelValues(); + ImmutableMap primarySkillExperienceValueMap = mmoDataSnapshot.getSkillExperienceValues(); writer.append(playerName).append(":"); - writer.append(primarySkillLevelMap.get(PrimarySkillType.MINING)).append(":"); + writer.append(primarySkillLevelMap.get(CoreSkills.MINING_CS)).append(":"); writer.append(":"); writer.append(":"); - writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.MINING)).append(":"); - writer.append(primarySkillLevelMap.get(PrimarySkillType.WOODCUTTING)).append(":"); - writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.WOODCUTTING)).append(":"); - writer.append(primarySkillLevelMap.get(PrimarySkillType.REPAIR)).append(":"); - writer.append(primarySkillLevelMap.get(PrimarySkillType.UNARMED)).append(":"); + writer.append(primarySkillExperienceValueMap.get(CoreSkills.MINING_CS)).append(":"); + writer.append(primarySkillLevelMap.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.UNARMED_CS)).append(":"); writer.append(primarySkillLevelMap.get(PrimarySkillType.HERBALISM)).append(":"); writer.append(primarySkillLevelMap.get(PrimarySkillType.EXCAVATION)).append(":"); - writer.append(primarySkillLevelMap.get(PrimarySkillType.ARCHERY)).append(":"); + writer.append(primarySkillLevelMap.get(CoreSkills.ARCHERY_CS)).append(":"); writer.append(primarySkillLevelMap.get(PrimarySkillType.SWORDS)).append(":"); - writer.append(primarySkillLevelMap.get(PrimarySkillType.AXES)).append(":"); - writer.append(primarySkillLevelMap.get(PrimarySkillType.ACROBATICS)).append(":"); - writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.REPAIR)).append(":"); - writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.UNARMED)).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(PrimarySkillType.ARCHERY)).append(":"); + writer.append(primarySkillExperienceValueMap.get(CoreSkills.ARCHERY_CS)).append(":"); writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.SWORDS)).append(":"); - writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.AXES)).append(":"); - writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.ACROBATICS)).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(":"); @@ -362,16 +367,16 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { writer.append((int) mmoDataSnapshot.getAbilityDATS(SuperAbilityType.SKULL_SPLITTER)).append(":"); writer.append((int) mmoDataSnapshot.getAbilityDATS(SuperAbilityType.SUPER_BREAKER)).append(":"); writer.append(":"); - writer.append(primarySkillLevelMap.get(PrimarySkillType.FISHING)).append(":"); - writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.FISHING)).append(":"); + writer.append(primarySkillLevelMap.get(CoreSkills.FISHING_CS)).append(":"); + writer.append(primarySkillExperienceValueMap.get(CoreSkills.FISHING_CS)).append(":"); writer.append((int) mmoDataSnapshot.getAbilityDATS(SuperAbilityType.BLAST_MINING)).append(":"); writer.append(System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR).append(":"); MobHealthBarType mobHealthbarType = mmoDataSnapshot.getMobHealthBarType(); writer.append(mobHealthbarType.toString()).append(":"); - writer.append(primarySkillLevelMap.get(PrimarySkillType.ALCHEMY)).append(":"); - writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.ALCHEMY)).append(":"); + writer.append(primarySkillLevelMap.get(CoreSkills.ALCHEMY_CS)).append(":"); + writer.append(primarySkillExperienceValueMap.get(CoreSkills.ALCHEMY_CS)).append(":"); writer.append(uuid != null ? uuid.toString() : "NULL").append(":"); writer.append(mmoDataSnapshot.getScoreboardTipsShown()).append(":"); writer.append(mmoDataSnapshot.getUniqueData(UniqueDataType.CHIMAERA_WING_DATS)).append(":"); @@ -406,21 +411,21 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { writer.append(primarySkillExperienceValueMap.get(PrimarySkillType.CROSSBOWS)).append(":"); //XPBar States - writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.ACROBATICS).toString()).append(":"); - writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.ALCHEMY).toString()).append(":"); - writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.ARCHERY).toString()).append(":"); - writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.AXES).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.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(PrimarySkillType.FISHING).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(PrimarySkillType.MINING).toString()).append(":"); - writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.REPAIR).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(PrimarySkillType.UNARMED).toString()).append(":"); - writer.append(mmoDataSnapshot.getBarStateMap().get(PrimarySkillType.WOODCUTTING).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(":"); @@ -562,7 +567,8 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { } } - public @Nullable PlayerProfile queryPlayerDataByName(@NotNull String playerName) { + @Override + public @Nullable MMOPlayerData queryPlayerByName(@NotNull String playerName) throws ProfileRetrievalException { BufferedReader bufferedReader = null; String usersFilePath = mcMMO.getUsersFilePath(); @@ -610,7 +616,7 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { return null; } - public @Nullable PlayerProfile queryPlayerDataByPlayer(@NotNull Player player) throws ProfileRetrievalException, NullArgumentException { + public @Nullable MMOPlayerData queryPlayerDataByPlayer(@NotNull Player player) throws ProfileRetrievalException, NullArgumentException { return queryPlayerDataByUUID(player.getUniqueId(), player.getName()); } @@ -624,7 +630,7 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { * @throws ProfileRetrievalException * @throws NullArgumentException */ - 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 { BufferedReader bufferedReader = null; String usersFilePath = mcMMO.getUsersFilePath(); @@ -800,19 +806,19 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { Map skills = getSkillMapFromLine(data); - powerLevel += putStat(acrobatics, playerName, skills.get(PrimarySkillType.ACROBATICS)); - powerLevel += putStat(alchemy, playerName, skills.get(PrimarySkillType.ALCHEMY)); - powerLevel += putStat(archery, playerName, skills.get(PrimarySkillType.ARCHERY)); - powerLevel += putStat(axes, playerName, skills.get(PrimarySkillType.AXES)); + 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(fishing, playerName, skills.get(PrimarySkillType.FISHING)); + powerLevel += putStat(fishing, playerName, skills.get(CoreSkills.FISHING_CS)); powerLevel += putStat(herbalism, playerName, skills.get(PrimarySkillType.HERBALISM)); - powerLevel += putStat(mining, playerName, skills.get(PrimarySkillType.MINING)); - powerLevel += putStat(repair, playerName, skills.get(PrimarySkillType.REPAIR)); + 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(unarmed, playerName, skills.get(PrimarySkillType.UNARMED)); - powerLevel += putStat(woodcutting, playerName, skills.get(PrimarySkillType.WOODCUTTING)); + 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)); @@ -851,19 +857,19 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { alchemy.sort(c); powerLevels.sort(c); - playerStatHash.put(PrimarySkillType.MINING, mining); - playerStatHash.put(PrimarySkillType.WOODCUTTING, woodcutting); - playerStatHash.put(PrimarySkillType.REPAIR, repair); - playerStatHash.put(PrimarySkillType.UNARMED, unarmed); + playerStatHash.put(CoreSkills.MINING_CS, mining); + 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(PrimarySkillType.ARCHERY, archery); + playerStatHash.put(CoreSkills.ARCHERY_CS, archery); playerStatHash.put(PrimarySkillType.SWORDS, swords); - playerStatHash.put(PrimarySkillType.AXES, axes); - playerStatHash.put(PrimarySkillType.ACROBATICS, acrobatics); + playerStatHash.put(CoreSkills.AXES_CS, axes); + playerStatHash.put(CoreSkills.ACROBATICS_CS, acrobatics); playerStatHash.put(PrimarySkillType.TAMING, taming); - playerStatHash.put(PrimarySkillType.FISHING, fishing); - playerStatHash.put(PrimarySkillType.ALCHEMY, alchemy); + playerStatHash.put(CoreSkills.FISHING_CS, fishing); + playerStatHash.put(CoreSkills.ALCHEMY_CS, alchemy); } /** @@ -1263,30 +1269,30 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { } } - private @Nullable PlayerProfile loadFromLine(@NotNull String[] dataStrSplit) { - PersistentPlayerDataBuilder playerDataBuilder = new PersistentPlayerDataBuilder(); + private @Nullable MMOPlayerData loadFromLine(@NotNull String[] dataStrSplit) { + MMODataBuilder playerDataBuilder = new MMODataBuilder(); - EnumMap skillLevelMap = getSkillMapFromLine(dataStrSplit); // Skill levels - EnumMap skillExperienceValueMap = new EnumMap(PrimarySkillType.class); // Skill & XP - EnumMap skillAbilityDeactivationTimeStamp = new EnumMap(SuperAbilityType.class); // Ability & Cooldown + 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); - EnumMap xpBarStateMap = new EnumMap(PrimarySkillType.class); + HashMap xpBarStateMap = new EnumMap(PrimarySkillType.class); // MobHealthBarType mobHealthbarType; int scoreboardTipsShown; skillExperienceValueMap.put(PrimarySkillType.TAMING, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_TAMING])); - skillExperienceValueMap.put(PrimarySkillType.MINING, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_MINING])); - skillExperienceValueMap.put(PrimarySkillType.REPAIR, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_REPAIR])); - skillExperienceValueMap.put(PrimarySkillType.WOODCUTTING, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_WOODCUTTING])); - skillExperienceValueMap.put(PrimarySkillType.UNARMED, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_UNARMED])); + 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(PrimarySkillType.ARCHERY, (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(PrimarySkillType.AXES, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_AXES])); - skillExperienceValueMap.put(PrimarySkillType.ACROBATICS, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_ACROBATICS])); - skillExperienceValueMap.put(PrimarySkillType.FISHING, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_FISHING])); - skillExperienceValueMap.put(PrimarySkillType.ALCHEMY, (float) Integer.parseInt(dataStrSplit[FlatFileMappings.EXP_ALCHEMY])); + 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])); @@ -1343,31 +1349,28 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { } try { - xpBarStateMap.put(PrimarySkillType.ACROBATICS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_ACROBATICS])); - xpBarStateMap.put(PrimarySkillType.ALCHEMY, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_ALCHEMY])); - xpBarStateMap.put(PrimarySkillType.ARCHERY, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_ARCHERY])); - xpBarStateMap.put(PrimarySkillType.AXES, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_AXES])); + xpBarStateMap.put(CoreSkills.ACROBATICS_CS, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_ACROBATICS])); + 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(PrimarySkillType.FISHING, 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(PrimarySkillType.MINING, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_MINING])); - xpBarStateMap.put(PrimarySkillType.REPAIR, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_REPAIR])); + 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(PrimarySkillType.UNARMED, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_UNARMED])); - xpBarStateMap.put(PrimarySkillType.WOODCUTTING, SkillUtils.asBarState(dataStrSplit[FlatFileMappings.BARSTATE_WOODCUTTING])); + 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])); } catch (Exception e) { xpBarStateMap = MMOExperienceBarManager.generateDefaultBarStateMap(); } - - - - PersistentPlayerData persistentPlayerData; + MMOPlayerData mmoPlayerData; try { //Set Player Data @@ -1381,8 +1384,7 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { .setBarStateMap(xpBarStateMap); //Build Data - persistentPlayerData = playerDataBuilder.build(); - return new PlayerProfile(persistentPlayerData); + return playerDataBuilder.build(); } catch (Exception e) { mcMMO.p.getLogger().severe("Critical failure when trying to construct persistent player data!"); e.printStackTrace(); @@ -1390,24 +1392,25 @@ public final class FlatFileDatabaseManager extends AbstractDatabaseManager { } } - private EnumMap getSkillMapFromLine(String[] stringDataArray) { - EnumMap skillLevelsMap = new EnumMap<>(PrimarySkillType.class); // Skill & Level + //TODO: Add tests + private @NotNull Map getSkillMapFromLine(@NotNull String[] stringDataArray) { + HashMap skillLevelsMap = new HashMap<>(); // Skill & Level - skillLevelsMap.put(PrimarySkillType.TAMING, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_TAMING])); - skillLevelsMap.put(PrimarySkillType.MINING, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_MINING])); - skillLevelsMap.put(PrimarySkillType.REPAIR, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_REPAIR])); - skillLevelsMap.put(PrimarySkillType.WOODCUTTING, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_WOODCUTTING])); - skillLevelsMap.put(PrimarySkillType.UNARMED, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_UNARMED])); - skillLevelsMap.put(PrimarySkillType.HERBALISM, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_HERBALISM])); - skillLevelsMap.put(PrimarySkillType.EXCAVATION, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_EXCAVATION])); - skillLevelsMap.put(PrimarySkillType.ARCHERY, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_ARCHERY])); - skillLevelsMap.put(PrimarySkillType.SWORDS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_SWORDS])); - skillLevelsMap.put(PrimarySkillType.AXES, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_AXES])); - skillLevelsMap.put(PrimarySkillType.ACROBATICS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_ACROBATICS])); - skillLevelsMap.put(PrimarySkillType.FISHING, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_FISHING])); - skillLevelsMap.put(PrimarySkillType.ALCHEMY, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_ALCHEMY])); - skillLevelsMap.put(PrimarySkillType.TRIDENTS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_TRIDENTS])); - skillLevelsMap.put(PrimarySkillType.CROSSBOWS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_CROSSBOWS])); + skillLevelsMap.put(CoreSkills.TAMING_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_TAMING])); + skillLevelsMap.put(CoreSkills.MINING_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_MINING])); + skillLevelsMap.put(CoreSkills.REPAIR_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_REPAIR])); + skillLevelsMap.put(CoreSkills.WOODCUTTING_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_WOODCUTTING])); + skillLevelsMap.put(CoreSkills.UNARMED_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_UNARMED])); + skillLevelsMap.put(CoreSkills.HERBALISM_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_HERBALISM])); + skillLevelsMap.put(CoreSkills.EXCAVATION_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_EXCAVATION])); + skillLevelsMap.put(CoreSkills.ARCHERY_CS, Integer.valueOf(stringDataArray[FlatFileMappings.SKILLS_ARCHERY])); + 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.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])); return skillLevelsMap; } diff --git a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java index 776f39440..e4b69d007 100644 --- a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java @@ -5,6 +5,7 @@ import com.gmail.nossr50.datatypes.database.DatabaseType; import com.gmail.nossr50.datatypes.database.PlayerStat; import com.gmail.nossr50.datatypes.database.UpgradeType; import com.gmail.nossr50.datatypes.player.*; +import com.gmail.nossr50.datatypes.skills.CoreSkills; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.mcMMO; @@ -258,17 +259,17 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { + ", fishing = ?, alchemy = ?, tridents = ?, crossbows = ?, total = ? WHERE user_id = ?"); statement.setInt(1, dataSnapshot.getSkillLevel(PrimarySkillType.TAMING)); statement.setInt(2, dataSnapshot.getSkillLevel(PrimarySkillType.MINING)); - statement.setInt(3, dataSnapshot.getSkillLevel(PrimarySkillType.REPAIR)); - statement.setInt(4, dataSnapshot.getSkillLevel(PrimarySkillType.WOODCUTTING)); - statement.setInt(5, dataSnapshot.getSkillLevel(PrimarySkillType.UNARMED)); + 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(10, dataSnapshot.getSkillLevel(PrimarySkillType.AXES)); - statement.setInt(11, dataSnapshot.getSkillLevel(PrimarySkillType.ACROBATICS)); + 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(13, dataSnapshot.getSkillLevel(PrimarySkillType.ALCHEMY)); + statement.setInt(13, dataSnapshot.getSkillLevel(CoreSkills.ALCHEMY_CS)); statement.setInt(14, dataSnapshot.getSkillLevel(PrimarySkillType.TRIDENTS)); statement.setInt(15, dataSnapshot.getSkillLevel(PrimarySkillType.CROSSBOWS)); int total = 0; @@ -290,17 +291,17 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { + ", fishing = ?, alchemy = ?, tridents = ?, crossbows = ?, WHERE user_id = ?"); statement.setInt(1, dataSnapshot.getSkillXpLevel(PrimarySkillType.TAMING)); statement.setInt(2, dataSnapshot.getSkillXpLevel(PrimarySkillType.MINING)); - statement.setInt(3, dataSnapshot.getSkillXpLevel(PrimarySkillType.REPAIR)); - statement.setInt(4, dataSnapshot.getSkillXpLevel(PrimarySkillType.WOODCUTTING)); - statement.setInt(5, dataSnapshot.getSkillXpLevel(PrimarySkillType.UNARMED)); + 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(10, dataSnapshot.getSkillXpLevel(PrimarySkillType.AXES)); - statement.setInt(11, dataSnapshot.getSkillXpLevel(PrimarySkillType.ACROBATICS)); + 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(13, dataSnapshot.getSkillXpLevel(PrimarySkillType.ALCHEMY)); + statement.setInt(13, dataSnapshot.getSkillXpLevel(CoreSkills.ALCHEMY_CS)); statement.setInt(14, dataSnapshot.getSkillXpLevel(PrimarySkillType.TRIDENTS)); statement.setInt(15, dataSnapshot.getSkillXpLevel(PrimarySkillType.CROSSBOWS)); statement.setInt(16, id); @@ -355,17 +356,17 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { + ", 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(3, dataSnapshot.getBarStateMap().get(PrimarySkillType.REPAIR).toString()); - statement.setString(4, dataSnapshot.getBarStateMap().get(PrimarySkillType.WOODCUTTING).toString()); - statement.setString(5, dataSnapshot.getBarStateMap().get(PrimarySkillType.UNARMED).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(10, dataSnapshot.getBarStateMap().get(PrimarySkillType.AXES).toString()); - statement.setString(11, dataSnapshot.getBarStateMap().get(PrimarySkillType.ACROBATICS).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(13, dataSnapshot.getBarStateMap().get(PrimarySkillType.ALCHEMY).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()); @@ -1188,7 +1189,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { } private @Nullable PlayerProfile loadFromResult(String playerName, ResultSet result) throws SQLException { - PersistentPlayerDataBuilder persistentPlayerDataBuilder = new PersistentPlayerDataBuilder(); + 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 @@ -1210,33 +1211,33 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { skills.put(PrimarySkillType.TAMING, result.getInt(OFFSET_SKILLS + 1)); skills.put(PrimarySkillType.MINING, result.getInt(OFFSET_SKILLS + 2)); - skills.put(PrimarySkillType.REPAIR, result.getInt(OFFSET_SKILLS + 3)); - skills.put(PrimarySkillType.WOODCUTTING, result.getInt(OFFSET_SKILLS + 4)); - skills.put(PrimarySkillType.UNARMED, result.getInt(OFFSET_SKILLS + 5)); + 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(PrimarySkillType.AXES, result.getInt(OFFSET_SKILLS + 10)); - skills.put(PrimarySkillType.ACROBATICS, result.getInt(OFFSET_SKILLS + 11)); + 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(PrimarySkillType.ALCHEMY, 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(PrimarySkillType.CROSSBOWS, 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(PrimarySkillType.REPAIR, result.getFloat(OFFSET_EXPERIENCE + 3)); - skillsXp.put(PrimarySkillType.WOODCUTTING, result.getFloat(OFFSET_EXPERIENCE + 4)); - skillsXp.put(PrimarySkillType.UNARMED, result.getFloat(OFFSET_EXPERIENCE + 5)); + 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(PrimarySkillType.AXES, result.getFloat(OFFSET_EXPERIENCE + 10)); - skillsXp.put(PrimarySkillType.ACROBATICS, result.getFloat(OFFSET_EXPERIENCE + 11)); + 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(PrimarySkillType.ALCHEMY, 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(PrimarySkillType.CROSSBOWS, result.getFloat(OFFSET_EXPERIENCE + 15)); @@ -1283,17 +1284,17 @@ 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(PrimarySkillType.REPAIR, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 3))); - xpBarStateMap.put(PrimarySkillType.WOODCUTTING, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 4))); - xpBarStateMap.put(PrimarySkillType.UNARMED, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 5))); + 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(PrimarySkillType.AXES, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 10))); - xpBarStateMap.put(PrimarySkillType.ACROBATICS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 11))); + 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(PrimarySkillType.ALCHEMY, 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(PrimarySkillType.SMELTING, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 15))); xpBarStateMap.put(PrimarySkillType.TRIDENTS, SkillUtils.asBarState(result.getString(OFFSET_XPBAR + 16))); @@ -1304,7 +1305,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { boolean rankLess = result.getBoolean(OFFSET_TOGGLE+2); //Build - persistentPlayerDataBuilder.setSkillLevelValues(skills) + MMODataBuilder.setSkillLevelValues(skills) .setSkillExperienceValues(skillsXp) .setAbilityDeactivationTimestamps(skillsDATS) .setUniquePlayerData(uniqueData) @@ -1320,7 +1321,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager { PersistentPlayerData persistentPlayerData; try { - persistentPlayerData = persistentPlayerDataBuilder.build(); + persistentPlayerData = MMODataBuilder.build(); return new PlayerProfile(persistentPlayerData); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/PersistentPlayerDataBuilder.java b/src/main/java/com/gmail/nossr50/datatypes/player/MMODataBuilder.java similarity index 81% rename from src/main/java/com/gmail/nossr50/datatypes/player/PersistentPlayerDataBuilder.java rename to src/main/java/com/gmail/nossr50/datatypes/player/MMODataBuilder.java index e3dc07a06..961dc7b37 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/PersistentPlayerDataBuilder.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/MMODataBuilder.java @@ -1,17 +1,14 @@ package com.gmail.nossr50.datatypes.player; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.experience.MMOExperienceBarManager; import com.neetgames.mcmmo.MobHealthBarType; import com.neetgames.mcmmo.UniqueDataType; -import com.neetgames.mcmmo.api.SkillRegister; +import com.neetgames.mcmmo.player.MMOPlayerData; import com.neetgames.mcmmo.skill.RootSkill; import com.neetgames.mcmmo.skill.SkillBossBarState; -import com.neetgames.mcmmo.skill.SkillIdentity; import com.neetgames.mcmmo.skill.SuperSkill; -import it.unimi.dsi.fastutil.Hash; import org.apache.commons.lang.NullArgumentException; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -23,7 +20,7 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; -public class PersistentPlayerDataBuilder { +public class MMODataBuilder { /* Player Stuff */ private @Nullable String playerName; @@ -49,28 +46,28 @@ public class PersistentPlayerDataBuilder { /* Scoreboards */ private int scoreboardTipsShown; - public @NotNull PersistentPlayerData buildNewPlayerData(@NotNull Player player) { + public @NotNull MMOPlayerData buildNewPlayerData(@NotNull Player player) { /* * New Profile with default values */ return buildNewPlayerData(player.getUniqueId(), player.getName()); } - public @Nullable PersistentPlayerData buildNewPlayerData(@NotNull OfflinePlayer offlinePlayer) { + public @Nullable MMOPlayerData buildNewPlayerData(@NotNull OfflinePlayer offlinePlayer) { if(offlinePlayer.getName() != null) return buildNewPlayerData(offlinePlayer.getUniqueId(), offlinePlayer.getName()); else return null; } - public @NotNull PersistentPlayerData buildNewPlayerData(@NotNull UUID playerUUID, @NotNull String playerName) { + public @NotNull MMOPlayerData buildNewPlayerData(@NotNull UUID playerUUID, @NotNull String playerName) { /* * New Profile with default values */ return new PersistentPlayerData(playerUUID, playerName); } - public @NotNull PersistentPlayerData build() throws Exception { + public @NotNull MMOPlayerData build() throws Exception { if(playerUUID == null) throw new NullArgumentException("playerUUID"); @@ -165,7 +162,7 @@ public class PersistentPlayerDataBuilder { return playerName; } - public @NotNull PersistentPlayerDataBuilder setPlayerName(@NotNull String playerName) { + public @NotNull MMODataBuilder setPlayerName(@NotNull String playerName) { this.playerName = playerName; return this; } @@ -174,7 +171,7 @@ public class PersistentPlayerDataBuilder { return playerUUID; } - public @NotNull PersistentPlayerDataBuilder setPlayerUUID(@NotNull UUID playerUUID) { + public @NotNull MMODataBuilder setPlayerUUID(@NotNull UUID playerUUID) { this.playerUUID = playerUUID; return this; } @@ -183,7 +180,7 @@ public class PersistentPlayerDataBuilder { return lastLogin; } - public @NotNull PersistentPlayerDataBuilder setLastLogin(long lastLogin) { + public @NotNull MMODataBuilder setLastLogin(long lastLogin) { this.lastLogin = lastLogin; return this; } @@ -192,7 +189,7 @@ public class PersistentPlayerDataBuilder { return skillLevelValues; } - public @NotNull PersistentPlayerDataBuilder setSkillLevelValues(@NotNull HashMap skillLevelValues) { + public @NotNull MMODataBuilder setSkillLevelValues(@NotNull HashMap skillLevelValues) { this.skillLevelValues = skillLevelValues; return this; } @@ -201,7 +198,7 @@ public class PersistentPlayerDataBuilder { return skillExperienceValues; } - public @NotNull PersistentPlayerDataBuilder setSkillExperienceValues(@NotNull HashMap skillExperienceValues) { + public @NotNull MMODataBuilder setSkillExperienceValues(@NotNull HashMap skillExperienceValues) { this.skillExperienceValues = skillExperienceValues; return this; } @@ -210,7 +207,7 @@ public class PersistentPlayerDataBuilder { return abilityDeactivationTimestamps; } - public @NotNull PersistentPlayerDataBuilder setAbilityDeactivationTimestamps(@NotNull HashMap abilityDeactivationTimestamps) { + public @NotNull MMODataBuilder setAbilityDeactivationTimestamps(@NotNull HashMap abilityDeactivationTimestamps) { this.abilityDeactivationTimestamps = abilityDeactivationTimestamps; return this; } @@ -219,7 +216,7 @@ public class PersistentPlayerDataBuilder { return uniquePlayerData; } - public @NotNull PersistentPlayerDataBuilder setUniquePlayerData(@NotNull EnumMap uniquePlayerData) { + public @NotNull MMODataBuilder setUniquePlayerData(@NotNull EnumMap uniquePlayerData) { this.uniquePlayerData = uniquePlayerData; return this; } @@ -228,12 +225,12 @@ public class PersistentPlayerDataBuilder { return barStateMap; } - public @NotNull PersistentPlayerDataBuilder setBarStateMap(@NotNull Map barStateMap) { + public @NotNull MMODataBuilder setBarStateMap(@NotNull Map barStateMap) { this.barStateMap = barStateMap; return this; } - public @NotNull PersistentPlayerDataBuilder setPartyChatSpying(boolean partyChatSpying) { + public @NotNull MMODataBuilder setPartyChatSpying(boolean partyChatSpying) { this.partyChatSpying = partyChatSpying; return this; } @@ -242,7 +239,7 @@ public class PersistentPlayerDataBuilder { return scoreboardTipsShown; } - public @NotNull PersistentPlayerDataBuilder setScoreboardTipsShown(int scoreboardTipsShown) { + public @NotNull MMODataBuilder setScoreboardTipsShown(int scoreboardTipsShown) { this.scoreboardTipsShown = scoreboardTipsShown; return this; } diff --git a/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java b/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java index 7ba930898..0beb85755 100644 --- a/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java @@ -2,11 +2,7 @@ package com.gmail.nossr50.runnables.player; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.player.McMMOPlayer; -import com.gmail.nossr50.datatypes.player.PersistentPlayerData; -import com.gmail.nossr50.datatypes.player.PersistentPlayerDataBuilder; import com.neetgames.mcmmo.player.MMOPlayerData; -import com.neetgames.mcmmo.player.OnlineMMOPlayer; -import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.runnables.commands.McScoreboardKeepTask;