forked from Upstream/mmocore
Fixed an issue w/ casting mode on logout
This commit is contained in:
parent
d6ec76573c
commit
2d779d19bf
@ -4,7 +4,7 @@ import net.Indyuce.mmocore.api.player.PlayerData;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link AsyncPlayerDataLoadEvent} instead
|
* @deprecated Use {@link io.lumine.mythic.lib.api.event.SynchronizedDataLoadEvent} instead
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class PlayerDataLoadEvent extends PlayerDataEvent {
|
public class PlayerDataLoadEvent extends PlayerDataEvent {
|
||||||
|
@ -7,13 +7,19 @@ import org.bukkit.event.HandlerList;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerEnterCastingModeEvent extends PlayerDataEvent implements Cancellable {
|
public class PlayerEnterCastingModeEvent extends PlayerDataEvent implements Cancellable {
|
||||||
private static final HandlerList handlerList = new HandlerList();
|
|
||||||
private boolean cancelled = false;
|
private boolean cancelled = false;
|
||||||
|
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public PlayerEnterCastingModeEvent(@NotNull Player who) {
|
public PlayerEnterCastingModeEvent(@NotNull Player who) {
|
||||||
super(PlayerData.get(who));
|
super(PlayerData.get(who));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlayerEnterCastingModeEvent(@NotNull PlayerData playerData) {
|
||||||
|
super(playerData);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return cancelled;
|
||||||
@ -30,7 +36,7 @@ public class PlayerEnterCastingModeEvent extends PlayerDataEvent implements Canc
|
|||||||
return getHandlerList();
|
return getHandlerList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList(){
|
public static HandlerList getHandlerList() {
|
||||||
return handlerList;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,18 @@ import org.bukkit.event.HandlerList;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerExitCastingModeEvent extends PlayerDataEvent implements Cancellable {
|
public class PlayerExitCastingModeEvent extends PlayerDataEvent implements Cancellable {
|
||||||
private static final HandlerList handlerList = new HandlerList();
|
|
||||||
private boolean cancelled = false;
|
private boolean cancelled = false;
|
||||||
|
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public PlayerExitCastingModeEvent(@NotNull Player who) {
|
public PlayerExitCastingModeEvent(@NotNull Player who) {
|
||||||
super(PlayerData.get(who));
|
super(PlayerData.get(who));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlayerExitCastingModeEvent(@NotNull PlayerData who) {
|
||||||
|
super(who);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
@ -29,10 +34,10 @@ public class PlayerExitCastingModeEvent extends PlayerDataEvent implements Cance
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlerList;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlerList;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -357,7 +357,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return If the item is unlocked by the player
|
* @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) {
|
public boolean hasUnlocked(Unlockable unlockable) {
|
||||||
return unlockable.isUnlockedByDefault() || unlockedItems.contains(unlockable.getUnlockNamespacedKey());
|
return unlockable.isUnlockedByDefault() || unlockedItems.contains(unlockable.getUnlockNamespacedKey());
|
||||||
@ -429,7 +429,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
|||||||
boundSkills.forEach((slot, info) -> info.close());
|
boundSkills.forEach((slot, info) -> info.close());
|
||||||
|
|
||||||
// Stop skill casting
|
// Stop skill casting
|
||||||
if (isCasting()) leaveSkillCasting();
|
if (isCasting()) leaveSkillCasting(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UUID> getFriends() {
|
public List<UUID> getFriends() {
|
||||||
@ -1012,23 +1012,16 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
|||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean setSkillCasting(@NotNull SkillCastingInstance skillCasting) {
|
public boolean setSkillCasting(@NotNull SkillCastingInstance skillCasting) {
|
||||||
Validate.isTrue(!isCasting(), "Player already in casting mode");
|
return setSkillCasting();
|
||||||
PlayerEnterCastingModeEvent event = new PlayerEnterCastingModeEvent(getPlayer());
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
if (event.isCancelled()) return false;
|
|
||||||
|
|
||||||
skillCasting.close();
|
|
||||||
setSkillCasting();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the PlayerEnterCastingModeEvent successfully put the player into casting mode, otherwise if the event is cancelled, returns false.
|
* @return If the PlayerEnterCastingModeEvent successfully put the player
|
||||||
* @apiNote Changed to a boolean to reflect the cancellation state of the event being fired
|
* into casting mode, otherwise if the event is cancelled, returns false.
|
||||||
*/
|
*/
|
||||||
public boolean setSkillCasting() {
|
public boolean setSkillCasting() {
|
||||||
Validate.isTrue(!isCasting(), "Player already in casting mode");
|
Validate.isTrue(!isCasting(), "Player already in casting mode");
|
||||||
PlayerEnterCastingModeEvent event = new PlayerEnterCastingModeEvent(getPlayer());
|
PlayerEnterCastingModeEvent event = new PlayerEnterCastingModeEvent(this);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) return false;
|
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 If player successfully left skill casting i.e the Bukkit
|
||||||
*
|
* event has not been cancelled
|
||||||
* @return true if the skill casting mode was left, or false if the event was cancelled, keeping the player in casting mode.
|
|
||||||
*/
|
*/
|
||||||
public boolean leaveSkillCasting() {
|
public boolean leaveSkillCasting() {
|
||||||
return leaveSkillCasting(false);
|
return leaveSkillCasting(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param skipEvent Skip Firing the PlayerExitCastingModeEvent
|
* @param skipEvent Skip firing the exit event
|
||||||
* @return true if the PlayerExitCastingModeEvent is not cancelled, or if the event is skipped.
|
* @return If player successfully left skill casting i.e the Bukkit
|
||||||
|
* event has not been cancelled
|
||||||
*/
|
*/
|
||||||
public boolean leaveSkillCasting(boolean skipEvent) {
|
public boolean leaveSkillCasting(boolean skipEvent) {
|
||||||
Validate.isTrue(isCasting(), "Player not in casting mode");
|
Validate.isTrue(isCasting(), "Player not in casting mode");
|
||||||
|
|
||||||
if (!skipEvent) {
|
if (!skipEvent) {
|
||||||
PlayerExitCastingModeEvent event = new PlayerExitCastingModeEvent(getPlayer());
|
PlayerExitCastingModeEvent event = new PlayerExitCastingModeEvent(this);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) return false;
|
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
|
* checks if they could potentially upgrade to one of these
|
||||||
*
|
*
|
||||||
* @return If the player can change its current class to
|
* @return If the player can change its current class to
|
||||||
* a subclass
|
* a subclass
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean canChooseSubclass() {
|
public boolean canChooseSubclass() {
|
||||||
|
@ -40,7 +40,7 @@ public abstract class SkillCastingInstance extends BukkitRunnable implements Lis
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!caster.isOnline() || caster.getPlayer().isDead()) {
|
if (!caster.isOnline() || caster.getPlayer().isDead()) {
|
||||||
caster.leaveSkillCasting();
|
caster.leaveSkillCasting(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ public class KeyCombos implements SkillCastingListener {
|
|||||||
// Hash current combo and check
|
// Hash current combo and check
|
||||||
if (casting.combos.getCombos().containsKey(casting.current)) {
|
if (casting.combos.getCombos().containsKey(casting.current)) {
|
||||||
final int spellSlot = casting.combos.getCombos().get(casting.current);
|
final int spellSlot = casting.combos.getCombos().get(casting.current);
|
||||||
playerData.leaveSkillCasting();
|
playerData.leaveSkillCasting(true);
|
||||||
|
|
||||||
// Cast spell
|
// Cast spell
|
||||||
if (playerData.hasSkillBound(spellSlot)) {
|
if (playerData.hasSkillBound(spellSlot)) {
|
||||||
@ -130,7 +130,7 @@ public class KeyCombos implements SkillCastingListener {
|
|||||||
|
|
||||||
// Check if current combo is too large
|
// Check if current combo is too large
|
||||||
if (casting.current.countKeys() >= casting.combos.getLongest()) {
|
if (casting.current.countKeys() >= casting.combos.getLongest()) {
|
||||||
playerData.leaveSkillCasting();
|
playerData.leaveSkillCasting(true);
|
||||||
if (failComboSound != null) failComboSound.playTo(player);
|
if (failComboSound != null) failComboSound.playTo(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -175,7 +175,7 @@ public class KeyCombos implements SkillCastingListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTick() {
|
public void onTick() {
|
||||||
if (getCaster().getBoundSkills().isEmpty()) getCaster().leaveSkillCasting();
|
if (getCaster().getBoundSkills().isEmpty()) getCaster().leaveSkillCasting(true);
|
||||||
else if (actionBarOptions != null) if (actionBarOptions.isSubtitle)
|
else if (actionBarOptions != null) if (actionBarOptions.isSubtitle)
|
||||||
getCaster().getPlayer().sendTitle(" ", actionBarOptions.format(this), 0, 20, 0);
|
getCaster().getPlayer().sendTitle(" ", actionBarOptions.format(this), 0, 20, 0);
|
||||||
else getCaster().displayActionBar(actionBarOptions.format(this));
|
else getCaster().displayActionBar(actionBarOptions.format(this));
|
||||||
|
@ -112,15 +112,10 @@ public class SkillBar implements SkillCastingListener {
|
|||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
if (disableSneak && player.isSneaking()) return;
|
if (disableSneak && player.isSneaking()) return;
|
||||||
|
|
||||||
MMOCore.plugin.soundManager.getSound(SoundEvent.SPELL_CAST_END).playTo(player);
|
if (getCaster().leaveSkillCasting()) {
|
||||||
|
MMOCore.plugin.soundManager.getSound(SoundEvent.SPELL_CAST_END).playTo(player);
|
||||||
new BukkitRunnable() {
|
MMOCore.plugin.configManager.getSimpleMessage("casting.no-longer").send(getCaster().getPlayer());
|
||||||
@Override
|
}
|
||||||
public void run() {
|
|
||||||
MMOCore.plugin.configManager.getSimpleMessage("casting.no-longer").send(getCaster().getPlayer());
|
|
||||||
}
|
|
||||||
}.runTask(MMOCore.plugin);
|
|
||||||
getCaster().leaveSkillCasting();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFormat(PlayerData data) {
|
private String getFormat(PlayerData data) {
|
||||||
|
@ -69,7 +69,8 @@ public class SkillScroller implements SkillCastingListener {
|
|||||||
// Cancel event if necessary
|
// Cancel event if necessary
|
||||||
if (event.getPressed().shouldCancelEvent()) event.setCancelled(true);
|
if (event.getPressed().shouldCancelEvent()) event.setCancelled(true);
|
||||||
|
|
||||||
playerData.leaveSkillCasting();
|
if (!playerData.leaveSkillCasting()) return;
|
||||||
|
|
||||||
if (leaveSound != null) leaveSound.playTo(player);
|
if (leaveSound != null) leaveSound.playTo(player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -81,9 +82,7 @@ public class SkillScroller implements SkillCastingListener {
|
|||||||
if (event.getPressed().shouldCancelEvent()) event.setCancelled(true);
|
if (event.getPressed().shouldCancelEvent()) event.setCancelled(true);
|
||||||
|
|
||||||
// Enter casting mode
|
// Enter casting mode
|
||||||
if (!playerData.setSkillCasting()) {
|
if (!playerData.setSkillCasting()) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enterSound != null) enterSound.playTo(player);
|
if (enterSound != null) enterSound.playTo(player);
|
||||||
}
|
}
|
||||||
@ -105,7 +104,7 @@ public class SkillScroller implements SkillCastingListener {
|
|||||||
if (!playerData.isCasting()) return;
|
if (!playerData.isCasting()) return;
|
||||||
|
|
||||||
if (playerData.getBoundSkills().isEmpty()) {
|
if (playerData.getBoundSkills().isEmpty()) {
|
||||||
playerData.leaveSkillCasting();
|
playerData.leaveSkillCasting(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user