Add Override annotations, remove redundant javadocs

This commit is contained in:
nossr50 2020-12-22 14:28:23 -08:00
parent 35be5bc17d
commit 73bc12841a

View File

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