Remove Static Abuse - Level Events

This commit is contained in:
nossr50 2019-07-03 00:22:32 -07:00
parent bc183cd4f9
commit 3bddfed72f
6 changed files with 33 additions and 29 deletions

View File

@ -18,17 +18,17 @@ public abstract class McMMOPlayerExperienceEvent extends PlayerEvent implements
private boolean cancelled;
@Deprecated
protected McMMOPlayerExperienceEvent(Player player, PrimarySkillType skill) {
protected McMMOPlayerExperienceEvent(Player player, PrimarySkillType skill, int skillLevel) {
super(player);
this.skill = skill;
this.skillLevel = pluginRef.getUserManager().getPlayer(player).getSkillLevel(skill);
this.skillLevel = skillLevel;
this.xpGainReason = XPGainReason.UNKNOWN;
}
protected McMMOPlayerExperienceEvent(Player player, PrimarySkillType skill, XPGainReason xpGainReason) {
protected McMMOPlayerExperienceEvent(Player player, PrimarySkillType skill, int skillLevel, XPGainReason xpGainReason) {
super(player);
this.skill = skill;
this.skillLevel = pluginRef.getUserManager().getPlayer(player).getSkillLevel(skill);
this.skillLevel = skillLevel;
this.xpGainReason = xpGainReason;
}

View File

@ -9,11 +9,11 @@ import org.bukkit.entity.Player;
*/
public abstract class McMMOPlayerLevelChangeEvent extends McMMOPlayerExperienceEvent {
@Deprecated
public McMMOPlayerLevelChangeEvent(Player player, PrimarySkillType skill) {
super(player, skill, XPGainReason.UNKNOWN);
public McMMOPlayerLevelChangeEvent(Player player, PrimarySkillType skill, int skillLevel) {
super(player, skill, skillLevel, XPGainReason.UNKNOWN);
}
public McMMOPlayerLevelChangeEvent(Player player, PrimarySkillType skill, XPGainReason xpGainReason) {
super(player, skill, xpGainReason);
public McMMOPlayerLevelChangeEvent(Player player, PrimarySkillType skill, int skillLevel, XPGainReason xpGainReason) {
super(player, skill, skillLevel, xpGainReason);
}
}

View File

@ -13,24 +13,24 @@ public class McMMOPlayerLevelDownEvent extends McMMOPlayerLevelChangeEvent {
private int levelsLost;
@Deprecated
public McMMOPlayerLevelDownEvent(Player player, PrimarySkillType skill) {
super(player, skill, XPGainReason.UNKNOWN);
public McMMOPlayerLevelDownEvent(Player player, PrimarySkillType skill, int skillLevel) {
super(player, skill, skillLevel, XPGainReason.UNKNOWN);
this.levelsLost = 1;
}
@Deprecated
public McMMOPlayerLevelDownEvent(Player player, PrimarySkillType skill, int levelsLost) {
super(player, skill, XPGainReason.UNKNOWN);
public McMMOPlayerLevelDownEvent(Player player, PrimarySkillType skill, int levelsLost, int skillLevel) {
super(player, skill, skillLevel, XPGainReason.UNKNOWN);
this.levelsLost = levelsLost;
}
public McMMOPlayerLevelDownEvent(Player player, PrimarySkillType skill, XPGainReason xpGainReason) {
super(player, skill, xpGainReason);
public McMMOPlayerLevelDownEvent(Player player, PrimarySkillType skill, int skillLevel, XPGainReason xpGainReason) {
super(player, skill, skillLevel, xpGainReason);
this.levelsLost = 1;
}
public McMMOPlayerLevelDownEvent(Player player, PrimarySkillType skill, int levelsLost, XPGainReason xpGainReason) {
super(player, skill, xpGainReason);
public McMMOPlayerLevelDownEvent(Player player, PrimarySkillType skill, int levelsLost, int skillLevel, XPGainReason xpGainReason) {
super(player, skill, skillLevel, xpGainReason);
this.levelsLost = levelsLost;
}

View File

@ -13,24 +13,24 @@ public class McMMOPlayerLevelUpEvent extends McMMOPlayerLevelChangeEvent {
private int levelsGained;
@Deprecated
public McMMOPlayerLevelUpEvent(Player player, PrimarySkillType skill) {
super(player, skill, XPGainReason.UNKNOWN);
public McMMOPlayerLevelUpEvent(Player player, PrimarySkillType skill, int skillLevel) {
super(player, skill, skillLevel, XPGainReason.UNKNOWN);
this.levelsGained = 1;
}
@Deprecated
public McMMOPlayerLevelUpEvent(Player player, PrimarySkillType skill, int levelsGained) {
super(player, skill, XPGainReason.UNKNOWN);
public McMMOPlayerLevelUpEvent(Player player, PrimarySkillType skill, int levelsGained, int skillLevel) {
super(player, skill, skillLevel, XPGainReason.UNKNOWN);
this.levelsGained = levelsGained;
}
public McMMOPlayerLevelUpEvent(Player player, PrimarySkillType skill, XPGainReason xpGainReason) {
super(player, skill, xpGainReason);
public McMMOPlayerLevelUpEvent(Player player, PrimarySkillType skill, int skillLevel, XPGainReason xpGainReason) {
super(player, skill, skillLevel, xpGainReason);
this.levelsGained = 1;
}
public McMMOPlayerLevelUpEvent(Player player, PrimarySkillType skill, int levelsGained, XPGainReason xpGainReason) {
super(player, skill, xpGainReason);
public McMMOPlayerLevelUpEvent(Player player, PrimarySkillType skill, int levelsGained, int skillLevel, XPGainReason xpGainReason) {
super(player, skill, skillLevel, xpGainReason);
this.levelsGained = levelsGained;
}

View File

@ -13,13 +13,13 @@ public class McMMOPlayerXpGainEvent extends McMMOPlayerExperienceEvent {
private double xpGained;
@Deprecated
public McMMOPlayerXpGainEvent(Player player, PrimarySkillType skill, double xpGained) {
super(player, skill, XPGainReason.UNKNOWN);
public McMMOPlayerXpGainEvent(Player player, PrimarySkillType skill, int skillLevel, double xpGained) {
super(player, skill, skillLevel, XPGainReason.UNKNOWN);
this.xpGained = xpGained;
}
public McMMOPlayerXpGainEvent(Player player, PrimarySkillType skill, double xpGained, XPGainReason xpGainReason) {
super(player, skill, xpGainReason);
public McMMOPlayerXpGainEvent(Player player, PrimarySkillType skill, int skillLevel, double xpGained, XPGainReason xpGainReason) {
super(player, skill, skillLevel, xpGainReason);
this.xpGained = xpGained;
}

View File

@ -315,7 +315,7 @@ public class EventManager {
}
public boolean handleXpGainEvent(Player player, PrimarySkillType skill, double xpGained, XPGainReason xpGainReason) {
McMMOPlayerXpGainEvent event = new McMMOPlayerXpGainEvent(player, skill, xpGained, xpGainReason);
McMMOPlayerXpGainEvent event = new McMMOPlayerXpGainEvent(player, skill, getSkillLevel(player, skill), xpGained, xpGainReason);
pluginRef.getServer().getPluginManager().callEvent(event);
boolean isCancelled = event.isCancelled();
@ -459,6 +459,10 @@ public class EventManager {
return event;
}
private int getSkillLevel(Player player, PrimarySkillType primarySkillType) {
return pluginRef.getUserManager().getPlayer(player).getSkillLevel(primarySkillType);
}
/**
* Creates and calls a McMMOPlayerNotificationEvent
* @param player target player