-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
EntityInfected.java
130 lines (105 loc) · 3.84 KB
/
EntityInfected.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package net.aufdemrand.denizen.objects.properties.entity;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Mechanism;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.tags.Attribute;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Zombie;
import org.bukkit.entity.ZombieVillager;
public class EntityInfected implements Property {
public static boolean describes(dObject entity) {
if (!(entity instanceof dEntity)) {
return false;
}
// Check if a Villager or Zombie -- the only two EntityTypes that can be 'infected'
return ((dEntity) entity).getBukkitEntityType() == EntityType.ZOMBIE
|| ((dEntity) entity).getBukkitEntityType() == EntityType.VILLAGER;
}
public static EntityInfected getFrom(dObject entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityInfected((dEntity) entity);
}
}
public static final String[] handledTags = new String[] {
"is_infected"
};
public static final String[] handledMechs = new String[] {
"is_infected"
};
///////////////////
// Instance Fields and Methods
/////////////
private EntityInfected(dEntity item) {
infected = item;
}
dEntity infected;
public boolean isInfected() {
return infected.getBukkitEntity() instanceof Zombie
&& infected.getBukkitEntityType() == EntityType.ZOMBIE_VILLAGER;
}
public void setInfected(boolean bool) {
if (bool) {
if (infected.isCitizensNPC()) {
NPC infected_npc = infected.getDenizenNPC().getCitizen();
infected_npc.setBukkitEntityType(EntityType.ZOMBIE_VILLAGER);
}
LivingEntity entity = infected.getLivingEntity();
// Make a new entity
ZombieVillager infect = (ZombieVillager) entity.getLocation().getWorld().spawnEntity(infected.getLocation(), EntityType.ZOMBIE_VILLAGER);
// Set health
infect.setHealth(entity.getHealth());
// Set equipment
infect.getEquipment().setArmorContents(entity.getEquipment().getArmorContents());
// Remove the Villager
entity.remove();
// Set the dEntity to the new entity
infected.setEntity(infect);
}
}
/////////
// Property Methods
///////
@Override
public String getPropertyString() {
if (isInfected()) {
return "true";
}
else {
return null;
}
}
@Override
public String getPropertyId() {
return "infected";
}
///////////
// dObject Attributes
////////
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
if (attribute.startsWith("is_infected")) {
dB.echoError("Different infection types are represented by different entity types. Please remove usage of the 'is_infected' tag.");
return new Element(isInfected())
.getAttribute(attribute.fulfill(1));
}
return null;
}
@Override
public void adjust(Mechanism mechanism) {
if (mechanism.matches("is_infected") && mechanism.requireBoolean()) {
dB.echoError("Different infection types are represented by different entity types. Please remove usage of the 'is_infected' mechanism.");
setInfected(mechanism.getValue().asBoolean());
}
}
}