-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
InventoryPicksUpItemScriptEvent.java
103 lines (93 loc) · 3.03 KB
/
InventoryPicksUpItemScriptEvent.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
package com.denizenscript.denizen.events.item;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.InventoryTag;
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.ObjectTag;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
public class InventoryPicksUpItemScriptEvent extends BukkitScriptEvent implements Listener {
// <--[event]
// @Events
// inventory picks up item
// inventory picks up <item>
// <inventory type> picks up item
// <inventory type> picks up <item>
//
// @Regex ^on [^\s]+ picks up [^\s]+$
//
// @Group Item
//
// @Location true
//
// @Cancellable true
//
// @Triggers when a hopper or hopper minecart picks up an item.
//
// @Context
// <context.inventory> returns the InventoryTag that picked up the item.
// <context.item> returns the ItemTag.
// <context.entity> returns a EntityTag of the item entity.
//
// -->
public InventoryPicksUpItemScriptEvent() {
instance = this;
}
public static InventoryPicksUpItemScriptEvent instance;
public InventoryTag inventory;
public ItemTag item;
public InventoryPickupItemEvent event;
@Override
public boolean couldMatch(ScriptPath path) {
if (!path.eventArgLowerAt(1).equals("picks") || !path.eventArgLowerAt(2).equals("up")) {
return false;
}
if (couldMatchEntity(path.eventArgLowerAt(0))) {
return false;
}
if (!couldMatchInventory(path.eventArgLowerAt(0))) {
return false;
}
if (!couldMatchItem(path.eventArgLowerAt(3))) {
return false;
}
return true;
}
@Override
public boolean matches(ScriptPath path) {
if (!tryInventory(inventory, path.eventArgLowerAt(0))) {
return false;
}
if (!tryItem(item, path.eventArgLowerAt(3))) {
return false;
}
if (!runInCheck(path, event.getItem().getLocation())) {
return false;
}
return super.matches(path);
}
@Override
public String getName() {
return "InventoryPicksUpItem";
}
@Override
public ObjectTag getContext(String name) {
switch (name) {
case "item":
return item;
case "inventory":
return inventory;
case "entity":
return new EntityTag(event.getItem());
}
return super.getContext(name);
}
@EventHandler
public void onInvPicksUpItem(InventoryPickupItemEvent event) {
this.event = event;
inventory = InventoryTag.mirrorBukkitInventory(event.getInventory());
item = new ItemTag(event.getItem());
fire(event);
}
}