/
FurnaceSmeltsItemScriptEvent.java
106 lines (94 loc) · 3.25 KB
/
FurnaceSmeltsItemScriptEvent.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
105
106
package com.denizenscript.denizen.events.block;
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.containers.ScriptContainer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
public class FurnaceSmeltsItemScriptEvent extends BukkitScriptEvent implements Listener {
// <--[event]
// @Events
// furnace smelts item (into <item>)
// furnace smelts <item> (into <item>)
//
// @Cancellable true
//
// @Regex ^on furnace smelts [^\s]+( into [^\s]+)?$
//
// @Group Block
//
// @Switch in <area>
//
// @Triggers when a furnace smelts an item.
//
// @Context
// <context.location> returns the LocationTag of the furnace.
// <context.source_item> returns the ItemTag that is being smelted.
// <context.result_item> returns the ItemTag that is the result of the smelting.
//
// @Determine
// ItemTag to set the item that is the result of the smelting.
//
// -->
public FurnaceSmeltsItemScriptEvent() {
instance = this;
}
public static FurnaceSmeltsItemScriptEvent instance;
public ItemTag source_item;
public ItemTag result_item;
public LocationTag location;
public FurnaceSmeltEvent event;
@Override
public boolean couldMatch(ScriptPath path) {
return path.eventLower.startsWith("furnace smelts");
}
@Override
public boolean matches(ScriptPath path) {
if (!tryItem(source_item, path.eventArgLowerAt(2))) {
return false;
}
if (path.eventArgLowerAt(3).equals("into")) {
if (!tryItem(result_item, path.eventArgLowerAt(4))) {
return false;
}
}
return runInCheck(path, location);
}
@Override
public String getName() {
return "FurnaceSmelts";
}
@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
String determination = determinationObj.toString();
if (ItemTag.matches(determination)) {
result_item = ItemTag.valueOf(determination, path.container);
event.setResult(result_item.getItemStack());
return true;
}
return super.applyDetermination(path, determinationObj);
}
@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
return location;
}
else if (name.equals("source_item")) {
return source_item;
}
else if (name.equals("result_item")) {
return result_item;
}
return super.getContext(name);
}
@EventHandler
public void onFurnaceSmelts(FurnaceSmeltEvent event) {
location = new LocationTag(event.getBlock().getLocation());
source_item = new ItemTag(event.getSource());
result_item = new ItemTag(event.getResult());
this.event = event;
fire(event);
}
}