/
NPC.java
402 lines (363 loc) · 12.4 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
package net.citizensnpcs.api.npc;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Minecart;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
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.event.SpawnReason;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitFactory;
import net.citizensnpcs.api.util.DataKey;
/**
* 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);
public BlockBreaker getBlockBreaker(Block targetBlock, BlockBreakerConfiguration config);
/**
* 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 Bukkit entity associated with this NPC. This may be <code>null</code> if {@link #isSpawned()} is false.
*
* @return Entity associated with this NPC
*/
public Entity getEntity();
/**
* 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();
/**
* @return The {@link NPCRegistry} that created this NPC.
*/
public NPCRegistry getOwningRegistry();
/**
* 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();
/**
* Gets the unique id of this NPC. This is guaranteed to be unique for all NPCs.
*
* @return The unique id
*/
public UUID getUniqueId();
/**
* 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);
/**
* Returns whether this NPC is flyable or not.
*
* @return Whether this NPC is flyable
*/
public boolean isFlyable();
/**
* Gets whether this NPC is protected from damage, movement and other events that players and mobs use to change the
* entity state of the NPC.
*
* @return Whether this NPC is protected
*/
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 whether this NPC is <tt>flyable</tt> or not. Note that this is intended for normally <em>ground-based</em>
* entities only - it will generally have no effect on mob types that were originally flyable.
*
* @param flyable
*/
public void setFlyable(boolean flyable);
/**
* 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);
/**
* Attempts to spawn this NPC.
*
* @param location
* Location to spawn this NPC
* @param reason
* Reason for spawning
* @return Whether this NPC was able to spawn at the location
*/
public boolean spawn(Location location, SpawnReason reason);
/**
* An alternative to {{@link #getBukkitEntity().getLocation()} that teleports passengers as well.
*
* @param location
* The destination location
* @param cause
* The cause for teleporting
*/
public void teleport(Location location, TeleportCause cause);
/**
* The Minecraft ambient sound played. String - Minecraft sound name
*/
public static final String AMBIENT_SOUND_METADATA = "ambient-sound";
/**
* Whether the NPC is collidable with Players or not. Boolean.
*/
public static final String COLLIDABLE_METADATA = "collidable";
/**
* Whether the NPC can damage other Entities. Boolean.
*/
public static final String DAMAGE_OTHERS_METADATA = "damage-others";
/**
* The Minecraft sound played when the NPC dies. String - Minecraft sound name.
*/
public static final String DEATH_SOUND_METADATA = "death-sound";
/**
* Whether the NPC is 'protected' i.e. invulnerable to damage. Boolean.
*/
public static final String DEFAULT_PROTECTED_METADATA = "protected";
/**
* Whether the NPC drops its inventory after death. Boolean.
*/
public static final String DROPS_ITEMS_METADATA = "drops-items";
/**
* Whether the NPC is 'flyable' i.e. will fly when pathfinding. Boolean.
*/
public static final String FLYABLE_METADATA = "flyable";
/**
* The color to glow using Minecraft's scoreboard glowing feature. Should be a {@link ChatColor#name()}
*/
public static final String GLOWING_COLOR_METADATA = "glowing-color";
/**
* Whether the NPC is currently glowing. Boolean.
*/
public static final String GLOWING_METADATA = "glowing";
/**
* The Minecraft sound to play when hurt. String - Minecraft sound name.
*/
public static final String HURT_SOUND_METADATA = "hurt-sound";
/**
* The Item data. Byte.
*/
public static final String ITEM_DATA_METADATA = "item-type-data";
/**
* The Item ID. Integer.
*/
public static final String ITEM_ID_METADATA = "item-type-id";
/**
* Whether the NPC is leashable. Boolean.
*/
public static final String LEASH_PROTECTED_METADATA = "protected-leash";
/**
* The Minecart item data. Byte.
*/
public static final String MINECART_ITEM_DATA_METADATA = "minecart-item-data";
/**
* The Minecart item name.
*/
public static final String MINECART_ITEM_METADATA = "minecart-item-name";
/**
* The Minecart item offset as defined by Minecraft. {@link Minecart#setDisplayBlockOffset(int)}
*/
public static final String MINECART_OFFSET_METADATA = "minecart-item-offset";
/**
* Whether the NPC's nameplate should be visible. Boolean.
*/
public static final String NAMEPLATE_VISIBLE_METADATA = "nameplate-visible";
/**
* @see Skinnable
*/
public static final String PLAYER_SKIN_TEXTURE_PROPERTIES_METADATA = "player-skin-textures";
/**
* @see Skinnable
*/
public static final String PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN_METADATA = "player-skin-signature";
/**
* @see Skinnable
*/
public static final String PLAYER_SKIN_USE_LATEST = "player-skin-use-latest-skin";
/**
* @see Skinnable
*/
public static final String PLAYER_SKIN_UUID_METADATA = "player-skin-name";
/**
* The Integer delay to respawn in ticks after death. Only works if non-zero.
*/
public static final String RESPAWN_DELAY_METADATA = "respawn-delay";
/**
* The fake NPC scoreboard team name because Minecraft requires a team name. Usually will be a random UUID in String
* form.
*/
public static final String SCOREBOARD_FAKE_TEAM_NAME_METADATA = "fake-scoreboard-team-name";
/**
* Whether to save / persist across server restarts. Boolean.
*/
public static final String SHOULD_SAVE_METADATA = "should-save";
/**
* Whether to suppress sounds. Boolean.
*/
public static final String SILENT_METADATA = "silent-sounds";
/**
* Whether to allow swimming. Boolean.
*/
public static final String SWIMMING_METADATA = "swim";
/**
* Whether to prevent NPC being targeted by hostile mobs. Boolean.
*/
public static final String TARGETABLE_METADATA = "protected-target";
}