-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
EntityAware.java
79 lines (66 loc) · 2.79 KB
/
EntityAware.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
package com.denizenscript.denizen.objects.properties.entity;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import org.bukkit.entity.Mob;
public class EntityAware implements Property {
public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag && ((EntityTag) entity).getBukkitEntity() instanceof Mob;
}
public static EntityAware getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
}
return new EntityAware((EntityTag) entity);
}
public static final String[] handledMechs = new String[] {
"is_aware"
};
private EntityAware(EntityTag entity) {
this.entity = entity;
}
EntityTag entity;
@Override
public String getPropertyString() {
return String.valueOf(((Mob) entity.getBukkitEntity()).isAware());
}
@Override
public String getPropertyId() {
return "is_aware";
}
public static void registerTags() {
// <--[tag]
// @attribute <EntityTag.is_aware>
// @returns ElementTag(Boolean)
// @mechanism EntityTag.is_aware
// @group attributes
// @description
// Returns whether the entity is aware of its surroundings.
// Unaware entities will not perform any actions on their own, such as pathfinding or attacking.
// Similar to <@link tag EntityTag.has_ai>, except allows the entity to be moved by gravity, being pushed or attacked, etc.
// -->
PropertyParser.<EntityAware>registerTag("is_aware", (attribute, entity) -> {
return new ElementTag(((Mob) entity.entity.getBukkitEntity()).isAware());
});
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object EntityTag
// @name is_aware
// @input ElementTag(Boolean)
// @description
// Sets whether the entity is aware of its surroundings.
// Unaware entities will not perform any actions on their own, such as pathfinding or attacking.
// Similar to <@link mechanism EntityTag.has_ai>, except allows the entity to be moved by gravity, being pushed or attacked, etc.
// @tags
// <EntityTag.is_aware>
// -->
if (mechanism.matches("is_aware") && mechanism.requireBoolean()) {
((Mob) entity.getBukkitEntity()).setAware(mechanism.getValue().asBoolean());
}
}
}