Class Player


public class Player extends CommandSender
Represents a player, both online and offline
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the IP address that this player is connected with
    int
    Gets the port that this player is connected with
    int
    Gets the number of health points this player has
    Gets the name of this player
    int
    getSlotAmount​(int slot)
    Gets the amount at specified inventory slot
    getSlotBlock​(int slot)
    Gets the block type at specified inventory slot
    int
    Gets the current strength value this player has
    double
    Gets the current X-coordinate of this player
    double
    Gets the current Y-coordinate of this player
    boolean
    giveBlock​(Block block, int amount)
    Gives the player the block with the amount specified
    boolean
    Gets if this player has played on the server
    boolean
    Gets if this player is an admin
    boolean
    Gets if this player has authenticated (logged in) to the server.
    boolean
    Gets if this player is banned
    boolean
    Gets whether the player is currently in the end dimension
    boolean
    Gets if this player is currently online
    boolean
    Gets if this player is whitelisted
    void
    Kicks this player from the server
    void
    kick​(String reason)
    Kicks this player from the server with the specified reason
    void
    Saves this players data to the disk
    void
    sendMessage​(String message)
    Sends a chat message to this player
    void
    setAdmin​(boolean admin)
    Sets the admin status of this player
    void
    setBanned​(boolean banned)
    Sets the banned status of this player
    void
    setHealth​(int health)
    Sets the number of health points of this player
    void
    setPos​(double x, double y, boolean endDimension)
    Sets the current position of this player
    void
    setSlotBlock​(int slot, Block block, int amount)
    Sets the specified inventory slot to the block and amount
    void
    setStrength​(int strength)
    Sets the strength value of this player
    void
    setWhitelisted​(boolean whitelisted)
    Sets the whitelisted status of this player
    void
    transfer​(String address, int port)
    Transfers this player to the specified server address and port

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isOnline

      public boolean isOnline()
      Gets if this player is currently online
      Returns:
      Whether online
    • hasPlayed

      public boolean hasPlayed()
      Gets if this player has played on the server
      Returns:
      Whether played
    • isAuthenticated

      public boolean isAuthenticated()
      Gets if this player has authenticated (logged in) to the server.
      Returns:
      Whether authenticated
      Throws:
      IllegalStateException - if player is offline
    • getName

      public String getName()
      Gets the name of this player

      If online, this will return the name case of online player

      If offline, this will return the name case of the stored offline player

      Overrides:
      getName in class CommandSender
      Returns:
      Player name
    • getConnectedIP

      public InetAddress getConnectedIP()
      Gets the IP address that this player is connected with
      Returns:
      Connected IP address
      Throws:
      IllegalStateException - if player is offline
    • getConnectedPort

      public int getConnectedPort()
      Gets the port that this player is connected with
      Returns:
      Connected port
      Throws:
      IllegalStateException - if player is offline
    • getX

      public double getX()
      Gets the current X-coordinate of this player
      Returns:
      X-coordinate position
      Throws:
      IllegalStateException - if player is offline
    • getY

      public double getY()
      Gets the current Y-coordinate of this player
      Returns:
      Y-coordinate position
      Throws:
      IllegalStateException - if player is offline
    • isInEnd

      public boolean isInEnd()
      Gets whether the player is currently in the end dimension
      Returns:
      Whether in end dimension
      Throws:
      IllegalStateException - if player is offline
    • setPos

      public void setPos(double x, double y, boolean endDimension)
      Sets the current position of this player
      Parameters:
      x - X-coordinate of the player
      y - Y-coordinate of the player
      endDimension - Dimension of this player (false = Overworld, true = End)
      Throws:
      IllegalStateException - if player is offline
    • getHealth

      public int getHealth()
      Gets the number of health points this player has
      Returns:
      Health points
      Throws:
      IllegalStateException - if player is offline
    • setHealth

      public void setHealth(int health)
      Sets the number of health points of this player
      Parameters:
      health - Health points
      Throws:
      IllegalStateException - if player is offline
    • getStrength

      public int getStrength()
      Gets the current strength value this player has
      Returns:
      Strength value
      Throws:
      IllegalStateException - if player is offline
    • setStrength

      public void setStrength(int strength)
      Sets the strength value of this player
      Parameters:
      strength - Strength value
      Throws:
      IllegalStateException - if player is offline
    • giveBlock

      public boolean giveBlock(Block block, int amount)
      Gives the player the block with the amount specified
      Parameters:
      block - Block type to give
      amount - Amount of blocks
      Returns:
      Whether the item was given, can return false if inventory was full
      Throws:
      IllegalStateException - if player is offline
      IllegalArgumentException - if block is null
    • setSlotBlock

      public void setSlotBlock(int slot, Block block, int amount)
      Sets the specified inventory slot to the block and amount

      If set to AIR, the slot will become empty

      Parameters:
      slot - Inventory slot
      block - Block type
      amount - Amount of blocks
      Throws:
      IllegalStateException - if player is offline
      IllegalArgumentException - if slot is out of bounds
      IllegalArgumentException - if block is null
    • getSlotBlock

      public Block getSlotBlock(int slot)
      Gets the block type at specified inventory slot
      Parameters:
      slot - Inventory slot
      Returns:
      Block type
      Throws:
      IllegalStateException - if player is offline
      IllegalArgumentException - if slot is out of bounds
    • getSlotAmount

      public int getSlotAmount(int slot)
      Gets the amount at specified inventory slot
      Parameters:
      slot - Inventory slot
      Returns:
      Amount of block
      Throws:
      IllegalStateException - if player is offline
      IllegalArgumentException - if slot is out of bounds
    • sendMessage

      public void sendMessage(String message)
      Sends a chat message to this player
      Overrides:
      sendMessage in class CommandSender
      Parameters:
      message - Message to send
      Throws:
      IllegalStateException - if player is offline
      IllegalArgumentException - if message is null
    • isAdmin

      public boolean isAdmin()
      Gets if this player is an admin
      Returns:
      Whether admin
    • setAdmin

      public void setAdmin(boolean admin)
      Sets the admin status of this player
      Parameters:
      admin - Whether admin
    • isBanned

      public boolean isBanned()
      Gets if this player is banned
      Returns:
      Whether banned
    • setBanned

      public void setBanned(boolean banned)
      Sets the banned status of this player
      Parameters:
      banned - Whether banned
    • isWhitelisted

      public boolean isWhitelisted()
      Gets if this player is whitelisted

      This always return true if whitelist is disabled on the server

      Returns:
      Whether whitelisted
    • setWhitelisted

      public void setWhitelisted(boolean whitelisted)
      Sets the whitelisted status of this player
      Parameters:
      whitelisted - Whether whitelisted
      Throws:
      IllegalArgumentException - if server whitelist is not enabled
    • kick

      public void kick()
      Kicks this player from the server
      Throws:
      IllegalStateException - if player is already currently leaving
      IllegalStateException - if player is offline
    • kick

      public void kick(String reason)
      Kicks this player from the server with the specified reason
      Parameters:
      reason - Kick reason
      Throws:
      IllegalStateException - if player is already currently leaving
      IllegalStateException - if player is offline
      IllegalArgumentException - if reason is null
    • transfer

      public void transfer(String address, int port)
      Transfers this player to the specified server address and port

      This will cause the player to be kicked from the server and they will be connected to the specified address

      Parameters:
      address - Server address
      port - Server port
      Throws:
      IllegalStateException - if player is already currently leaving
      IllegalStateException - if player is offline
      IllegalArgumentException - if address is null
    • save

      public void save()
      Saves this players data to the disk
      Throws:
      IllegalStateException - if player is offline