Fixed an issue w/ casting mode on logout

This commit is contained in:
Jules 2023-10-02 00:01:49 +02:00
parent d6ec76573c
commit 2d779d19bf
8 changed files with 44 additions and 45 deletions

View File

@ -4,7 +4,7 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import org.bukkit.event.HandlerList;
/**
* @deprecated Use {@link AsyncPlayerDataLoadEvent} instead
* @deprecated Use {@link io.lumine.mythic.lib.api.event.SynchronizedDataLoadEvent} instead
*/
@Deprecated
public class PlayerDataLoadEvent extends PlayerDataEvent {

View File

@ -7,13 +7,19 @@ import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class PlayerEnterCastingModeEvent extends PlayerDataEvent implements Cancellable {
private static final HandlerList handlerList = new HandlerList();
private boolean cancelled = false;
private static final HandlerList HANDLERS = new HandlerList();
@Deprecated
public PlayerEnterCastingModeEvent(@NotNull Player who) {
super(PlayerData.get(who));
}
public PlayerEnterCastingModeEvent(@NotNull PlayerData playerData) {
super(playerData);
}
@Override
public boolean isCancelled() {
return cancelled;
@ -30,7 +36,7 @@ public class PlayerEnterCastingModeEvent extends PlayerDataEvent implements Canc
return getHandlerList();
}
public static HandlerList getHandlerList(){
return handlerList;
public static HandlerList getHandlerList() {
return HANDLERS;
}
}

View File

@ -8,13 +8,18 @@ import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class PlayerExitCastingModeEvent extends PlayerDataEvent implements Cancellable {
private static final HandlerList handlerList = new HandlerList();
private boolean cancelled = false;
private static final HandlerList HANDLERS = new HandlerList();
@Deprecated
public PlayerExitCastingModeEvent(@NotNull Player who) {
super(PlayerData.get(who));
}
public PlayerExitCastingModeEvent(@NotNull PlayerData who) {
super(who);
}
@Override
public boolean isCancelled() {
@ -29,10 +34,10 @@ public class PlayerExitCastingModeEvent extends PlayerDataEvent implements Cance
@NotNull
@Override
public HandlerList getHandlers() {
return handlerList;
return HANDLERS;
}
public static HandlerList getHandlerList() {
return handlerList;
return HANDLERS;
}
}

View File

@ -357,7 +357,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
/**
* @return If the item is unlocked by the player
* This is used for skills that can be locked & unlocked.
* This is used for skills that can be locked & unlocked.
*/
public boolean hasUnlocked(Unlockable unlockable) {
return unlockable.isUnlockedByDefault() || unlockedItems.contains(unlockable.getUnlockNamespacedKey());
@ -429,7 +429,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
boundSkills.forEach((slot, info) -> info.close());
// Stop skill casting
if (isCasting()) leaveSkillCasting();
if (isCasting()) leaveSkillCasting(true);
}
public List<UUID> getFriends() {
@ -1012,23 +1012,16 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
@Deprecated
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()) return false;
skillCasting.close();
setSkillCasting();
return true;
return setSkillCasting();
}
/**
* @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
* @return If the PlayerEnterCastingModeEvent successfully put the player
* into casting mode, otherwise if the event is cancelled, returns false.
*/
public boolean setSkillCasting() {
Validate.isTrue(!isCasting(), "Player already in casting mode");
PlayerEnterCastingModeEvent event = new PlayerEnterCastingModeEvent(getPlayer());
PlayerEnterCastingModeEvent event = new PlayerEnterCastingModeEvent(this);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) return false;
@ -1042,22 +1035,23 @@ 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.
* @return If player successfully left skill casting i.e the Bukkit
* event has not been cancelled
*/
public boolean leaveSkillCasting() {
return leaveSkillCasting(false);
}
/**
* @param skipEvent Skip Firing the PlayerExitCastingModeEvent
* @return true if the PlayerExitCastingModeEvent is not cancelled, or if the event is skipped.
* @param skipEvent Skip firing the exit event
* @return If player successfully left skill casting i.e the Bukkit
* event has not been cancelled
*/
public boolean leaveSkillCasting(boolean skipEvent) {
Validate.isTrue(isCasting(), "Player not in casting mode");
if (!skipEvent) {
PlayerExitCastingModeEvent event = new PlayerExitCastingModeEvent(getPlayer());
PlayerExitCastingModeEvent event = new PlayerExitCastingModeEvent(this);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) return false;
}
@ -1227,7 +1221,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
* checks if they could potentially upgrade to one of these
*
* @return If the player can change its current class to
* a subclass
* a subclass
*/
@Deprecated
public boolean canChooseSubclass() {

View File

@ -40,7 +40,7 @@ public abstract class SkillCastingInstance extends BukkitRunnable implements Lis
@Override
public void run() {
if (!caster.isOnline() || caster.getPlayer().isDead()) {
caster.leaveSkillCasting();
caster.leaveSkillCasting(true);
return;
}

View File

@ -118,7 +118,7 @@ public class KeyCombos implements SkillCastingListener {
// Hash current combo and check
if (casting.combos.getCombos().containsKey(casting.current)) {
final int spellSlot = casting.combos.getCombos().get(casting.current);
playerData.leaveSkillCasting();
playerData.leaveSkillCasting(true);
// Cast spell
if (playerData.hasSkillBound(spellSlot)) {
@ -130,7 +130,7 @@ public class KeyCombos implements SkillCastingListener {
// Check if current combo is too large
if (casting.current.countKeys() >= casting.combos.getLongest()) {
playerData.leaveSkillCasting();
playerData.leaveSkillCasting(true);
if (failComboSound != null) failComboSound.playTo(player);
}
}
@ -175,7 +175,7 @@ public class KeyCombos implements SkillCastingListener {
@Override
public void onTick() {
if (getCaster().getBoundSkills().isEmpty()) getCaster().leaveSkillCasting();
if (getCaster().getBoundSkills().isEmpty()) getCaster().leaveSkillCasting(true);
else if (actionBarOptions != null) if (actionBarOptions.isSubtitle)
getCaster().getPlayer().sendTitle(" ", actionBarOptions.format(this), 0, 20, 0);
else getCaster().displayActionBar(actionBarOptions.format(this));

View File

@ -112,15 +112,10 @@ public class SkillBar implements SkillCastingListener {
final Player player = event.getPlayer();
if (disableSneak && player.isSneaking()) return;
MMOCore.plugin.soundManager.getSound(SoundEvent.SPELL_CAST_END).playTo(player);
new BukkitRunnable() {
@Override
public void run() {
MMOCore.plugin.configManager.getSimpleMessage("casting.no-longer").send(getCaster().getPlayer());
}
}.runTask(MMOCore.plugin);
getCaster().leaveSkillCasting();
if (getCaster().leaveSkillCasting()) {
MMOCore.plugin.soundManager.getSound(SoundEvent.SPELL_CAST_END).playTo(player);
MMOCore.plugin.configManager.getSimpleMessage("casting.no-longer").send(getCaster().getPlayer());
}
}
private String getFormat(PlayerData data) {

View File

@ -69,7 +69,8 @@ public class SkillScroller implements SkillCastingListener {
// Cancel event if necessary
if (event.getPressed().shouldCancelEvent()) event.setCancelled(true);
playerData.leaveSkillCasting();
if (!playerData.leaveSkillCasting()) return;
if (leaveSound != null) leaveSound.playTo(player);
return;
}
@ -81,9 +82,7 @@ public class SkillScroller implements SkillCastingListener {
if (event.getPressed().shouldCancelEvent()) event.setCancelled(true);
// Enter casting mode
if (!playerData.setSkillCasting()) {
return;
}
if (!playerData.setSkillCasting()) return;
if (enterSound != null) enterSound.playTo(player);
}
@ -105,7 +104,7 @@ public class SkillScroller implements SkillCastingListener {
if (!playerData.isCasting()) return;
if (playerData.getBoundSkills().isEmpty()) {
playerData.leaveSkillCasting();
playerData.leaveSkillCasting(true);
return;
}