Add boolean for particle effects to ability events.

This commit is contained in:
GJ 2013-10-21 11:00:54 -04:00 committed by TfT_02
parent d5fb19a7db
commit 071c568353
4 changed files with 47 additions and 14 deletions

View File

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

View File

@ -9,22 +9,39 @@ import com.gmail.nossr50.datatypes.skills.SkillType;
public abstract class McMMOPlayerAbilityEvent extends PlayerEvent {
private AbilityType ability;
private boolean useParticleEffects;
@Deprecated
protected McMMOPlayerAbilityEvent(Player player, SkillType skill) {
super(player);
ability = skill.getAbility();
useParticleEffects = true;
}
protected McMMOPlayerAbilityEvent(Player player, AbilityType ability) {
super(player);
this.ability = ability;
this.useParticleEffects = true;
}
protected McMMOPlayerAbilityEvent(Player player, AbilityType ability, boolean useParticleEffects) {
super(player);
this.ability = ability;
this.useParticleEffects = useParticleEffects;
}
public AbilityType getAbility() {
return ability;
}
public boolean useParticleEffects() {
return useParticleEffects;
}
public void shouldUseParticleEffects(boolean useParticleEffects) {
this.useParticleEffects = useParticleEffects;
}
/** Rest of file is required boilerplate for custom events **/
private static final HandlerList handlers = new HandlerList();

View File

@ -9,7 +9,6 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
import com.gmail.nossr50.util.skills.PerksUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
@ -46,18 +45,11 @@ public class AbilityDisableTask extends BukkitRunnable {
break;
}
EventUtils.callAbilityDeactivateEvent(player, ability);
EventUtils.handleAbilityDeactivateEvent(player, ability);
mcMMOPlayer.setAbilityMode(ability, false);
mcMMOPlayer.setAbilityInformed(ability, false);
ParticleEffectUtils.playAbilityDisabledEffect(player);
if (mcMMOPlayer.useChatNotifications()) {
player.sendMessage(ability.getAbilityOff());
}
SkillUtils.sendSkillMessage(player, ability.getAbilityPlayerOff(player));
new AbilityCooldownTask(mcMMOPlayer, ability).runTaskLaterAsynchronously(mcMMO.p, PerksUtils.handleCooldownPerks(player, ability.getCooldown()) * Misc.TICK_CONVERSION_FACTOR);
}
}

View File

@ -35,13 +35,29 @@ import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
import com.gmail.nossr50.events.skills.unarmed.McMMOPlayerDisarmEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public class EventUtils {
public static McMMOPlayerAbilityActivateEvent callPlayerAbilityActivateEvent(Player player, AbilityType ability) {
public static boolean handlePlayerAbilityActivateEvent(Player player, AbilityType ability) {
McMMOPlayerAbilityActivateEvent event = new McMMOPlayerAbilityActivateEvent(player, ability);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return event;
boolean isCancelled = event.isCancelled();
if (!isCancelled) {
if (event.useParticleEffects()) {
ParticleEffectUtils.playAbilityEnabledEffect(player);
}
if (UserManager.getPlayer(player).useChatNotifications()) {
player.sendMessage(ability.getAbilityOn());
}
SkillUtils.sendSkillMessage(player, ability.getAbilityPlayer(player));
}
return !isCancelled;
}
public static FakePlayerAnimationEvent callFakeArmSwingEvent(Player player) {
@ -124,11 +140,19 @@ public class EventUtils {
return !isCancelled;
}
public static McMMOPlayerAbilityDeactivateEvent callAbilityDeactivateEvent(Player player, AbilityType ability) {
public static void handleAbilityDeactivateEvent(Player player, AbilityType ability) {
McMMOPlayerAbilityDeactivateEvent event = new McMMOPlayerAbilityDeactivateEvent(player, ability);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return event;
if (event.useParticleEffects()) {
ParticleEffectUtils.playAbilityDisabledEffect(player);
}
if (UserManager.getPlayer(player).useChatNotifications()) {
player.sendMessage(ability.getAbilityOff());
}
SkillUtils.sendSkillMessage(player, ability.getAbilityPlayerOff(player));
}
public static McMMOPlayerFishingTreasureEvent callFishingTreasureEvent(Player player, ItemStack treasureDrop, int treasureXp, Map<Enchantment, Integer> enchants) {