-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
MobType.java
66 lines (56 loc) · 1.38 KB
/
MobType.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
package net.citizensnpcs.api.trait.trait;
import org.bukkit.entity.EntityType;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.api.util.DataKey;
/**
* Represents an NPC's mob type.
*/
@TraitName("type")
public class MobType extends Trait {
private EntityType type = EntityType.PLAYER;
public MobType() {
super("type");
}
/**
* Gets the type of mob that an NPC is.
*
* @return The mob type
*/
public EntityType getType() {
return type;
}
@Override
@SuppressWarnings("deprecation")
public void load(DataKey key) {
try {
type = EntityType.valueOf(key.getString(""));
} catch (IllegalArgumentException ex) {
type = EntityType.fromName(key.getString(""));
}
if (type == null) {
type = EntityType.PLAYER;
}
}
@Override
public void onSpawn() {
type = npc.getEntity().getType();
}
@Override
public void save(DataKey key) {
key.setString("", type.name());
}
/**
* Sets the type of mob that an NPC is.
*
* @param type
* Mob type to set the NPC as
*/
public void setType(EntityType type) {
this.type = type;
}
@Override
public String toString() {
return "MobType{" + type + "}";
}
}