mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-04 02:53:43 +01:00 
			
		
		
		
	Merge remote-tracking branch 'origin/tridentsxbows' into tridentsxbows
This commit is contained in:
		@@ -1338,7 +1338,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            //Build Data
 | 
					            //Build Data
 | 
				
			||||||
            return playerDataBuilder.build();
 | 
					            return playerDataBuilder.build();
 | 
				
			||||||
        } catch (NullArgumentException e) {
 | 
					        } catch (Exception e) {
 | 
				
			||||||
            mcMMO.p.getLogger().severe("Critical failure when trying to construct persistent player data!");
 | 
					            mcMMO.p.getLogger().severe("Critical failure when trying to construct persistent player data!");
 | 
				
			||||||
            e.printStackTrace();
 | 
					            e.printStackTrace();
 | 
				
			||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,6 @@ import com.neetgames.mcmmo.experience.ExperienceProcessor;
 | 
				
			|||||||
import com.neetgames.mcmmo.experience.XPGainReason;
 | 
					import com.neetgames.mcmmo.experience.XPGainReason;
 | 
				
			||||||
import com.neetgames.mcmmo.experience.XPGainSource;
 | 
					import com.neetgames.mcmmo.experience.XPGainSource;
 | 
				
			||||||
import com.neetgames.mcmmo.party.Party;
 | 
					import com.neetgames.mcmmo.party.Party;
 | 
				
			||||||
import com.neetgames.mcmmo.player.MMOPlayer;
 | 
					 | 
				
			||||||
import org.bukkit.GameMode;
 | 
					import org.bukkit.GameMode;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
import org.jetbrains.annotations.NotNull;
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
@@ -43,7 +42,7 @@ public class OnlineExperienceProcessor implements ExperienceProcessor {
 | 
				
			|||||||
    public int getPowerLevel() {
 | 
					    public int getPowerLevel() {
 | 
				
			||||||
        int powerLevel = 0;
 | 
					        int powerLevel = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Map<PrimarySkillType, Integer> primarySkillTypeLevelMap = mmoPlayerData.getDirtySkillLevelMap().unwrapMap();
 | 
					        Map<PrimarySkillType, Integer> primarySkillTypeLevelMap = mmoPlayerData.getSkillLevelMap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (PrimarySkillType primarySkillType : primarySkillTypeLevelMap.keySet()) {
 | 
					        for (PrimarySkillType primarySkillType : primarySkillTypeLevelMap.keySet()) {
 | 
				
			||||||
            powerLevel += primarySkillTypeLevelMap.get(primarySkillType);
 | 
					            powerLevel += primarySkillTypeLevelMap.get(primarySkillType);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,6 +5,7 @@ import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
 | 
				
			|||||||
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.neetgames.mcmmo.UniqueDataType;
 | 
					import com.neetgames.mcmmo.UniqueDataType;
 | 
				
			||||||
 | 
					import com.neetgames.mcmmo.exceptions.UnexpectedValueException;
 | 
				
			||||||
import com.neetgames.mcmmo.skill.SkillBossBarState;
 | 
					import com.neetgames.mcmmo.skill.SkillBossBarState;
 | 
				
			||||||
import org.apache.commons.lang.NullArgumentException;
 | 
					import org.apache.commons.lang.NullArgumentException;
 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					import org.bukkit.OfflinePlayer;
 | 
				
			||||||
@@ -59,7 +60,7 @@ public class MMODataBuilder {
 | 
				
			|||||||
        return new PlayerData(playerUUID, playerName);
 | 
					        return new PlayerData(playerUUID, playerName);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public PlayerData build() throws NullArgumentException {
 | 
					    public PlayerData build() throws UnexpectedValueException, NullPointerException, NullArgumentException {
 | 
				
			||||||
        if(playerUUID == null)
 | 
					        if(playerUUID == null)
 | 
				
			||||||
            throw new NullArgumentException("playerUUID");
 | 
					            throw new NullArgumentException("playerUUID");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,6 +47,7 @@ import java.util.Map;
 | 
				
			|||||||
import java.util.UUID;
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//TODO: Update javadocs
 | 
					//TODO: Update javadocs
 | 
				
			||||||
 | 
					//TODO: T&C Look over IDE inspection warnings, things have changed
 | 
				
			||||||
public class McMMOPlayer extends PlayerProfile implements OnlineMMOPlayer, Identified {
 | 
					public class McMMOPlayer extends PlayerProfile implements OnlineMMOPlayer, Identified {
 | 
				
			||||||
    private final @NotNull Player player;
 | 
					    private final @NotNull Player player;
 | 
				
			||||||
    private final @NotNull Identity identity;
 | 
					    private final @NotNull Identity identity;
 | 
				
			||||||
@@ -140,8 +141,8 @@ public class McMMOPlayer extends PlayerProfile implements OnlineMMOPlayer, Ident
 | 
				
			|||||||
         * If in the future someone wants to remove this, don't forget to also remove what is in the PrimarySkillType enum. - bm01
 | 
					         * If in the future someone wants to remove this, don't forget to also remove what is in the PrimarySkillType enum. - bm01
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            for (CoreRootSkill coreRootSkill : PrimarySkillType.getCoreRootSkills()) {
 | 
					            for (PrimarySkillType primarySkillType : PrimarySkillType.getCoreRootSkills()) {
 | 
				
			||||||
                skillManagers.put(coreRootSkill, coreRootSkill.getSkillManagerClass().getConstructor(McMMOPlayer.class).newInstance(this));
 | 
					                skillManagers.put(primarySkillType, coreRootSkill.getSkillManagerClass().getConstructor(McMMOPlayer.class).newInstance(this));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        catch (Exception e) {
 | 
					        catch (Exception e) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,16 +7,11 @@ import com.gmail.nossr50.datatypes.validation.NonNullRule;
 | 
				
			|||||||
import com.gmail.nossr50.datatypes.validation.PositiveIntegerRule;
 | 
					import com.gmail.nossr50.datatypes.validation.PositiveIntegerRule;
 | 
				
			||||||
import com.gmail.nossr50.datatypes.validation.Validator;
 | 
					import com.gmail.nossr50.datatypes.validation.Validator;
 | 
				
			||||||
import com.gmail.nossr50.util.experience.MMOExperienceBarManager;
 | 
					import com.gmail.nossr50.util.experience.MMOExperienceBarManager;
 | 
				
			||||||
 | 
					import com.google.common.base.Objects;
 | 
				
			||||||
import com.google.common.collect.ImmutableMap;
 | 
					import com.google.common.collect.ImmutableMap;
 | 
				
			||||||
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.SkillBossBarState;
 | 
					import com.neetgames.mcmmo.skill.SkillBossBarState;
 | 
				
			||||||
import com.neetgames.neetlib.dirtydata.DirtyData;
 | 
					 | 
				
			||||||
import com.neetgames.neetlib.dirtydata.DirtyMap;
 | 
					 | 
				
			||||||
import com.neetgames.neetlib.mutableprimitives.MutableBoolean;
 | 
					 | 
				
			||||||
import com.neetgames.neetlib.mutableprimitives.MutableInteger;
 | 
					 | 
				
			||||||
import com.neetgames.neetlib.mutableprimitives.MutableLong;
 | 
					 | 
				
			||||||
import com.neetgames.neetlib.mutableprimitives.MutableString;
 | 
					 | 
				
			||||||
import org.apache.commons.lang.NullArgumentException;
 | 
					import org.apache.commons.lang.NullArgumentException;
 | 
				
			||||||
import org.jetbrains.annotations.NotNull;
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
import org.jetbrains.annotations.Nullable;
 | 
					import org.jetbrains.annotations.Nullable;
 | 
				
			||||||
@@ -28,28 +23,28 @@ import java.util.UUID;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public class PlayerData {
 | 
					public class PlayerData {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final @NotNull MutableBoolean dirtyFlag; //Dirty values in this class will change this flag as needed
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* Player Stuff */
 | 
					    /* Player Stuff */
 | 
				
			||||||
    private final @NotNull DirtyData<MutableString> playerName;
 | 
					    private @NotNull String playerName;
 | 
				
			||||||
    private final @Nullable UUID playerUUID;
 | 
					    private final @Nullable UUID playerUUID; //TODO: T&C See if this is ever actually null, and if it is maybe we shouldn't allow it to be
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Records */
 | 
					    /* Records */
 | 
				
			||||||
    private final DirtyData<MutableLong> lastLogin;
 | 
					    private long lastLogin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Skill Data */
 | 
					    /* Skill Data */
 | 
				
			||||||
    private final @NotNull DirtyMap<PrimarySkillType, Integer> skillLevelValues;
 | 
					    private final @NotNull Map<PrimarySkillType, Integer> skillLevelValues;
 | 
				
			||||||
    private final @NotNull DirtyMap<PrimarySkillType, Float> skillExperienceValues;
 | 
					    private final @NotNull Map<PrimarySkillType, Float> skillExperienceValues;
 | 
				
			||||||
    private final @NotNull DirtyMap<SuperAbilityType, Integer> abilityDeactivationTimestamps; // Ability & Cooldown
 | 
					    private final @NotNull Map<SuperAbilityType, 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 Map<UniqueDataType, Integer> uniquePlayerData; //Misc data that doesn't fit into other categories (chimaera wing, etc..)
 | 
				
			||||||
    private final @NotNull DirtyMap<PrimarySkillType, SkillBossBarState> barStateMap;
 | 
					    private final @NotNull Map<PrimarySkillType, SkillBossBarState> barStateMap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Special Flags */
 | 
					    /* Special Flags */
 | 
				
			||||||
    private final @NotNull DirtyData<MutableBoolean> partyChatSpying;
 | 
					    private boolean partyChatSpying;
 | 
				
			||||||
    private final @NotNull DirtyData<MutableBoolean> leaderBoardExclusion;
 | 
					    private boolean leaderBoardExclusion;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Scoreboards */
 | 
					    /* Scoreboards */
 | 
				
			||||||
    private final @NotNull DirtyData<MutableInteger> scoreboardTipsShown;
 | 
					    private int scoreboardTipsShown;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private int lastUpdateHash;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Create new persistent player data for a player
 | 
					     * Create new persistent player data for a player
 | 
				
			||||||
@@ -57,22 +52,20 @@ public class PlayerData {
 | 
				
			|||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param playerUUID target player's UUID
 | 
					     * @param playerUUID target player's UUID
 | 
				
			||||||
     * @param playerName target player's name
 | 
					     * @param playerName target player's name
 | 
				
			||||||
     * @throws NullArgumentException thrown when never null arguments are null
 | 
					 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public PlayerData(@Nullable UUID playerUUID, @NotNull String playerName) throws NullArgumentException {
 | 
					    public PlayerData(@Nullable UUID playerUUID, @NotNull String playerName) {
 | 
				
			||||||
        /*
 | 
					        /*
 | 
				
			||||||
         * New Data
 | 
					         * New Data
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        this.dirtyFlag = new MutableBoolean(false); //Set this one first
 | 
					 | 
				
			||||||
        this.playerUUID = playerUUID;
 | 
					        this.playerUUID = playerUUID;
 | 
				
			||||||
        this.playerName = new DirtyData<>(new MutableString(playerName), dirtyFlag);
 | 
					        this.playerName = playerName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.skillLevelValues = new DirtyMap<>(new HashMap<>(), dirtyFlag);
 | 
					        this.skillLevelValues = new HashMap<>();
 | 
				
			||||||
        this.skillExperienceValues = new DirtyMap<>(new HashMap<>(), dirtyFlag);
 | 
					        this.skillExperienceValues = new HashMap<>();
 | 
				
			||||||
        this.abilityDeactivationTimestamps = new DirtyMap<>(new HashMap<>(), dirtyFlag);
 | 
					        this.abilityDeactivationTimestamps = new HashMap<>();
 | 
				
			||||||
        this.uniquePlayerData = new DirtyMap<>(new EnumMap<>(UniqueDataType.class), dirtyFlag);
 | 
					        this.uniquePlayerData = new EnumMap<>(UniqueDataType.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.scoreboardTipsShown = new DirtyData<>(new MutableInteger(0), dirtyFlag);
 | 
					        this.scoreboardTipsShown = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for(SuperAbilityType superSkill : SuperAbilityType.values()) {
 | 
					        for(SuperAbilityType superSkill : SuperAbilityType.values()) {
 | 
				
			||||||
            abilityDeactivationTimestamps.put(superSkill, 0);
 | 
					            abilityDeactivationTimestamps.put(superSkill, 0);
 | 
				
			||||||
@@ -92,11 +85,13 @@ public class PlayerData {
 | 
				
			|||||||
        //Unique Player Data
 | 
					        //Unique Player Data
 | 
				
			||||||
        this.uniquePlayerData.put(UniqueDataType.CHIMAERA_WING_DATS, 0);
 | 
					        this.uniquePlayerData.put(UniqueDataType.CHIMAERA_WING_DATS, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.partyChatSpying = new DirtyData<>(new MutableBoolean(false), dirtyFlag);
 | 
					        this.partyChatSpying = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.barStateMap = new DirtyMap<>(MMOExperienceBarManager.generateDefaultBarStateMap(), dirtyFlag);
 | 
					        this.barStateMap = MMOExperienceBarManager.generateDefaultBarStateMap();
 | 
				
			||||||
        this.lastLogin = new DirtyData<>(new MutableLong(0), dirtyFlag); //Value of 0 will represent that the user hasn't been seen online
 | 
					        this.lastLogin = 0L; //Value of 0 will represent that the user hasn't been seen online
 | 
				
			||||||
        this.leaderBoardExclusion = new DirtyData<>(new MutableBoolean(false), dirtyFlag);
 | 
					        this.leaderBoardExclusion = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.lastUpdateHash = hashCode();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -124,34 +119,32 @@ public class PlayerData {
 | 
				
			|||||||
                      @NotNull Map<PrimarySkillType, SkillBossBarState> barStateMap,
 | 
					                      @NotNull Map<PrimarySkillType, SkillBossBarState> barStateMap,
 | 
				
			||||||
                      int scoreboardTipsShown,
 | 
					                      int scoreboardTipsShown,
 | 
				
			||||||
                      long lastLogin,
 | 
					                      long lastLogin,
 | 
				
			||||||
                      boolean leaderBoardExclusion) throws Exception {
 | 
					                      boolean leaderBoardExclusion) throws UnexpectedValueException, NullPointerException {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /*
 | 
					        /*
 | 
				
			||||||
         * Skills Data
 | 
					         * Skills Data
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        this.dirtyFlag = new MutableBoolean(false); //Set this one first
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        validateRootSkillMap(skillLevelValues);
 | 
					        validateRootSkillMap(skillLevelValues);
 | 
				
			||||||
        this.skillLevelValues = new DirtyMap<>(skillLevelValues, dirtyFlag);
 | 
					        this.skillLevelValues = skillLevelValues;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        validateRootSkillMap(skillExperienceValues);
 | 
					        validateRootSkillMap(skillExperienceValues);
 | 
				
			||||||
        this.skillExperienceValues = new DirtyMap<>(skillExperienceValues, dirtyFlag);
 | 
					        this.skillExperienceValues = skillExperienceValues;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        validateSuperSkillMap(abilityDeactivationTimestamps);
 | 
					        validateSuperSkillMap(abilityDeactivationTimestamps);
 | 
				
			||||||
        this.abilityDeactivationTimestamps = new DirtyMap<>(abilityDeactivationTimestamps, dirtyFlag);
 | 
					        this.abilityDeactivationTimestamps = abilityDeactivationTimestamps;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.uniquePlayerData = new DirtyMap<>(uniquePlayerData, dirtyFlag);
 | 
					        this.uniquePlayerData = uniquePlayerData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.scoreboardTipsShown = new DirtyData<>(new MutableInteger(scoreboardTipsShown), dirtyFlag);
 | 
					        this.scoreboardTipsShown = scoreboardTipsShown;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.playerUUID = playerUUID;
 | 
					        this.playerUUID = playerUUID;
 | 
				
			||||||
        this.playerName = new DirtyData<>(new MutableString(playerName), dirtyFlag);
 | 
					        this.playerName = playerName;
 | 
				
			||||||
        this.barStateMap = new DirtyMap<>(barStateMap, dirtyFlag);
 | 
					        this.barStateMap = barStateMap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.partyChatSpying = new DirtyData<>(new MutableBoolean(partyChatSpying), dirtyFlag);
 | 
					        this.partyChatSpying = partyChatSpying;
 | 
				
			||||||
        this.lastLogin = new DirtyData<>(new MutableLong(lastLogin), dirtyFlag);
 | 
					        this.lastLogin = lastLogin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.leaderBoardExclusion = new DirtyData<>(new MutableBoolean(leaderBoardExclusion), dirtyFlag);
 | 
					        this.leaderBoardExclusion = leaderBoardExclusion;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -159,20 +152,30 @@ public class PlayerData {
 | 
				
			|||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param map 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
 | 
					 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private void validateRootSkillMap(Map<PrimarySkillType, ? extends Number> map) throws UnexpectedValueException, Exception {
 | 
					    private void validateRootSkillMap(Map<PrimarySkillType, ? extends Number> map) throws UnexpectedValueException, NullPointerException {
 | 
				
			||||||
        //TODO: Check for missing/unregistered
 | 
					        //TODO: Check for missing/unregistered
 | 
				
			||||||
        Validator<Number> validator = new Validator<>();
 | 
					        Validator<Number> positiveValidator = new Validator<>();
 | 
				
			||||||
 | 
					        Validator<Number> nullValidator = new Validator<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        validator.addRule(new PositiveIntegerRule<>());
 | 
					        positiveValidator.addRule(new PositiveIntegerRule<>());
 | 
				
			||||||
        validator.addRule(new NonNullRule<>());
 | 
					        nullValidator.addRule(new NonNullRule<>());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
 | 
					        for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
 | 
				
			||||||
            if(primarySkillType.isChildSkill())
 | 
					            if(primarySkillType.isChildSkill())
 | 
				
			||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
            
 | 
					
 | 
				
			||||||
            validator.validate(map.get(primarySkillType));
 | 
					            try {
 | 
				
			||||||
 | 
					                positiveValidator.validate(map.get(primarySkillType));
 | 
				
			||||||
 | 
					            } catch (Exception e) {
 | 
				
			||||||
 | 
					                throw new UnexpectedValueException();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                nullValidator.validate(map.get(primarySkillType));
 | 
				
			||||||
 | 
					            } catch (Exception e) {
 | 
				
			||||||
 | 
					                throw new NullPointerException();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -183,7 +186,7 @@ public class PlayerData {
 | 
				
			|||||||
     * @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 validateSuperSkillMap(Map<? extends SuperAbilityType, ? extends Number> map) throws UnexpectedValueException, Exception {
 | 
					    private void validateSuperSkillMap(Map<? extends SuperAbilityType, ? extends Number> map) throws UnexpectedValueException, NullPointerException {
 | 
				
			||||||
        //TODO: Check for missing/unregistered
 | 
					        //TODO: Check for missing/unregistered
 | 
				
			||||||
        Validator<Number> validator = new Validator<>();
 | 
					        Validator<Number> validator = new Validator<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -191,7 +194,11 @@ public class PlayerData {
 | 
				
			|||||||
        validator.addRule(new NonNullRule<>());
 | 
					        validator.addRule(new NonNullRule<>());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for(SuperAbilityType superSkill : SuperAbilityType.values()) {
 | 
					        for(SuperAbilityType superSkill : SuperAbilityType.values()) {
 | 
				
			||||||
            validator.validate(map.get(superSkill));
 | 
					            try {
 | 
				
			||||||
 | 
					                validator.validate(map.get(superSkill));
 | 
				
			||||||
 | 
					            } catch (Exception e) {
 | 
				
			||||||
 | 
					                throw new UnexpectedValueException();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@@ -204,30 +211,31 @@ public class PlayerData {
 | 
				
			|||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public boolean isDirtyProfile() {
 | 
					    public boolean isProfileDirty() {
 | 
				
			||||||
        return dirtyFlag.getImmutableCopy();
 | 
					        return lastUpdateHash != hashCode();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //TODO: T&C this needs to be called or pointless save operations won't be avoided
 | 
				
			||||||
    public void resetDirtyFlag() {
 | 
					    public void resetDirtyFlag() {
 | 
				
			||||||
        dirtyFlag.setBoolean(false);
 | 
					        lastUpdateHash = hashCode();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public @NotNull String getPlayerName() {
 | 
					    public @NotNull String getPlayerName() {
 | 
				
			||||||
        return playerName.getData().getImmutableCopy();
 | 
					        return playerName;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public @NotNull UUID getPlayerUUID() {
 | 
					    public @Nullable UUID getPlayerUUID() {
 | 
				
			||||||
        return playerUUID;
 | 
					        return playerUUID;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public boolean isPartyChatSpying() { return partyChatSpying.getData().getImmutableCopy(); }
 | 
					    public boolean isPartyChatSpying() { return partyChatSpying; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void togglePartyChatSpying() {
 | 
					    public void togglePartyChatSpying() {
 | 
				
			||||||
        partyChatSpying.getData().setBoolean(!partyChatSpying.getData().getImmutableCopy());
 | 
					        partyChatSpying = !partyChatSpying;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void setPartyChatSpying(boolean bool) {
 | 
					    public void setPartyChatSpying(boolean bool) {
 | 
				
			||||||
        this.partyChatSpying.getData().setBoolean(bool);
 | 
					        this.partyChatSpying = bool;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
@@ -235,11 +243,11 @@ public class PlayerData {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public int getScoreboardTipsShown() {
 | 
					    public int getScoreboardTipsShown() {
 | 
				
			||||||
        return scoreboardTipsShown.getData(false).getImmutableCopy();
 | 
					        return scoreboardTipsShown;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void setScoreboardTipsShown(int newValue) {
 | 
					    public void setScoreboardTipsShown(int newValue) {
 | 
				
			||||||
        scoreboardTipsShown.getData(true).setInt(newValue);
 | 
					        this.scoreboardTipsShown = newValue;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public int getChimaeraWingDATS() {
 | 
					    public int getChimaeraWingDATS() {
 | 
				
			||||||
@@ -273,22 +281,6 @@ public class PlayerData {
 | 
				
			|||||||
        return barStateMap;
 | 
					        return barStateMap;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public @NotNull DirtyMap<PrimarySkillType, SkillBossBarState> getDirtyBarStateMap() {
 | 
					 | 
				
			||||||
        return barStateMap;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public @NotNull DirtyMap<PrimarySkillType, Integer> getDirtySkillLevelMap() {
 | 
					 | 
				
			||||||
        return skillLevelValues;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public @NotNull DirtyMap<PrimarySkillType, Float> getDirtyExperienceValueMap() {
 | 
					 | 
				
			||||||
        return skillExperienceValues;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public @NotNull DirtyData<MutableBoolean> getDirtyPartyChatSpying() {
 | 
					 | 
				
			||||||
        return partyChatSpying;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public @NotNull Map<PrimarySkillType, Integer> getSkillLevelsMap() {
 | 
					    public @NotNull Map<PrimarySkillType, Integer> getSkillLevelsMap() {
 | 
				
			||||||
        return skillLevelValues;
 | 
					        return skillLevelValues;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -305,24 +297,20 @@ public class PlayerData {
 | 
				
			|||||||
        return uniquePlayerData;
 | 
					        return uniquePlayerData;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void setDirtyProfile() {
 | 
					 | 
				
			||||||
        this.dirtyFlag.setBoolean(true);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public long getLastLogin() {
 | 
					    public long getLastLogin() {
 | 
				
			||||||
        return lastLogin.getData().getImmutableCopy();
 | 
					        return lastLogin;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void setLastLogin(long newValue) {
 | 
					    public void setLastLogin(long newValue) {
 | 
				
			||||||
        lastLogin.getData().setLong(newValue);
 | 
					        this.lastLogin = newValue;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public boolean isLeaderBoardExcluded() {
 | 
					    public boolean isLeaderBoardExcluded() {
 | 
				
			||||||
        return leaderBoardExclusion.getData().getImmutableCopy();
 | 
					        return leaderBoardExclusion;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void setLeaderBoardExclusion(boolean bool) {
 | 
					    public void setLeaderBoardExclusion(boolean bool) {
 | 
				
			||||||
        leaderBoardExclusion.getData(true).setBoolean(bool);
 | 
					        this.leaderBoardExclusion = bool;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public @NotNull ImmutableMap<PrimarySkillType, Integer> copyPrimarySkillLevelsMap() {
 | 
					    public @NotNull ImmutableMap<PrimarySkillType, Integer> copyPrimarySkillLevelsMap() {
 | 
				
			||||||
@@ -332,4 +320,26 @@ public class PlayerData {
 | 
				
			|||||||
    public @NotNull ImmutableMap<PrimarySkillType, Float> copyPrimarySkillExperienceValuesMap() {
 | 
					    public @NotNull ImmutableMap<PrimarySkillType, Float> copyPrimarySkillExperienceValuesMap() {
 | 
				
			||||||
        return ImmutableMap.copyOf(getSkillsExperienceMap());
 | 
					        return ImmutableMap.copyOf(getSkillsExperienceMap());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean equals(Object o) {
 | 
				
			||||||
 | 
					        if (this == o) return true;
 | 
				
			||||||
 | 
					        if (o == null || getClass() != o.getClass()) return false;
 | 
				
			||||||
 | 
					        PlayerData that = (PlayerData) o;
 | 
				
			||||||
 | 
					        return lastLogin == that.lastLogin
 | 
				
			||||||
 | 
					                && partyChatSpying == that.partyChatSpying
 | 
				
			||||||
 | 
					                && leaderBoardExclusion == that.leaderBoardExclusion
 | 
				
			||||||
 | 
					                && scoreboardTipsShown == that.scoreboardTipsShown
 | 
				
			||||||
 | 
					                && Objects.equal(playerName, that.playerName)
 | 
				
			||||||
 | 
					                && Objects.equal(playerUUID, that.playerUUID)
 | 
				
			||||||
 | 
					                && Objects.equal(skillLevelValues, that.skillLevelValues)
 | 
				
			||||||
 | 
					                && Objects.equal(skillExperienceValues, that.skillExperienceValues)
 | 
				
			||||||
 | 
					                && Objects.equal(abilityDeactivationTimestamps, that.abilityDeactivationTimestamps)
 | 
				
			||||||
 | 
					                && Objects.equal(uniquePlayerData, that.uniquePlayerData) && Objects.equal(barStateMap, that.barStateMap);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int hashCode() {
 | 
				
			||||||
 | 
					        return Objects.hashCode(playerName, playerUUID, lastLogin, skillLevelValues, skillExperienceValues, abilityDeactivationTimestamps, uniquePlayerData, barStateMap, partyChatSpying, leaderBoardExclusion, scoreboardTipsShown);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import java.util.UUID;
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//TODO: T&C update javadocs?
 | 
				
			||||||
public class PlayerProfile extends AbstractMMOPlayer {
 | 
					public class PlayerProfile extends AbstractMMOPlayer {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,7 @@ package com.gmail.nossr50.datatypes.validation;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public class NonNullRule<T> extends Rule<T> {
 | 
					public class NonNullRule<T> extends Rule<T> {
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void applyRule(T object) throws Exception {
 | 
					    public void applyRule(T object) throws NullPointerException {
 | 
				
			||||||
        if(object == null)
 | 
					        if(object == null)
 | 
				
			||||||
            throw new NullPointerException();
 | 
					            throw new NullPointerException();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,10 +1,10 @@
 | 
				
			|||||||
package com.gmail.nossr50.datatypes.validation;
 | 
					package com.gmail.nossr50.datatypes.validation;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.gmail.nossr50.api.exceptions.UnexpectedValueException;
 | 
					import com.neetgames.mcmmo.exceptions.UnexpectedValueException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class PositiveIntegerRule<T extends Number> extends Rule<T> {
 | 
					public class PositiveIntegerRule<T extends Number> extends Rule<T> {
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void applyRule(T number) throws Exception {
 | 
					    public void applyRule(T number) throws UnexpectedValueException {
 | 
				
			||||||
        if(number.intValue() < 0)
 | 
					        if(number.intValue() < 0)
 | 
				
			||||||
            throw new UnexpectedValueException();
 | 
					            throw new UnexpectedValueException();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,58 +1,7 @@
 | 
				
			|||||||
package com.gmail.nossr50.party;
 | 
					package com.gmail.nossr50.party;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.common.base.Objects;
 | 
					 | 
				
			||||||
import com.neetgames.mcmmo.party.PartyMember;
 | 
					 | 
				
			||||||
import com.neetgames.neetlib.dirtydata.DirtyData;
 | 
					 | 
				
			||||||
import com.neetgames.neetlib.dirtydata.DirtySet;
 | 
					 | 
				
			||||||
import com.neetgames.neetlib.mutableprimitives.MutableBoolean;
 | 
					 | 
				
			||||||
import com.neetgames.neetlib.mutableprimitives.MutableString;
 | 
					 | 
				
			||||||
import org.jetbrains.annotations.NotNull;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.HashSet;
 | 
					 | 
				
			||||||
import java.util.Set;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class PersistentPartyData {
 | 
					public class PersistentPartyData {
 | 
				
			||||||
 | 
					    private int hashCodeCache; //TODO: T&C wire this up later, see PlayerData for example
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final @NotNull MutableBoolean dirtyFlag; //Dirty values in this class will change this flag as needed
 | 
					 | 
				
			||||||
    private final @NotNull DirtyData<MutableString> partyName;
 | 
					 | 
				
			||||||
    private final @NotNull DirtySet<PartyMember> partyMembers; //TODO: Add cache for subsets
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public PersistentPartyData(@NotNull String partyName, @NotNull Set<PartyMember> partyMembers) throws RuntimeException {
 | 
					 | 
				
			||||||
        dirtyFlag = new MutableBoolean(false);
 | 
					 | 
				
			||||||
        this.partyName = new DirtyData<>(new MutableString(partyName), dirtyFlag);
 | 
					 | 
				
			||||||
        this.partyMembers = new DirtySet<>(new HashSet<>(partyMembers), dirtyFlag);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public @NotNull String getPartyName() {
 | 
					 | 
				
			||||||
        return partyName.getData().getImmutableCopy();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public @NotNull Set<PartyMember> getPartyMembers() {
 | 
					 | 
				
			||||||
        return partyMembers;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean isDataDirty() {
 | 
					 | 
				
			||||||
        return dirtyFlag.getImmutableCopy();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String toString() {
 | 
					 | 
				
			||||||
        return "PersistentPartyData{" +
 | 
					 | 
				
			||||||
                "partyName=" + partyName +
 | 
					 | 
				
			||||||
                ", partyMembers=" + partyMembers +
 | 
					 | 
				
			||||||
                '}';
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean equals(Object o) {
 | 
					 | 
				
			||||||
        if (this == o) return true;
 | 
					 | 
				
			||||||
        if (o == null || getClass() != o.getClass()) return false;
 | 
					 | 
				
			||||||
        PersistentPartyData that = (PersistentPartyData) o;
 | 
					 | 
				
			||||||
        return Objects.equal(partyName, that.partyName) && Objects.equal(partyMembers, that.partyMembers);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int hashCode() {
 | 
					 | 
				
			||||||
        return Objects.hashCode(partyName, partyMembers);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,7 +44,7 @@ public class PlayerSaveHandler {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public void save(@NotNull PlayerData playerData, boolean useSync) {
 | 
					    public void save(@NotNull PlayerData playerData, boolean useSync) {
 | 
				
			||||||
        //TODO: We no longer check if a profile is loaded or not as it should never be unloaded if a save operation is being called, need to double check this to be true
 | 
					        //TODO: We no longer check if a profile is loaded or not as it should never be unloaded if a save operation is being called, need to double check this to be true
 | 
				
			||||||
        if(!playerData.isDirtyProfile()) {
 | 
					        if(!playerData.isProfileDirty()) {
 | 
				
			||||||
            return; //Don't save data that hasn't changed
 | 
					            return; //Don't save data that hasn't changed
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user