-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
NPC.java
246 lines (214 loc) · 7.09 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
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.trait.TraitFactory;
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, Cloneable {
/**
* Adds a trait to this NPC. This will use the {@link TraitFactory} defined
* for this NPC to construct and attach a trait using
* {@link #addTrait(Trait)}.
*
* @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 A clone of the NPC. May not be an exact copy depending on the
* {@link Trait}s installed.
*/
public NPC clone();
/**
* @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();
/**
* Faces a given {@link Location} if the NPC is spawned.
*/
public void faceLocation(Location location);
/**
* 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. This is not guaranteed to be globally
* unique across server sessions.
*
* @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();
/**
* If the NPC is not spawned, then this method will return the last known
* location, or null if it has never been spawned. Otherwise, it is
* equivalent to calling <code>npc.getBukkitEntity().getLocation()</code>.
*
* @return The stored location, or <code>null</code> if none was found.
*/
public Location getStoredLocation();
/**
* Gets a trait from the given class. If the NPC does not currently have the
* trait then it will be created and attached using {@link #addTrait(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);
public boolean isProtected();
/**
* 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);
/**
* A helper method for using {@link #DEFAULT_PROTECTED_METADATA} to set the
* NPC as protected or not protected from damage/entity target events.
* Equivalent to
* <code>npc.data().set(NPC.DEFAULT_PROTECTED_METADATA, isProtected);</code>
*
* @param isProtected
* Whether the NPC should be protected
*/
public void setProtected(boolean isProtected);
/**
* 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";
public static final String LEASH_PROTECTED_METADATA = "protected-leash";
public static final String RESPAWN_DELAY_METADATA = "respawn-delay";
public static final String TARGETABLE_METADATA = "protected-target";
}