/
EntityPlayingDead.java
80 lines (67 loc) · 2.59 KB
/
EntityPlayingDead.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
package com.denizenscript.denizen.objects.properties.entity;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import org.bukkit.entity.Axolotl;
public class EntityPlayingDead implements Property {
public static boolean describes(ObjectTag entity) {
if (!(entity instanceof EntityTag)) {
return false;
}
return ((EntityTag) entity).getBukkitEntity() instanceof Axolotl;
}
public static EntityPlayingDead getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
} else {
return new EntityPlayingDead((EntityTag) entity);
}
}
public static final String[] handledMechs = new String[] {
"playing_dead"
};
private EntityPlayingDead(EntityTag _entity) {
entity = _entity;
}
EntityTag entity;
public static void registerTags() {
// <--[tag]
// @attribute <EntityTag.playing_dead>
// @returns ElementTag(Boolean)
// @mechanism EntityTag.playing_dead
// @group properties
// @description
// If the entity is an axolotl, returns whether the entity is playing dead.
// -->
PropertyParser.<EntityPlayingDead, ElementTag>registerTag(ElementTag.class, "playing_dead", (attribute, entity) -> {
return new ElementTag(((Axolotl) entity.entity.getBukkitEntity()).isPlayingDead());
});
}
@Override
public String getPropertyString() {
return ((Axolotl) entity.getBukkitEntity()).isPlayingDead() ? "true" : null;
}
@Override
public String getPropertyId() {
return "playing_dead";
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object EntityTag
// @name playing_dead
// @input ElementTag(Boolean)
// @description
// If the entity is an axolotl, sets whether the entity is playing dead.
// This won't be successful unless the entity is unaware of its surroundings. See <@link mechanism EntityTag.is_aware>.
// @tags
// <EntityTag.playing_dead>
// -->
if (mechanism.matches("playing_dead") && mechanism.requireBoolean()) {
((Axolotl) entity.getBukkitEntity()).setPlayingDead(mechanism.getValue().asBoolean());
}
}
}