From 51f4f7be1b9c1ec5ad69ded6a1458a6344e35c1c Mon Sep 17 00:00:00 2001 From: Rosenthalk0 Date: Sat, 24 Jun 2023 15:06:17 -0500 Subject: [PATCH] Cleaning up the events, removing lambok from events, and making leaveCastingMode and setCastingMode as booleans to reflect the events they fire! --- .../event/PlayerEnterCastingModeEvent.java | 2 -- .../api/event/PlayerExitCastingModeEvent.java | 4 ++-- .../mmocore/api/player/PlayerData.java | 23 +++++++++++++------ .../skill/cast/listener/KeyCombos.java | 8 +++---- .../mmocore/skill/cast/listener/SkillBar.java | 6 ++--- .../skill/cast/listener/SkillScroller.java | 4 ++-- 6 files changed, 26 insertions(+), 21 deletions(-) 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 index 3656a398..bc40bd99 100644 --- 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 @@ -1,13 +1,11 @@ package net.Indyuce.mmocore.api.event; -import lombok.Getter; import net.Indyuce.mmocore.api.player.PlayerData; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; -@Getter public class PlayerEnterCastingModeEvent extends PlayerDataEvent implements Cancellable { private static final HandlerList handlerList = new HandlerList(); private boolean cancelled = false; 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 index 4f065738..6f859a32 100644 --- 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 @@ -1,13 +1,12 @@ package net.Indyuce.mmocore.api.event; -import lombok.Getter; + import net.Indyuce.mmocore.api.player.PlayerData; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; -@Getter public class PlayerExitCastingModeEvent extends PlayerDataEvent implements Cancellable { private static final HandlerList handlerList = new HandlerList(); private boolean cancelled = false; @@ -16,6 +15,7 @@ public class PlayerExitCastingModeEvent extends PlayerDataEvent implements Cance super(PlayerData.get(who.getUniqueId())); } + @Override public boolean isCancelled() { return cancelled; 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 b9347df0..4f8cdbbd 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 @@ -1003,16 +1003,21 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD return skillCasting != null; } - public void setSkillCasting(@NotNull SkillCastingInstance skillCasting) { + /** + * @return true if the PlayerEnterCastingModeEvent successfully put the player into casting mode, otherwise if the event is cancelled, returns false. + * @apiNote Changed to a boolean to reflect the cancellation state of the event being fired + */ + public boolean setSkillCasting(@NotNull SkillCastingInstance skillCasting) { Validate.isTrue(!isCasting(), "Player already in casting mode"); PlayerEnterCastingModeEvent event = new PlayerEnterCastingModeEvent(getPlayer()); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()){ skillCasting.close(); - return; + return false; } this.skillCasting = skillCasting; + return true; } /** @@ -1030,27 +1035,31 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD /** * API Method to leave casting mode and fire the PlayerExitCastingModeEvent + * @return true if the skill casting mode was left, or false if the event was cancelled, keeping the player in casting mode. */ - public void leaveSkillCasting(){ - this.leaveSkillCasting(false); + public boolean leaveSkillCasting(){ + return this.leaveSkillCasting(false); } /** - * @param skipEvent Skip the PlayerExitCastingModeEvent + * @param skipEvent Skip Firing the PlayerExitCastingModeEvent + * @return true if the PlayerExitCastingModeEvent is not cancelled, or if the event is skipped. + * */ - public void leaveSkillCasting(boolean skipEvent) { + public boolean leaveSkillCasting(boolean skipEvent) { Validate.isTrue(isCasting(), "Player not in casting mode"); if (!skipEvent) { PlayerExitCastingModeEvent event = new PlayerExitCastingModeEvent(getPlayer()); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { - return; + return false; } } skillCasting.close(); this.skillCasting = null; setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE, 0); // Reset action bar + return true; } public void displayActionBar(String message) { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java index b6de6f7f..2f693f3c 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java @@ -79,8 +79,9 @@ public class KeyCombos implements SkillCastingListener { if (event.getPressed().shouldCancelEvent()) event.setCancelled(true); // Start combo - playerData.setSkillCasting(new CustomSkillCastingInstance(playerData)); - if (beginComboSound != null) beginComboSound.playTo(player); + if (playerData.setSkillCasting(new CustomSkillCastingInstance(playerData))) { + if (beginComboSound != null) beginComboSound.playTo(player); + } } return; } @@ -95,8 +96,7 @@ public class KeyCombos implements SkillCastingListener { final @NotNull ComboMap comboMap = Objects.requireNonNullElse(playerData.getProfess().getComboMap(), this.comboMap); if (comboMap.isComboStart(event.getPressed())) { casting = new CustomSkillCastingInstance(playerData); - playerData.setSkillCasting(casting); - if (!playerData.isCasting()){ + if (!playerData.setSkillCasting(casting)) { return; } if (beginComboSound != null) beginComboSound.playTo(player); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillBar.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillBar.java index f4e5873a..6f338ff1 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillBar.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillBar.java @@ -56,11 +56,9 @@ public class SkillBar implements SkillCastingListener { // Enter spell casting final PlayerData playerData = event.getData(); if (player.getGameMode() != GameMode.SPECTATOR && (MMOCore.plugin.configManager.canCreativeCast || player.getGameMode() != GameMode.CREATIVE) && !playerData.isCasting() && !playerData.getBoundSkills().isEmpty()) { - playerData.setSkillCasting(new CustomSkillCastingInstance(playerData)); - if (!playerData.isCasting()){ - return; + if (playerData.setSkillCasting(new CustomSkillCastingInstance(playerData))) { + MMOCore.plugin.soundManager.getSound(SoundEvent.SPELL_CAST_BEGIN).playTo(player); } - MMOCore.plugin.soundManager.getSound(SoundEvent.SPELL_CAST_BEGIN).playTo(player); } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillScroller.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillScroller.java index 72a2db96..2cb07ce1 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillScroller.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/SkillScroller.java @@ -77,10 +77,10 @@ public class SkillScroller implements SkillCastingListener { if (event.getPressed().shouldCancelEvent()) event.setCancelled(true); // Enter casting mode - playerData.setSkillCasting(new CustomSkillCastingInstance(playerData)); - if (!playerData.isCasting()){ + if (!playerData.setSkillCasting(new CustomSkillCastingInstance(playerData))) { return; } + if (enterSound != null) enterSound.playTo(player); }