public interface NPC extends Agent, Cloneable
Trait
s.Modifier and Type | Field and Description |
---|---|
static String |
ALWAYS_USE_NAME_HOLOGRAM_METADATA |
static String |
AMBIENT_SOUND_METADATA
The Minecraft ambient sound played.
|
static String |
COLLIDABLE_METADATA
Whether the NPC is collidable with Players or not.
|
static String |
DAMAGE_OTHERS_METADATA
Whether the NPC can damage other Entities.
|
static String |
DEATH_SOUND_METADATA
The Minecraft sound played when the NPC dies.
|
static String |
DEFAULT_PROTECTED_METADATA
Whether the NPC is 'protected' i.e.
|
static String |
DISABLE_DEFAULT_STUCK_ACTION_METADATA |
static String |
DROPS_ITEMS_METADATA
Whether the NPC drops its inventory after death.
|
static String |
FLYABLE_METADATA
Whether the NPC is 'flyable' i.e.
|
static String |
GLOWING_COLOR_METADATA
The color to glow using Minecraft's scoreboard glowing feature.
|
static String |
GLOWING_METADATA
Whether the NPC is currently glowing.
|
static String |
HURT_SOUND_METADATA
The Minecraft sound to play when hurt.
|
static String |
ITEM_DATA_METADATA
The Item data.
|
static String |
ITEM_ID_METADATA
The Item ID.
|
static String |
LEASH_PROTECTED_METADATA
Whether the NPC is leashable.
|
static String |
MINECART_ITEM_DATA_METADATA
The Minecart item data.
|
static String |
MINECART_ITEM_METADATA
The Minecart item name.
|
static String |
MINECART_OFFSET_METADATA
The Minecart item offset as defined by Minecraft.
|
static String |
NAMEPLATE_VISIBLE_METADATA
Whether the NPC's nameplate should be visible.
|
static String |
PATHFINDER_OPEN_DOORS_METADATA
Whether to open doors while pathfinding.
|
static String |
PLAYER_SKIN_TEXTURE_PROPERTIES_METADATA
Deprecated.
|
static String |
PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN_METADATA
Deprecated.
|
static String |
PLAYER_SKIN_USE_LATEST
Deprecated.
|
static String |
PLAYER_SKIN_UUID_METADATA
Deprecated.
|
static String |
RESPAWN_DELAY_METADATA
The Integer delay to respawn in ticks after death.
|
static String |
SCOREBOARD_FAKE_TEAM_NAME_METADATA
The fake NPC scoreboard team name because Minecraft requires a team name.
|
static String |
SHOULD_SAVE_METADATA
Whether to save / persist across server restarts.
|
static String |
SILENT_METADATA
Whether to suppress sounds.
|
static String |
SWIMMING_METADATA
Whether to allow swimming.
|
static String |
TARGETABLE_METADATA
Whether to prevent NPC being targeted by hostile mobs.
|
static String |
USE_MINECRAFT_AI_METADATA
Whether to use Minecraft AI.
|
Modifier and Type | Method and Description |
---|---|
void |
addTrait(Class<? extends Trait> trait)
Adds a trait to this NPC.
|
void |
addTrait(Trait trait)
Adds a trait to this NPC.
|
NPC |
clone() |
NPC |
copy() |
MetadataStore |
data() |
boolean |
despawn()
Despawns this NPC.
|
boolean |
despawn(DespawnReason reason)
Despawns this NPC.
|
void |
destroy()
Permanently removes this NPC and all data about it from the registry it's attached to.
|
void |
destroy(org.bukkit.command.CommandSender source)
Permanently removes this NPC and all data about it from the registry it's attached to.
|
void |
faceLocation(org.bukkit.Location location)
Faces a given
Location if the NPC is spawned. |
BlockBreaker |
getBlockBreaker(org.bukkit.block.Block targetBlock,
BlockBreaker.BlockBreakerConfiguration config) |
GoalController |
getDefaultGoalController()
Gets the default
GoalController of this NPC. |
SpeechController |
getDefaultSpeechController()
Gets the default
SpeechController of this NPC. |
org.bukkit.entity.Entity |
getEntity()
Gets the Bukkit entity associated with this NPC.
|
String |
getFullName()
Gets the full name of this NPC.
|
int |
getId()
Gets the unique ID of this NPC.
|
String |
getName()
Gets the name of this NPC with color codes stripped.
|
Navigator |
getNavigator() |
<T extends Trait> |
getOrAddTrait(Class<T> trait)
Gets a trait from the given class.
|
NPCRegistry |
getOwningRegistry() |
org.bukkit.Location |
getStoredLocation()
If the NPC is not spawned, then this method will return the last known location, or null if it has never been
spawned.
|
<T extends Trait> |
getTrait(Class<T> trait)
Deprecated.
for intransparent naming. Use
getOrAddTrait(Class) for the same behavior. |
<T extends Trait> |
getTraitNullable(Class<T> trait)
Gets a trait from the given class.
|
Iterable<Trait> |
getTraits()
Returns the currently attached
Trait s |
UUID |
getUniqueId()
Gets the unique id of this NPC.
|
boolean |
hasTrait(Class<? extends Trait> trait)
Checks if this NPC has the given trait.
|
boolean |
isFlyable()
Returns whether this NPC is flyable or not.
|
boolean |
isProtected()
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.
|
boolean |
isSpawned()
Gets whether this NPC is currently spawned.
|
void |
load(DataKey key)
|
void |
removeTrait(Class<? extends Trait> trait)
Removes a trait from this NPC.
|
boolean |
requiresNameHologram() |
void |
save(DataKey key)
|
void |
setAlwaysUseNameHologram(boolean use)
Sets whether to always use a name hologram instead of the in-built Minecraft name.
|
void |
setBukkitEntityType(org.bukkit.entity.EntityType type)
Sets the
EntityType of this NPC. |
void |
setFlyable(boolean flyable)
Sets whether this NPC is flyable or not.
|
void |
setName(String name)
Sets the name of this NPC.
|
void |
setProtected(boolean isProtected)
A helper method for using
DEFAULT_PROTECTED_METADATA to set the NPC as protected or not protected from
damage/entity target events. |
void |
setUseMinecraftAI(boolean use)
Set the NPC to use Minecraft AI where possible.
|
boolean |
spawn(org.bukkit.Location location)
Attempts to spawn this NPC.
|
boolean |
spawn(org.bukkit.Location location,
SpawnReason reason)
Attempts to spawn this NPC.
|
void |
teleport(org.bukkit.Location location,
org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause)
An alternative to
npc.getEntity().getLocation() that teleports passengers as well. |
boolean |
useMinecraftAI()
Whether the NPC is currently set to use Minecraft AI.
|
static final String ALWAYS_USE_NAME_HOLOGRAM_METADATA
static final String AMBIENT_SOUND_METADATA
static final String COLLIDABLE_METADATA
static final String DAMAGE_OTHERS_METADATA
static final String DEATH_SOUND_METADATA
static final String DEFAULT_PROTECTED_METADATA
static final String DISABLE_DEFAULT_STUCK_ACTION_METADATA
static final String DROPS_ITEMS_METADATA
static final String FLYABLE_METADATA
static final String GLOWING_COLOR_METADATA
Enum.name()
. DEPRECATED:
use ScoreboardTrait insteadstatic final String GLOWING_METADATA
static final String HURT_SOUND_METADATA
static final String ITEM_DATA_METADATA
static final String ITEM_ID_METADATA
static final String LEASH_PROTECTED_METADATA
static final String MINECART_ITEM_DATA_METADATA
static final String MINECART_ITEM_METADATA
static final String MINECART_OFFSET_METADATA
Minecart.setDisplayBlockOffset(int)
static final String NAMEPLATE_VISIBLE_METADATA
static final String PATHFINDER_OPEN_DOORS_METADATA
@Deprecated static final String PLAYER_SKIN_TEXTURE_PROPERTIES_METADATA
SkinTrait
,
Constant Field Values@Deprecated static final String PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN_METADATA
SkinTrait
,
Constant Field Values@Deprecated static final String PLAYER_SKIN_USE_LATEST
SkinTrait
,
Constant Field Values@Deprecated static final String PLAYER_SKIN_UUID_METADATA
SkinTrait
,
Constant Field Valuesstatic final String RESPAWN_DELAY_METADATA
static final String SCOREBOARD_FAKE_TEAM_NAME_METADATA
static final String SHOULD_SAVE_METADATA
static final String SILENT_METADATA
static final String SWIMMING_METADATA
static final String TARGETABLE_METADATA
static final String USE_MINECRAFT_AI_METADATA
void addTrait(Class<? extends Trait> trait)
TraitFactory
defined for this NPC to construct and attach a
trait using addTrait(Trait)
.trait
- The class of the trait to addvoid addTrait(Trait trait)
trait
- Trait to addNPC clone()
Trait
s installed.NPC copy()
Trait
s installed.MetadataStore data()
boolean despawn()
despawn(DespawnReason)
with
DespawnReason.PLUGIN
.boolean despawn(DespawnReason reason)
reason
- The reason for despawning, for use in NPCDespawnEvent
void destroy()
void destroy(org.bukkit.command.CommandSender source)
source
- The source of the removalvoid faceLocation(org.bukkit.Location location)
Location
if the NPC is spawned.BlockBreaker getBlockBreaker(org.bukkit.block.Block targetBlock, BlockBreaker.BlockBreakerConfiguration config)
GoalController getDefaultGoalController()
GoalController
of this NPC.SpeechController getDefaultSpeechController()
SpeechController
of this NPC.org.bukkit.entity.Entity getEntity()
null
if isSpawned()
is false.String getFullName()
int getId()
String getName()
<T extends Trait> T getOrAddTrait(Class<T> trait)
addTrait(Class)
.trait
- Trait to getNPCRegistry getOwningRegistry()
NPCRegistry
that created this NPC.org.bukkit.Location getStoredLocation()
npc.getBukkitEntity().getLocation()
.null
if none was found.@Deprecated <T extends Trait> T getTrait(Class<T> trait)
getOrAddTrait(Class)
for the same behavior.addTrait(Class)
.trait
- Trait to get<T extends Trait> T getTraitNullable(Class<T> trait)
null
will be
returned.trait
- Trait to getIterable<Trait> getTraits()
Trait
sUUID getUniqueId()
boolean hasTrait(Class<? extends Trait> trait)
trait
- Trait to checkboolean isFlyable()
boolean isProtected()
boolean isSpawned()
void load(DataKey key)
NPC
from the given DataKey
. This reloads all traits, respawns the NPC and sets it up
for execution. Should not be called often.key
- The root data keyvoid removeTrait(Class<? extends Trait> trait)
trait
- Trait to removeboolean requiresNameHologram()
void save(DataKey key)
NPC
to the given DataKey
. This includes all metadata, traits, and spawn information
that will allow it to respawn at a later time via load(DataKey)
.key
- The root data keyvoid setAlwaysUseNameHologram(boolean use)
use
- Whether to use a hologramvoid setBukkitEntityType(org.bukkit.entity.EntityType type)
EntityType
of this NPC. Currently only accepts living entity types, with scope for
additional types in the future. The NPC will respawned if currently spawned, or will remain despawned otherwise.type
- The new mob typeIllegalArgumentException
- If the type is not a living entity typevoid setFlyable(boolean flyable)
flyable
- void setName(String name)
name
- Name to give this NPCvoid setProtected(boolean isProtected)
DEFAULT_PROTECTED_METADATA
to set the NPC as protected or not protected from
damage/entity target events. Equivalent to
npc.data().set(NPC.DEFAULT_PROTECTED_METADATA, isProtected);
isProtected
- Whether the NPC should be protectedvoid setUseMinecraftAI(boolean use)
boolean spawn(org.bukkit.Location location)
location
- Location to spawn this NPCboolean spawn(org.bukkit.Location location, SpawnReason reason)
location
- Location to spawn this NPCreason
- Reason for spawningvoid teleport(org.bukkit.Location location, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause)
npc.getEntity().getLocation()
that teleports passengers as well.location
- The destination locationcause
- The cause for teleportingboolean useMinecraftAI()
Copyright © 2021. All rights reserved.