Skip to content

Commit

Permalink
Level Cap bugfixes and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
nossr50 committed Jun 22, 2019
1 parent e17afe3 commit b479d45
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 17 deletions.
9 changes: 9 additions & 0 deletions Changelog.txt
@@ -1,3 +1,12 @@
Version 2.1.87
(Level caps are not on by default in mcMMO, this is something you can turn on)

Players who reach either the power level cap or skill level cap will now be informed that they have done so
XP Bars will no longer be sent to players who have reached the power level or skill level cap respectively
Level up messages will no longer be sent to players who have reached the power level or skill level cap respectively
Fixed a bug where mcMMO would send level up notifications to a player if the custom level up event from mcMMO was cancelled
New locale strings 'LevelCap.PowerLevel' & 'LevelCap.Skill'

Version 2.1.86
Players will no longer be told they got a perfect result when salvaging if they are below max skill level
Salvage results will now travel towards the player instead of moving in a random direction
Expand Down
Expand Up @@ -30,7 +30,7 @@ protected void handleCommand(Player player, PlayerProfile profile, PrimarySkillT
return;
}

EventUtils.handleLevelChangeEvent(player, skill, value, xpRemoved, true, XPGainReason.COMMAND);
EventUtils.tryLevelChangeEvent(player, skill, value, xpRemoved, true, XPGainReason.COMMAND);
}

@Override
Expand Down
Expand Up @@ -36,7 +36,7 @@ protected void handleCommand(Player player, PlayerProfile profile, PrimarySkillT
return;
}

EventUtils.handleLevelChangeEventEdit(player, skill, value, xpRemoved, value > skillLevel, XPGainReason.COMMAND, skillLevel);
EventUtils.tryLevelEditEvent(player, skill, value, xpRemoved, value > skillLevel, XPGainReason.COMMAND, skillLevel);
}

@Override
Expand Down
Expand Up @@ -126,7 +126,7 @@ protected void handleCommand(Player player, PlayerProfile profile, PrimarySkillT
return;
}

EventUtils.handleLevelChangeEvent(player, skill, levelsRemoved, xpRemoved, false, XPGainReason.COMMAND);
EventUtils.tryLevelChangeEvent(player, skill, levelsRemoved, xpRemoved, false, XPGainReason.COMMAND);
}

