-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
EntityInfected.java
120 lines (92 loc) · 3.59 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
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 net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.trait.ZombieModifier;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Zombie;
public class EntityInfected implements Property {
public static boolean describes(dEntity entity) {
return entity.getEntityType() == EntityType.ZOMBIE
|| entity.getEntityType() == EntityType.VILLAGER;
}
public static EntityInfected getFrom(dEntity entity) {
if (!describes(entity)) return null;
else return new EntityInfected(entity);
}
///////////////////
// Instance Fields and Methods
/////////////
private EntityInfected(dEntity item) {
infected = item;
}
dEntity infected;
public boolean isInfected() {
if (infected.getBukkitEntity() instanceof Zombie
&& ((Zombie) infected.getBukkitEntity()).isVillager())
return true;
else return false;
}
public void setInfected(boolean bool) {
if (bool) {
if (infected.isNPC()) {
NPC infected_npc = infected.getNPC();
infected_npc.setBukkitEntityType(EntityType.ZOMBIE);
if (!infected_npc.getTrait(ZombieModifier.class).toggleVillager())
infected_npc.getTrait(ZombieModifier.class).toggleVillager();
}
// If it's a Villager, we need to spawn a Zombie instead.
// This is kind of messy, and can be improved upon.
// TODO: Improve upon.
else if (infected.getBukkitEntity() instanceof Villager) {
// Make a new entity
Entity infect = infected.getLocation().getWorld().spawnEntity(infected.getLocation(), EntityType.ZOMBIE);
((Zombie) infect).setVillager(true);
// Set health
((Zombie) infect).setHealth(((Villager) infected.getBukkitEntity()).getHealth());
// Set equipment
((Zombie) infect).getEquipment().setArmorContents(((Villager) infected.getBukkitEntity()).getEquipment().getArmorContents());
// Remove the Villager
infected.getBukkitEntity().remove();
// Set the dEntity to the new entity
infected.setEntity(infect);
}
// Much much easier
else if (infected.getBukkitEntity() instanceof Zombie) {
((Zombie) infected).setVillager(true);
}
}
}
/////////
// Property Methods
///////
@Override
public String getPropertyString() {
return getPropertyId() + '=' + isInfected() + ';';
}
@Override
public String getPropertyId() {
return "infected";
}
///////////
// dObject Attributes
////////
@Override
public String getAttributes(Attribute attribute) {
if (attribute == null) return "null";
// <--[tag]
// @attribute <e@infectable_entity.is_infected>
// @returns Element(Boolean)
// @description
// Returns 'true' if the entity is 'infected', otherwise false.
// Currently only 'Zombie' or 'Villager' entities can be infected.
// -->
if (attribute.startsWith("is_infected"))
return new Element(isInfected())
.getAttribute(attribute.fulfill(1));
return null;
}
}