mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-24 00:15:16 +01:00
Key combos now always cancel corresponding events
This commit is contained in:
parent
8a5a1b1070
commit
a49a375eed
@ -5,6 +5,12 @@ import net.Indyuce.mmocore.skill.cast.PlayerKey;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Basically an event wrapper for multiple bukkit events that
|
||||
* correspond to keys the player can use to cast skill combos.
|
||||
*
|
||||
* @author jules
|
||||
*/
|
||||
public class PlayerKeyPressEvent extends PlayerDataEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
@ -18,6 +24,7 @@ public class PlayerKeyPressEvent extends PlayerDataEvent implements Cancellable
|
||||
*
|
||||
* @param playerData Player pressing the key
|
||||
* @param pressed Key being pressed
|
||||
* @param cancellable Cancellable event being wrapped
|
||||
*/
|
||||
public PlayerKeyPressEvent(PlayerData playerData, PlayerKey pressed, Cancellable cancellable) {
|
||||
super(playerData);
|
||||
|
@ -15,11 +15,14 @@ import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
|
||||
/**
|
||||
* This registers all the KeyPress events
|
||||
* This registers all the KeyPress events. All events are registered
|
||||
* with LOWEST priority so that if the wrapped event happens to be
|
||||
* cancelled because of a key press, it is canceled before any plugin
|
||||
* can deal with it.
|
||||
*/
|
||||
public class PlayerPressKeyListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void registerCrouchKey(PlayerToggleSneakEvent event) {
|
||||
if (event.isSneaking()) {
|
||||
PlayerKeyPressEvent called = new PlayerKeyPressEvent(PlayerData.get(event.getPlayer()), PlayerKey.CROUCH, event);
|
||||
@ -27,7 +30,7 @@ public class PlayerPressKeyListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void registerClickKey(PlayerInteractEvent event) {
|
||||
if (event.useItemInHand() != Event.Result.DENY && event.getAction().name().contains("CLICK")) {
|
||||
boolean rightClick = event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK;
|
||||
@ -36,13 +39,13 @@ public class PlayerPressKeyListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void registerDropKey(PlayerDropItemEvent event) {
|
||||
PlayerKeyPressEvent called = new PlayerKeyPressEvent(PlayerData.get(event.getPlayer()), PlayerKey.DROP, event);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void registerSwapHandsKey(PlayerSwapHandItemsEvent event) {
|
||||
PlayerKeyPressEvent called = new PlayerKeyPressEvent(PlayerData.get(event.getPlayer()), PlayerKey.SWAP_HANDS, event);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
|
@ -100,8 +100,7 @@ public class KeyCombos implements Listener {
|
||||
if (!event.getData().isCasting()) {
|
||||
if (event.getPressed() == initializerKey) {
|
||||
|
||||
// Cancel event if necessary
|
||||
if (event.getPressed().shouldCancelEvent())
|
||||
// Always cancel event
|
||||
event.setCancelled(true);
|
||||
|
||||
// Start combo
|
||||
@ -119,8 +118,7 @@ public class KeyCombos implements Listener {
|
||||
if (comboClickSound != null)
|
||||
comboClickSound.playTo(player);
|
||||
|
||||
// Cancel event if necessary
|
||||
if (event.getPressed().shouldCancelEvent())
|
||||
// Always cancel event
|
||||
event.setCancelled(true);
|
||||
|
||||
// Hash current combo and check
|
||||
|
Loading…
Reference in New Issue
Block a user