Make ability events separate from skill events

This commit is contained in:
GJ 2013-10-21 10:19:21 -04:00 committed by TfT_02
parent badabeb8e4
commit d5fb19a7db
6 changed files with 60 additions and 28 deletions

View File

@ -777,7 +777,7 @@ public class McMMOPlayer {
return; return;
} }
if (EventUtils.callPlayerAbilityActivateEvent(player, skill).isCancelled()) { if (EventUtils.callPlayerAbilityActivateEvent(player, ability).isCancelled()) {
return; return;
} }

View File

@ -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.entity.Player;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
public class McMMOPlayerAbilityActivateEvent extends McMMOPlayerAbilityEvent implements Cancellable { public class McMMOPlayerAbilityActivateEvent extends McMMOPlayerAbilityEvent implements Cancellable {
private boolean cancelled; private boolean cancelled;
@Deprecated
public McMMOPlayerAbilityActivateEvent(Player player, SkillType skill) { public McMMOPlayerAbilityActivateEvent(Player player, SkillType skill) {
super(player, skill); super(player, skill);
cancelled = false; cancelled = false;
} }
public McMMOPlayerAbilityActivateEvent(Player player, AbilityType ability) {
super(player, ability);
cancelled = false;
}
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return cancelled;
} }

View File

@ -1,11 +1,17 @@
package com.gmail.nossr50.events.skills.abilities; package com.gmail.nossr50.events.abilities;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
public class McMMOPlayerAbilityDeactivateEvent extends McMMOPlayerAbilityEvent { public class McMMOPlayerAbilityDeactivateEvent extends McMMOPlayerAbilityEvent {
@Deprecated
public McMMOPlayerAbilityDeactivateEvent(Player player, SkillType skill) { public McMMOPlayerAbilityDeactivateEvent(Player player, SkillType skill) {
super(player, skill); super(player, skill);
} }
public McMMOPlayerAbilityDeactivateEvent(Player player, AbilityType ability) {
super(player, ability);
}
} }

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -15,6 +15,8 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; 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.McMMOPlayerLevelChangeEvent;
import com.gmail.nossr50.events.experience.levels.McMMOPlayerLevelDownEvent; import com.gmail.nossr50.events.experience.levels.McMMOPlayerLevelDownEvent;
import com.gmail.nossr50.events.experience.levels.McMMOPlayerLevelUpEvent; 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.fake.FakePlayerFishEvent;
import com.gmail.nossr50.events.hardcore.McMMOPlayerDeathPenaltyEvent; import com.gmail.nossr50.events.hardcore.McMMOPlayerDeathPenaltyEvent;
import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent; 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.McMMOPlayerFishingTreasureEvent;
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerMagicHunterEvent; import com.gmail.nossr50.events.skills.fishing.McMMOPlayerMagicHunterEvent;
import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent; 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; import com.gmail.nossr50.util.player.UserManager;
public class EventUtils { public class EventUtils {
public static McMMOPlayerAbilityActivateEvent callPlayerAbilityActivateEvent(Player player, SkillType skill) { public static McMMOPlayerAbilityActivateEvent callPlayerAbilityActivateEvent(Player player, AbilityType ability) {
McMMOPlayerAbilityActivateEvent event = new McMMOPlayerAbilityActivateEvent(player, skill); McMMOPlayerAbilityActivateEvent event = new McMMOPlayerAbilityActivateEvent(player, ability);
mcMMO.p.getServer().getPluginManager().callEvent(event); mcMMO.p.getServer().getPluginManager().callEvent(event);
return event; return event;
@ -125,7 +125,7 @@ public class EventUtils {
} }
public static McMMOPlayerAbilityDeactivateEvent callAbilityDeactivateEvent(Player player, AbilityType ability) { 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); mcMMO.p.getServer().getPluginManager().callEvent(event);
return event; return event;