mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-30 01:13:38 +01:00
Cleaning up the events, removing lambok from events, and making leaveCastingMode and setCastingMode as booleans to reflect the events they fire!
This commit is contained in:
parent
96ac7a9c00
commit
51f4f7be1b
@ -1,13 +1,11 @@
|
|||||||
package net.Indyuce.mmocore.api.event;
|
package net.Indyuce.mmocore.api.event;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class PlayerEnterCastingModeEvent extends PlayerDataEvent implements Cancellable {
|
public class PlayerEnterCastingModeEvent extends PlayerDataEvent implements Cancellable {
|
||||||
private static final HandlerList handlerList = new HandlerList();
|
private static final HandlerList handlerList = new HandlerList();
|
||||||
private boolean cancelled = false;
|
private boolean cancelled = false;
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
package net.Indyuce.mmocore.api.event;
|
package net.Indyuce.mmocore.api.event;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class PlayerExitCastingModeEvent extends PlayerDataEvent implements Cancellable {
|
public class PlayerExitCastingModeEvent extends PlayerDataEvent implements Cancellable {
|
||||||
private static final HandlerList handlerList = new HandlerList();
|
private static final HandlerList handlerList = new HandlerList();
|
||||||
private boolean cancelled = false;
|
private boolean cancelled = false;
|
||||||
@ -16,6 +15,7 @@ public class PlayerExitCastingModeEvent extends PlayerDataEvent implements Cance
|
|||||||
super(PlayerData.get(who.getUniqueId()));
|
super(PlayerData.get(who.getUniqueId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return cancelled;
|
||||||
|
@ -1003,16 +1003,21 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
|||||||
return skillCasting != null;
|
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");
|
Validate.isTrue(!isCasting(), "Player already in casting mode");
|
||||||
PlayerEnterCastingModeEvent event = new PlayerEnterCastingModeEvent(getPlayer());
|
PlayerEnterCastingModeEvent event = new PlayerEnterCastingModeEvent(getPlayer());
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
if (event.isCancelled()){
|
if (event.isCancelled()){
|
||||||
skillCasting.close();
|
skillCasting.close();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
this.skillCasting = skillCasting;
|
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
|
* 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(){
|
public boolean leaveSkillCasting(){
|
||||||
this.leaveSkillCasting(false);
|
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");
|
Validate.isTrue(isCasting(), "Player not in casting mode");
|
||||||
if (!skipEvent) {
|
if (!skipEvent) {
|
||||||
PlayerExitCastingModeEvent event = new PlayerExitCastingModeEvent(getPlayer());
|
PlayerExitCastingModeEvent event = new PlayerExitCastingModeEvent(getPlayer());
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
skillCasting.close();
|
skillCasting.close();
|
||||||
this.skillCasting = null;
|
this.skillCasting = null;
|
||||||
setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE, 0); // Reset action bar
|
setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE, 0); // Reset action bar
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayActionBar(String message) {
|
public void displayActionBar(String message) {
|
||||||
|
@ -79,8 +79,9 @@ public class KeyCombos implements SkillCastingListener {
|
|||||||
if (event.getPressed().shouldCancelEvent()) event.setCancelled(true);
|
if (event.getPressed().shouldCancelEvent()) event.setCancelled(true);
|
||||||
|
|
||||||
// Start combo
|
// Start combo
|
||||||
playerData.setSkillCasting(new CustomSkillCastingInstance(playerData));
|
if (playerData.setSkillCasting(new CustomSkillCastingInstance(playerData))) {
|
||||||
if (beginComboSound != null) beginComboSound.playTo(player);
|
if (beginComboSound != null) beginComboSound.playTo(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -95,8 +96,7 @@ public class KeyCombos implements SkillCastingListener {
|
|||||||
final @NotNull ComboMap comboMap = Objects.requireNonNullElse(playerData.getProfess().getComboMap(), this.comboMap);
|
final @NotNull ComboMap comboMap = Objects.requireNonNullElse(playerData.getProfess().getComboMap(), this.comboMap);
|
||||||
if (comboMap.isComboStart(event.getPressed())) {
|
if (comboMap.isComboStart(event.getPressed())) {
|
||||||
casting = new CustomSkillCastingInstance(playerData);
|
casting = new CustomSkillCastingInstance(playerData);
|
||||||
playerData.setSkillCasting(casting);
|
if (!playerData.setSkillCasting(casting)) {
|
||||||
if (!playerData.isCasting()){
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (beginComboSound != null) beginComboSound.playTo(player);
|
if (beginComboSound != null) beginComboSound.playTo(player);
|
||||||
|
@ -56,11 +56,9 @@ public class SkillBar implements SkillCastingListener {
|
|||||||
// Enter spell casting
|
// Enter spell casting
|
||||||
final PlayerData playerData = event.getData();
|
final PlayerData playerData = event.getData();
|
||||||
if (player.getGameMode() != GameMode.SPECTATOR && (MMOCore.plugin.configManager.canCreativeCast || player.getGameMode() != GameMode.CREATIVE) && !playerData.isCasting() && !playerData.getBoundSkills().isEmpty()) {
|
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.setSkillCasting(new CustomSkillCastingInstance(playerData))) {
|
||||||
if (!playerData.isCasting()){
|
MMOCore.plugin.soundManager.getSound(SoundEvent.SPELL_CAST_BEGIN).playTo(player);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
MMOCore.plugin.soundManager.getSound(SoundEvent.SPELL_CAST_BEGIN).playTo(player);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,10 +77,10 @@ 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
|
||||||
playerData.setSkillCasting(new CustomSkillCastingInstance(playerData));
|
if (!playerData.setSkillCasting(new CustomSkillCastingInstance(playerData))) {
|
||||||
if (!playerData.isCasting()){
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enterSound != null) enterSound.playTo(player);
|
if (enterSound != null) enterSound.playTo(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user