Class FakePlayer
java.lang.Object
net.minestom.server.entity.Entity
net.minestom.server.entity.LivingEntity
net.minestom.server.entity.Player
net.minestom.server.entity.fakeplayer.FakePlayer
- All Implemented Interfaces:
Audience
,Identified
,Pointered
,Sound.Emitter
,HoverEventSource<HoverEvent.ShowEntity>
,Localizable
,CommandSender
,NavigableEntity
,EventHandler<EntityEvent>
,EquipmentHandler
,PermissionHandler
,Snapshotable
,Taggable
,TagReadable
,TagWritable
,Tickable
,Schedulable
,NamedAndIdentified
,Viewable
A fake player will behave exactly the same way as would do a
Player
backed by a socket connection
(events, velocity, gravity, player list, etc...) with the exception that you need to control it server-side
using a FakePlayerController
(see getController()
).
You can create one using initPlayer(UUID, String, Consumer)
. Be aware that this really behave exactly like a player
and this is a feature not a bug, you will need to check at some place if the player is a fake one or not (instanceof) if you want to change it.
-
Nested Class Summary
Nested classes/interfaces inherited from class net.minestom.server.entity.Player
Player.FacePoint, Player.Hand, Player.MainHand, Player.PlayerSettings
Nested classes/interfaces inherited from class net.minestom.server.entity.Entity
Entity.Pose
-
Field Summary
Fields inherited from class net.minestom.server.entity.Player
experiencePickupCooldown, inventory, playerConnection
Fields inherited from class net.minestom.server.entity.LivingEntity
canPickupItem, expandedBoundingBox, invulnerable, isDead, itemPickupCooldown, lastDamageSource
Fields inherited from class net.minestom.server.entity.Entity
currentChunk, entityMeta, entityType, gravityAcceleration, gravityDragPerTick, gravityTickCount, hasPhysics, instance, lastSyncedPosition, lastVelocityWasZero, metadata, onGround, position, previousPosition, trackingUpdate, uuid, vehicle, velocity, viewEngine, viewers
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
FakePlayer
(@NotNull UUID uuid, @NotNull String username, @NotNull FakePlayerOption option, @Nullable Consumer<FakePlayer> spawnCallback) -
Method Summary
Modifier and TypeMethodDescription@NotNull FakePlayerController
Retrieves the controller for the fake player.@NotNull Navigator
@NotNull FakePlayerOption
Gets the fake player option container.static void
initPlayer
(@NotNull UUID uuid, @NotNull String username, @NotNull FakePlayerOption option, @Nullable Consumer<FakePlayer> spawnCallback) Initializes a newFakePlayer
.static void
initPlayer
(@NotNull UUID uuid, @NotNull String username, @Nullable Consumer<FakePlayer> spawnCallback) Initializes a newFakePlayer
without adding it in cache.setInstance
(@NotNull Instance instance, @NotNull Pos spawnPosition) Changes the player instance and load surrounding chunks if needed.protected void
showPlayer
(@NotNull PlayerConnection connection) Sends all the related packet to have the player sent to another with related data (create player, spawn position, velocity, metadata, equipments, passengers, team).void
update
(long time) Called each tick.void
updateNewViewer
(@NotNull Player player) Called when a new viewer must be shown.Methods inherited from class net.minestom.server.entity.Player
addPacketToQueue, asHoverEvent, asPlayer, callItemUpdateStateEvent, callItemUpdateStateEvent, clearTitle, closeInventory, didAnswerKeepAlive, didCloseInventory, dropItem, facePosition, facePosition, getAdditionalHearts, getAddPlayerToList, getBoots, getChestplate, getDefaultEatingTime, getDimensionType, getDisplayName, getEatingHand, getEntityMeta, getExp, getEyeHeight, getFieldViewModifier, getFlyingSpeed, getFood, getFoodSaturation, getGameMode, getHeldSlot, getHelmet, getInventory, getItemInMainHand, getItemInOffHand, getLastKeepAlive, getLastReceivedTeleportId, getLastSentTeleportId, getLatency, getLeggings, getLevel, getLocale, getName, getNextTeleportId, getOpenInventory, getPermissionLevel, getPlayerConnection, getRemovePlayerToList, getRespawnPoint, getSettings, getSkin, getStatisticValueMap, getUsername, getVehicleInformation, hasReducedDebugScreenInformation, hideBossBar, identity, interpretPacketQueue, isAllowFlying, isCreative, isEating, isEnableRespawnScreen, isFlying, isImmune, isInstantBreak, isInvulnerable, isOnGround, isOnline, isPlayer, kick, kick, kill, openBook, openInventory, playEffect, playerConnectionInit, playSound, playSound, playSound, playSound, pointers, refreshAbilities, refreshAfterTeleport, refreshAnswerKeepAlive, refreshCommands, refreshEating, refreshEating, refreshFlying, refreshHealth, refreshHeldSlot, refreshKeepAlive, refreshLatency, refreshOnGround, refreshReceivedTeleportId, refreshVehicleSteer, remove, resetTitle, respawn, sendActionBar, sendChunkUpdates, sendDimension, sendMessage, sendPacket, sendPackets, sendPackets, sendPacketToViewersAndSelf, sendPlayerListHeaderAndFooter, sendPluginMessage, sendPluginMessage, sendTitlePart, setAdditionalHearts, setAllowFlying, setBelowNameTag, setBoots, setChestplate, setDefaultEatingTime, setDisplayName, setEnableRespawnScreen, setExp, setFieldViewModifier, setFlying, setFlyingSpeed, setFood, setFoodSaturation, setGameMode, setHealth, setHeldItemSlot, setHelmet, setInstance, setInstantBreak, setInvulnerable, setItemInMainHand, setItemInOffHand, setLeggings, setLevel, setLocale, setPermissionLevel, setReducedDebugScreenInformation, setResourcePack, setRespawnPoint, setSkin, setSneaking, setTeam, setUsernameField, setUuid, showBossBar, spectate, stopSound, stopSpectating, synchronizePosition, teleport, UNSAFE_changeDidCloseInventory, UNSAFE_init, updateOldViewer, updateSnapshot
Methods inherited from class net.minestom.server.entity.LivingEntity
canPickupItem, damage, getArrowCount, getAttribute, getAttributeValue, getFireDamagePeriod, getHealth, getLastDamageSource, getLivingEntityMeta, getMaxHealth, getPropertiesPacket, getTargetBlockPosition, getTeam, handleVoid, heal, isDead, isFlyingWithElytra, onAttributeChanged, refreshActiveHand, refreshIsDead, setArrowCount, setBoundingBox, setCanPickupItem, setFireDamagePeriod, setFireDamagePeriod, setFireForDuration, setFireForDuration, setFireForDuration, setFlyingWithElytra, swingMainHand, swingOffHand, takeKnockback
Methods inherited from class net.minestom.server.entity.Entity
addEffect, addPassenger, addViewer, askSynchronization, autoViewEntities, clearEffects, eventNode, generateId, getAcquirable, getActiveEffects, getAliveTicks, getAllPermissions, getBoundingBox, getChunk, getCustomName, getDistance, getDistance, getDistanceSquared, getEntity, getEntity, getEntityId, getEntityType, getGravityAcceleration, getGravityDragPerTick, getGravityTickCount, getInstance, getLineOfSight, getLineOfSightEntity, getMetadataPacket, getPassengers, getPassengersPacket, getPose, getPosition, getUuid, getVehicle, getVelocity, getVelocityForPacket, getVelocityPacket, getViewers, hasLineOfSight, hasLineOfSight, hasNoGravity, hasPassenger, hasPredictableViewers, hasVelocity, isActive, isAutoViewable, isCustomNameVisible, isGlowing, isInvisible, isOnFire, isRemoved, isSilent, isSneaking, isSprinting, lookAt, lookAt, refreshCurrentChunk, refreshPosition, refreshPosition, removeEffect, removePassenger, removeViewer, scheduleNextTick, scheduler, scheduleRemove, scheduleRemove, setAutoViewable, setAutoViewEntities, setBoundingBox, setCustomName, setCustomNameVisible, setCustomSynchronizationCooldown, setGlowing, setGravity, setInstance, setInvisible, setNoGravity, setOnFire, setPose, setSilent, setSprinting, setVelocity, setView, spawn, switchEntityType, tagHandler, teleport, tick, triggerStatus, updatePose, updateVelocity, updateViewableRule, updateViewableRule, updateViewerRule, updateViewerRule
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.kyori.adventure.audience.Audience
deleteMessage, deleteMessage, filterAudience, forEachAudience, openBook, sendActionBar, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendPlayerListFooter, sendPlayerListFooter, sendPlayerListHeader, sendPlayerListHeader, sendPlayerListHeaderAndFooter, showTitle, stopSound
Methods inherited from interface net.minestom.server.command.CommandSender
asConsole, isConsole, sendMessage, sendMessage
Methods inherited from interface net.minestom.server.inventory.EquipmentHandler
getEquipment, getEquipmentsPacket, getItemInHand, hasEquipment, setEquipment, setItemInHand, syncEquipment
Methods inherited from interface net.kyori.adventure.text.event.HoverEventSource
asHoverEvent
Methods inherited from interface net.minestom.server.utils.identity.NamedAndIdentified
getUuid
Methods inherited from interface net.minestom.server.permission.PermissionHandler
addPermission, getAllPermissions, getPermission, hasPermission, hasPermission, hasPermission, removePermission, removePermission
Methods inherited from interface net.kyori.adventure.pointer.Pointered
get, getOrDefault, getOrDefaultFrom
Methods inherited from interface net.minestom.server.tag.Taggable
getTag, hasTag, removeTag, setTag, tagHandler
Methods inherited from interface net.minestom.server.Viewable
getViewersAsAudience, getViewersAsAudiences, isViewer, sendPacketsToViewers, sendPacketsToViewers, sendPacketToViewers
-
Constructor Details
-
FakePlayer
protected FakePlayer(@NotNull @NotNull UUID uuid, @NotNull @NotNull String username, @NotNull @NotNull FakePlayerOption option, @Nullable @Nullable Consumer<FakePlayer> spawnCallback) - Parameters:
uuid
- The unique identifier for the fake player.username
- The username for the fake player.option
- Any option for the fake player.
-
-
Method Details
-
initPlayer
public static void initPlayer(@NotNull @NotNull UUID uuid, @NotNull @NotNull String username, @NotNull @NotNull FakePlayerOption option, @Nullable @Nullable Consumer<FakePlayer> spawnCallback) Initializes a newFakePlayer
.- Parameters:
uuid
- the FakePlayer uuidusername
- the FakePlayer usernamespawnCallback
- the optional callback called when the fake player first spawn
-
initPlayer
public static void initPlayer(@NotNull @NotNull UUID uuid, @NotNull @NotNull String username, @Nullable @Nullable Consumer<FakePlayer> spawnCallback) Initializes a newFakePlayer
without adding it in cache.If you want the fake player to be obtainable with the
ConnectionManager
you need to specify it in aFakePlayerOption
and useinitPlayer(UUID, String, FakePlayerOption, Consumer)
.- Parameters:
uuid
- the FakePlayer uuidusername
- the FakePlayer usernamespawnCallback
- the optional callback called when the fake player first spawn
-
getOption
Gets the fake player option container.- Returns:
- the fake player option
-
getController
Retrieves the controller for the fake player.- Returns:
- The fake player's controller.
-
update
public void update(long time) Description copied from class:Entity
Called each tick. -
setInstance
public CompletableFuture<Void> setInstance(@NotNull @NotNull Instance instance, @NotNull @NotNull Pos spawnPosition) Description copied from class:Player
Changes the player instance and load surrounding chunks if needed.Be aware that because chunk operations are expensive, it is possible for this method to be non-blocking when retrieving chunks is required.
- Overrides:
setInstance
in classPlayer
- Parameters:
instance
- the new player instancespawnPosition
- the new position of the player- Returns:
- a future called once the player instance changed
-
updateNewViewer
Description copied from class:Entity
Called when a new viewer must be shown. Method can be subject to deadlocking if the target's viewers are also accessed.- Overrides:
updateNewViewer
in classLivingEntity
- Parameters:
player
- the player to send the packets to
-
showPlayer
Sends all the related packet to have the player sent to another with related data (create player, spawn position, velocity, metadata, equipments, passengers, team).WARNING: this alone does not sync the player, please use
Entity.addViewer(Player)
.- Overrides:
showPlayer
in classPlayer
- Parameters:
connection
- the connection to show the player to
-