From 18813964dcf464c30e9f8e79f7d0ab2ba14a5b56 Mon Sep 17 00:00:00 2001 From: Alex 'mcmonkey' Goodwin Date: Thu, 25 Feb 2021 06:51:50 -0800 Subject: [PATCH] Clicks Block event: default to player eye loc when clicking air --- .../events/player/PlayerClicksBlockScriptEvent.java | 8 ++++---- .../denizen/scripts/commands/core/ZapCommand.java | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/player/PlayerClicksBlockScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/player/PlayerClicksBlockScriptEvent.java index 6969e77235..ab48481f0d 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/player/PlayerClicksBlockScriptEvent.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/player/PlayerClicksBlockScriptEvent.java @@ -41,8 +41,8 @@ public class PlayerClicksBlockScriptEvent extends BukkitScriptEvent implements L // // @Context // returns the ItemTag the player is clicking with. - // returns the LocationTag the player is clicking on. - // returns a LocationTag of the air block in front of the clicked block. + // returns the LocationTag the player is clicking on. If the player clicked air, will be the player's head location. + // returns a LocationTag of the air block in front of the clicked block. If the player clicked air, will be null. // returns an ElementTag of the Spigot API click type <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/block/Action.html>. // returns an ElementTag of the used hand. // @@ -140,7 +140,7 @@ public boolean matches(ScriptPath path) { if (!runUsingCheck(path)) { return false; } - if (!runInCheck(path, location != null ? location : event.getPlayer().getLocation())) { + if (!runInCheck(path, location)) { return false; } return super.matches(path); @@ -197,7 +197,7 @@ public void playerClicksBlock(PlayerInteractEvent event) { blockMaterial = event.hasBlock() ? new MaterialTag(event.getClickedBlock()) : new MaterialTag(Material.AIR); hand = new ElementTag(event.getHand().name()); item = new ItemTag(event.getItem()); - location = event.hasBlock() ? new LocationTag(event.getClickedBlock().getLocation()) : null; + location = new LocationTag(event.hasBlock() ? event.getClickedBlock().getLocation() : event.getPlayer().getEyeLocation()); click_type = new ElementTag(event.getAction().name()); cancelled = event.isCancelled() && event.useItemInHand() == Event.Result.DENY; // Spigot is dumb! this.event = event; diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/core/ZapCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/core/ZapCommand.java index a1aeca4014..c6f61e7d43 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/core/ZapCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/core/ZapCommand.java @@ -15,6 +15,7 @@ import com.denizenscript.denizencore.scripts.ScriptEntry; import com.denizenscript.denizencore.scripts.commands.AbstractCommand; import com.denizenscript.denizencore.utilities.CoreUtilities; +import com.denizenscript.denizencore.utilities.Deprecations; import org.bukkit.event.Listener; public class ZapCommand extends AbstractCommand implements Listener { @@ -77,17 +78,15 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException && !scriptEntry.hasObject("step") && arg.hasPrefix() && arg.getPrefix().matchesArgumentType(ScriptTag.class)) { + Deprecations.zapPrefix.warn(scriptEntry); scriptEntry.addObject("script", arg.getPrefix().asType(ScriptTag.class)); scriptEntry.addObject("step", arg.asElement()); } else if (!scriptEntry.hasObject("script") && arg.matchesArgumentType(ScriptTag.class) + && arg.asType(ScriptTag.class).getType().equals("interact") && !arg.matchesPrefix("step")) { - ScriptTag script = arg.asType(ScriptTag.class); - if (!CoreUtilities.toLowerCase(script.getType()).equals("interact")) { - throw new InvalidArgumentsException("Script specified must be an 'interact' script!"); - } - scriptEntry.addObject("script", script); + scriptEntry.addObject("script", arg.asType(ScriptTag.class)); } else if (!scriptEntry.hasObject("step")) { scriptEntry.addObject("step", arg.asElement());