Skip to content

Commit

Permalink
meta patches and clicks entity offhand support
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 9, 2021
1 parent 7392f8e commit 910b209
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Expand Up @@ -4,6 +4,7 @@
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.utilities.Deprecations;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -35,6 +36,7 @@ public class PlayerRightClicksEntityScriptEvent extends BukkitScriptEvent implem
// @Context
// <context.entity> returns the EntityTag the player is clicking on.
// <context.item> returns the ItemTag the player is clicking with.
// <context.hand> returns "offhand" or "mainhand" to indicate which hand was used to fire the event. Some events fire twice - once for each hand.
// <context.click_position> returns a LocationTag of the click position (as a world-less vector, relative to the entity's center). This is only available when clicking armor stands.
//
// @Player Always.
Expand Down Expand Up @@ -94,6 +96,9 @@ public ObjectTag getContext(String name) {
else if (name.equals("item")) {
return item;
}
else if (name.equals("hand")) {
return new ElementTag(event.getHand() == EquipmentSlot.OFF_HAND ? "offhand" : "mainhand");
}
else if (name.equals("location")) {
Deprecations.playerRightClicksEntityContext.warn();
return entity.getLocation();
Expand All @@ -118,11 +123,8 @@ public void playerRightClicksEntity(PlayerInteractEntityEvent event) {
}

public void playerRightClicksEntityHandler(PlayerInteractEntityEvent event) {
if (event.getHand() == EquipmentSlot.OFF_HAND) {
return;
}
entity = new EntityTag(event.getRightClicked());
item = new ItemTag(event.getPlayer().getEquipment().getItemInMainHand());
item = new ItemTag(event.getPlayer().getEquipment().getItem(event.getHand()));
this.event = event;
fire(event);
}
Expand Down
Expand Up @@ -56,7 +56,7 @@ public class EntityScriptContainer extends ScriptContainer {
// age: baby/adult/<#>
// </code>
//
// MORE OPTIONS ARE LISTED HERE: <@link url /denizen/mecs/entitytag.>
// MORE OPTIONS ARE LISTED HERE: <@link url https://meta.denizenscript.com/Docs/Mechanisms/entitytag.>
//
// -->

Expand Down
Expand Up @@ -192,7 +192,7 @@ public boolean needsHandleArgPrefix(String prefix) {
// - assign set script:MyScript npc:<entry[save].created_npc>
//
// Denizen tracks a "linked player" and a "linked NPC" in queues and the commands within.
// Many commands automatically operate on the linked player/NPC or by default or exclusively
// Many commands automatically operate on the linked player/NPC default or exclusively
// (for example, "give" defaults to giving items to the linked player but that can be changed with the "to" argument,
// "assignment" exclusively changes the assignment of the linked NPC, and that cannot be changed except by the global NPC argument).
//
Expand Down

0 comments on commit 910b209

Please sign in to comment.