diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java new file mode 100644 index 00000000..7cefbaa9 --- /dev/null +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerEnterCastingModeEvent.java @@ -0,0 +1,38 @@ +package net.Indyuce.mmocore.api.event; + +import lombok.Getter; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; +import org.jetbrains.annotations.NotNull; + +@Getter +public class PlayerEnterCastingModeEvent extends PlayerEvent implements Cancellable { + private static HandlerList handlerList = new HandlerList(); + private boolean cancelled = false; + + public PlayerEnterCastingModeEvent(@NotNull Player who) { + super(who); + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } + + public static HandlerList getHandlerList(){ + return handlerList; + } +} diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java new file mode 100644 index 00000000..ce98c45c --- /dev/null +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/event/PlayerExitCastingModeEvent.java @@ -0,0 +1,38 @@ +package net.Indyuce.mmocore.api.event; + +import lombok.Getter; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; +import org.jetbrains.annotations.NotNull; + +@Getter +public class PlayerExitCastingModeEvent extends PlayerEvent implements Cancellable { + private static final HandlerList handlerList = new HandlerList(); + private boolean cancelled = false; + + public PlayerExitCastingModeEvent(@NotNull Player who) { + super(who); + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlerList; + } + + public static HandlerList getHandlerList() { + return handlerList; + } +} diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 291b0c6f..089ce5ff 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -9,9 +9,7 @@ import io.lumine.mythic.lib.player.cooldown.CooldownMap; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigMessage; import net.Indyuce.mmocore.api.SoundEvent; -import net.Indyuce.mmocore.api.event.PlayerExperienceGainEvent; -import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent; -import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent; +import net.Indyuce.mmocore.api.event.*; import net.Indyuce.mmocore.api.event.unlocking.ItemLockedEvent; import net.Indyuce.mmocore.api.event.unlocking.ItemUnlockedEvent; import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute; @@ -1007,6 +1005,12 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD public void setSkillCasting(@NotNull SkillCastingInstance skillCasting) { Validate.isTrue(!isCasting(), "Player already in casting mode"); + PlayerEnterCastingModeEvent event = new PlayerEnterCastingModeEvent(getPlayer()); + Bukkit.getPluginManager().callEvent(event); + + if (event.isCancelled()){ + return; + } this.skillCasting = skillCasting; } @@ -1025,6 +1029,13 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD public void leaveSkillCasting() { Validate.isTrue(isCasting(), "Player not in casting mode"); + PlayerExitCastingModeEvent event = new PlayerExitCastingModeEvent(getPlayer()); + Bukkit.getPluginManager().callEvent(event); + + if (event.isCancelled()){ + return; + } + skillCasting.close(); this.skillCasting = null; setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE, 0); // Reset action bar