/
NPC.java
204 lines (177 loc) · 5.36 KB
/
NPC.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package net.citizensnpcs.api.npc;
import net.citizensnpcs.api.ai.GoalController;
import net.citizensnpcs.api.ai.Navigator;
import net.citizensnpcs.api.ai.speech.SpeechController;
import net.citizensnpcs.api.astar.Agent;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCDespawnEvent;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
/**
* Represents an NPC with optional {@link Trait}s.
*/
public interface NPC extends Agent {
/**
* Adds a trait to this NPC.
*
* @param trait
* The class of the trait to add
*/
public void addTrait(Class<? extends Trait> trait);
/**
* Adds a trait to this NPC.
*
* @param trait
* Trait to add
*/
public void addTrait(Trait trait);
/**
* @return The metadata store of this NPC.
*/
public MetadataStore data();
/**
* Despawns this NPC. This is equivalent to calling
* {@link #despawn(DespawnReason)} with {@link DespawnReason#PLUGIN}.
*
* @return Whether this NPC was able to despawn
*/
public boolean despawn();
/**
* Despawns this NPC.
*
* @param reason
* The reason for despawning, for use in {@link NPCDespawnEvent}
* @return Whether this NPC was able to despawn
*/
boolean despawn(DespawnReason reason);
/**
* Permanently removes this NPC and all data about it from the registry it's
* attached to.
*/
public void destroy();
/**
* Gets the Bukkit entity associated with this NPC. This may be
* <code>null</code> if {@link #isSpawned()} is false.
*
* @return Entity associated with this NPC
*/
public LivingEntity getBukkitEntity();
/**
* Gets the default {@link GoalController} of this NPC.
*
* @return Default goal controller
*/
public GoalController getDefaultGoalController();
/**
* Gets the default {@link SpeechController} of this NPC.
*
* @return Default speech controller
*/
public SpeechController getDefaultSpeechController();
/**
* Gets the full name of this NPC.
*
* @return Full name of this NPC
*/
public String getFullName();
/**
* Gets the unique ID of this NPC.
*
* @return ID of this NPC
*/
public int getId();
/**
* Gets the name of this NPC with color codes stripped.
*
* @return Stripped name of this NPC
*/
public String getName();
/**
* @return The {@link Navigator} of this NPC.
*/
public Navigator getNavigator();
/**
* Gets a trait from the given class.
*
* @param trait
* Trait to get
* @return Trait with the given name
*/
public <T extends Trait> T getTrait(Class<T> trait);
/**
* Returns the currently attached {@link Trait}s
*
* @return An Iterable of the current traits
*/
public Iterable<Trait> getTraits();
/**
* Checks if this NPC has the given trait.
*
* @param trait
* Trait to check
* @return Whether this NPC has the given trait
*/
public boolean hasTrait(Class<? extends Trait> trait);
/**
* Gets whether this NPC is currently spawned.
*
* @return Whether this NPC is spawned
*/
public boolean isSpawned();
/**
* Loads the {@link NPC} from the given {@link DataKey}. This reloads all
* traits, respawns the NPC and sets it up for execution. Should not be
* called often.
*
* @param key
* The root data key
*/
public void load(DataKey key);
/**
* Removes a trait from this NPC.
*
* @param trait
* Trait to remove
*/
public void removeTrait(Class<? extends Trait> trait);
/**
* Saves the {@link NPC} to the given {@link DataKey}. This includes all
* metadata, traits, and spawn information that will allow it to respawn at
* a later time via {@link #load(DataKey)}.
*
* @param key
* The root data key
*/
public void save(DataKey key);
/**
* Sets the {@link EntityType} of this NPC. Currently only accepts
* <em>living</em> entity types, with scope for additional types in the
* future. The NPC will respawned if currently spawned, or will remain
* despawned otherwise.
*
* @param type
* The new mob type
* @throws IllegalArgumentException
* If the type is not a living entity type
*/
public void setBukkitEntityType(EntityType type);
/**
* Sets the name of this NPC.
*
* @param name
* Name to give this NPC
*/
public void setName(String name);
/**
* Attempts to spawn this NPC.
*
* @param location
* Location to spawn this NPC
* @return Whether this NPC was able to spawn at the location
*/
public boolean spawn(Location location);
public static final String DEFAULT_PROTECTED_METADATA = "protected";
}