- Description
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- Constructor Details
- Method Details
- getComponentType()
- addToStore(Store)
- addedToStore(Ref)
- removeFromStore()
- isValid()
- getReference()
- getHolder()
- getComponent(ComponentType)
- getComponentConcurrent(ComponentType)
- getUuid()
- getUsername()
- hasPermission(String)
- hasPermission(String, boolean)
- hasPermission(PermissionQuery)
- hasPermission(PermissionQuery, boolean)
- getPacketHandler()
- getChunkTracker()
- getHiddenPlayersManager()
- getTeleportAckTracker()
- getLanguage()
- setLanguage(String)
- getTransform()
- getWorldUuid()
- setWorldUuid(UUID)
- getHeadRotation()
- updatePosition(World, Transform, Rotation3f)
- replaceHolder(Holder)
- clone()
- toMetricResults()
- referToServer(String, int)
- referToServer(String, int, byte[])
- sendMessage(Message)
Class PlayerRef
- All Implemented Interfaces:
Component<EntityStore>, MetricProvider, CommandSender, PermissionHolder, IMessageReceiver, Cloneable
This class is used to reference a player in a way that is independent of any single entity component store. This is needed because players, unlike other entities, can be moved between stores or even exist without a store.
(e.g. when joining, teleporting between worlds). This is designed to be
a single instance that will be updated to point to the player's current
Ref if in a store, or Holder if moving/joining one.
This stores some state that may be used outside a store e.g. the packet handler.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MetricsRegistry<PlayerRef> Metrics registry for component-dependent player data.static final MetricsRegistry<PlayerRef> The metrics registry for thread-safe player reference data.Fields inherited from interface Component
EMPTY_ARRAY -
Constructor Summary
ConstructorsConstructorDescriptionPlayerRef(Holder<EntityStore> holder, UUID uuid, String username, String language, PacketHandler packetHandler, ChunkTracker chunkTracker) Default Constructor for aPlayerRefinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddedToStore(Ref<EntityStore> ref) Called when the player has been added to the store, after HolderSystems have run, but before RefSystems.addToStore(Store<EntityStore> store) Not thread safe.clone()<T extends Component<EntityStore>>
TgetComponent(ComponentType<EntityStore, T> componentType) Deprecated.Blocks in some cases.<T extends Component<EntityStore>>
TgetComponentConcurrent(ComponentType<EntityStore, T> componentType) Reads a component from any thread, whether the player is held out of world or live in a store, without blocking the caller.static ComponentType<EntityStore, PlayerRef> getUuid()booleanhasPermission(PermissionQuery query) Determines whether the associated instance has the given permission.booleanhasPermission(PermissionQuery query, boolean def) booleanhasPermission(String id) Checks if the player has the specified permission.booleanhasPermission(String id, boolean def) Determines if the player has a specific permission.booleanisValid()If invalid, neither a reference nor a holder is present.voidreferToServer(String host, int port) Refers this player to another server, allowing server-to-server transfers with optional data.voidreferToServer(String host, int port, byte[] data) Refers this player to another server, allowing server-to-server transfers with optional data.Note: Not thread safe.voidreplaceHolder(Holder<EntityStore> holder) Deprecated.Exists for resetPlayervoidsendMessage(Message message) Called to send a message to this receiver.voidsetLanguage(String language) Called to set the language of the player.voidsetWorldUuid(UUID worldUuid) Records the world the player is joining, sogetWorldUuid()is correct from the moment they are added to a world rather than only after their first position update.voidupdatePosition(World world, Transform transform, Rotation3f headRotation) Called to update the current position information of the player ref.Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Component
cloneSerializable
-
Field Details
-
METRICS_REGISTRY
The metrics registry for thread-safe player reference data. Component-dependent metrics are inCOMPONENT_METRICS_REGISTRYand collected separately on world threads. -
COMPONENT_METRICS_REGISTRY
Metrics registry for component-dependent player data. Must be called on the world thread where the player's entity resides.
-
-
Constructor Details
-
PlayerRef
public PlayerRef(@Nonnull Holder<EntityStore> holder, @Nonnull UUID uuid, @Nonnull String username, @Nonnull String language, @Nonnull PacketHandler packetHandler, @Nonnull ChunkTracker chunkTracker) Default Constructor for aPlayerRefinstance.- Parameters:
holder- The holder containing the player's components.uuid- TheUUIDof the player.username- The username of the player.language- The language of the player.packetHandler- The packet handler for the player.chunkTracker- The chunk tracker for the player.
-
-
Method Details
-
getComponentType
- Returns:
- the component type for the
PlayerRefcomponent.
-
addToStore
Not thread safe. Must be run on the store thread that the player is being added to.- Parameters:
store- The store to add the player to.- Returns:
- The reference to the player in the store.
-
addedToStore
Called when the player has been added to the store, after HolderSystems have run, but before RefSystems.Ensures that the PlayerRef has a reference to its entity Ref and nulls the Holder.
- Parameters:
ref- this player's ref.
-
removeFromStore
Note: Not thread safe. Must be run on the store thread that the player is being added to.- Returns:
- The holder containing the components of the player
-
isValid
public boolean isValid()If invalid, neither a reference nor a holder is present.- Returns:
trueif valid in some form,falseotherwise.
-
getReference
- Returns:
- the entity reference of this player, or
nullif not in a store.
-
getHolder
- Returns:
- the holder of this player's components, or
nullif in a store.
-
getComponent
@Nullable @Deprecated public <T extends Component<EntityStore>> T getComponent(@Nonnull ComponentType<EntityStore, T> componentType) Deprecated.Blocks in some cases. Ideally you should know if it's a ref or holder at any given point if then manually inspect this and handle as needed.Gets the component from the entity whether its in the world or not.If the entity is in a world but this isn't called on the world thread then it may be blocking as it fetches from the world thread.
- Type Parameters:
T- The component type.- Parameters:
componentType- The component to look up.- Returns:
- The component or null.
-
getComponentConcurrent
@Nullable public <T extends Component<EntityStore>> T getComponentConcurrent(@Nonnull ComponentType<EntityStore, T> componentType) Reads a component from any thread, whether the player is held out of world or live in a store, without blocking the caller. The holder read takes its own lock; the store read is seqlock-safe against slot reuse but not field mutation, so only presence checks and immutable-component reads are safe off the world thread.- Type Parameters:
T- The component type.- Parameters:
componentType- The component to look up.- Returns:
- the component, or
nullif the entity does not have it, the store reference is invalidated mid-read, or the player currently has neither a holder nor a store reference.
-
getUuid
- Specified by:
getUuidin interfaceCommandSender- Returns:
- the
UUIDof the player.
-
getUsername
- Specified by:
getUsernamein interfaceCommandSender- Returns:
- the username of the player.
-
hasPermission
Checks if the player has the specified permission.- Specified by:
hasPermissionin interfacePermissionHolder- Parameters:
id- the identifier of the permission to check; must not be null- Returns:
- true if the player has the specified permission, false otherwise
-
hasPermission
Determines if the player has a specific permission.- Specified by:
hasPermissionin interfacePermissionHolder- Parameters:
id- The identifier of the permission to check.def- The default value to return if the permission is not explicitly set.- Returns:
trueif the player has the specified permission,falseotherwise.
-
hasPermission
Description copied from interface:PermissionHolderDetermines whether the associated instance has the given permission.A holder that resolves permissions itself should override this, because a lookup built once and reused costs an order of magnitude less than one built for each check.
- Specified by:
hasPermissionin interfacePermissionHolder- Parameters:
query- The lookup for the permission.- Returns:
trueif they have the permission,falseotherwise.
-
hasPermission
- Specified by:
hasPermissionin interfacePermissionHolder- Parameters:
query- The lookup for the permission.def- The default value to return if nothing decides.- Returns:
trueif they have the permission,falseotherwise.- See Also:
-
getPacketHandler
- Returns:
- the packet handler for the player.
-
getChunkTracker
- Returns:
- the chunk tracker for the player.
-
getHiddenPlayersManager
- Returns:
- the affiliated
HiddenPlayersManagerinstance
-
getTeleportAckTracker
- Returns:
- the teleport acknowledgement tracker for this player's connection.
-
getLanguage
- Returns:
- the language of the player.
-
setLanguage
Called to set the language of the player.- Parameters:
language- The new language of the player.
-
getTransform
-
getWorldUuid
-
setWorldUuid
Records the world the player is joining, sogetWorldUuid()is correct from the moment they are added to a world rather than only after their first position update.- Parameters:
worldUuid- TheUUIDof the world the player is joining.
-
getHeadRotation
- Returns:
- the head rotation of the player when they last ticked
-
updatePosition
public void updatePosition(@Nonnull World world, @Nonnull Transform transform, @Nonnull Rotation3f headRotation) Called to update the current position information of the player ref.- Parameters:
world- The current world the player is in.transform- The current transform of the player.headRotation- The current head rotation of the player.
-
replaceHolder
Deprecated.Exists for resetPlayerCalled to replace the holder of the player with another instance.- Parameters:
holder- The new holder for the player.
-
clone
- Specified by:
clonein interfaceComponent<EntityStore>- Returns:
- a clone instance of the original component instance.
-
toMetricResults
- Specified by:
toMetricResultsin interfaceMetricProvider
-
referToServer
Refers this player to another server, allowing server-to-server transfers with optional data.- Parameters:
host- the hostname/IP of the destination serverport- the port of the destination server
-
referToServer
Refers this player to another server, allowing server-to-server transfers with optional data.- Parameters:
host- the hostname/IP of the destination serverport- the port of the destination serverdata- optional byte array data to send along with the referral (can be null, max 4KB)- Throws:
IllegalArgumentException- if data exceeds maximum size
-
sendMessage
Description copied from interface:IMessageReceiverCalled to send a message to this receiver.- Specified by:
sendMessagein interfaceIMessageReceiver- Parameters:
message- The message to be sent.
-