More work on Skill API migration

This commit is contained in:
nossr50 2020-12-17 16:22:22 -08:00
parent abcf6413f5
commit 573d9d014e
13 changed files with 273 additions and 179 deletions

View File

@ -492,7 +492,7 @@ public final class ExperienceAPI {
* @throws UnsupportedOperationException if the given skill is a child skill * @throws UnsupportedOperationException if the given skill is a child skill
*/ */
public static int getXPToNextLevel(Player player, String skillType) { public static int getXPToNextLevel(Player player, String skillType) {
return getPlayer(player).getExperienceManager().getXpToLevel(getNonChildSkillType(skillType)); return getPlayer(player).getExperienceManager().getExperienceToNextLevel(getNonChildSkillType(skillType));
} }
/** /**
@ -510,7 +510,7 @@ public final class ExperienceAPI {
*/ */
@Deprecated @Deprecated
public static int getOfflineXPToNextLevel(String playerName, String skillType) { public static int getOfflineXPToNextLevel(String playerName, String skillType) {
return getOfflineProfile(playerName).getExperienceManager().getXpToLevel(getNonChildSkillType(skillType)); return getOfflineProfile(playerName).getExperienceManager().getExperienceToNextLevel(getNonChildSkillType(skillType));
} }
/** /**
@ -527,7 +527,7 @@ public final class ExperienceAPI {
* @throws UnsupportedOperationException if the given skill is a child skill * @throws UnsupportedOperationException if the given skill is a child skill
*/ */
public static int getOfflineXPToNextLevel(UUID uuid, String skillType) { public static int getOfflineXPToNextLevel(UUID uuid, String skillType) {
return getOfflineProfile(uuid).getExperienceManager().getXpToLevel(getNonChildSkillType(skillType)); return getOfflineProfile(uuid).getExperienceManager().getExperienceToNextLevel(getNonChildSkillType(skillType));
} }
/** /**
@ -547,7 +547,7 @@ public final class ExperienceAPI {
PlayerProfile profile = getPlayer(player); PlayerProfile profile = getPlayer(player);
return profile.getExperienceManager().getXpToLevel(skill) - profile.getExperienceManager().getSkillXpValue(skill); return profile.getExperienceManager().getExperienceToNextLevel(skill) - profile.getExperienceManager().getSkillXpValue(skill);
} }
/** /**
@ -568,7 +568,7 @@ public final class ExperienceAPI {
PrimarySkillType skill = getNonChildSkillType(skillType); PrimarySkillType skill = getNonChildSkillType(skillType);
PlayerProfile profile = getOfflineProfile(playerName); PlayerProfile profile = getOfflineProfile(playerName);
return profile.getExperienceManager().getXpToLevel(skill) - profile.getExperienceManager().getSkillXpValue(skill); return profile.getExperienceManager().getExperienceToNextLevel(skill) - profile.getExperienceManager().getSkillXpValue(skill);
} }
/** /**
@ -588,7 +588,7 @@ public final class ExperienceAPI {
PrimarySkillType skill = getNonChildSkillType(skillType); PrimarySkillType skill = getNonChildSkillType(skillType);
PlayerProfile profile = getOfflineProfile(uuid); PlayerProfile profile = getOfflineProfile(uuid);
return profile.getExperienceManager().getXpToLevel(skill) - profile.getExperienceManager().getSkillXpLevelRaw(skill); return profile.getExperienceManager().getExperienceToNextLevel(skill) - profile.getExperienceManager().getSkillXpLevelRaw(skill);
} }
/** /**

View File

@ -153,7 +153,7 @@ public abstract class SkillCommand implements TabExecutor {
mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.XPGain.Overhaul", LocaleLoader.getString("Commands.XPGain." + StringUtils.getCapitalized(skill.toString())))); mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.XPGain.Overhaul", LocaleLoader.getString("Commands.XPGain." + StringUtils.getCapitalized(skill.toString()))));
//LEVEL //LEVEL
mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Effects.Level.Overhaul", skillValue, mmoPlayer.getExperienceManager().getSkillXpValue(skill), mmoPlayer.getExperienceManager().getXpToLevel(skill))); mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Effects.Level.Overhaul", skillValue, mmoPlayer.getExperienceManager().getSkillXpValue(skill), mmoPlayer.getExperienceManager().getExperienceToNextLevel(skill)));
} else { } else {
/* /*

View File

@ -6,9 +6,11 @@ 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.util.text.StringUtils; import com.gmail.nossr50.util.text.StringUtils;
import com.neetgames.mcmmo.MobHealthBarType; import com.neetgames.mcmmo.MobHealthBarType;
import com.neetgames.mcmmo.skill.SkillIdentity;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -549,8 +551,8 @@ public class Config extends AutoUpdateConfigLoader {
return (cap <= 0) ? Integer.MAX_VALUE : cap; return (cap <= 0) ? Integer.MAX_VALUE : cap;
} }
public int getLevelCap(PrimarySkillType skill) { public int getLevelCap(@NotNull SkillIdentity skillIdentity) {
int cap = config.getInt("Skills." + StringUtils.getCapitalized(skill.toString()) + ".Level_Cap", 0); int cap = config.getInt("Skills." + StringUtils.getCapitalized(skillIdentity.getSkillName()) + ".Level_Cap", 0);
return (cap <= 0) ? Integer.MAX_VALUE : cap; return (cap <= 0) ? Integer.MAX_VALUE : cap;
} }

View File

@ -5,6 +5,7 @@ import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PersistentPlayerData; import com.gmail.nossr50.datatypes.player.PersistentPlayerData;
import com.gmail.nossr50.datatypes.skills.CoreSkillConstants;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.ShareHandler; import com.gmail.nossr50.party.ShareHandler;
@ -15,7 +16,8 @@ import com.gmail.nossr50.util.player.NotificationManager;
import com.gmail.nossr50.util.skills.PerksUtils; import com.gmail.nossr50.util.skills.PerksUtils;
import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType; import com.gmail.nossr50.util.sounds.SoundType;
import org.apache.commons.lang.Validate; import com.neetgames.mcmmo.exceptions.UnknownSkillException;
import com.neetgames.mcmmo.skill.SkillIdentity;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -67,30 +69,30 @@ public class ExperienceManager {
/** /**
* Get the value of XP a player has accumulated in target skill * Get the value of XP a player has accumulated in target skill
* Child Skills will return 0 (Child Skills will be removed in a future update) * Child Skills will return 0 (Child Skills will be removed in a future update)
* @param primarySkillType target skill * @param skillIdentity target skill
* @return the value for XP the player has accumulated in target skill * @return the value for XP the player has accumulated in target skill
*/ */
public int getSkillXpValue(@NotNull PrimarySkillType primarySkillType) { public int getSkillXpValue(@NotNull SkillIdentity skillIdentity) {
if(primarySkillType.isChildSkill()) { if(CoreSkillConstants.isChildSkill(skillIdentity)) {
return 0; return 0;
} }
return (int) Math.floor(getSkillXpLevelRaw(primarySkillType)); return (int) Math.floor(getSkillXpLevelRaw(skillIdentity));
} }
public void setSkillXpValue(@NotNull PrimarySkillType primarySkillType, float xpLevel) { public void setSkillXpValue(@NotNull SkillIdentity skillIdentity, float xpLevel) {
if (primarySkillType.isChildSkill()) { if (CoreSkillConstants.isChildSkill(skillIdentity)) {
return; return;
} }
persistentPlayerDataRef.getSkillsExperienceMap().put(primarySkillType, xpLevel); persistentPlayerDataRef.getSkillsExperienceMap().put(skillIdentity, xpLevel);
} }
public float levelUp(@NotNull PrimarySkillType primarySkillType) { public float levelUp(@NotNull SkillIdentity skillIdentity) {
float xpRemoved = getXpToLevel(primarySkillType); float xpRemoved = getExperienceToNextLevel(skillIdentity);
setSkillLevel(primarySkillType, getSkillLevel(primarySkillType) + 1); setSkillLevel(skillIdentity, getSkillLevel(skillIdentity) + 1);
setSkillXpValue(primarySkillType, getSkillXpValue(primarySkillType) - xpRemoved); setSkillXpValue(skillIdentity, getSkillXpValue(skillIdentity) - xpRemoved);
return xpRemoved; return xpRemoved;
} }
@ -99,14 +101,14 @@ public class ExperienceManager {
* Whether or not a player is level capped * Whether or not a player is level capped
* If they are at the power level cap, this will return true, otherwise it checks their skill level * If they are at the power level cap, this will return true, otherwise it checks their skill level
* *
* @param primarySkillType * @param skillIdentity
* @return * @return
*/ */
public boolean hasReachedLevelCap(@NotNull PrimarySkillType primarySkillType) { public boolean hasReachedLevelCap(@NotNull SkillIdentity skillIdentity) {
if(hasReachedPowerLevelCap()) if(hasReachedPowerLevelCap())
return true; return true;
return getSkillLevel(primarySkillType) >= Config.getInstance().getLevelCap(primarySkillType); return getSkillLevel(skillIdentity) >= Config.getInstance().getLevelCap(skillIdentity);
} }
/** /**
@ -119,21 +121,21 @@ public class ExperienceManager {
} }
/** /**
* Begins an experience gain. The amount will be affected by primarySkillType modifiers, global rate, perks, and may be shared with the party * Begins an experience gain. The amount will be affected by skill modifiers, global rate, perks, and may be shared with the party
* *
* @param primarySkillType Skill being used * @param skillIdentity Skill being used
* @param xp Experience amount to process * @param xp Experience amount to process
*/ */
public void beginXpGain(@NotNull PrimarySkillType primarySkillType, float xp, @NotNull XPGainReason xpGainReason, @NotNull XPGainSource xpGainSource) { public void beginXpGain(@NotNull SkillIdentity skillIdentity, float xp, @NotNull XPGainReason xpGainReason, @NotNull XPGainSource xpGainSource) {
if (xp <= 0.0) { if (xp <= 0.0) {
return; return;
} }
if (primarySkillType.isChildSkill()) { if (CoreSkillConstants.isChildSkill(skillIdentity)) {
Set<PrimarySkillType> parentSkills = FamilyTree.getParents(primarySkillType); Set<SkillIdentity> parentSkills = FamilyTree.getParentSkills(skillIdentity);
float splitXp = xp / parentSkills.size(); float splitXp = xp / parentSkills.size();
for (PrimarySkillType parentSkill : parentSkills) { for (SkillIdentity parentSkill : parentSkills) {
beginXpGain(parentSkill, splitXp, xpGainReason, xpGainSource); beginXpGain(parentSkill, splitXp, xpGainReason, xpGainSource);
} }
@ -143,61 +145,61 @@ public class ExperienceManager {
//TODO: The logic here is so stupid... rewrite later //TODO: The logic here is so stupid... rewrite later
// Return if the experience has been shared // Return if the experience has been shared
if (mmoPlayer.getParty() != null && ShareHandler.handleXpShare(xp, mmoPlayer, mmoPlayer.getParty(), primarySkillType, ShareHandler.getSharedXpGainReason(xpGainReason))) { if (mmoPlayer.getParty() != null && ShareHandler.handleXpShare(xp, mmoPlayer, mmoPlayer.getParty(), skillIdentity, ShareHandler.getSharedXpGainReason(xpGainReason))) {
return; return;
} }
beginUnsharedXpGain(primarySkillType, xp, xpGainReason, xpGainSource); beginUnsharedXpGain(skillIdentity, xp, xpGainReason, xpGainSource);
} }
/** /**
* Begins an experience gain. The amount will be affected by primarySkillType modifiers, global rate and perks * Begins an experience gain. The amount will be affected by skill modifiers, global rate and perks
* *
* @param primarySkillType Skill being used * @param skillIdentity Skill being used
* @param xp Experience amount to process * @param xp Experience amount to process
*/ */
public void beginUnsharedXpGain(@NotNull PrimarySkillType primarySkillType, float xp, @NotNull XPGainReason xpGainReason, @NotNull XPGainSource xpGainSource) { public void beginUnsharedXpGain(@NotNull SkillIdentity skillIdentity, float xp, @NotNull XPGainReason xpGainReason, @NotNull XPGainSource xpGainSource) {
if(mmoPlayer.getPlayer().getGameMode() == GameMode.CREATIVE) if(mmoPlayer.getPlayer().getGameMode() == GameMode.CREATIVE)
return; return;
ExperienceUtils.applyXpGain(mmoPlayer, primarySkillType, modifyXpGain(primarySkillType, xp), xpGainReason, xpGainSource); ExperienceUtils.applyXpGain(mmoPlayer, skillIdentity, modifyXpGain(skillIdentity, xp), xpGainReason, xpGainSource);
Party party = mmoPlayer.getParty(); Party party = mmoPlayer.getParty();
if (party != null) { if (party != null) {
if (!Config.getInstance().getPartyXpNearMembersNeeded() || !mcMMO.getPartyManager().getNearMembers(mmoPlayer).isEmpty()) { if (!Config.getInstance().getPartyXpNearMembersNeeded() || !mcMMO.getPartyManager().getNearMembers(mmoPlayer).isEmpty()) {
party.getPartyExperienceManager().applyXpGain(modifyXpGain(primarySkillType, xp)); party.getPartyExperienceManager().applyXpGain(modifyXpGain(skillIdentity, xp));
} }
} }
} }
public int getSkillLevel(@NotNull PrimarySkillType skill) { public int getSkillLevel(@NotNull SkillIdentity skillIdentity) {
return skill.isChildSkill() ? getChildSkillLevel(skill) : getSkillLevel(skill); return CoreSkillConstants.isChildSkill(skillIdentity) ? getChildSkillLevel(skillIdentity) : getSkillLevel(skillIdentity);
} }
/** /**
* Get the amount of Xp remaining before the next level. * Get the amount of Xp remaining before the next level.
* *
* @param primarySkillType Type of skill to check * @param skillIdentity Type of skill to check
* @return the total amount of Xp until next level * @return the total amount of Xp until next level
*/ */
public int getXpToLevel(@NotNull PrimarySkillType primarySkillType) { public int getExperienceToNextLevel(@NotNull SkillIdentity skillIdentity) {
if(primarySkillType.isChildSkill()) { if(CoreSkillConstants.isChildSkill(skillIdentity)) {
return 0; return 0;
} }
int level = (ExperienceConfig.getInstance().getCumulativeCurveEnabled()) ? getPowerLevel() : getSkillLevel(primarySkillType); int level = (ExperienceConfig.getInstance().getCumulativeCurveEnabled()) ? getPowerLevel() : getSkillLevel(skillIdentity);
FormulaType formulaType = ExperienceConfig.getInstance().getFormulaType(); FormulaType formulaType = ExperienceConfig.getInstance().getFormulaType();
return mcMMO.getFormulaManager().getXPtoNextLevel(level, formulaType); return mcMMO.getFormulaManager().getXPtoNextLevel(level, formulaType);
} }
private int getChildSkillLevel(@NotNull PrimarySkillType primarySkillType) { private int getChildSkillLevel(@NotNull SkillIdentity skillIdentity) {
Set<PrimarySkillType> parents = FamilyTree.getParents(primarySkillType); Set<SkillIdentity> parents = FamilyTree.getParentSkills(skillIdentity);
int sum = 0; int sum = 0;
for (PrimarySkillType parent : parents) { for (SkillIdentity parentIdentity : parents) {
sum += Math.min(getSkillLevel(parent), parent.getMaxLevel()); sum += getSkillLevel(parentIdentity);
} }
return sum / parents.size(); return sum / parents.size();
@ -320,28 +322,28 @@ public class ExperienceManager {
/** /**
* Modifies an experience gain using skill modifiers, global rate and perks * Modifies an experience gain using skill modifiers, global rate and perks
* *
* @param primarySkillType Skill being used * @param skillIdentity Skill being used
* @param xp Experience amount to process * @param xp Experience amount to process
* @return Modified experience * @return Modified experience
*/ */
private float modifyXpGain(PrimarySkillType primarySkillType, float xp) { private float modifyXpGain(@NotNull SkillIdentity skillIdentity, float xp) {
if ((primarySkillType.getMaxLevel() <= getSkillLevel(primarySkillType)) || (Config.getInstance().getPowerLevelCap() <= getPowerLevel())) { if ((skillIdentity.getMaxLevel() <= getSkillLevel(skillIdentity)) || (Config.getInstance().getPowerLevelCap() <= getPowerLevel())) {
return 0; return 0;
} }
xp = (float) (xp / primarySkillType.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()); xp = (float) (xp / skillIdentity.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier());
return PerksUtils.handleXpPerks(mmoPlayer.getPlayer(), xp, primarySkillType); return PerksUtils.handleXpPerks(mmoPlayer.getPlayer(), xp, skillIdentity);
} }
public double getProgressInCurrentSkillLevel(PrimarySkillType primarySkillType) public double getProgressInCurrentSkillLevel(@NotNull SkillIdentity skillIdentity) throws UnknownSkillException
{ {
if(primarySkillType.isChildSkill()) { if(CoreSkillConstants.isChildSkill(skillIdentity)) {
return 1.0D; return 1.0D;
} }
double currentXP = getSkillXpValue(primarySkillType); double currentXP = getSkillXpValue(skillIdentity);
double maxXP = getXpToLevel(primarySkillType); double maxXP = getExperienceToNextLevel(skillIdentity);
return (currentXP / maxXP); return (currentXP / maxXP);
} }
@ -417,7 +419,7 @@ public class ExperienceManager {
if(hasReachedLevelCap(primarySkillType)) if(hasReachedLevelCap(primarySkillType))
return; return;
if (getSkillXpLevelRaw(primarySkillType) < getXpToLevel(primarySkillType)) { if (getSkillXpLevelRaw(primarySkillType) < getExperienceToNextLevel(primarySkillType)) {
processPostXpEvent(primarySkillType, mcMMO.p, xpGainSource); processPostXpEvent(primarySkillType, mcMMO.p, xpGainSource);
return; return;
} }
@ -425,7 +427,7 @@ public class ExperienceManager {
int levelsGained = 0; int levelsGained = 0;
float xpRemoved = 0; float xpRemoved = 0;
while (getSkillXpLevelRaw(primarySkillType) >= getXpToLevel(primarySkillType)) { while (getSkillXpLevelRaw(primarySkillType) >= getExperienceToNextLevel(primarySkillType)) {
if (hasReachedLevelCap(primarySkillType)) { if (hasReachedLevelCap(primarySkillType)) {
setSkillXpValue(primarySkillType, 0); setSkillXpValue(primarySkillType, 0);
break; break;

View File

@ -33,9 +33,9 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.experience.MMOExperienceBarManager; import com.gmail.nossr50.util.experience.MMOExperienceBarManager;
import com.gmail.nossr50.util.input.AbilityActivationProcessor; import com.gmail.nossr50.util.input.AbilityActivationProcessor;
import com.gmail.nossr50.util.input.SuperAbilityManager; import com.gmail.nossr50.util.input.SuperAbilityManager;
import com.neetgames.jmal.core.player.OnlinePlayer; import com.neetgames.mcmmo.exceptions.UnknownSkillException;
import com.neetgames.mcmmo.player.MMOPlayer;
import com.neetgames.mcmmo.player.OnlineMMOPlayer; import com.neetgames.mcmmo.player.OnlineMMOPlayer;
import com.neetgames.mcmmo.skill.SkillIdentity;
import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identified;
import net.kyori.adventure.identity.Identity; import net.kyori.adventure.identity.Identity;
import org.bukkit.Location; import org.bukkit.Location;
@ -478,12 +478,12 @@ public class McMMOPlayer extends PlayerProfile implements OnlineMMOPlayer, Ident
/** /**
* Update the experience bars for this player * Update the experience bars for this player
* @param primarySkillType target skill * @param skillIdentity target skill
* @param plugin your {@link Plugin} * @param plugin your {@link Plugin}
*/ */
public void updateXPBar(PrimarySkillType primarySkillType, Plugin plugin) { public void updateXPBar(@NotNull SkillIdentity skillIdentity, Plugin plugin) {
//XP BAR UPDATES //XP BAR UPDATES
experienceBarManager.updateExperienceBar(primarySkillType, plugin); experienceBarManager.updateExperienceBar(skillIdentity, plugin);
} }
/** /**
@ -618,4 +618,24 @@ public class McMMOPlayer extends PlayerProfile implements OnlineMMOPlayer, Ident
public boolean isChatSpying() { public boolean isChatSpying() {
return false; return false;
} }
@Override
public double getProgressInCurrentSkillLevel(@NotNull SkillIdentity skillIdentity) throws UnknownSkillException {
return experienceManager.getProgressInCurrentSkillLevel(skillIdentity);
}
@Override
public int getSkillLevel(@NotNull SkillIdentity skillIdentity) throws UnknownSkillException {
return experienceManager.getSkillLevel(skillIdentity);
}
@Override
public int getSkillExperience(@NotNull SkillIdentity skillIdentity) throws UnknownSkillException {
return experienceManager.getSkillXpValue(skillIdentity);
}
@Override
public int getExperienceToNextLevel(@NotNull SkillIdentity skillIdentity) throws UnknownSkillException {
return experienceManager.getExperienceToNextLevel(skillIdentity);
}
} }

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.datatypes.player; 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.PrimarySkillType; 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;
@ -68,9 +69,9 @@ public class PersistentPlayerData implements MMOPlayerData {
this.playerUUID = playerUUID; this.playerUUID = playerUUID;
this.playerName = new DirtyData<>(new MutableString(playerName), dirtyFlag); this.playerName = new DirtyData<>(new MutableString(playerName), dirtyFlag);
this.skillLevelValues = new DirtyMap<>(new HashMap<>(SkillIdentity.class), dirtyFlag); this.skillLevelValues = new DirtyMap<>(new HashMap<>(), dirtyFlag);
this.skillExperienceValues = new DirtyMap<>(new HashMap<>(SkillIdentity.class), dirtyFlag); this.skillExperienceValues = new DirtyMap<>(new HashMap<>(), dirtyFlag);
this.abilityDeactivationTimestamps = new DirtyMap<>(new EnumMap<>(SkillIdentity.class), dirtyFlag); this.abilityDeactivationTimestamps = new DirtyMap<>(new HashMap<>(), dirtyFlag);
this.uniquePlayerData = new DirtyMap<>(new EnumMap<>(UniqueDataType.class), dirtyFlag); this.uniquePlayerData = new DirtyMap<>(new EnumMap<>(UniqueDataType.class), dirtyFlag);
this.scoreboardTipsShown = new DirtyData<>(new MutableInteger(0), dirtyFlag); this.scoreboardTipsShown = new DirtyData<>(new MutableInteger(0), dirtyFlag);
@ -79,9 +80,11 @@ public class PersistentPlayerData implements MMOPlayerData {
abilityDeactivationTimestamps.put(rootSkill.getSkillIdentity(), 0); abilityDeactivationTimestamps.put(rootSkill.getSkillIdentity(), 0);
} }
for(PrimarySkillType primarySkillType : PrimarySkillType.values()) { //Core skills
skillLevelValues.put(primarySkillType, AdvancedConfig.getInstance().getStartingLevel()); //TODO: Don't store values for disabled skills
skillExperienceValues.put(primarySkillType, 0F); for(RootSkill rootSkill : CoreSkillConstants.getImmutableCoreRootSkillSet()) {
skillLevelValues.put(rootSkill.getSkillIdentity(), AdvancedConfig.getInstance().getStartingLevel());
skillExperienceValues.put(rootSkill.getSkillIdentity(), 0F);
} }
//Unique Player Data //Unique Player Data
@ -106,7 +109,6 @@ public class PersistentPlayerData implements MMOPlayerData {
* @param uniquePlayerData target player's misc unique data * @param uniquePlayerData target player's misc unique data
* @param barStateMap target player's XP bar state settings * @param barStateMap target player's XP bar state settings
* @param scoreboardTipsShown target player's scoreboard tip view count * @param scoreboardTipsShown target player's scoreboard tip view count
* @param mobHealthBarType target player's mob health bar type
* @param lastLogin target player's last login * @param lastLogin target player's last login
* @param leaderBoardExclusion target player's leaderboard exemption status * @param leaderBoardExclusion target player's leaderboard exemption status
*/ */
@ -119,7 +121,6 @@ public class PersistentPlayerData implements MMOPlayerData {
@NotNull EnumMap<UniqueDataType, Integer> uniquePlayerData, @NotNull EnumMap<UniqueDataType, Integer> uniquePlayerData,
@NotNull EnumMap<PrimarySkillType, SkillBossBarState> barStateMap, @NotNull EnumMap<PrimarySkillType, SkillBossBarState> barStateMap,
int scoreboardTipsShown, int scoreboardTipsShown,
@NotNull MobHealthBarType mobHealthBarType,
long lastLogin, long lastLogin,
boolean leaderBoardExclusion) throws Exception { boolean leaderBoardExclusion) throws Exception {
@ -140,7 +141,6 @@ public class PersistentPlayerData implements MMOPlayerData {
this.uniquePlayerData = new DirtyMap<>(uniquePlayerData, dirtyFlag); this.uniquePlayerData = new DirtyMap<>(uniquePlayerData, dirtyFlag);
this.scoreboardTipsShown = new DirtyData<>(new MutableInteger(scoreboardTipsShown), dirtyFlag); this.scoreboardTipsShown = new DirtyData<>(new MutableInteger(scoreboardTipsShown), dirtyFlag);
this.mobHealthBarType = new DirtyData<>(mobHealthBarType, dirtyFlag);
this.playerUUID = playerUUID; this.playerUUID = playerUUID;
this.playerName = new DirtyData<>(new MutableString(playerName), dirtyFlag); this.playerName = new DirtyData<>(new MutableString(playerName), dirtyFlag);
@ -174,8 +174,9 @@ public class PersistentPlayerData implements MMOPlayerData {
* @param primarySkillType target Primary Skill * @param primarySkillType target Primary Skill
* @param newSkillLevel the new value of the skill * @param newSkillLevel the new value of the skill
*/ */
public void setSkillLevel(PrimarySkillType primarySkillType, int newSkillLevel) { @Override
skillLevelValues.put(primarySkillType, newSkillLevel); public void setSkillLevel(@NotNull SkillIdentity skillIdentity, int newSkillLevel) {
skillLevelValues.put(skillIdentity, newSkillLevel);
} }
/** /**

View File

@ -1,6 +1,8 @@
package com.gmail.nossr50.datatypes.skills; package com.gmail.nossr50.datatypes.skills;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.neetgames.mcmmo.skill.RootSkill;
import com.neetgames.mcmmo.skill.Skill;
import com.neetgames.mcmmo.skill.SkillIdentity; import com.neetgames.mcmmo.skill.SkillIdentity;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -9,32 +11,75 @@ import java.util.Set;
public class CoreSkillConstants { public class CoreSkillConstants {
private static final @NotNull ImmutableSet<CoreRootSkill> immutableCoreRootSkillSet; private static final @NotNull ImmutableSet<RootSkill> CORE_ROOT_SKILLS_IMMUTABLE_SET;
private static final @NotNull ImmutableSet<RootSkill> CORE_CHILD_SKILLS;
public static @NotNull CoreRootSkill ACROBATICS, ALCHEMY, ARCHERY, AXES, EXCAVATION, public static final @NotNull CoreRootSkill ACROBATICS, ALCHEMY, ARCHERY, AXES, EXCAVATION,
FISHING, HERBALISM, MINING, REPAIR, SALVAGE, SMELTING, SWORDS, TAMING, UNARMED, FISHING, HERBALISM, MINING, REPAIR, SALVAGE, SMELTING, SWORDS, TAMING, UNARMED,
WOODCUTTING, TRIDENTS, CROSSBOWS; WOODCUTTING, TRIDENTS, CROSSBOWS;
public static final @NotNull SkillIdentity ACROBATICS_ID, ALCHEMY_ID, ARCHERY_ID, AXES_ID, EXCAVATION_ID,
FISHING_ID, HERBALISM_ID, MINING_ID, REPAIR_ID, SALVAGE_ID, SMELTING_ID, SWORDS_ID, TAMING_ID, UNARMED_ID,
WOODCUTTING_ID, TRIDENTS_ID, CROSSBOWS_ID;
static { static {
HashSet<CoreRootSkill> rootSkillSet = new HashSet<>(); HashSet<CoreRootSkill> rootSkillSet = new HashSet<>();
HashSet<CoreRootSkill> childSkillSet = new HashSet<>();
ACROBATICS = new CoreRootSkill("acrobatics"); ACROBATICS = new CoreRootSkill("acrobatics");
ACROBATICS_ID = ACROBATICS.getSkillIdentity();
ALCHEMY = new CoreRootSkill("alchemy"); ALCHEMY = new CoreRootSkill("alchemy");
ALCHEMY_ID = ALCHEMY.getSkillIdentity();
ARCHERY = new CoreRootSkill("archery"); ARCHERY = new CoreRootSkill("archery");
ARCHERY_ID = ARCHERY.getSkillIdentity();
AXES = new CoreRootSkill("axes"); AXES = new CoreRootSkill("axes");
AXES_ID = AXES.getSkillIdentity();
EXCAVATION = new CoreRootSkill("excavation"); EXCAVATION = new CoreRootSkill("excavation");
EXCAVATION_ID = EXCAVATION.getSkillIdentity();
FISHING = new CoreRootSkill("fishing"); FISHING = new CoreRootSkill("fishing");
FISHING_ID = FISHING.getSkillIdentity();
HERBALISM = new CoreRootSkill("herbalism"); HERBALISM = new CoreRootSkill("herbalism");
HERBALISM_ID = HERBALISM.getSkillIdentity();
MINING = new CoreRootSkill("mining"); MINING = new CoreRootSkill("mining");
MINING_ID = MINING.getSkillIdentity();
REPAIR = new CoreRootSkill("repair"); REPAIR = new CoreRootSkill("repair");
REPAIR_ID = REPAIR.getSkillIdentity();
SALVAGE = new CoreRootSkill("salvage"); SALVAGE = new CoreRootSkill("salvage");
SALVAGE_ID = SALVAGE.getSkillIdentity();
SMELTING = new CoreRootSkill("smelting"); SMELTING = new CoreRootSkill("smelting");
SMELTING_ID = SMELTING.getSkillIdentity();
SWORDS = new CoreRootSkill("swords"); SWORDS = new CoreRootSkill("swords");
SWORDS_ID = SWORDS.getSkillIdentity();
TAMING = new CoreRootSkill("taming"); TAMING = new CoreRootSkill("taming");
TAMING_ID = TAMING.getSkillIdentity();
UNARMED = new CoreRootSkill("unarmed"); UNARMED = new CoreRootSkill("unarmed");
UNARMED_ID = UNARMED.getSkillIdentity();
WOODCUTTING = new CoreRootSkill("woodcutting"); WOODCUTTING = new CoreRootSkill("woodcutting");
WOODCUTTING_ID = WOODCUTTING.getSkillIdentity();
TRIDENTS = new CoreRootSkill("tridents"); TRIDENTS = new CoreRootSkill("tridents");
TRIDENTS_ID = TRIDENTS.getSkillIdentity();
CROSSBOWS = new CoreRootSkill("crossbows"); CROSSBOWS = new CoreRootSkill("crossbows");
CROSSBOWS_ID = CROSSBOWS.getSkillIdentity();
//Child skills (soon to be removed)
childSkillSet.add(SMELTING);
childSkillSet.add(SALVAGE);
rootSkillSet.add(ACROBATICS); rootSkillSet.add(ACROBATICS);
rootSkillSet.add(ALCHEMY); rootSkillSet.add(ALCHEMY);
@ -54,7 +99,8 @@ public class CoreSkillConstants {
rootSkillSet.add(TRIDENTS); rootSkillSet.add(TRIDENTS);
rootSkillSet.add(CROSSBOWS); rootSkillSet.add(CROSSBOWS);
immutableCoreRootSkillSet = ImmutableSet.copyOf(rootSkillSet); CORE_ROOT_SKILLS_IMMUTABLE_SET = ImmutableSet.copyOf(rootSkillSet);
CORE_CHILD_SKILLS = ImmutableSet.copyOf(childSkillSet);
} }
/** /**
@ -63,7 +109,43 @@ public class CoreSkillConstants {
* *
* @return a set of all root skills built into mcMMO * @return a set of all root skills built into mcMMO
*/ */
public static @NotNull Set<CoreRootSkill> getImmutableCoreRootSkillSet() { public static @NotNull Set<RootSkill> getImmutableCoreRootSkillSet() {
return immutableCoreRootSkillSet; return CORE_ROOT_SKILLS_IMMUTABLE_SET;
}
/**
* Returns a set of built in skills for mcMMO which are child skills
* No guarantees for whether or not the skills are registered or active or inactive
*
* @return a set of all "child" root skills for mcMMO
* @deprecated child skills will be removed in an upcoming update
*/
@Deprecated
public static @NotNull Set<RootSkill> getChildSkills() {
return CORE_CHILD_SKILLS;
}
/**
* Whether or not a skill is considered a child skill
* @param skillIdentity target skill identity
* @return true if the skill identity belongs to a core "child" root skill
*/
public static boolean isChildSkill(@NotNull SkillIdentity skillIdentity) {
for(RootSkill rootSkill : CORE_CHILD_SKILLS) {
if(rootSkill.getSkillIdentity().equals(skillIdentity)) {
return true;
}
}
return false;
}
/**
* Whether or not a skill is considered a child skill
* @param skill target skill
* @return true if the skill identity belongs to a core "child" root skill
*/
public static boolean isChildSkill(@NotNull Skill skill) {
return isChildSkill(skill.getSkillIdentity());
} }
} }

View File

@ -143,9 +143,9 @@ public class SkillRegisterImpl implements SkillRegister {
} }
private void registerCoreSkills() { private void registerCoreSkills() {
for(CoreRootSkill coreRootSkill : CoreSkillConstants.getImmutableCoreRootSkillSet()) { for(RootSkill rootSkill : CoreSkillConstants.getImmutableCoreRootSkillSet()) {
mcMMO.p.getLogger().info("Registering core skill: "+coreRootSkill.getSkillName()); mcMMO.p.getLogger().info("Registering core skill: "+rootSkill.getSkillName());
registerSkill(coreRootSkill); registerSkill(rootSkill);
} }
} }

View File

@ -122,7 +122,7 @@ public class SelfListener implements Listener {
//Give some bonus XP for low levels //Give some bonus XP for low levels
if(PlayerLevelUtils.qualifiesForEarlyGameBoost(mmoPlayer, primarySkillType)) if(PlayerLevelUtils.qualifiesForEarlyGameBoost(mmoPlayer, primarySkillType))
{ {
earlyGameBonusXP += (mmoPlayer.getExperienceManager().getXpToLevel(primarySkillType) * 0.05); earlyGameBonusXP += (mmoPlayer.getExperienceManager().getExperienceToNextLevel(primarySkillType) * 0.05);
event.setRawXpGained(event.getRawXpGained() + earlyGameBonusXP); event.setRawXpGained(event.getRawXpGained() + earlyGameBonusXP);
} }
} }

View File

@ -1,53 +1,44 @@
package com.gmail.nossr50.skills.child; package com.gmail.nossr50.skills.child;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.CoreSkillConstants;
import com.neetgames.mcmmo.exceptions.UnknownSkillException;
import com.neetgames.mcmmo.skill.SkillIdentity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections; import java.util.HashSet;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Set; import java.util.Set;
public class FamilyTree { public class FamilyTree {
private static final HashMap<PrimarySkillType, Set<PrimarySkillType>> tree = new HashMap<>();
public static Set<PrimarySkillType> getParents(PrimarySkillType childSkill) { /*
enforceChildSkill(childSkill); * Hacky crap, will remove later
*/
// We do not check if we have the child skill in question, as not having it would mean we did something wrong, and an NPE is desired. private static @Nullable Set<SkillIdentity> smeltingParents;
return tree.get(childSkill); private static @Nullable Set<SkillIdentity> salvageParents;
}
protected static void registerParent(PrimarySkillType childSkill, PrimarySkillType parentSkill) { public static @NotNull Set<SkillIdentity> getParentSkills(@NotNull SkillIdentity skillIdentity) throws UnknownSkillException {
enforceChildSkill(childSkill); if(CoreSkillConstants.isChildSkill(skillIdentity)) {
enforceNotChildSkill(parentSkill); if(smeltingParents == null || salvageParents == null) {
smeltingParents = new HashSet<>();
salvageParents = new HashSet<>();
if (!tree.containsKey(childSkill)) { smeltingParents.add(CoreSkillConstants.MINING_ID);
tree.put(childSkill, EnumSet.noneOf(PrimarySkillType.class)); smeltingParents.add(CoreSkillConstants.REPAIR_ID);
}
tree.get(childSkill).add(parentSkill); salvageParents.add(CoreSkillConstants.FISHING_ID);
} salvageParents.add(CoreSkillConstants.REPAIR_ID);
}
protected static void closeRegistration() { if(skillIdentity.equals(CoreSkillConstants.SALVAGE_ID)) {
for (PrimarySkillType childSkill : tree.keySet()) { return salvageParents;
Set<PrimarySkillType> immutableSet = Collections.unmodifiableSet(tree.get(childSkill)); } else {
tree.put(childSkill, immutableSet); return smeltingParents;
} }
}
protected static void clearRegistrations() { } else {
tree.clear(); throw new UnknownSkillException();
}
protected static void enforceChildSkill(PrimarySkillType skill) {
if (!skill.isChildSkill()) {
throw new IllegalArgumentException(skill.name() + " is not a child skill!");
}
}
protected static void enforceNotChildSkill(PrimarySkillType skill) {
if (skill.isChildSkill()) {
throw new IllegalArgumentException(skill.name() + " is a child skill!");
} }
} }
} }

View File

@ -1,13 +1,11 @@
package com.gmail.nossr50.util.experience; package com.gmail.nossr50.util.experience;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.player.PersistentPlayerData;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.player.PlayerLevelUtils; import com.gmail.nossr50.util.player.PlayerLevelUtils;
import com.gmail.nossr50.util.text.StringUtils; import com.gmail.nossr50.util.text.StringUtils;
import com.neetgames.mcmmo.player.MMOPlayerData;
import com.neetgames.mcmmo.player.OnlineMMOPlayer; import com.neetgames.mcmmo.player.OnlineMMOPlayer;
import com.neetgames.mcmmo.skill.SkillIdentity;
import org.bukkit.boss.BarColor; import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle; import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar; import org.bukkit.boss.BossBar;
@ -21,9 +19,9 @@ import java.util.List;
*/ */
public class ExperienceBarWrapper { public class ExperienceBarWrapper {
private final @NotNull PrimarySkillType primarySkillType; //Primary Skill private final @NotNull SkillIdentity skillIdentity; //Primary Skill
private @NotNull BossBar bossBar; private @NotNull BossBar bossBar;
protected final @NotNull MMOPlayerData mmoPlayerData; protected final @NotNull OnlineMMOPlayer onlineMMOPlayer;
private int lastLevelUpdated; private int lastLevelUpdated;
/* /*
@ -32,14 +30,14 @@ public class ExperienceBarWrapper {
protected String niceSkillName; protected String niceSkillName;
protected String title; protected String title;
public ExperienceBarWrapper(@NotNull PrimarySkillType primarySkillType, @NotNull OnlineMMOPlayer mmoPlayer) { public ExperienceBarWrapper(@NotNull SkillIdentity skillIdentity, @NotNull OnlineMMOPlayer onlineMMOPlayer) {
this.mmoPlayerData = mmoPlayer.getMMOPlayerData(); this.onlineMMOPlayer = onlineMMOPlayer;
this.primarySkillType = primarySkillType; this.skillIdentity = skillIdentity;
title = ""; title = "";
lastLevelUpdated = 0; lastLevelUpdated = 0;
//These vars are stored to help reduce operations involving strings //These vars are stored to help reduce operations involving strings
niceSkillName = StringUtils.getCapitalized(primarySkillType.toString()); niceSkillName = StringUtils.getCapitalized(skillIdentity.toString());
//Create the bar //Create the bar
initBar(); initBar();
@ -58,7 +56,7 @@ public class ExperienceBarWrapper {
private String getTitleTemplate() { private String getTitleTemplate() {
//If they are using extra details //If they are using extra details
if(ExperienceConfig.getInstance().isEarlyGameBoostEnabled() && PlayerLevelUtils.qualifiesForEarlyGameBoost(persistentPlayerData, primarySkillType)) { if(ExperienceConfig.getInstance().isEarlyGameBoostEnabled() && PlayerLevelUtils.qualifiesForEarlyGameBoost(onlineMMOPlayer, skillIdentity)) {
return LocaleLoader.getString("XPBar.Template.EarlyGameBoost"); return LocaleLoader.getString("XPBar.Template.EarlyGameBoost");
} else if(ExperienceConfig.getInstance().getAddExtraDetails()) } else if(ExperienceConfig.getInstance().getAddExtraDetails())
return LocaleLoader.getString("XPBar.Complex.Template", LocaleLoader.getString("XPBar."+niceSkillName, getLevel()), getCurrentXP(), getMaxXP(), getPowerLevel(), getPercentageOfLevel()); return LocaleLoader.getString("XPBar.Complex.Template", LocaleLoader.getString("XPBar."+niceSkillName, getLevel()), getCurrentXP(), getMaxXP(), getPowerLevel(), getPercentageOfLevel());
@ -67,16 +65,16 @@ public class ExperienceBarWrapper {
} }
private int getLevel() { private int getLevel() {
return persistentPlayerData.getSkillLevel(primarySkillType); return onlineMMOPlayer.getSkillLevel(skillIdentity);
} }
private int getCurrentXP() { private int getCurrentXP() {
return mmoPlayer.getSkillXpLevel(primarySkillType); return onlineMMOPlayer.getSkillExperience(skillIdentity);
} }
private int getMaxXP() { private int getMaxXP() {
return mmoPlayer.getXpToLevel(primarySkillType); return onlineMMOPlayer.getExperienceToNextLevel(skillIdentity);
} }
private int getPowerLevel() { return mmoPlayer.getPowerLevel(); } private int getPowerLevel() { return onlineMMOPlayer.getPowerLevel(); }
private int getPercentageOfLevel() { return (int) (mmoPlayer.getProgressInCurrentSkillLevel(primarySkillType) * 100); } private int getPercentageOfLevel() { return (int) (onlineMMOPlayer.getProgressInCurrentSkillLevel(skillIdentity) * 100); }
public String getTitle() { public String getTitle() {
return bossBar.getTitle(); return bossBar.getTitle();
@ -113,10 +111,10 @@ public class ExperienceBarWrapper {
bossBar.setProgress(v); bossBar.setProgress(v);
//Check player level //Check player level
if(ExperienceConfig.getInstance().isEarlyGameBoostEnabled() && PlayerLevelUtils.qualifiesForEarlyGameBoost(mmoPlayer, primarySkillType)) { if(ExperienceConfig.getInstance().isEarlyGameBoostEnabled() && PlayerLevelUtils.qualifiesForEarlyGameBoost(mmoPlayer, skillIdentity)) {
setColor(BarColor.YELLOW); setColor(BarColor.YELLOW);
} else { } else {
setColor(ExperienceConfig.getInstance().getExperienceBarColor(primarySkillType)); setColor(ExperienceConfig.getInstance().getExperienceBarColor(skillIdentity));
} }
//Every time progress updates we need to check for a title update //Every time progress updates we need to check for a title update
@ -156,7 +154,7 @@ public class ExperienceBarWrapper {
private void createBossBar() private void createBossBar()
{ {
bossBar = mmoPlayer.getPlayer().getServer().createBossBar(title, ExperienceConfig.getInstance().getExperienceBarColor(primarySkillType), ExperienceConfig.getInstance().getExperienceBarStyle(primarySkillType)); bossBar = mmoPlayer.getPlayer().getServer().createBossBar(title, ExperienceConfig.getInstance().getExperienceBarColor(skillIdentity), ExperienceConfig.getInstance().getExperienceBarStyle(skillIdentity));
bossBar.addPlayer(mmoPlayer.getPlayer()); bossBar.addPlayer(mmoPlayer.getPlayer());
} }
} }

View File

@ -2,17 +2,18 @@ package com.gmail.nossr50.util.experience;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.CoreSkillConstants;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.skills.ExperienceBarHideTask; import com.gmail.nossr50.runnables.skills.ExperienceBarHideTask;
import com.gmail.nossr50.util.player.NotificationManager; import com.gmail.nossr50.util.player.NotificationManager;
import com.neetgames.mcmmo.skill.SkillBossBarSetting; import com.neetgames.mcmmo.skill.*;
import com.neetgames.mcmmo.skill.SkillBossBarState;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
@ -24,20 +25,20 @@ public class MMOExperienceBarManager {
int delaySeconds = 3; int delaySeconds = 3;
private @NotNull final Map<PrimarySkillType, SkillBossBarState> barStateMapRef; private @NotNull final Map<SkillIdentity, SkillBossBarState> barStateMapRef;
private @NotNull final EnumMap<PrimarySkillType, ExperienceBarWrapper> experienceBars; private @NotNull final HashMap<SkillIdentity, ExperienceBarWrapper> experienceBars;
private @NotNull final EnumMap<PrimarySkillType, ExperienceBarHideTask> experienceBarHideTaskHashMap; private @NotNull final HashMap<SkillIdentity, ExperienceBarHideTask> experienceBarHideTaskHashMap;
public MMOExperienceBarManager(@NotNull McMMOPlayer mmoPlayer, @NotNull Map<PrimarySkillType, SkillBossBarState> barStateMapRef) public MMOExperienceBarManager(@NotNull McMMOPlayer mmoPlayer, @NotNull Map<SkillIdentity, SkillBossBarState> barStateMapRef)
{ {
this.mmoPlayer = mmoPlayer; this.mmoPlayer = mmoPlayer;
this.barStateMapRef = barStateMapRef; this.barStateMapRef = barStateMapRef;
//Init maps //Init maps
experienceBars = new EnumMap<>(PrimarySkillType.class); experienceBars = new HashMap<>();
experienceBarHideTaskHashMap = new EnumMap<>(PrimarySkillType.class); experienceBarHideTaskHashMap = new HashMap<>();
init(); init();
} }
@ -47,8 +48,8 @@ public class MMOExperienceBarManager {
} }
private void syncBarStates() { private void syncBarStates() {
for(Map.Entry<PrimarySkillType, SkillBossBarState> entry : barStateMapRef.entrySet()) { for(Map.Entry<SkillIdentity, SkillBossBarState> entry : barStateMapRef.entrySet()) {
PrimarySkillType key = entry.getKey(); SkillIdentity key = entry.getKey();
SkillBossBarState barState = entry.getValue(); SkillBossBarState barState = entry.getValue();
switch(barState) { switch(barState) {
@ -66,31 +67,31 @@ public class MMOExperienceBarManager {
barStateMapRef.putAll(generateDefaultBarStateMap()); barStateMapRef.putAll(generateDefaultBarStateMap());
} }
public void updateExperienceBar(@NotNull PrimarySkillType primarySkillType, @NotNull Plugin plugin) public void updateExperienceBar(@NotNull SkillIdentity skillIdentity, @NotNull Plugin plugin)
{ {
if(isBarDisabled(primarySkillType)) if(isBarDisabled(skillIdentity))
return; return;
//Init Bar //Init Bar
if(experienceBars.get(primarySkillType) == null) if(experienceBars.get(skillIdentity) == null)
experienceBars.put(primarySkillType, new ExperienceBarWrapper(primarySkillType, mmoPlayer.getPersistentPlayerData())); experienceBars.put(skillIdentity, new ExperienceBarWrapper(skillIdentity, mmoPlayer.getPersistentPlayerData()));
//Get Bar //Get Bar
ExperienceBarWrapper experienceBarWrapper = experienceBars.get(primarySkillType); ExperienceBarWrapper experienceBarWrapper = experienceBars.get(skillIdentity);
//Update Progress //Update Progress
experienceBarWrapper.setProgress(mmoPlayer.getExperienceManager().getProgressInCurrentSkillLevel(primarySkillType)); experienceBarWrapper.setProgress(mmoPlayer.getExperienceManager().getProgressInCurrentSkillLevel(skillIdentity));
//Show Bar //Show Bar
experienceBarWrapper.showExperienceBar(); experienceBarWrapper.showExperienceBar();
//Setup Hide Bar Task //Setup Hide Bar Task
if(experienceBarHideTaskHashMap.get(primarySkillType) != null) if(experienceBarHideTaskHashMap.get(skillIdentity) != null)
{ {
experienceBarHideTaskHashMap.get(primarySkillType).cancel(); experienceBarHideTaskHashMap.get(skillIdentity).cancel();
} }
scheduleHideTask(primarySkillType, plugin); scheduleHideTask(skillIdentity, plugin);
} }
private boolean isBarDisabled(PrimarySkillType primarySkillType) { private boolean isBarDisabled(PrimarySkillType primarySkillType) {
@ -132,34 +133,34 @@ public class MMOExperienceBarManager {
NotificationManager.sendPlayerInformationChatOnlyPrefixed(mmoPlayer.getPlayer(), "Commands.XPBar.DisableAll"); NotificationManager.sendPlayerInformationChatOnlyPrefixed(mmoPlayer.getPlayer(), "Commands.XPBar.DisableAll");
} }
public void xpBarSettingToggle(@NotNull SkillBossBarSetting skillBossBarSetting, @Nullable PrimarySkillType skillType) { public void xpBarSettingToggle(@NotNull SkillBossBarSetting skillBossBarSetting, @Nullable SkillIdentity skillIdentity) {
switch(skillBossBarSetting) { switch(skillBossBarSetting) {
case SHOW: case SHOW:
barStateMapRef.put(skillType, SkillBossBarState.ALWAYS_ON); barStateMapRef.put(skillIdentity, SkillBossBarState.ALWAYS_ON);
//Remove lingering tasks //Remove lingering tasks
if(experienceBarHideTaskHashMap.containsKey(skillType)) { if(experienceBarHideTaskHashMap.containsKey(skillIdentity)) {
experienceBarHideTaskHashMap.get(skillType).cancel(); experienceBarHideTaskHashMap.get(skillIdentity).cancel();
} }
updateExperienceBar(skillType, mcMMO.p); updateExperienceBar(skillIdentity, mcMMO.p);
break; break;
case HIDE: case HIDE:
barStateMapRef.put(skillType, SkillBossBarState.DISABLED); barStateMapRef.put(skillIdentity, SkillBossBarState.DISABLED);
//Remove lingering tasks //Remove lingering tasks
if(experienceBarHideTaskHashMap.containsKey(skillType)) { if(experienceBarHideTaskHashMap.containsKey(skillIdentity)) {
experienceBarHideTaskHashMap.get(skillType).cancel(); experienceBarHideTaskHashMap.get(skillIdentity).cancel();
} }
hideExperienceBar(skillType); hideExperienceBar(skillIdentity);
break; break;
case RESET: case RESET:
resetBarSettings(); resetBarSettings();
break; break;
} }
informPlayer(skillBossBarSetting, skillType); informPlayer(skillBossBarSetting, skillIdentity);
} }
private void resetBarSettings() { private void resetBarSettings() {
@ -175,24 +176,21 @@ public class MMOExperienceBarManager {
} }
} }
/* public static @NotNull HashMap<SkillIdentity, SkillBossBarState> generateDefaultBarStateMap() {
* Utility Methods HashMap<SkillIdentity, SkillBossBarState> barStateMap = new HashMap<>();
*/
public static @NotNull EnumMap<PrimarySkillType, SkillBossBarState> generateDefaultBarStateMap() {
EnumMap<PrimarySkillType, SkillBossBarState> barStateMap = new EnumMap<>(PrimarySkillType.class);
setBarStateDefaults(barStateMap); setBarStateDefaults(barStateMap);
return barStateMap; return barStateMap;
} }
public static void setBarStateDefaults(EnumMap<PrimarySkillType, SkillBossBarState> barStateHashMap) { public static void setBarStateDefaults(HashMap<SkillIdentity, SkillBossBarState> barStateHashMap) {
for(PrimarySkillType skillType : PrimarySkillType.values()) { for(RootSkill rootSkill : CoreSkillConstants.getImmutableCoreRootSkillSet()) {
if(skillType.isChildSkill()) {
barStateHashMap.put(skillType, SkillBossBarState.DISABLED); if(CoreSkillConstants.isChildSkill(rootSkill.getSkillIdentity())) {
barStateHashMap.put(rootSkill.getSkillIdentity(), SkillBossBarState.DISABLED);
} else { } else {
barStateHashMap.put(skillType, SkillBossBarState.NORMAL); barStateHashMap.put(rootSkill.getSkillIdentity(), SkillBossBarState.NORMAL);
} }
} }
} }

View File

@ -449,7 +449,7 @@ public class ScoreboardWrapper {
int currentXP = mmoPlayer.getExperienceManager().getSkillXpValue(targetSkill); int currentXP = mmoPlayer.getExperienceManager().getSkillXpValue(targetSkill);
sidebarObjective.getScore(ScoreboardManager.LABEL_CURRENT_XP).setScore(currentXP); sidebarObjective.getScore(ScoreboardManager.LABEL_CURRENT_XP).setScore(currentXP);
sidebarObjective.getScore(ScoreboardManager.LABEL_REMAINING_XP).setScore(mmoPlayer.getExperienceManager().getXpToLevel(targetSkill) - currentXP); sidebarObjective.getScore(ScoreboardManager.LABEL_REMAINING_XP).setScore(mmoPlayer.getExperienceManager().getExperienceToNextLevel(targetSkill) - currentXP);
} }
else { else {
for (PrimarySkillType parentSkill : FamilyTree.getParents(targetSkill)) { for (PrimarySkillType parentSkill : FamilyTree.getParents(targetSkill)) {