-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
EntityPatrolTarget.java
91 lines (78 loc) · 3.04 KB
/
EntityPatrolTarget.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
package com.denizenscript.denizen.objects.properties.entity;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.LocationTag;
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.block.Block;
import org.bukkit.entity.Raider;
public class EntityPatrolTarget implements Property {
public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag && ((EntityTag) entity).getBukkitEntity() instanceof Raider;
}
public static EntityPatrolTarget getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityPatrolTarget((EntityTag) entity);
}
}
public static final String[] handledMechs = new String[] {
"patrol_target"
};
private EntityPatrolTarget(EntityTag entity) {
this.entity = entity;
}
EntityTag entity;
@Override
public String getPropertyString() {
Block target = ((Raider) entity.getBukkitEntity()).getPatrolTarget();
if (target == null) {
return null;
}
return new LocationTag(target.getLocation()).identify();
}
@Override
public String getPropertyId() {
return "patrol_target";
}
public static void registerTags() {
// <--[tag]
// @attribute <EntityTag.patrol_target>
// @returns LocationTag
// @mechanism EntityTag.patrol_target
// @group properties
// @description
// If the entity is raider mob (like a pillager), returns whether the entity is allowed to join active raids.
// -->
PropertyParser.registerTag(EntityPatrolTarget.class, LocationTag.class, "patrol_target", (attribute, object) -> {
Block target = ((Raider) object.entity.getBukkitEntity()).getPatrolTarget();
if (target == null) {
return null;
}
return new LocationTag(target.getLocation());
});
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object EntityTag
// @name patrol_target
// @input LocationTag
// @description
// If the entity is raider mob (like a pillager), changes whether the entity is allowed to join active raids.
// @tags
// <EntityTag.patrol_target>
// -->
if (mechanism.matches("patrol_target")) {
if (mechanism.hasValue() && mechanism.requireObject(LocationTag.class)) {
((Raider) entity.getBukkitEntity()).setPatrolTarget(mechanism.valueAsType(LocationTag.class).getBlock());
}
else {
((Raider) entity.getBukkitEntity()).setPatrolTarget(null);
}
}
}
}