Class GeyserSession

java.lang.Object
org.geysermc.geyser.session.GeyserSession
All Implemented Interfaces:
Connection, GeyserConnection, CommandSender

public class GeyserSession extends Object implements GeyserConnection, CommandSender
  • Field Details

    • sentSpawnPacket

      protected boolean sentSpawnPacket
  • Constructor Details

    • GeyserSession

      public GeyserSession(GeyserImpl geyser, com.nukkitx.protocol.bedrock.BedrockServerSession bedrockServerSession, io.netty.channel.EventLoop eventLoop)
  • Method Details

    • connect

      public void connect()
      Send all necessary packets to load Bedrock into the server
    • login

      public void login()
    • authenticate

      public void authenticate(String username)
    • authenticate

      public void authenticate(String username, String password)
    • authenticateWithMicrosoftCode

      public void authenticateWithMicrosoftCode()
      Present a form window to the user asking to log in with another web browser
    • handleDownstreamPacket

      public void handleDownstreamPacket(com.github.steveice10.packetlib.packet.Packet packet)
    • disconnect

      public void disconnect(String reason)
    • close

      public void close()
    • executeInEventLoop

      public void executeInEventLoop(Runnable runnable)
      Executes a task and prints a stack trace if an error occurs.
    • scheduleInEventLoop

      public ScheduledFuture<?> scheduleInEventLoop(Runnable runnable, long duration, TimeUnit timeUnit)
      Schedules a task and prints a stack trace if an error occurs.
    • tick

      protected void tick()
      Called every 50 milliseconds - one Minecraft tick.
    • setAuthenticationData

      public void setAuthenticationData(AuthData authData)
    • setSneaking

      public void setSneaking(boolean sneaking)
    • setSwimming

      public void setSwimming(boolean swimming)
    • setFlying

      public void setFlying(boolean flying)
    • adjustSpeed

      public com.nukkitx.protocol.bedrock.data.AttributeData adjustSpeed()
      Adjusts speed if the player is crawling.
      Returns:
      not null if attributes should be updated.
    • disableSrvResolving

      protected void disableSrvResolving()
      Will be overwritten for GeyserConnect.
    • name

      public String name()
      Description copied from interface: Connection
      Gets the name of the connection.
      Specified by:
      name in interface CommandSender
      Specified by:
      name in interface Connection
      Returns:
      the name of the connection
    • uuid

      public UUID uuid()
      Description copied from interface: Connection
      Gets the UUID of the connection.
      Specified by:
      uuid in interface Connection
      Returns:
      the UUID of the connection
    • xuid

      public String xuid()
      Description copied from interface: Connection
      Gets the XUID of the connection.
      Specified by:
      xuid in interface Connection
      Returns:
      the XUID of the connection
    • sendMessage

      public void sendMessage(String message)
      Specified by:
      sendMessage in interface CommandSender
    • isConsole

      public boolean isConsole()
      Specified by:
      isConsole in interface CommandSender
      Returns:
      true if the specified sender is from the console.
    • getLocale

      public String getLocale()
      Description copied from interface: CommandSender
      Returns the locale of the command sender. Defaults to the default locale at GeyserLocale.getDefaultLocale().
      Specified by:
      getLocale in interface CommandSender
      Returns:
      the locale of the command sender.
    • setRenderDistance

      public void setRenderDistance(int renderDistance)
    • getSocketAddress

      public InetSocketAddress getSocketAddress()
    • sendForm

      public void sendForm(org.geysermc.cumulus.Form form)
    • sendForm

      public void sendForm(org.geysermc.cumulus.util.FormBuilder<?,​?> formBuilder)
    • getNextItemNetId

      public int getNextItemNetId()
      Returns:
      the next Bedrock item network ID to use for a new item
    • addTeleport

      public void addTeleport(TeleportCache teleportCache)
    • confirmTeleport

      public void confirmTeleport(com.nukkitx.math.vector.Vector3d position)
    • sendUpstreamPacket

      public void sendUpstreamPacket(com.nukkitx.protocol.bedrock.BedrockPacket packet)
      Queue a packet to be sent to player.
      Parameters:
      packet - the bedrock packet from the NukkitX protocol lib
    • receiveUpstreamPacket

      public boolean receiveUpstreamPacket(com.nukkitx.protocol.bedrock.BedrockPacket packet)
      Inject a packet as if it was received by the upstream client
      Parameters:
      packet - the bedrock packet to be injected
      Returns:
      true if handled
    • receiveDownstreamPacket

      public void receiveDownstreamPacket(com.github.steveice10.packetlib.packet.Packet packet)
      Inject a packet as if it was received by the downstream server
      Parameters:
      packet - the java packet to be injected
    • sendUpstreamPacketImmediately

      public void sendUpstreamPacketImmediately(com.nukkitx.protocol.bedrock.BedrockPacket packet)
      Send a packet immediately to the player.
      Parameters:
      packet - the bedrock packet from the NukkitX protocol lib
    • sendDownstreamPacket

      public void sendDownstreamPacket(com.github.steveice10.packetlib.packet.Packet packet)
      Send a packet to the remote server.
      Parameters:
      packet - the java edition packet from MCProtocolLib
    • setReducedDebugInfo

      public void setReducedDebugInfo(boolean value)
      Update the cached value for the reduced debug info gamerule. If enabled, also hides the player's coordinates.
      Parameters:
      value - The new value for reducedDebugInfo
    • setDaylightCycle

      public void setDaylightCycle(boolean doCycle)
      Changes the daylight cycle gamerule on the client This is used in the login screen along-side normal usage
      Parameters:
      doCycle - If the cycle should continue
    • sendGameRule

      public void sendGameRule(String gameRule, Object value)
      Send a gamerule value to the client
      Parameters:
      gameRule - The gamerule to send
      value - The value of the gamerule
    • hasPermission

      public boolean hasPermission(String permission)
      Checks if the given session's player has a permission
      Specified by:
      hasPermission in interface CommandSender
      Parameters:
      permission - The permission node to check
      Returns:
      true if the player has the requested permission, false if not
    • sendAdventureSettings

      public void sendAdventureSettings()
      Send an AdventureSettingsPacket to the client with the latest flags
    • updateStatistics

      public void updateStatistics(@NonNull @NonNull Map<com.github.steveice10.mc.protocol.data.game.statistic.Statistic,​Integer> statistics)
      Used for updating statistic values since we only get changes from the server
      Parameters:
      statistics - Updated statistics values
    • refreshEmotes

      public void refreshEmotes(List<UUID> emotes)
    • sendPluginMessage

      public void sendPluginMessage(String channel, byte[] data)
      Send message on a Plugin Channel - https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel
      Parameters:
      channel - channel to send on
      data - payload
    • registerPluginChannel

      public void registerPluginChannel(String channel)
      Register a Plugin Channel
      Parameters:
      channel - Channel to register
    • unregisterPluginChannel

      public void unregisterPluginChannel(String channel)
      Unregister a Plugin Channel
      Parameters:
      channel - Channel to unregister
    • getGeyser

      public GeyserImpl getGeyser()
    • getUpstream

      public UpstreamSession getUpstream()
    • getEventLoop

      public io.netty.channel.EventLoop getEventLoop()
      The loop where all packets and ticking is processed to prevent concurrency issues. If this is manually called, ensure that any exceptions are properly handled.
    • getDownstream

      public com.github.steveice10.packetlib.tcp.TcpSession getDownstream()
    • getAuthData

      public AuthData getAuthData()
    • getClientData

      public BedrockClientData getClientData()
    • getRemoteAddress

      public String getRemoteAddress()
    • getRemotePort

      public int getRemotePort()
    • getRemoteAuthType

      public AuthType getRemoteAuthType()
    • isMicrosoftAccount

      @Deprecated public boolean isMicrosoftAccount()
      Deprecated.
    • getPlayerEntity

      public SessionPlayerEntity getPlayerEntity()
    • getAdvancementsCache

      public AdvancementsCache getAdvancementsCache()
    • getBookEditCache

      public BookEditCache getBookEditCache()
    • getChunkCache

      public ChunkCache getChunkCache()
    • getEntityCache

      public EntityCache getEntityCache()
    • getEffectCache

      public EntityEffectCache getEffectCache()
    • getFormCache

      public FormCache getFormCache()
    • getLodestoneCache

      public LodestoneCache getLodestoneCache()
    • getPistonCache

      public PistonCache getPistonCache()
    • getPreferencesCache

      public PreferencesCache getPreferencesCache()
    • getTagCache

      public TagCache getTagCache()
    • getWorldCache

      public WorldCache getWorldCache()
    • getTeleportMap

      public it.unimi.dsi.fastutil.ints.Int2ObjectMap<TeleportCache> getTeleportMap()
    • getWorldBorder

      public WorldBorder getWorldBorder()
    • isInWorldBorderWarningArea

      public boolean isInWorldBorderWarningArea()
      Whether simulated fog has been sent to the client or not.
    • getPlayerInventory

      public PlayerInventory getPlayerInventory()
    • getOpenInventory

      public Inventory getOpenInventory()
    • isClosingInventory

      public boolean isClosingInventory()
    • getInventoryTranslator

      public InventoryTranslator getInventoryTranslator()
    • getCraftingGridFuture

      public ScheduledFuture<?> getCraftingGridFuture()
    • getCollisionManager

      public CollisionManager getCollisionManager()
      Stores session collision
    • getBlockMappings

      public BlockMappings getBlockMappings()
      Stores the block mappings for this specific version.
    • getItemMappings

      public ItemMappings getItemMappings()
      Stores the item translations for this specific version.
    • getSkullCache

      public Map<com.nukkitx.math.vector.Vector3i,​SkullPlayerEntity> getSkullCache()
    • getStoredMaps

      public it.unimi.dsi.fastutil.longs.Long2ObjectMap<com.nukkitx.protocol.bedrock.packet.ClientboundMapItemDataPacket> getStoredMaps()
    • getBiomeGlobalPalette

      public int getBiomeGlobalPalette()
      Required to decode biomes correctly.
    • getBiomeTranslations

      public it.unimi.dsi.fastutil.ints.Int2IntMap getBiomeTranslations()
      Stores the map between Java and Bedrock biome network IDs.
    • getItemFrameCache

      public Map<com.nukkitx.math.vector.Vector3i,​ItemFrameEntity> getItemFrameCache()
      A map of Vector3i positions to Java entities. Used for translating Bedrock block actions to Java entity actions.
    • getLecternCache

      public Set<com.nukkitx.math.vector.Vector3i> getLecternCache()
      Stores a list of all lectern locations and their block entity tags. See WorldManager.getLecternDataAt(GeyserSession, int, int, int, boolean) for more information.
    • getPlayerWithCustomHeads

      public Set<UUID> getPlayerWithCustomHeads()
      A list of all players that have a player head on with a custom texture. Our workaround for these players is to give them a custom skin and geometry to emulate wearing a custom skull.
    • isDroppingLecternBook

      public boolean isDroppingLecternBook()
    • getLastChunkPosition

      public com.nukkitx.math.vector.Vector2i getLastChunkPosition()
    • getRenderDistance

      public int getRenderDistance()
    • isSentSpawnPacket

      public boolean isSentSpawnPacket()
    • isLoggedIn

      public boolean isLoggedIn()
    • isLoggingIn

      public boolean isLoggingIn()
    • isSpawned

      public boolean isSpawned()
    • isClosed

      public boolean isClosed()
      Accessed on the initial Java and Bedrock packet processing threads
    • getGameMode

      public com.github.steveice10.mc.protocol.data.game.entity.player.GameMode getGameMode()
    • getWorldName

      public String getWorldName()
      Keeps track of the world name for respawning.
    • isSneaking

      public boolean isSneaking()
    • getPose

      public com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose getPose()
      Stores the Java pose that the server and/or Geyser believes the player currently has.
    • isSprinting

      public boolean isSprinting()
    • isSwimmingInWater

      public boolean isSwimmingInWater()
      Whether the player is swimming in water. Used to update speed when crawling.
    • getOriginalSpeedAttribute

      public float getOriginalSpeedAttribute()
      Tracks the original speed attribute. We need to do this in order to emulate speeds when sneaking under 1.5-blocks-tall areas if the player isn't sneaking, and when crawling.
    • getDimension

      public String getDimension()
      The dimension of the player. As all entities are in the same world, this can be safely applied to all other entities.
    • getBreakingBlock

      public int getBreakingBlock()
    • getLastBlockPlacePosition

      public com.nukkitx.math.vector.Vector3i getLastBlockPlacePosition()
    • getLastBlockPlacedId

      public String getLastBlockPlacedId()
    • isInteracting

      public boolean isInteracting()
    • getLastInteractionBlockPosition

      public com.nukkitx.math.vector.Vector3i getLastInteractionBlockPosition()
      Stores the last position of the block the player interacted with. This can either be a block that the client placed or an existing block the player interacted with (for example, a chest).
      Initialized as (0, 0, 0) so it is always not-null.
    • getLastInteractionPlayerPosition

      public com.nukkitx.math.vector.Vector3f getLastInteractionPlayerPosition()
      Stores the position of the player the last time they interacted. Used to verify that the player did not move since their last interaction.
      Initialized as (0, 0, 0) so it is always not-null.
    • getRidingVehicleEntity

      public Entity getRidingVehicleEntity()
    • getMouseoverEntity

      public Entity getMouseoverEntity()
      The entity that the client is currently looking at.
    • getCraftingRecipes

      public it.unimi.dsi.fastutil.ints.Int2ObjectMap<com.github.steveice10.mc.protocol.data.game.recipe.Recipe> getCraftingRecipes()
    • getUnlockedRecipes

      public Set<String> getUnlockedRecipes()
    • getLastRecipeNetId

      public AtomicInteger getLastRecipeNetId()
    • getStonecutterRecipes

      public it.unimi.dsi.fastutil.ints.Int2ObjectMap<it.unimi.dsi.fastutil.ints.IntList> getStonecutterRecipes()
      Saves a list of all stonecutter recipes, for use in a stonecutter inventory. The key is the Java ID of the item; the values are all the possible outputs' Java IDs sorted by their string identifier
    • getAttackSpeed

      public double getAttackSpeed()
      The current attack speed of the player. Used for sending proper cooldown timings. Setting a default fixes cooldowns not showing up on a fresh world.
    • getLastHitTime

      public long getLastHitTime()
      The time of the last hit. Used to gauge how long the cooldown is taking. This is a session variable in order to prevent more scheduled threads than necessary.
    • isSteeringLeft

      public boolean isSteeringLeft()
      Saves if the client is steering left on a boat.
    • isSteeringRight

      public boolean isSteeringRight()
      Saves if the client is steering right on a boat.
    • getLastInteractionTime

      public long getLastInteractionTime()
      Store the last time the player interacted. Used to fix a right-click spam bug. See https://github.com/GeyserMC/Geyser/issues/503 for context.
    • getBucketScheduledFuture

      public ScheduledFuture<?> getBucketScheduledFuture()
      Stores a future interaction to place a bucket. Will be cancelled if the client instead intended to interact with a block.
    • getLastMovementTimestamp

      public long getLastMovementTimestamp()
      Used to send a movement packet every three seconds if the player hasn't moved. Prevents timeouts when AFK in certain instances.
    • getLastVehicleMoveTimestamp

      public long getLastVehicleMoveTimestamp()
      Used to send a ServerboundMoveVehiclePacket for every PlayerInputPacket after idling on a boat/horse for more than 100ms
    • isDaylightCycle

      public boolean isDaylightCycle()
      Controls whether the daylight cycle gamerule has been sent to the client, so the sun/moon remain motionless.
    • isReducedDebugInfo

      public boolean isReducedDebugInfo()
    • getOpPermissionLevel

      public int getOpPermissionLevel()
      The op permission level set by the server
    • isCanFly

      public boolean isCanFly()
      If the current player can fly
    • isFlying

      public boolean isFlying()
      If the current player is flying
    • isRaining

      public boolean isRaining()
      Caches current rain status.
    • isThunder

      public boolean isThunder()
      Caches current thunder status.
    • getLastSignMessage

      public String getLastSignMessage()
      Stores the last text inputted into a sign.

      Bedrock sends packets every time you update the sign, Java only wants the final packet. Until we determine that the user has finished editing, we save the sign's current status.

    • getStatistics

      public Map<com.github.steveice10.mc.protocol.data.game.statistic.Statistic,​Integer> getStatistics()
      Stores a map of all statistics sent from the server. The server only sends new statistics back to us, so in order to show all statistics we need to cache existing ones.
    • isWaitingForStatistics

      public boolean isWaitingForStatistics()
      Whether we're expecting statistics to be sent back to us.
    • getEmotes

      public Set<UUID> getEmotes()
    • isAdvancedTooltips

      public boolean isAdvancedTooltips()
      Whether advanced tooltips will be added to the player's items.
    • getTickThread

      public ScheduledFuture<?> getTickThread()
      The thread that will run every 50 milliseconds - one Minecraft tick.
    • getProtocol

      public com.github.steveice10.mc.protocol.MinecraftProtocol getProtocol()
    • setAuthData

      public void setAuthData(AuthData authData)
    • setClientData

      public void setClientData(BedrockClientData clientData)
    • setRemoteAddress

      public void setRemoteAddress(String remoteAddress)
    • setRemotePort

      public void setRemotePort(int remotePort)
    • setRemoteAuthType

      public void setRemoteAuthType(AuthType remoteAuthType)
    • setMicrosoftAccount

      @Deprecated public void setMicrosoftAccount(boolean microsoftAccount)
      Deprecated.
    • setOpenInventory

      public void setOpenInventory(Inventory openInventory)
    • setClosingInventory

      public void setClosingInventory(boolean closingInventory)
    • setInventoryTranslator

      public void setInventoryTranslator(InventoryTranslator inventoryTranslator)
    • setCraftingGridFuture

      public void setCraftingGridFuture(ScheduledFuture<?> craftingGridFuture)
    • setBlockMappings

      public void setBlockMappings(BlockMappings blockMappings)
      Stores the block mappings for this specific version.
    • setItemMappings

      public void setItemMappings(ItemMappings itemMappings)
      Stores the item translations for this specific version.
    • setBiomeGlobalPalette

      public void setBiomeGlobalPalette(int biomeGlobalPalette)
      Required to decode biomes correctly.
    • setDroppingLecternBook

      public void setDroppingLecternBook(boolean droppingLecternBook)
    • setLastChunkPosition

      public void setLastChunkPosition(com.nukkitx.math.vector.Vector2i lastChunkPosition)
    • setSpawned

      public void setSpawned(boolean spawned)
    • setGameMode

      public void setGameMode(com.github.steveice10.mc.protocol.data.game.entity.player.GameMode gameMode)
    • setWorldName

      public void setWorldName(String worldName)
      Keeps track of the world name for respawning.
    • setPose

      public void setPose(com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose pose)
      Stores the Java pose that the server and/or Geyser believes the player currently has.
    • setSprinting

      public void setSprinting(boolean sprinting)
    • setSwimmingInWater

      public void setSwimmingInWater(boolean swimmingInWater)
      Whether the player is swimming in water. Used to update speed when crawling.
    • setOriginalSpeedAttribute

      public void setOriginalSpeedAttribute(float originalSpeedAttribute)
      Tracks the original speed attribute. We need to do this in order to emulate speeds when sneaking under 1.5-blocks-tall areas if the player isn't sneaking, and when crawling.
    • setDimension

      public void setDimension(String dimension)
      The dimension of the player. As all entities are in the same world, this can be safely applied to all other entities.
    • setBreakingBlock

      public void setBreakingBlock(int breakingBlock)
    • setLastBlockPlacePosition

      public void setLastBlockPlacePosition(com.nukkitx.math.vector.Vector3i lastBlockPlacePosition)
    • setLastBlockPlacedId

      public void setLastBlockPlacedId(String lastBlockPlacedId)
    • setInteracting

      public void setInteracting(boolean interacting)
    • setLastInteractionBlockPosition

      public void setLastInteractionBlockPosition(com.nukkitx.math.vector.Vector3i lastInteractionBlockPosition)
      Stores the last position of the block the player interacted with. This can either be a block that the client placed or an existing block the player interacted with (for example, a chest).
      Initialized as (0, 0, 0) so it is always not-null.
    • setLastInteractionPlayerPosition

      public void setLastInteractionPlayerPosition(com.nukkitx.math.vector.Vector3f lastInteractionPlayerPosition)
      Stores the position of the player the last time they interacted. Used to verify that the player did not move since their last interaction.
      Initialized as (0, 0, 0) so it is always not-null.
    • setRidingVehicleEntity

      public void setRidingVehicleEntity(Entity ridingVehicleEntity)
    • setMouseoverEntity

      public void setMouseoverEntity(Entity mouseoverEntity)
      The entity that the client is currently looking at.
    • setCraftingRecipes

      public void setCraftingRecipes(it.unimi.dsi.fastutil.ints.Int2ObjectMap<com.github.steveice10.mc.protocol.data.game.recipe.Recipe> craftingRecipes)
    • setStonecutterRecipes

      public void setStonecutterRecipes(it.unimi.dsi.fastutil.ints.Int2ObjectMap<it.unimi.dsi.fastutil.ints.IntList> stonecutterRecipes)
      Saves a list of all stonecutter recipes, for use in a stonecutter inventory. The key is the Java ID of the item; the values are all the possible outputs' Java IDs sorted by their string identifier
    • setAttackSpeed

      public void setAttackSpeed(double attackSpeed)
      The current attack speed of the player. Used for sending proper cooldown timings. Setting a default fixes cooldowns not showing up on a fresh world.
    • setLastHitTime

      public void setLastHitTime(long lastHitTime)
      The time of the last hit. Used to gauge how long the cooldown is taking. This is a session variable in order to prevent more scheduled threads than necessary.
    • setSteeringLeft

      public void setSteeringLeft(boolean steeringLeft)
      Saves if the client is steering left on a boat.
    • setSteeringRight

      public void setSteeringRight(boolean steeringRight)
      Saves if the client is steering right on a boat.
    • setLastInteractionTime

      public void setLastInteractionTime(long lastInteractionTime)
      Store the last time the player interacted. Used to fix a right-click spam bug. See https://github.com/GeyserMC/Geyser/issues/503 for context.
    • setBucketScheduledFuture

      public void setBucketScheduledFuture(ScheduledFuture<?> bucketScheduledFuture)
      Stores a future interaction to place a bucket. Will be cancelled if the client instead intended to interact with a block.
    • setLastMovementTimestamp

      public void setLastMovementTimestamp(long lastMovementTimestamp)
      Used to send a movement packet every three seconds if the player hasn't moved. Prevents timeouts when AFK in certain instances.
    • setLastVehicleMoveTimestamp

      public void setLastVehicleMoveTimestamp(long lastVehicleMoveTimestamp)
      Used to send a ServerboundMoveVehiclePacket for every PlayerInputPacket after idling on a boat/horse for more than 100ms
    • setOpPermissionLevel

      public void setOpPermissionLevel(int opPermissionLevel)
      The op permission level set by the server
    • setCanFly

      public void setCanFly(boolean canFly)
      If the current player can fly
    • setRaining

      public void setRaining(boolean raining)
      Caches current rain status.
    • setThunder

      public void setThunder(boolean thunder)
      Caches current thunder status.
    • setLastSignMessage

      public void setLastSignMessage(String lastSignMessage)
      Stores the last text inputted into a sign.

      Bedrock sends packets every time you update the sign, Java only wants the final packet. Until we determine that the user has finished editing, we save the sign's current status.

    • setWaitingForStatistics

      public void setWaitingForStatistics(boolean waitingForStatistics)
      Whether we're expecting statistics to be sent back to us.
    • setAdvancedTooltips

      public void setAdvancedTooltips(boolean advancedTooltips)
      Whether advanced tooltips will be added to the player's items.