/
MaterialSides.java
174 lines (156 loc) · 6.52 KB
/
MaterialSides.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package com.denizenscript.denizen.objects.properties.material;
import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.*;
import org.bukkit.block.data.type.RedstoneWire;
import org.bukkit.block.data.type.Wall;
public class MaterialSides implements Property {
public static boolean describes(ObjectTag material) {
if (!(material instanceof MaterialTag)) {
return false;
}
MaterialTag mat = (MaterialTag) material;
if (!mat.hasModernData()) {
return false;
}
BlockData data = mat.getModernData();
if (!(data instanceof Wall) && !(data instanceof RedstoneWire)) {
return false;
}
return true;
}
public static MaterialSides getFrom(ObjectTag _material) {
if (!describes(_material)) {
return null;
}
else {
return new MaterialSides((MaterialTag) _material);
}
}
public static final String[] handledMechs = new String[] {
"sides", "heights"
};
private MaterialSides(MaterialTag _material) {
material = _material;
}
MaterialTag material;
public static void registerTags() {
// <--[tag]
// @attribute <MaterialTag.heights>
// @returns ListTag
// @mechanism MaterialTag.heights
// @group properties
// @deprecated Use 'sides'
// @description
// Deprecated in favor of <@link tag MaterialTag.sides>
// -->
// <--[tag]
// @attribute <MaterialTag.sides>
// @returns ListTag
// @mechanism MaterialTag.sides
// @group properties
// @description
// Returns the list of heights for a wall block, or connections for a redstone wire, in order North|East|South|West|Vertical.
// For wall blocks: For n/e/s/w, can be "tall", "low", or "none". For vertical, can be "tall" or "none".
// For redstone wires: For n/e/s/w, can be "none", "side", or "up". No vertical.
// -->
PropertyParser.registerStaticTag(MaterialSides.class, ListTag.class, "sides", (attribute, material) -> {
return material.getSidesList();
}, "heights");
}
public boolean isWall() {
return material.getModernData() instanceof Wall;
}
public Wall getWall() {
return (Wall) material.getModernData();
}
public boolean isWire() {
return material.getModernData() instanceof RedstoneWire;
}
public RedstoneWire getWire() {
return (RedstoneWire) material.getModernData();
}
public ListTag getSidesList() {
ListTag list = new ListTag(5);
if (isWall()) {
Wall wall = getWall();
list.add(wall.getHeight(BlockFace.NORTH).name());
list.add(wall.getHeight(BlockFace.EAST).name());
list.add(wall.getHeight(BlockFace.SOUTH).name());
list.add(wall.getHeight(BlockFace.WEST).name());
list.add(wall.isUp() ? "TALL" : "NONE");
}
else if (isWire()) {
RedstoneWire wire = getWire();
list.add(wire.getFace(BlockFace.NORTH).name());
list.add(wire.getFace(BlockFace.EAST).name());
list.add(wire.getFace(BlockFace.SOUTH).name());
list.add(wire.getFace(BlockFace.WEST).name());
}
return list;
}
@Override
public String getPropertyString() {
return getSidesList().identify();
}
@Override
public String getPropertyId() {
return "sides";
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object MaterialTag
// @name heights
// @input ElementTag
// @deprecated Use 'sides'
// @description
// Deprecated in favor of <@link mechanism MaterialTag.sides>
// @tags
// <MaterialTag.heights>
// -->
// <--[mechanism]
// @object MaterialTag
// @name sides
// @input ElementTag
// @description
// Sets the list of heights for a wall block, or connections for a redstone wire, in order North|East|South|West|Vertical.
// For wall blocks: For n/e/s/w, can be "tall", "low", or "none". For vertical, can be "tall" or "none".
// For redstone wires: For n/e/s/w, can be "none", "side", or "up". No vertical.
// @tags
// <MaterialTag.sides>
// -->
if ((mechanism.matches("sides") || mechanism.matches("heights")) && mechanism.requireObject(ListTag.class)) {
ListTag list = mechanism.valueAsType(ListTag.class);
if (isWall()) {
if (list.size() != 5) {
mechanism.echoError("Invalid sides list, size must be 5.");
return;
}
Wall wall = getWall();
wall.setHeight(BlockFace.NORTH, Wall.Height.valueOf(list.get(0).toUpperCase()));
wall.setHeight(BlockFace.EAST, Wall.Height.valueOf(list.get(1).toUpperCase()));
wall.setHeight(BlockFace.SOUTH, Wall.Height.valueOf(list.get(2).toUpperCase()));
wall.setHeight(BlockFace.WEST, Wall.Height.valueOf(list.get(3).toUpperCase()));
wall.setUp(CoreUtilities.toLowerCase(list.get(4)).equals("tall"));
}
else if (isWire()) {
if (list.size() != 4) {
mechanism.echoError("Invalid sides list, size must be 4.");
return;
}
RedstoneWire wire = getWire();
wire.setFace(BlockFace.NORTH, RedstoneWire.Connection.valueOf(list.get(0).toUpperCase()));
wire.setFace(BlockFace.EAST, RedstoneWire.Connection.valueOf(list.get(1).toUpperCase()));
wire.setFace(BlockFace.SOUTH, RedstoneWire.Connection.valueOf(list.get(2).toUpperCase()));
wire.setFace(BlockFace.WEST, RedstoneWire.Connection.valueOf(list.get(3).toUpperCase()));
}
}
}
}