Interface ServerPlayer

    • Method Detail

      • isOnline

        boolean isOnline()
        Returns whether this player is online or not.

        If this returns false, this player should be considered stale and all references to it should be discarded immediately.

        Returns:
        True if online, false if not
      • isViewingInventory

        default boolean isViewingInventory()
        Returns whether this player has an open inventory at the moment or not.
        Returns:
        Whether this player is viewing an inventory or not
      • openInventory

        java.util.Optional<Container> openInventory()
        Gets the currently viewed inventory of this player, if it is currently viewing one.
        Returns:
        An inventory if this player is viewing one, otherwise Optional.empty()
      • openInventory

        java.util.Optional<Container> openInventory​(Inventory inventory)
                                             throws java.lang.IllegalArgumentException
        Opens the given Inventory for the player to view.
        Parameters:
        inventory - The inventory to view
        Returns:
        The opened Container if the inventory was opened, otherwise Optional.empty()
        Throws:
        java.lang.IllegalArgumentException - if a PluginContainer is not the root of the cause
      • openInventory

        java.util.Optional<Container> openInventory​(Inventory inventory,
                                                    Component displayName)
        Opens a given Inventory for the player to view with a custom displayName.

        Note that not all inventories support a custom display name.

        Parameters:
        inventory - The inventory to view
        displayName - The display name to set
        Returns:
        The opened Container if the inventory was opened, otherwise Optional.empty()
      • closeInventory

        boolean closeInventory()
                        throws java.lang.IllegalArgumentException
        Closes the currently viewed entity of this player, if it is currently viewing one.
        Returns:
        whether or not closing the inventory succeeded
        Throws:
        java.lang.IllegalArgumentException - if a PluginContainer is not the root of the cause
      • simulateChat

        PlayerChatEvent simulateChat​(Component message,
                                     Cause cause)
        Simulates a chat message from a player.

        This method sends a message as if it came from this player. To send a message to this player instead, see Audience.sendMessage(Identity, Component).

        If text formatting is not supported in the implementation it will be displayed as plain text.

        Parameters:
        message - The message to send
        cause - The cause for the message
        Returns:
        The event that was thrown from sending the message
      • sendResourcePack

        void sendResourcePack​(ResourcePack pack)
        Sends a given ResourcePack to this player.
        Parameters:
        pack - The ResourcePack to send
      • tabList

        TabList tabList()
        Gets this player's TabList.
        Returns:
        This player's TabList
      • kick

        boolean kick()
        Kicks the player, showing the default kick reason (the translation key disconnect.disconnected).
        Returns:
        whether or not kicking the player succeeded
      • kick

        boolean kick​(Component reason)
        Kicks the player given a reason.
        Parameters:
        reason - The reason for the kick
        Returns:
        whether or not kicking the player succeeded
      • scoreboard

        Scoreboard scoreboard()
        Gets the Scoreboard displayed to the player.
        Returns:
        The scoreboard displayed to the player
      • setScoreboard

        void setScoreboard​(Scoreboard scoreboard)
        Sets the Scoreboard displayed to the player.
        Parameters:
        scoreboard - The scoreboard to display
      • respawn

        boolean respawn()
        Manually respawns the player.

        If the player is not dead, this method will return false

        Returns:
        Whether the respawn was successful
      • worldBorder

        java.util.Optional<WorldBorder> worldBorder()
        Gets the WorldBorder for this player, if present. If no border is set, an empty Optional is returned.
        Returns:
        The WorldBorder of this player as an Optional, if present
      • setWorldBorder

        java.util.Optional<WorldBorder> setWorldBorder​(@Nullable WorldBorder border)
        Sets the WorldBorder that this player sees. If null, the border is unset, reverting to the border of the world the player is currently in.

        The values that are set may be altered by events, so users should check the returned value if they need to know if an event altered the values in some way. If no alterations were made, the supplied object and the returned object (within the optional) will be the same.

        Parameters:
        border - The world border to be used, may be null
        Returns:
        the values that were actually set, which may be different from those requested. If the result is an empty optional, then the player does not have a personal border, and uses that of the world they are in instead.
      • cooldownTracker

        CooldownTracker cooldownTracker()
        Gets the CooldownTracker for this player, allowing control over the player's item cooldowns.
        Returns:
        This player's cooldown tracker
      • unlockedAdvancementTrees

        java.util.Collection<AdvancementTree> unlockedAdvancementTrees()
        Gets all the AdvancementTrees that this Player already unlocked.
        Returns:
        The advancement trees
      • hasPlayedBefore

        default boolean hasPlayedBefore()
        Gets if the Player has played on the Server before. Added as a utility.
        Returns:
        True if played before, false otherwise
      • chatFormatter

        PlayerChatFormatter chatFormatter()
        Gets the chat router.
        Returns:
        The chat router
      • setChatFormatter

        void setChatFormatter​(PlayerChatFormatter router)
        Sets the chat router.
        Parameters:
        router - the chat router
      • healthScale

        default java.util.Optional<Value.Mutable<java.lang.Double>> healthScale()
        Returns:
        The value the player max-health (excluding absorption) in the GUI will scale to
      • lastJoined

        default java.util.Optional<Value.Mutable<java.time.Instant>> lastJoined()
        Returns:
        The last timestamp value when this player has joined
      • lastPlayed

        default java.util.Optional<Value.Mutable<java.time.Instant>> lastPlayed()
        Returns:
        The last timestamp value when this player has played