Browse Source

Add Override annotations, remove redundant javadocs

nossr50 4 years ago
parent
commit
73bc12841a
1 changed files with 80 additions and 208 deletions
  1. 80 208
      src/main/java/com/gmail/nossr50/datatypes/player/PersistentPlayerData.java

+ 80 - 208
src/main/java/com/gmail/nossr50/datatypes/player/PersistentPlayerData.java

@@ -2,7 +2,6 @@ package com.gmail.nossr50.datatypes.player;
 
 import com.gmail.nossr50.config.AdvancedConfig;
 import com.gmail.nossr50.datatypes.skills.CoreSkillConstants;
-import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
 import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
 import com.gmail.nossr50.datatypes.validation.NonNullRule;
 import com.gmail.nossr50.datatypes.validation.PositiveIntegerRule;
@@ -10,7 +9,6 @@ import com.gmail.nossr50.datatypes.validation.Validator;
 import com.gmail.nossr50.mcMMO;
 import com.gmail.nossr50.util.experience.MMOExperienceBarManager;
 import com.google.common.collect.ImmutableMap;
-import com.neetgames.mcmmo.MobHealthBarType;
 import com.neetgames.mcmmo.UniqueDataType;
 import com.neetgames.mcmmo.exceptions.UnexpectedValueException;
 import com.neetgames.mcmmo.skill.*;
