-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
MobType.java
61 lines (51 loc) · 1.22 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
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
public void load(DataKey key) {
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.getName());
}
/**
* 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 + "}";
}
}