From d5fb19a7dbab6f55bbd0dc5a03390850d7881234 Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 21 Oct 2013 10:19:21 -0400 Subject: [PATCH] Make ability events separate from skill events --- .../nossr50/datatypes/player/McMMOPlayer.java | 2 +- .../McMMOPlayerAbilityActivateEvent.java | 9 ++++- .../McMMOPlayerAbilityDeactivateEvent.java | 8 +++- .../abilities/McMMOPlayerAbilityEvent.java | 39 +++++++++++++++++++ .../abilities/McMMOPlayerAbilityEvent.java | 20 ---------- .../com/gmail/nossr50/util/EventUtils.java | 10 ++--- 6 files changed, 60 insertions(+), 28 deletions(-) rename src/main/java/com/gmail/nossr50/events/{skills => }/abilities/McMMOPlayerAbilityActivateEvent.java (67%) rename src/main/java/com/gmail/nossr50/events/{skills => }/abilities/McMMOPlayerAbilityDeactivateEvent.java (54%) create mode 100644 src/main/java/com/gmail/nossr50/events/abilities/McMMOPlayerAbilityEvent.java delete mode 100644 src/main/java/com/gmail/nossr50/events/skills/abilities/McMMOPlayerAbilityEvent.java diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index b62f1b4cc..53b9bb66c 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -777,7 +777,7 @@ public class McMMOPlayer { return; } - if (EventUtils.callPlayerAbilityActivateEvent(player, skill).isCancelled()) { + if (EventUtils.callPlayerAbilityActivateEvent(player, ability).isCancelled()) { return; } diff --git a/src/main/java/com/gmail/nossr50/events/skills/abilities/McMMOPlayerAbilityActivateEvent.java b/src/main/java/com/gmail/nossr50/events/abilities/McMMOPlayerAbilityActivateEvent.java similarity index 67% rename from src/main/java/com/gmail/nossr50/events/skills/abilities/McMMOPlayerAbilityActivateEvent.java rename to src/main/java/com/gmail/nossr50/events/abilities/McMMOPlayerAbilityActivateEvent.java index f0b371fd3..dfd6358d6 100644 --- a/src/main/java/com/gmail/nossr50/events/skills/abilities/McMMOPlayerAbilityActivateEvent.java +++ b/src/main/java/com/gmail/nossr50/events/abilities/McMMOPlayerAbilityActivateEvent.java @@ -1,18 +1,25 @@ -package com.gmail.nossr50.events.skills.abilities; +package com.gmail.nossr50.events.abilities; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; +import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.SkillType; public class McMMOPlayerAbilityActivateEvent extends McMMOPlayerAbilityEvent implements Cancellable { private boolean cancelled; + @Deprecated public McMMOPlayerAbilityActivateEvent(Player player, SkillType skill) { super(player, skill); cancelled = false; } + public McMMOPlayerAbilityActivateEvent(Player player, AbilityType ability) { + super(player, ability); + cancelled = false; + } + public boolean isCancelled() { return cancelled; } diff --git a/src/main/java/com/gmail/nossr50/events/skills/abilities/McMMOPlayerAbilityDeactivateEvent.java b/src/main/java/com/gmail/nossr50/events/abilities/McMMOPlayerAbilityDeactivateEvent.java similarity index 54% rename from src/main/java/com/gmail/nossr50/events/skills/abilities/McMMOPlayerAbilityDeactivateEvent.java rename to src/main/java/com/gmail/nossr50/events/abilities/McMMOPlayerAbilityDeactivateEvent.java index 6eeb7f479..ef5ef643b 100644 --- a/src/main/java/com/gmail/nossr50/events/skills/abilities/McMMOPlayerAbilityDeactivateEvent.java +++ b/src/main/java/com/gmail/nossr50/events/abilities/McMMOPlayerAbilityDeactivateEvent.java @@ -1,11 +1,17 @@ -package com.gmail.nossr50.events.skills.abilities; +package com.gmail.nossr50.events.abilities; import org.bukkit.entity.Player; +import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.SkillType; public class McMMOPlayerAbilityDeactivateEvent extends McMMOPlayerAbilityEvent { + @Deprecated public McMMOPlayerAbilityDeactivateEvent(Player player, SkillType skill) { super(player, skill); } + + public McMMOPlayerAbilityDeactivateEvent(Player player, AbilityType ability) { + super(player, ability); + } } diff --git a/src/main/java/com/gmail/nossr50/events/abilities/McMMOPlayerAbilityEvent.java b/src/main/java/com/gmail/nossr50/events/abilities/McMMOPlayerAbilityEvent.java new file mode 100644 index 000000000..b27f4c8cc --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/abilities/McMMOPlayerAbilityEvent.java @@ -0,0 +1,39 @@ +package com.gmail.nossr50.events.abilities; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +import com.gmail.nossr50.datatypes.skills.AbilityType; +import com.gmail.nossr50.datatypes.skills.SkillType; + +public abstract class McMMOPlayerAbilityEvent extends PlayerEvent { + private AbilityType ability; + + @Deprecated + protected McMMOPlayerAbilityEvent(Player player, SkillType skill) { + super(player); + ability = skill.getAbility(); + } + + protected McMMOPlayerAbilityEvent(Player player, AbilityType ability) { + super(player); + this.ability = ability; + } + + public AbilityType getAbility() { + return ability; + } + + /** Rest of file is required boilerplate for custom events **/ + private static final HandlerList handlers = new HandlerList(); + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/main/java/com/gmail/nossr50/events/skills/abilities/McMMOPlayerAbilityEvent.java b/src/main/java/com/gmail/nossr50/events/skills/abilities/McMMOPlayerAbilityEvent.java deleted file mode 100644 index a65752c55..000000000 --- a/src/main/java/com/gmail/nossr50/events/skills/abilities/McMMOPlayerAbilityEvent.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.gmail.nossr50.events.skills.abilities; - -import org.bukkit.entity.Player; - -import com.gmail.nossr50.datatypes.skills.AbilityType; -import com.gmail.nossr50.datatypes.skills.SkillType; -import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent; - -public class McMMOPlayerAbilityEvent extends McMMOPlayerSkillEvent { - private AbilityType ability; - - protected McMMOPlayerAbilityEvent(Player player, SkillType skill) { - super(player, skill); - ability = skill.getAbility(); - } - - public AbilityType getAbility() { - return ability; - } -} diff --git a/src/main/java/com/gmail/nossr50/util/EventUtils.java b/src/main/java/com/gmail/nossr50/util/EventUtils.java index b6d0e030c..2c44dbb56 100644 --- a/src/main/java/com/gmail/nossr50/util/EventUtils.java +++ b/src/main/java/com/gmail/nossr50/util/EventUtils.java @@ -15,6 +15,8 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.SkillType; +import com.gmail.nossr50.events.abilities.McMMOPlayerAbilityActivateEvent; +import com.gmail.nossr50.events.abilities.McMMOPlayerAbilityDeactivateEvent; import com.gmail.nossr50.events.experience.levels.McMMOPlayerLevelChangeEvent; import com.gmail.nossr50.events.experience.levels.McMMOPlayerLevelDownEvent; import com.gmail.nossr50.events.experience.levels.McMMOPlayerLevelUpEvent; @@ -27,8 +29,6 @@ import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.events.fake.FakePlayerFishEvent; import com.gmail.nossr50.events.hardcore.McMMOPlayerDeathPenaltyEvent; import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent; -import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent; -import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent; import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent; import com.gmail.nossr50.events.skills.fishing.McMMOPlayerMagicHunterEvent; import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent; @@ -37,8 +37,8 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.player.UserManager; public class EventUtils { - public static McMMOPlayerAbilityActivateEvent callPlayerAbilityActivateEvent(Player player, SkillType skill) { - McMMOPlayerAbilityActivateEvent event = new McMMOPlayerAbilityActivateEvent(player, skill); + public static McMMOPlayerAbilityActivateEvent callPlayerAbilityActivateEvent(Player player, AbilityType ability) { + McMMOPlayerAbilityActivateEvent event = new McMMOPlayerAbilityActivateEvent(player, ability); mcMMO.p.getServer().getPluginManager().callEvent(event); return event; @@ -125,7 +125,7 @@ public class EventUtils { } public static McMMOPlayerAbilityDeactivateEvent callAbilityDeactivateEvent(Player player, AbilityType ability) { - McMMOPlayerAbilityDeactivateEvent event = new McMMOPlayerAbilityDeactivateEvent(player, SkillType.byAbility(ability)); + McMMOPlayerAbilityDeactivateEvent event = new McMMOPlayerAbilityDeactivateEvent(player, ability); mcMMO.p.getServer().getPluginManager().callEvent(event); return event;