/
EntityStrength.java
83 lines (69 loc) · 2.59 KB
/
EntityStrength.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
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.Llama;
public class EntityStrength implements Property {
public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag && ((EntityTag) entity).getBukkitEntity() instanceof Llama;
}
public static EntityStrength getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityStrength((EntityTag) entity);
}
}
public static final String[] handledMechs = new String[] {
"strength"
};
private EntityStrength(EntityTag entity) {
this.entity = entity;
}
EntityTag entity;
public ElementTag getStrength() {
return new ElementTag(((Llama) entity.getBukkitEntity()).getStrength());
}
@Override
public String getPropertyString() {
return getStrength().asString();
}
@Override
public String getPropertyId() {
return "strength";
}
public static void registerTags() {
// <--[tag]
// @attribute <EntityTag.strength>
// @returns ElementTag
// @mechanism EntityTag.strength
// @group properties
// @description
// Returns the strength of a Llama. A llama's inventory contains (strength times three) slots.
// Can be from 1 to 5 (inclusive).
// -->
PropertyParser.<EntityStrength, ElementTag>registerTag(ElementTag.class, "strength", (attribute, object) -> {
return object.getStrength();
});
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object EntityTag
// @name strength
// @input ElementTag(Boolean)
// @description
// Sets the strength of a Llama. A llama's inventory contains (strength times three) slots.
// Can be from 1 to 5 (inclusive).
// @tags
// <EntityTag.strength>
// -->
if (mechanism.matches("strength") && mechanism.requireInteger()) {
((Llama) entity.getBukkitEntity()).setStrength(mechanism.getValue().asInt());
}
}
}