protected boolean permissionsCheckSelf(CommandSender sender) {
Expand Down
49 changes: 40 additions & 9 deletions src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java
Expand Up @@ -41,6 +41,7 @@
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.experience.ExperienceBarManager;
import com.gmail.nossr50.util.player.NotificationManager;
import com.gmail.nossr50.util.player.UserManager;
Expand Down Expand Up @@ -150,8 +151,15 @@ public String getPlayerName() {
experienceBarManager.hideExperienceBar(primarySkillType);
}*/

public void processPostXpEvent(XPGainReason xpGainReason, PrimarySkillType primarySkillType, Plugin plugin, XPGainSource xpGainSource)
public void processPostXpEvent(PrimarySkillType primarySkillType, Plugin plugin, XPGainSource xpGainSource)
{
//Check if they've reached the power level cap just now
if(hasReachedPowerLevelCap()) {
NotificationManager.sendPlayerInformationChatOnly(player, "LevelCap.PowerLevel", String.valueOf(Config.getInstance().getPowerLevelCap()));
} else if(hasReachedLevelCap(primarySkillType)) {
NotificationManager.sendPlayerInformationChatOnly(player, "LevelCap.Skill", String.valueOf(Config.getInstance().getPowerLevelCap()), primarySkillType.getName());
}

//Updates from Party sources
if(xpGainSource == XPGainSource.PARTY_MEMBERS && !ExperienceConfig.getInstance().isPartyExperienceBarsEnabled())
return;
Expand Down Expand Up @@ -459,6 +467,31 @@ public int getPowerLevel() {
return powerLevel;
}

/**
* 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
* @param primarySkillType
* @return
*/
public boolean hasReachedLevelCap(PrimarySkillType primarySkillType) {
if(hasReachedPowerLevelCap())
return true;

if(getSkillLevel(primarySkillType) >= Config.getInstance().getLevelCap(primarySkillType))
return true;

return false;
}

/**
* Whether or not a player is power level capped
* Compares their power level total to the current set limit
* @return true if they have reached the power level cap
*/
public boolean hasReachedPowerLevelCap() {
return this.getPowerLevel() >= Config.getInstance().getPowerLevelCap();
}

/**
* Begins an experience gain. The amount will be affected by skill modifiers, global rate, perks, and may be shared with the party
*
Expand Down Expand Up @@ -549,8 +582,11 @@ public void applyXpGain(PrimarySkillType primarySkillType, float xp, XPGainReaso
* @param primarySkillType The skill to check
*/
private void checkXp(PrimarySkillType primarySkillType, XPGainReason xpGainReason, XPGainSource xpGainSource) {
if(hasReachedLevelCap(primarySkillType))
return;

if (getSkillXpLevelRaw(primarySkillType) < getXpToLevel(primarySkillType)) {
processPostXpEvent(xpGainReason, primarySkillType, mcMMO.p, xpGainSource);
processPostXpEvent(primarySkillType, mcMMO.p, xpGainSource);
return;
}

Expand All @@ -567,8 +603,7 @@ private void checkXp(PrimarySkillType primarySkillType, XPGainReason xpGainReaso
levelsGained++;
}

if (!EventUtils.handleLevelChangeEvent(player, primarySkillType, levelsGained, xpRemoved, true, xpGainReason)) {
processPostXpEvent(xpGainReason, primarySkillType, mcMMO.p, xpGainSource);
if (EventUtils.tryLevelChangeEvent(player, primarySkillType, levelsGained, xpRemoved, true, xpGainReason)) {
return;
}

Expand All @@ -583,7 +618,7 @@ private void checkXp(PrimarySkillType primarySkillType, XPGainReason xpGainReaso
NotificationManager.sendPlayerLevelUpNotification(this, primarySkillType, levelsGained, profile.getSkillLevel(primarySkillType));

//UPDATE XP BARS
processPostXpEvent(xpGainReason, primarySkillType, mcMMO.p, xpGainSource);
processPostXpEvent(primarySkillType, mcMMO.p, xpGainSource);
}

/*
Expand Down Expand Up @@ -934,10 +969,6 @@ public int calculateTimeRemaining(SuperAbilityType ability) {
return (int) (((deactivatedTimestamp + (PerksUtils.handleCooldownPerks(player, ability.getCooldown()) * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR);
}

private boolean hasReachedLevelCap(PrimarySkillType skill) {
return (skill.getMaxLevel() < getSkillLevel(skill) + 1) || (Config.getInstance().getPowerLevelCap() < getPowerLevel() + 1);
}

/*
* These functions are wrapped from PlayerProfile so that we don't always have to store it alongside the McMMOPlayer object.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/gmail/nossr50/util/EventUtils.java
Expand Up @@ -187,7 +187,7 @@ public static FakePlayerAnimationEvent callFakeArmSwingEvent(Player player) {
return event;
}

public static boolean handleLevelChangeEvent(Player player, PrimarySkillType skill, int levelsChanged, float xpRemoved, boolean isLevelUp, XPGainReason xpGainReason) {
public static boolean tryLevelChangeEvent(Player player, PrimarySkillType skill, int levelsChanged, float xpRemoved, boolean isLevelUp, XPGainReason xpGainReason) {
McMMOPlayerLevelChangeEvent event = isLevelUp ? new McMMOPlayerLevelUpEvent(player, skill, levelsChanged, xpGainReason) : new McMMOPlayerLevelDownEvent(player, skill, levelsChanged, xpGainReason);
mcMMO.p.getServer().getPluginManager().callEvent(event);

Expand All @@ -200,10 +200,10 @@ public static boolean handleLevelChangeEvent(Player player, PrimarySkillType ski
profile.addXp(skill, xpRemoved);
}

return !isCancelled;
return isCancelled;
}

public static boolean handleLevelChangeEventEdit(Player player, PrimarySkillType skill, int levelsChanged, float xpRemoved, boolean isLevelUp, XPGainReason xpGainReason, int oldLevel) {
public static boolean tryLevelEditEvent(Player player, PrimarySkillType skill, int levelsChanged, float xpRemoved, boolean isLevelUp, XPGainReason xpGainReason, int oldLevel) {
McMMOPlayerLevelChangeEvent event = isLevelUp ? new McMMOPlayerLevelUpEvent(player, skill, levelsChanged - oldLevel, xpGainReason) : new McMMOPlayerLevelDownEvent(player, skill, levelsChanged, xpGainReason);
mcMMO.p.getServer().getPluginManager().callEvent(event);

Expand All @@ -216,7 +216,7 @@ public static boolean handleLevelChangeEventEdit(Player player, PrimarySkillType
profile.addXp(skill, xpRemoved);
}

return !isCancelled;
return isCancelled;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/locale/locale_en_US.properties
Expand Up @@ -1095,4 +1095,7 @@ Holiday.Anniversary=[[BLUE]]Happy {0} Year Anniversary!\n[[BLUE]]In honor of all
#Reminder Messages
Reminder.Squelched=[[GRAY]]Reminder: You are currently not receiving notifications from mcMMO, to enable notifications please run the /mcnotify command again. This is an automated hourly reminder.
#Locale
Locale.Reloaded=[[GREEN]]Locale reloaded!
Locale.Reloaded=[[GREEN]]Locale reloaded!
#Player Leveling Stuff
LevelCap.PowerLevel=[[GOLD]]([[GREEN]]mcMMO[[GOLD]]) [[YELLOW]]You have reached the power level cap of [[RED]]{0}[[YELLOW]]. You will cease to level in skills from this point on.
LevelCap.Skill=[[GOLD]]([[GREEN]]mcMMO[[GOLD]]) [[YELLOW]]You have reached the level cap of [[RED]]{0}[[YELLOW]] for [[GOLD]]{1}[[YELLOW]]. You will cease to level in this skill from this point on.

0 comments on commit b479d45

Please sign in to comment.