@@ -40,11 +38,11 @@ public class PersistentPlayerData implements MMOPlayerData {
     private final DirtyData<MutableLong> lastLogin;
 
     /* Skill Data */
-    private final @NotNull DirtyMap<SkillIdentity, Integer> skillLevelValues;
-    private final @NotNull DirtyMap<SkillIdentity, Float> skillExperienceValues;
-    private final @NotNull DirtyMap<SkillIdentity, Integer> abilityDeactivationTimestamps; // Ability & Cooldown
+    private final @NotNull DirtyMap<RootSkill, Integer> skillLevelValues;
+    private final @NotNull DirtyMap<RootSkill, Float> skillExperienceValues;
+    private final @NotNull DirtyMap<SuperSkill, Integer> abilityDeactivationTimestamps; // Ability & Cooldown
     private final @NotNull DirtyMap<UniqueDataType, Integer> uniquePlayerData; //Misc data that doesn't fit into other categories (chimaera wing, etc..)
-    private final @NotNull DirtyMap<SkillIdentity, SkillBossBarState> barStateMap;
+    private final @NotNull DirtyMap<RootSkill, SkillBossBarState> barStateMap;
 
     /* Special Flags */
     private final @NotNull DirtyData<MutableBoolean> partyChatSpying;
@@ -76,15 +74,15 @@ public class PersistentPlayerData implements MMOPlayerData {
 
         this.scoreboardTipsShown = new DirtyData<>(new MutableInteger(0), dirtyFlag);
 
-        for(RootSkill rootSkill : mcMMO.p.getSkillRegister().getRootSkills()) {
-            abilityDeactivationTimestamps.put(rootSkill.getSkillIdentity(), 0);
+        for(SuperSkill superSkill : mcMMO.p.getSkillRegister().getSuperSkills()) {
+            abilityDeactivationTimestamps.put(superSkill, 0);
         }
 
         //Core skills
         //TODO: Don't store values for disabled skills
         for(RootSkill rootSkill : CoreSkillConstants.getImmutableCoreRootSkillSet()) {
-            skillLevelValues.put(rootSkill.getSkillIdentity(), AdvancedConfig.getInstance().getStartingLevel());
-            skillExperienceValues.put(rootSkill.getSkillIdentity(), 0F);
+            skillLevelValues.put(rootSkill, AdvancedConfig.getInstance().getStartingLevel());
+            skillExperienceValues.put(rootSkill, 0F);
         }
 
         //Unique Player Data
@@ -115,11 +113,11 @@ public class PersistentPlayerData implements MMOPlayerData {
     public PersistentPlayerData(@NotNull UUID playerUUID,
                                 @NotNull String playerName,
                                 boolean partyChatSpying,
-                                @NotNull EnumMap<PrimarySkillType, Integer> skillLevelValues,
-                                @NotNull EnumMap<PrimarySkillType, Float> skillExperienceValues,
-                                @NotNull EnumMap<SuperAbilityType, Integer> abilityDeactivationTimestamps,
-                                @NotNull EnumMap<UniqueDataType, Integer> uniquePlayerData,
-                                @NotNull EnumMap<PrimarySkillType, SkillBossBarState> barStateMap,
+                                @NotNull Map<RootSkill, Integer> skillLevelValues,
+                                @NotNull Map<RootSkill, Float> skillExperienceValues,
+                                @NotNull Map<SuperSkill, Integer> abilityDeactivationTimestamps,
+                                @NotNull Map<UniqueDataType, Integer> uniquePlayerData,
+                                @NotNull Map<RootSkill, SkillBossBarState> barStateMap,
                                 int scoreboardTipsShown,
                                 long lastLogin,
                                 boolean leaderBoardExclusion) throws Exception {
@@ -129,13 +127,13 @@ public class PersistentPlayerData implements MMOPlayerData {
          */
         this.dirtyFlag = new MutableBoolean(false); //Set this one first
 
-        validateMap(skillLevelValues);
+        validateRootSkillMap(skillLevelValues);
         this.skillLevelValues = new DirtyMap<>(skillLevelValues, dirtyFlag);
 
-        validateMap(skillExperienceValues);
+        validateRootSkillMap(skillExperienceValues);
         this.skillExperienceValues = new DirtyMap<>(skillExperienceValues, dirtyFlag);
 
-        validateMap(abilityDeactivationTimestamps);
+        validateSuperSkillMap(abilityDeactivationTimestamps);
         this.abilityDeactivationTimestamps = new DirtyMap<>(abilityDeactivationTimestamps, dirtyFlag);
 
         this.uniquePlayerData = new DirtyMap<>(uniquePlayerData, dirtyFlag);
@@ -153,44 +151,45 @@ public class PersistentPlayerData implements MMOPlayerData {
     }
 
     /**
-     * Makes sure a target map only contains positive numbers and no null values for its keyset
-     * @param hashMap target map
+     * Checks the map for a few potential logic issues such as negative numbers, or null entries
+     *
+     * @param map target map
      * @throws UnexpectedValueException when values are outside of expected norms
      * @throws Exception when values are outside of expected norms
      */
-    private void validateMap(Map<? extends Enum<?>, ? extends Number> hashMap) throws UnexpectedValueException, Exception {
+    private void validateRootSkillMap(Map<? extends RootSkill, ? extends Number> map) throws UnexpectedValueException, Exception {
+        //TODO: Check for missing/unregistered
         Validator<Number> validator = new Validator<>();
 
         validator.addRule(new PositiveIntegerRule<>());
         validator.addRule(new NonNullRule<>());
 
-        for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
-            validator.validate(hashMap.get(primarySkillType));
+        for(RootSkill rootSkill : mcMMO.p.getSkillRegister().getRootSkills()) {
+            validator.validate(map.get(rootSkill));
         }
     }
 
     /**
-     * Set the level of a Primary Skill for the Player
-     * @param primarySkillType target Primary Skill
-     * @param newSkillLevel the new value of the skill
+     * Checks the map for a few potential logic issues such as negative numbers, or null entries
+     *
+     * @param map target map
+     * @throws UnexpectedValueException when values are outside of expected norms
+     * @throws Exception when values are outside of expected norms
      */
-    @Override
-    public void setSkillLevel(@NotNull SkillIdentity skillIdentity, int newSkillLevel) {
-        skillLevelValues.put(skillIdentity, newSkillLevel);
-    }
+    private void validateSuperSkillMap(Map<? extends SuperSkill, ? extends Number> map) throws UnexpectedValueException, Exception {
+        //TODO: Check for missing/unregistered
+        Validator<Number> validator = new Validator<>();
 
-    /**
-     * Get the skill level the player currently has for target Primary Skill
-     * @param primarySkillType target Primary Skill
-     * @return the current level value of target Primary Skill
-     */
-    public Integer getSkillLevel(PrimarySkillType primarySkillType) {
-        return skillLevelValues.get(primarySkillType);
-    }
+        validator.addRule(new PositiveIntegerRule<>());
+        validator.addRule(new NonNullRule<>());
 
+        for(SuperSkill superSkill : mcMMO.p.getSkillRegister().getSuperSkills()) {
+            validator.validate(map.get(superSkill));
+        }
+    }
     @Override
     public void setSkillLevel(@NotNull RootSkill rootSkill, int i) {
-
+        skillLevelValues.put(rootSkill, i);
     }
 
     @Override
@@ -198,75 +197,35 @@ public class PersistentPlayerData implements MMOPlayerData {
         return 0;
     }
 
-    /**
-     * True if the persistent data has changed state and not yet saved to DB
-     * @return true if data is dirty (not saved)
-     */
+    @Override
     public boolean isDirtyProfile() {
         return dirtyFlag.getImmutableCopy();
     }
 
-    /**
-     * Set the dirty flag back to false
-     * Should be called after saving the player data to avoid unnecessary saves
-     */
+    @Override
     public void resetDirtyFlag() {
         dirtyFlag.setBoolean(false);
     }
 
-    /**
-     * The saved player name for the player associated with this data
-     * @return the saved player name for the player associated with this data
-     */
+    @Override
     public @NotNull String getPlayerName() {
         return playerName.getData().getImmutableCopy();
     }
 
-    /**
-     * The {@link UUID} for the player associated with this data
-     * @return the UUID for the player associated with this data
-     */
+    @Override
     public @NotNull UUID getPlayerUUID() {
         return playerUUID;
     }
 
-    /**
-     * This player's saved mob health bar type
-     * @return the saved mob health bar type for this player
-     */
-    public @NotNull MobHealthBarType getMobHealthBarType() {
-        return mobHealthBarType.getData();
-    }
-
-    /**
-     * Change the mob health bar type for this player
-     * @param mobHealthBarType the new mob health bar type for this player
-     */
-    public void setMobHealthBarType(@NotNull MobHealthBarType mobHealthBarType) {
-        this.mobHealthBarType.setData(mobHealthBarType);
-    }
-
-    /*
-     * Party Chat Spy
-     */
-
-    /**
-     * Whether or not this player is currently spying on all party chat
-     * @return true if this player is spying on party chat
-     */
+    @Override
     public boolean isPartyChatSpying() { return partyChatSpying.getData().getImmutableCopy(); }
 
-    /**
-     * Toggle this player's party chat spying
-     */
+    @Override
     public void togglePartyChatSpying() {
         partyChatSpying.getData().setBoolean(!partyChatSpying.getData().getImmutableCopy());
     }
 
-    /**
-     * Modify whether or not this player is spying on party chat
-     * @param bool the new value of party chat spying (true for spying, false for not spying)
-     */
+    @Override
     public void setPartyChatSpying(boolean bool) {
         this.partyChatSpying.getData().setBoolean(bool);
     }
@@ -275,212 +234,125 @@ public class PersistentPlayerData implements MMOPlayerData {
      * Scoreboards
      */
 
-    /**
-     * The currently tracked number of times scoreboard tips have been viewed for this player
-     * @return the currently tracked number of times scoreboard tips have been viewed for this player
-     */
+    @Override
     public int getScoreboardTipsShown() {
         return scoreboardTipsShown.getData(false).getImmutableCopy();
     }
 
-    /**
-     * Modify the count of how many times scoreboard tips have been displayed to this player
-     * @param newValue the new value
-     */
+    @Override
     public void setScoreboardTipsShown(int newValue) {
         scoreboardTipsShown.getData(true).setInt(newValue);
     }
 
-    /*
-     * Cooldowns
-     */
-
-    /**
-     * The time stamp for the last Chimaera Wing use for this player
-     * @return the Chimaera Wing last use time stamp for this player
-     */
+    @Override
     public int getChimaeraWingDATS() {
         return uniquePlayerData.get((UniqueDataType.CHIMAERA_WING_DATS));
     }
 
-    /**
-     * Set the time stamp for Chimaera Wing's last use for this player
-     * @param DATS the new time stamp
-     */
+    @Override
     public void setChimaeraWingDATS(int DATS) {
         uniquePlayerData.put(UniqueDataType.CHIMAERA_WING_DATS, DATS);
     }
 
-    /**
-     * Change one of the unique data map entries
-     * @param uniqueDataType target unique data
-     * @param newData new unique data value
-     */
+    @Override
     public void setUniqueData(@NotNull UniqueDataType uniqueDataType, int newData) {
         uniquePlayerData.put(uniqueDataType, newData);
     }
 
-    /**
-     * Get the value associated with a specific {@link UniqueDataType}
-     * @param uniqueDataType target unique data
-     * @return associated value of this unique data
-     */
+    @Override
     public long getUniqueData(@NotNull UniqueDataType uniqueDataType) { return uniquePlayerData.get(uniqueDataType); }
 
     @Override
     public long getAbilityDATS(@NotNull SuperSkill superSkill) {
-        return 0;
+        return abilityDeactivationTimestamps.get(superSkill);
     }
 
-    @Override
-    public void setAbilityDATS(@NotNull SuperSkill superSkill, long l) {
-
+    public void setAbilityDATS(@NotNull SuperSkill superSkill, long DATS) {
+        abilityDeactivationTimestamps.put(superSkill, (int) (DATS * .001D));
     }
 
-    /**
-     * Get the current deactivation timestamp of an superAbilityType.
-     *
-     * @param superAbilityType The {@link SuperAbilityType} to get the DATS for
-     * @return the deactivation timestamp for the superAbilityType
-     */
-    public long getAbilityDATS(@NotNull SuperAbilityType superAbilityType) {
-        return abilityDeactivationTimestamps.get(superAbilityType);
-    }
-
-    /**
-     * Set the current deactivation timestamp of an superAbilityType.
-     *
-     * @param superAbilityType The {@link SuperAbilityType} to set the DATS for
-     * @param DATS the DATS of the superAbilityType
-     */
-    public void setAbilityDATS(@NotNull SuperAbilityType superAbilityType, long DATS) {
-        abilityDeactivationTimestamps.put(superAbilityType, (int) (DATS * .001D));
-    }
-
-    /**
-     * Reset all ability cooldowns.
-     */
+    @Override
     public void resetCooldowns() {
         abilityDeactivationTimestamps.replaceAll((a, v) -> 0);
     }
 
-    /**
-     * Get the {@link Map} for the related {@link SkillBossBarState}'s of this player
-     * @return the bar state map for this player
-     */
-    public @NotNull Map<PrimarySkillType, SkillBossBarState> getBarStateMap() {
+    @Override
+    public @NotNull Map<RootSkill, SkillBossBarState> getBarStateMap() {
         return barStateMap;
     }
 
-    /**
-     * Get the {@link DirtyMap} for the related {@link SkillBossBarState}'s of this player
-     * @return the dirty bar state map for this player
-     */
-    public @NotNull DirtyMap<PrimarySkillType, SkillBossBarState> getDirtyBarStateMap() {
+    @Override
+    public @NotNull DirtyMap<RootSkill, SkillBossBarState> getDirtyBarStateMap() {
         return barStateMap;
     }
 
-    /**
-     * Get the {@link DirtyMap} for the skill levels of this player
-     * @return the dirty skill level map for this player
-     */
-    public @NotNull DirtyMap<PrimarySkillType, Integer> getDirtySkillLevelMap() {
+    @Override
+    public @NotNull DirtyMap<RootSkill, Integer> getDirtySkillLevelMap() {
         return skillLevelValues;
     }
 
-    /**
-     * Get the {@link DirtyMap} for the skill experience values of this player
-     * @return the dirty skill experience values map for this player
-     */
-    public @NotNull DirtyMap<PrimarySkillType, Float> getDirtyExperienceValueMap() {
+    @Override
+    public @NotNull DirtyMap<RootSkill, Float> getDirtyExperienceValueMap() {
         return skillExperienceValues;
     }
 
-    /**
-     * Get the {@link DirtyData<MutableBoolean>} for the party chat toggle for this player
-     * @return the dirty data for the party chat toggle for this player
-     */
+    @Override
     public @NotNull DirtyData<MutableBoolean> getDirtyPartyChatSpying() {
         return partyChatSpying;
     }
 
-    /**
-     * Get the skill level map for this player
-     * @return the map of skill levels for this player
-     */
-    public @NotNull Map<PrimarySkillType, Integer> getSkillLevelsMap() {
+    @Override
+    public @NotNull Map<RootSkill, Integer> getSkillLevelsMap() {
         return skillLevelValues;
     }
 
-    /**
-     * Get the map of experience values for skills for this player
-     * @return the experience values map for this player
-     */
-    public @NotNull Map<PrimarySkillType, Float> getSkillsExperienceMap() {
+    @Override
+    public @NotNull Map<RootSkill, Float> getSkillsExperienceMap() {
         return skillExperienceValues;
     }
 
-    /**
-     * Get the map of timestamps representing the last use of abilities for this player
-     * @return the ability deactivation timestamps map for this player
-     */
-    public @NotNull Map<SuperAbilityType, Integer> getAbilityDeactivationTimestamps() {
+    @Override
+    public @NotNull Map<SuperSkill, Integer> getAbilityDeactivationTimestamps() {
         return abilityDeactivationTimestamps;
     }
 
-    /**
-     * Get a map of various unique data for this player
-     * @return a map of unique data for this player
-     */
+    @Override
     public @NotNull Map<UniqueDataType, Integer> getUniquePlayerData() {
         return uniquePlayerData;
     }
 
-    /**
-     * Mark this data as dirty which will flag this data for the next appropriate save
-     * Saves happen periodically, they also can happen on server shutdown and when the player disconnects from the server
-     */
+    @Override
     public void setDirtyProfile() {
         this.dirtyFlag.setBoolean(true);
     }
 
-    /**
-     * The timestamp of when this player last logged in
-     * @return the timestamp of when this player last logged in
-     */
+    @Override
     public long getLastLogin() {
         return lastLogin.getData().getImmutableCopy();
     }
 
-    /**
-     * Set the value of when this player last logged in
-     * @param newValue the new time stamp
-     */
+    @Override
     public void setLastLogin(long newValue) {
         lastLogin.getData().setLong(newValue);
     }
 
-    /**
-     * Whether or not this player is exempt from leader boards
-     * @return true if excluded from leader boards
-     */
+    @Override
     public boolean isLeaderBoardExcluded() {
         return leaderBoardExclusion.getData().getImmutableCopy();
     }
 
-    /**
-     * Set whether or not this player is excluded from leader boards
-     * @param bool new value
-     */
+    @Override
     public void setLeaderBoardExclusion(boolean bool) {
         leaderBoardExclusion.getData(true).setBoolean(bool);
     }
 
-    public ImmutableMap<PrimarySkillType, Integer> copyPrimarySkillLevelsMap() {
+    @Override
+    public @NotNull ImmutableMap<RootSkill, Integer> copyPrimarySkillLevelsMap() {
         return ImmutableMap.copyOf(getSkillLevelsMap());
     }
 
-    public ImmutableMap<PrimarySkillType, Float> copyPrimarySkillExperienceValuesMap() {
+    @Override
+    public @NotNull ImmutableMap<RootSkill, Float> copyPrimarySkillExperienceValuesMap() {
         return ImmutableMap.copyOf(getSkillsExperienceMap());
     }
 }