Skip to content

Commit

Permalink
Clicks Block event: default to player eye loc when clicking air
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 25, 2021
1 parent 4eda734 commit 1881396
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Expand Up @@ -41,8 +41,8 @@ public class PlayerClicksBlockScriptEvent extends BukkitScriptEvent implements L
//
// @Context
// <context.item> returns the ItemTag the player is clicking with.
// <context.location> returns the LocationTag the player is clicking on.
// <context.relative> returns a LocationTag of the air block in front of the clicked block.
// <context.location> returns the LocationTag the player is clicking on. If the player clicked air, will be the player's head location.
// <context.relative> returns a LocationTag of the air block in front of the clicked block. If the player clicked air, will be null.
// <context.click_type> returns an ElementTag of the Spigot API click type <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/block/Action.html>.
// <context.hand> returns an ElementTag of the used hand.
//
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 1881396

Please sign in to comment.