-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
EntityCanJoinRaid.java
77 lines (64 loc) · 2.55 KB
/
EntityCanJoinRaid.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
package com.denizenscript.denizen.objects.properties.entity;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import org.bukkit.entity.Raider;
public class EntityCanJoinRaid implements Property {
public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag && ((EntityTag) entity).getBukkitEntity() instanceof Raider;
}
public static EntityCanJoinRaid getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityCanJoinRaid((EntityTag) entity);
}
}
public static final String[] handledMechs = new String[] {
"can_join_raid"
};
private EntityCanJoinRaid(EntityTag entity) {
this.entity = entity;
}
EntityTag entity;
@Override
public String getPropertyString() {
return ((Raider) entity.getBukkitEntity()).isCanJoinRaid() ? "true" : "false";
}
@Override
public String getPropertyId() {
return "can_join_raid";
}
public static void registerTags() {
// <--[tag]
// @attribute <EntityTag.can_join_raid>
// @returns ElementTag(Boolean)
// @mechanism EntityTag.can_join_raid
// @group properties
// @description
// If the entity is raider mob (like a pillager), returns whether the entity is allowed to join active raids.
// -->
PropertyParser.<EntityCanJoinRaid>registerTag("can_join_raid", (attribute, object) -> {
return new ElementTag(((Raider) object.entity.getBukkitEntity()).isCanJoinRaid());
});
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object EntityTag
// @name can_join_raid
// @input ElementTag(Boolean)
// @description
// If the entity is raider mob (like a pillager), changes whether the entity is allowed to join active raids.
// @tags
// <EntityTag.can_join_raid>
// -->
if (mechanism.matches("can_join_raid") && mechanism.requireBoolean()) {
((Raider) entity.getBukkitEntity()).setCanJoinRaid(mechanism.getValue().asBoolean());
}
}
}