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; private boolean cancelled;
@Deprecated @Deprecated
protected McMMOPlayerExperienceEvent(Player player, PrimarySkillType skill) { protected McMMOPlayerExperienceEvent(Player player, PrimarySkillType skill, int skillLevel) {
super(player); super(player);
this.skill = skill; this.skill = skill;
this.skillLevel = pluginRef.getUserManager().getPlayer(player).getSkillLevel(skill); this.skillLevel = skillLevel;
this.xpGainReason = XPGainReason.UNKNOWN; this.xpGainReason = XPGainReason.UNKNOWN;
} }
protected McMMOPlayerExperienceEvent(Player player, PrimarySkillType skill, XPGainReason xpGainReason) { protected McMMOPlayerExperienceEvent(Player player, PrimarySkillType skill, int skillLevel, XPGainReason xpGainReason) {
super(player); super(player);
this.skill = skill; this.skill = skill;
this.skillLevel = pluginRef.getUserManager().getPlayer(player).getSkillLevel(skill); this.skillLevel = skillLevel;
this.xpGainReason = xpGainReason; this.xpGainReason = xpGainReason;
} }

View File

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

View File

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

View File

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

View File

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

View File

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