-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
PlayerArmorStandManipulateScriptEvent.java
104 lines (95 loc) · 4.51 KB
/
PlayerArmorStandManipulateScriptEvent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.denizenscript.denizen.events.player;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.NMSVersion;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
public class PlayerArmorStandManipulateScriptEvent extends BukkitScriptEvent implements Listener {
// <--[event]
// @Events
// player changes armor stand item
//
// @Group Player
//
// @Location true
//
// @Cancellable true
//
// @Triggers when a player modifies an armor stand entity.
//
// @Switch from:<item> to only process the event if the item on the armor stand being interacted with matches the specified item matcher.
// @Switch hand:<hand> to only process the event if the player is using a specific hand to interact with the armor stand. Available only on MC versions 1.19+.
// @Switch to:<item> to only process the event if the item held by the player matches the specified item matcher.
// @Switch slot:<slot> to only process the event if the armor stand's item slot that was interacted with is the specified slot.
// @Switch armor_stand:<entity> to only process the event if the armor stand being interacted with matches the specified entity matcher.
//
// @Context
// <context.armor_stand_item> returns the ItemTag being interacted with on the armor stand.
// <context.entity> returns an EntityTag of the armor stand.
// <context.hand> returns an ElementTag of the hand used by the player to interact with the armor stand, can be either HAND or OFF_HAND. Available only on MC versions 1.19+.
// <context.player_item> returns the ItemTag held by the player.
// <context.slot> returns an ElementTag of the armor stand's item slot that was interacted with. Valid equipment slot values can be found at <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/EquipmentSlot.html>.
//
// @Player Always.
// -->
public PlayerArmorStandManipulateScriptEvent() {
registerCouldMatcher("player changes armor stand item");
registerSwitches("from", "to", "hand", "slot", "armor_stand");
}
public PlayerArmorStandManipulateEvent event;
public EntityTag entity;
public ItemTag armorStandItem;
public ItemTag playerItem;
@Override
public boolean matches(ScriptPath path) {
if (!runInCheck(path, event.getRightClicked().getLocation())) {
return false;
}
if (!path.tryObjectSwitch("from", armorStandItem)) {
return false;
}
if (!path.tryObjectSwitch("armor_stand", entity)) {
return false;
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && !runGenericSwitchCheck(path, "hand", event.getHand().name())) {
return false;
}
if (!path.tryObjectSwitch("to", playerItem)) {
return false;
}
if (!runGenericSwitchCheck(path, "slot", event.getSlot().name())) {
return false;
}
return super.matches(path);
}
@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(event.getPlayer());
}
@Override
public ObjectTag getContext(String name) {
return switch (name) {
case "armor_stand_item" -> armorStandItem;
case "entity" -> entity;
case "hand" -> NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) ? new ElementTag(event.getHand()) : null;
case "player_item" -> playerItem;
case "slot" -> new ElementTag(event.getSlot());
default -> super.getContext(name);
};
}
@EventHandler
public void onPlayerManipulatesArmorStand(PlayerArmorStandManipulateEvent event) {
this.event = event;
entity = new EntityTag(event.getRightClicked());
playerItem = new ItemTag(event.getPlayerItem());
armorStandItem = new ItemTag(event.getArmorStandItem());
fire(event);
}
}