/
EntityProfessional.java
84 lines (59 loc) · 2.03 KB
/
EntityProfessional.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
package net.aufdemrand.denizen.objects.properties;
import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.tags.Attribute;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Villager;
public class EntityProfessional implements Property {
public static boolean describes(dEntity entity) {
return entity.getEntityType() == EntityType.VILLAGER;
}
public static EntityProfessional getFrom(dEntity entity) {
if (!describes(entity)) return null;
else return new EntityProfessional(entity);
}
///////////////////
// Instance Fields and Methods
/////////////
private EntityProfessional(dEntity entity) {
professional = entity;
}
dEntity professional;
private Villager.Profession getProfession() {
if (professional == null) return null;
return ((Villager) professional.getBukkitEntity()).getProfession();
}
public void setProfession(Villager.Profession profession) {
if (professional != null)
((Villager) professional.getBukkitEntity()).setProfession(profession);
}
/////////
// Property Methods
///////
@Override
public String getPropertyString() {
return getPropertyId() + '=' + getProfession() + ';';
}
@Override
public String getPropertyId() {
return "professional";
}
///////////
// dObject Attributes
////////
@Override
public String getAttributes(Attribute attribute) {
if (attribute == null) return "null";
// <--[tag]
// @attribute <e@professional_entity.profession>
// @returns Element
// @description
// Returns the profession of a professional entity.
// Currently, only 'Villager'-type entities can be professionals.
// -->
if (attribute.startsWith("profession"))
return new Element(getProfession().name())
.getAttribute(attribute.fulfill(1));
return null;
}
}