/
EntityAgeLocked.java
77 lines (67 loc) · 2.64 KB
/
EntityAgeLocked.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.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import net.citizensnpcs.trait.Age;
import org.bukkit.entity.Breedable;
public class EntityAgeLocked extends EntityProperty {
public static boolean describes(EntityTag entity) {
return entity.getBukkitEntity() instanceof Breedable;
}
@Override
public ElementTag getPropertyValue() {
return as(Breedable.class).getAgeLock() ? new ElementTag(true) : null;
}
@Override
public String getPropertyId() {
return "age_locked";
}
public static void register() {
// <--[tag]
// @attribute <EntityTag.is_age_locked>
// @returns ElementTag(Boolean)
// @group properties
// @deprecated use 'age_locked'.
// @description
// Deprecated in favor of <@link tag EntityTag.age_locked>.
// -->
// <--[tag]
// @attribute <EntityTag.age_locked>
// @returns ElementTag(Boolean)
// @mechanism EntityTag.age_locked
// @group properties
// @description
// Returns whether the entity is locked into its current age.
// -->
PropertyParser.registerTag(EntityAgeLocked.class, ElementTag.class, "age_locked", (attribute, prop) -> {
return new ElementTag(prop.as(Breedable.class).getAgeLock());
}, "is_age_locked");
// <--[mechanism]
// @object EntityTag
// @name age_lock
// @input ElementTag(Boolean)
// @deprecated use 'age_locked'.
// @description
// Deprecated in favor of <@link mechanism EntityTag.age_locked>.
// -->
// <--[mechanism]
// @object EntityTag
// @name age_locked
// @input ElementTag(Boolean)
// @description
// Sets whether the entity is locked into its current age.
// @tags
// <EntityTag.age_locked>
// -->
PropertyParser.registerMechanism(EntityAgeLocked.class, ElementTag.class, "age_locked", (prop, mechanism, input) -> {
if (mechanism.requireBoolean()) {
if (prop.object.isCitizensNPC()) {
prop.object.getDenizenNPC().getCitizen().getOrAddTrait(Age.class).setLocked(input.asBoolean());
}
else {
prop.as(Breedable.class).setAgeLock(input.asBoolean());
}
}
}, "age_lock");
}
}