diff --git a/paper/src/main/java/com/denizenscript/denizen/paper/events/EntityLoadCrossbowScriptEvent.java b/paper/src/main/java/com/denizenscript/denizen/paper/events/EntityLoadCrossbowScriptEvent.java index ec03acb00d..042b7add6e 100644 --- a/paper/src/main/java/com/denizenscript/denizen/paper/events/EntityLoadCrossbowScriptEvent.java +++ b/paper/src/main/java/com/denizenscript/denizen/paper/events/EntityLoadCrossbowScriptEvent.java @@ -29,6 +29,8 @@ public class EntityLoadCrossbowScriptEvent extends BukkitScriptEvent implements // // @Cancellable true // + // @Switch crossbow: to only process the event if the crossbow is a specified item. + // // @Triggers when a living entity loads a crossbow with a projectile. // // @Context @@ -71,6 +73,9 @@ public boolean matches(ScriptPath path) { if (!tryEntity(entity, path.eventArgLowerAt(0))) { return false; } + if (!runWithCheck(path, new ItemTag(event.getCrossbow()), "crossbow")) { + return false; + } return super.matches(path); } diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/BukkitScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/BukkitScriptEvent.java index fd67dfcf3c..b4501f68fd 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/BukkitScriptEvent.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/BukkitScriptEvent.java @@ -761,8 +761,12 @@ else if (isAdvancedMatchable(lower)) { } } - public boolean runWithCheck(ScriptPath path, ItemTag held) { - String with = path.switches.get("with"); + public static boolean runWithCheck(ScriptPath path, ItemTag held) { + return runWithCheck(path, held, "with"); + } + + public static boolean runWithCheck(ScriptPath path, ItemTag held, String key) { + String with = path.switches.get(key); if (with != null) { if (CoreUtilities.equalsIgnoreCase(with, "item")) { return true; 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 64684a32b9..0f4a7a40b0 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 @@ -36,6 +36,7 @@ public class PlayerClicksBlockScriptEvent extends BukkitScriptEvent implements L // @Switch with: to only process the event if a specified item was held. // @Switch using:hand/off_hand/either_hand to only process the event if the specified hand was used to click. // @Switch type: to only run if the block clicked matches the material input. + // // @Location true // // @Triggers when a player clicks on a block or in the air. diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/player/PlayerFishesScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/player/PlayerFishesScriptEvent.java index 805cebe3fa..7d1772c939 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/player/PlayerFishesScriptEvent.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/player/PlayerFishesScriptEvent.java @@ -9,12 +9,14 @@ import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.scripts.ScriptEntryData; import com.denizenscript.denizencore.utilities.CoreUtilities; +import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Item; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.inventory.ItemStack; public class PlayerFishesScriptEvent extends BukkitScriptEvent implements Listener { @@ -30,6 +32,8 @@ public class PlayerFishesScriptEvent extends BukkitScriptEvent implements Listen // // @Cancellable true // + // @Switch with: to only process the event if the fishing rod is a specified item. + // // @Triggers when a player uses a fishing rod. // // @Context @@ -43,7 +47,8 @@ public class PlayerFishesScriptEvent extends BukkitScriptEvent implements Listen // "CAUGHT:" + ItemTag to change the item that was caught (only if an item was already being caught). // "XP:" + ElementTag(Number) to change how much experience will drop. // - // @Player Always. + // @Player If the fisher or the caught entity is a player (in most cases, the fisher can be assumed to be a real player). + // @NPC If the fisher or the caught entity is an NPC. // // --> @@ -66,7 +71,6 @@ public boolean couldMatch(ScriptPath path) { @Override public boolean matches(ScriptPath path) { String fish = path.eventArgLowerAt(2); - if (!fish.isEmpty() && !fish.equals("in") && !fish.equals("while")) { if (entity == null) { return false; @@ -80,18 +84,27 @@ public boolean matches(ScriptPath path) { } } } - String[] data = path.eventArgsLower; for (int index = 2; index < data.length; index++) { if (data[index].equals("while") && !data[index + 1].equalsIgnoreCase(state.asString())) { return false; } } - if (!runInCheck(path, hook.getLocation())) { return false; } - + if (path.switches.containsKey("with")) { + if (!EntityTag.isPlayer(event.getPlayer())) { + return false; + } + ItemStack held = event.getPlayer().getEquipment().getItemInMainHand(); + if (held.getType() != Material.FISHING_ROD) { + held = event.getPlayer().getEquipment().getItemInOffHand(); + } + if (!runWithCheck(path, new ItemTag(held))) { + return false; + } + } return super.matches(path); } diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/player/BlockCrackCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/player/BlockCrackCommand.java index 0a7da803c6..883ef1de52 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/player/BlockCrackCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/player/BlockCrackCommand.java @@ -63,9 +63,7 @@ public BlockCrackCommand() { @Override public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { - for (Argument arg : scriptEntry) { - if (arg.matchesPrefix("players") && arg.matchesArgumentList(PlayerTag.class)) { scriptEntry.addObject("players", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry)); @@ -83,17 +81,13 @@ else if (arg.matches("stack")) { else { arg.reportUnhandled(); } - } - if (!scriptEntry.hasObject("progress")) { throw new InvalidArgumentsException("Must specify crack animation progress!"); } - if (!scriptEntry.hasObject("location")) { throw new InvalidArgumentsException("Must specify a valid location!"); } - scriptEntry.defaultObject("players", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry))) .defaultObject("stack", new ElementTag(false)); } @@ -113,25 +107,17 @@ public void execute(ScriptEntry scriptEntry) { ElementTag progress = scriptEntry.getElement("progress"); LocationTag location = scriptEntry.getObjectTag("location"); ElementTag stack = scriptEntry.getElement("stack"); - if (scriptEntry.dbCallShouldDebug()) { - - Debug.report(scriptEntry, getName(), ArgumentHelper.debugList("players", players) - + progress.debug() + location.debug() + stack.debug()); - + Debug.report(scriptEntry, getName(), ArgumentHelper.debugList("players", players), progress, location, stack); } - Location loc = location.getBlock().getLocation(); if (!progressTracker.containsKey(loc)) { progressTracker.put(loc, new HashMap<>()); lastBase += 10; } Map uuidInt = progressTracker.get(loc); - boolean stackVal = stack.asBoolean(); - PacketHelper packetHelper = NMSHandler.getPacketHelper(); - for (PlayerTag player : players) { if (!player.isOnline()) { Debug.echoError("Players must be online!");