-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
EntityArmorPose.java
245 lines (210 loc) · 7.73 KB
/
EntityArmorPose.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
package net.aufdemrand.denizen.objects.properties.entity;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.Mechanism;
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.util.EulerAngle;
import java.util.Iterator;
public class EntityArmorPose implements Property {
public static boolean describes(dObject entity) {
return entity instanceof dEntity
&& ((dEntity) entity).getBukkitEntityType() == EntityType.ARMOR_STAND;
}
public static EntityArmorPose getFrom(dObject entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityArmorPose((dEntity) entity);
}
}
///////////////////
// Instance Fields and Methods
/////////////
private EntityArmorPose(dEntity ent) {
entity = ent;
}
dEntity entity;
/////////
// Property Methods
///////
@Override
public String getPropertyString() {
return getPoseList().identify();
}
@Override
public String getPropertyId() {
return "armor_pose";
}
private dList getPoseList() {
ArmorStand armorStand = (ArmorStand) entity.getBukkitEntity();
dList list = new dList();
for (PosePart posePart : PosePart.values()) {
list.add(CoreUtilities.toLowerCase(posePart.name()));
list.add(fromEulerAngle(posePart.getAngle(armorStand)).identify());
}
return list;
}
///////////
// dObject Attributes
////////
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// <--[tag]
// @attribute <e@entity.armor_pose_list>
// @returns dList
// @group attributes
// @description
// Returns a list of all poses and angles for the armor stand in the
// format: PART|ANGLE|...
// For example, head|4.5,3,4.5|body|5.4,3.2,1
// Angles are in radians!
// -->
if (attribute.startsWith("armor_pose_list")) {
return getPoseList().getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <e@entity.armor_pose[<part>]>
// @returns dLocation
// @group attributes
// @description
// Returns the current angle pose for the specified part.
// Valid parts: HEAD, BODY, LEFT_ARM, RIGHT_ARM, LEFT_LEG, RIGHT_LEG
// Angles are in radians!
// -->
else if (attribute.startsWith("armor_pose") && attribute.hasContext(1)) {
String name = attribute.getContext(1);
PosePart posePart = PosePart.fromName(name);
if (posePart == null) {
dB.echoError("Invalid pose part specified: " + name);
return null;
}
else {
return fromEulerAngle(posePart.getAngle((ArmorStand) entity.getBukkitEntity()))
.getAttribute(attribute.fulfill(1));
}
}
return null;
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object dEntity
// @name armor_pose
// @input dList
// @description
// Sets the angle for various parts of the armor stand in the
// format: PART|ANGLE|...
// For example, head|4.5,3,4.5|body|5.4,3.2,1
// Valid parts: HEAD, BODY, LEFT_ARM, RIGHT_ARM, LEFT_LEG, RIGHT_LEG
// Angles are in radians!
// @tags
// <e@entity.armor_pose_list>
// <e@entity.armor_pose[<part>]>
// -->
if (mechanism.matches("armor_pose")) {
ArmorStand armorStand = (ArmorStand) entity.getBukkitEntity();
dList list = mechanism.getValue().asType(dList.class);
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()) {
String name = iterator.next();
String angle = iterator.next();
PosePart posePart = PosePart.fromName(name);
if (posePart == null) {
dB.echoError("Invalid pose part specified: " + name + "; ignoring next: " + angle);
}
else {
posePart.setAngle(armorStand, toEulerAngle(dLocation.valueOf(angle)));
}
}
}
}
private static dLocation fromEulerAngle(EulerAngle eulerAngle) {
return new dLocation(null, eulerAngle.getX(), eulerAngle.getY(), eulerAngle.getZ());
}
private static EulerAngle toEulerAngle(dLocation location) {
return new EulerAngle(location.getX(), location.getY(), location.getZ());
}
private enum PosePart {
HEAD {
@Override
EulerAngle getAngle(ArmorStand armorStand) {
return armorStand.getHeadPose();
}
@Override
void setAngle(ArmorStand armorStand, EulerAngle eulerAngle) {
armorStand.setHeadPose(eulerAngle);
}
},
BODY {
@Override
EulerAngle getAngle(ArmorStand armorStand) {
return armorStand.getBodyPose();
}
@Override
void setAngle(ArmorStand armorStand, EulerAngle eulerAngle) {
armorStand.setBodyPose(eulerAngle);
}
},
LEFT_ARM {
@Override
EulerAngle getAngle(ArmorStand armorStand) {
return armorStand.getLeftArmPose();
}
@Override
void setAngle(ArmorStand armorStand, EulerAngle eulerAngle) {
armorStand.setLeftArmPose(eulerAngle);
}
},
RIGHT_ARM {
@Override
EulerAngle getAngle(ArmorStand armorStand) {
return armorStand.getRightArmPose();
}
@Override
void setAngle(ArmorStand armorStand, EulerAngle eulerAngle) {
armorStand.setRightArmPose(eulerAngle);
}
},
LEFT_LEG {
@Override
EulerAngle getAngle(ArmorStand armorStand) {
return armorStand.getLeftLegPose();
}
@Override
void setAngle(ArmorStand armorStand, EulerAngle eulerAngle) {
armorStand.setLeftLegPose(eulerAngle);
}
},
RIGHT_LEG {
@Override
EulerAngle getAngle(ArmorStand armorStand) {
return armorStand.getRightLegPose();
}
@Override
void setAngle(ArmorStand armorStand, EulerAngle eulerAngle) {
armorStand.setRightLegPose(eulerAngle);
}
};
abstract EulerAngle getAngle(ArmorStand armorStand);
abstract void setAngle(ArmorStand armorStand, EulerAngle eulerAngle);
static PosePart fromName(String name) {
for (PosePart posePart : PosePart.values()) {
if (posePart.name().equalsIgnoreCase(name)) {
return posePart;
}
}
return null;
}
}
}