mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 07:06:45 +01:00
Make McMMOPlayerLevelUpEvent fully cancellable.
This commit is contained in:
parent
e78cbcfcc8
commit
05a9c8b7e5
@ -26,11 +26,4 @@ public class McMMOPlayerLevelUpEvent extends McMMOPlayerExperienceEvent {
|
|||||||
public int getLevelsGained() {
|
public int getLevelsGained() {
|
||||||
return levelsGained;
|
return levelsGained;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param levelsGained int number of levels gained in this event
|
|
||||||
*/
|
|
||||||
public void setLevelsGained(int levelsGained) {
|
|
||||||
this.levelsGained = levelsGained;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import com.gmail.nossr50.mcMMO;
|
|||||||
import com.gmail.nossr50.config.AdvancedConfig;
|
import com.gmail.nossr50.config.AdvancedConfig;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.config.HiddenConfig;
|
import com.gmail.nossr50.config.HiddenConfig;
|
||||||
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||||
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
@ -234,23 +235,33 @@ public class SkillTools {
|
|||||||
*/
|
*/
|
||||||
public static void xpCheckSkill(SkillType skillType, Player player, PlayerProfile profile) {
|
public static void xpCheckSkill(SkillType skillType, Player player, PlayerProfile profile) {
|
||||||
int skillups = 0;
|
int skillups = 0;
|
||||||
|
int xpRemoved = 0;
|
||||||
|
|
||||||
if (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
|
if (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
|
||||||
|
|
||||||
while (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
|
while (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
|
||||||
if ((skillType.getMaxLevel() >= profile.getSkillLevel(skillType) + 1) && (Misc.getPowerLevelCap() >= Users.getPlayer(player).getPowerLevel() + 1)) {
|
if ((skillType.getMaxLevel() >= profile.getSkillLevel(skillType) + 1) && (Misc.getPowerLevelCap() >= Users.getPlayer(player).getPowerLevel() + 1)) {
|
||||||
profile.removeXp(skillType, profile.getXpToLevel(skillType));
|
int xp = profile.getXpToLevel(skillType);
|
||||||
|
xpRemoved += xp;
|
||||||
|
|
||||||
|
profile.removeXp(skillType, xp);
|
||||||
skillups++;
|
skillups++;
|
||||||
profile.skillUp(skillType, 1);
|
profile.skillUp(skillType, 1);
|
||||||
|
|
||||||
McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType);
|
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(eventToFire);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
profile.addLevels(skillType, 0);
|
profile.addLevels(skillType, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType, skillups);
|
||||||
|
mcMMO.p.getServer().getPluginManager().callEvent(eventToFire);
|
||||||
|
|
||||||
|
if (eventToFire.isCancelled()) {
|
||||||
|
profile.modifySkill(skillType, profile.getSkillLevel(skillType) - skillups);
|
||||||
|
profile.setSkillXpLevel(skillType, profile.getSkillXpLevel(skillType) + xpRemoved);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String capitalized = StringUtils.getCapitalized(skillType.toString());
|
String capitalized = StringUtils.getCapitalized(skillType.toString());
|
||||||
|
|
||||||
/* Spout Stuff */
|
/* Spout Stuff */
|
||||||
|
Loading…
Reference in New Issue
Block a user