-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
PrismActionBlock.java
112 lines (94 loc) · 3.38 KB
/
PrismActionBlock.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
107
108
109
110
111
112
package com.morphanone.depenizenbukkit.objects.prism.properties;
import me.botsko.prism.actions.Handler;
import net.aufdemrand.denizen.objects.dMaterial;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Mechanism;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.tags.Attribute;
import com.morphanone.depenizenbukkit.objects.prism.PrismAction;
import org.bukkit.Material;
public class PrismActionBlock implements Property {
public static boolean describes(dObject obj) {
return obj instanceof PrismAction;
}
public static PrismActionBlock getFrom(dObject action) {
if (!describes(action)) {
return null;
}
else {
return new PrismActionBlock((PrismAction) action);
}
}
///////////////////
// Instance Fields and Methods
/////////////
PrismAction prismAction;
Handler action;
private PrismActionBlock(PrismAction action) {
this.prismAction = action;
this.action = action.getAction();
}
@Override
public String getPropertyString() {
return action.getBlockId() + "," + action.getBlockSubId() + "/"
+ action.getOldBlockId() + "," + action.getOldBlockSubId();
}
@Override
public String getPropertyId() {
return "block";
}
@Override
public String getAttribute(Attribute attribute) {
// <--[tag]
// @attribute <prism@action.block>
// @returns dMaterial
// @description
// Returns the main material for this action.
// @plugin Depenizen, Prism
// -->
if (attribute.startsWith("block")) {
int id = action.getBlockId();
int subId = action.getBlockSubId();
if (id == -1) {
return null;
}
else {
return dMaterial.getMaterialFrom(Material.getMaterial(id), subId > -1 ? subId : 0)
.getAttribute(attribute.fulfill(1));
}
}
// <--[tag]
// @attribute <prism@action.alt_block>
// @returns dMaterial
// @description
// Returns the alternate material for this action.
// @plugin Depenizen, Prism
// -->
if (attribute.startsWith("alt_block")) {
int id = action.getOldBlockId();
int subId = action.getOldBlockSubId();
if (id == -1) {
return null;
}
else {
return dMaterial.getMaterialFrom(Material.getMaterial(id), subId > -1 ? subId : 0)
.getAttribute(attribute.fulfill(1));
}
}
return null;
}
@Override
public void adjust(Mechanism mechanism) {
// No documentation, internal only
if (mechanism.matches("block") && mechanism.requireObject(Element.class)) {
String[] materials = mechanism.getValue().asString().split("/");
String[] material = materials[0].split(",");
String[] old_material = materials[1].split(",");
prismAction.setBlockData(Integer.parseInt(material[0]),
Integer.parseInt(material[1]),
Integer.parseInt(old_material[0]),
Integer.parseInt(old_material[1]));
}
}
}