From 73bc12841a4f9d3983189d4e76644e8846f53f46 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 22 Dec 2020 14:28:23 -0800 Subject: [PATCH] Add Override annotations, remove redundant javadocs --- .../player/PersistentPlayerData.java | 290 +++++------------- 1 file changed, 81 insertions(+), 209 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/PersistentPlayerData.java b/src/main/java/com/gmail/nossr50/datatypes/player/PersistentPlayerData.java index 69ef64024..ec171c039 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/PersistentPlayerData.java +++ b/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 lastLogin; /* Skill Data */ - private final @NotNull DirtyMap skillLevelValues; - private final @NotNull DirtyMap skillExperienceValues; - private final @NotNull DirtyMap abilityDeactivationTimestamps; // Ability & Cooldown + private final @NotNull DirtyMap skillLevelValues; + private final @NotNull DirtyMap skillExperienceValues; + private final @NotNull DirtyMap abilityDeactivationTimestamps; // Ability & Cooldown private final @NotNull DirtyMap uniquePlayerData; //Misc data that doesn't fit into other categories (chimaera wing, etc..) - private final @NotNull DirtyMap barStateMap; + private final @NotNull DirtyMap barStateMap; /* Special Flags */ private final @NotNull DirtyData 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 skillLevelValues, - @NotNull EnumMap skillExperienceValues, - @NotNull EnumMap abilityDeactivationTimestamps, - @NotNull EnumMap uniquePlayerData, - @NotNull EnumMap barStateMap, + @NotNull Map skillLevelValues, + @NotNull Map skillExperienceValues, + @NotNull Map abilityDeactivationTimestamps, + @NotNull Map uniquePlayerData, + @NotNull Map 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 Number> hashMap) throws UnexpectedValueException, Exception { + private void validateRootSkillMap(Map map) throws UnexpectedValueException, Exception { + //TODO: Check for missing/unregistered Validator 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 map) throws UnexpectedValueException, Exception { + //TODO: Check for missing/unregistered + Validator 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); + } + + public void setAbilityDATS(@NotNull SuperSkill superSkill, long DATS) { + abilityDeactivationTimestamps.put(superSkill, (int) (DATS * .001D)); } @Override - public void setAbilityDATS(@NotNull SuperSkill superSkill, long l) { - - } - - /** - * 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. - */ 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 getBarStateMap() { + @Override + public @NotNull Map 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 getDirtyBarStateMap() { + @Override + public @NotNull DirtyMap 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 getDirtySkillLevelMap() { + @Override + public @NotNull DirtyMap 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 getDirtyExperienceValueMap() { + @Override + public @NotNull DirtyMap getDirtyExperienceValueMap() { return skillExperienceValues; } - /** - * Get the {@link DirtyData} for the party chat toggle for this player - * @return the dirty data for the party chat toggle for this player - */ + @Override public @NotNull DirtyData getDirtyPartyChatSpying() { return partyChatSpying; } - /** - * Get the skill level map for this player - * @return the map of skill levels for this player - */ - public @NotNull Map getSkillLevelsMap() { + @Override + public @NotNull Map 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 getSkillsExperienceMap() { + @Override + public @NotNull Map 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 getAbilityDeactivationTimestamps() { + @Override + public @NotNull Map 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 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 copyPrimarySkillLevelsMap() { + @Override + public @NotNull ImmutableMap copyPrimarySkillLevelsMap() { return ImmutableMap.copyOf(getSkillLevelsMap()); } - public ImmutableMap copyPrimarySkillExperienceValuesMap() { + @Override + public @NotNull ImmutableMap copyPrimarySkillExperienceValuesMap() { return ImmutableMap.copyOf(getSkillsExperienceMap()); } }