Interface ServerApi

All Known Implementing Classes:
ServerApiImpl

public interface ServerApi
This class provides all supported APIs working with the server.
  • Method Details

    • login

      void login(String playerName)
      Allows creating an instance of a player in the server. The player does not contain session, it should act like a server's bot.
      Parameters:
      playerName - a unique player's name (String value) on the server
      See Also:
    • login

      void login(String playerName, Session session)
      Allows creating an instance of a player in the server.
      Parameters:
      playerName - a unique player's name (String value) on the server
      session - a Session associated to the player
      See Also:
    • login

      void login(Player player)
      Allows creating an instance of a player on the server which could be a custom one.
      Parameters:
      player - a Player who must have a unique name on the server
      Since:
      0.5.0
      See Also:
    • logout

      void logout(Player player, ConnectionDisconnectMode connectionDisconnectMode, PlayerDisconnectMode playerDisconnectMode)
      Removes a player from the management list and from the server as well. This is a silent logout, so please do not perform any responding to the client since it may not work as expected (each command runs in different threads, so it may not get synchronized. In case you want to send a message to the client before closing connect or logout the player, please use this method Response.writeThenClose()
      Parameters:
      player - the current Player in the management list, on the server
      connectionDisconnectMode - ConnectionDisconnectMode session disconnected reason
      playerDisconnectMode - PlayerDisconnectMode player disconnected reason
      Since:
      0.5.0
      See Also:
    • kickPlayer

      default void kickPlayer(Player player, String message, int delayInSeconds)
      Removes a player manually from the server.
      Parameters:
      player - the Player needs to be removed
      message - a String text delivered to the player before it leaves
      delayInSeconds - a countdown time in seconds (integer value) for removing the player. In case the player has to be out immediately, this value should be set to 0
      Throws:
      UnsupportedOperationException - this method is not supported at the moment
    • banPlayer

      default void banPlayer(Player player, String message, PlayerBanMode banMode, int durationInMinutes, int delayInSeconds)
      Prevents a player from logging on the server.
      Parameters:
      player - the Player needs to be banned
      message - a text (String value) delivered to the player before it is banned
      banMode - a rule (PlayerBanMode) applied for the player
      durationInMinutes - how long the player takes punishment calculated in minutes (integer value)
      delayInSeconds - a countdown time in seconds (integer value) for banning the player. In case the player has to be banned immediately, this value should be set to 0
      Throws:
      UnsupportedOperationException - this method is not supported at the moment
    • createRoom

      default Room createRoom(InitialRoomSetting roomSetting)
      Creates a new room on the server without an owner.
      Parameters:
      roomSetting - all room InitialRoomSetting at the time its created
      Returns:
      a new instance of Room if available, otherwise null
    • createRoom

      Room createRoom(InitialRoomSetting roomSetting, Player roomOwner)
      Creates a new room on the server.
      Parameters:
      roomSetting - all room InitialRoomSetting at the time its created
      roomOwner - a Player owner of this room, owner can also be declared by null value
      Returns:
      a new instance of Room if available, otherwise null
    • addRoom

      Room addRoom(Room room, InitialRoomSetting roomSetting, Player roomOwner)
      Adds a new room to the server.
      Parameters:
      room - an instance of Room
      roomSetting - all settings created by a InitialRoomSetting builder
      roomOwner - a Player as the room's owner
      Returns:
      the room instance
      Throws:
      AddedDuplicatedRoomException - when a room is already available on the server, but it is mentioned again
      Since:
      0.5.0
    • getPlayerByName

      Optional<Player> getPlayerByName(String playerName)
      Retrieves a player on the server by using its name.
      Parameters:
      playerName - a unique String value for player's name on the server
      Returns:
      a corresponding instance of optional Player
      See Also:
    • getPlayerCount

      int getPlayerCount()
      Fetches the current number of players activating on the server.
      Returns:
      the current number of players (integer value)
      Since:
      0.5.0
    • getPlayerIterator

      Iterator<Player> getPlayerIterator()
      Retrieves an iterator for the global player management list on the server. This method should be used to prevent the "escape references" issue.
      Returns:
      an iterator of Player management list
      See Also:
    • getReadonlyPlayersList

      List<Player> getReadonlyPlayersList()
      Retrieves a read-only global player management list on the server. This method should be used to prevent the "escape references" issue.
      Returns:
      a list of all Players in the management list on the server
      See Also:
    • getRoomById

      Optional<Room> getRoomById(long roomId)
      Retrieves a room instance by using its ID.
      Parameters:
      roomId - a unique room ID (long value)
      Returns:
      an optional Room instance
      See Also:
    • getRoomIterator

      Iterator<Room> getRoomIterator()
      Retrieves an iterator for the room management list on the server. This method should be used to prevent the "escape references" issue.
      Returns:
      a list of all rooms Room in the management list on the server
      See Also:
    • getReadonlyRoomsList

      List<Room> getReadonlyRoomsList()
      Retrieves a read-only global room management list on the server. This method should be used to prevent the "escape references" issue.
      Returns:
      a list of all rooms Room in the management list on the server
      See Also:
    • getRoomCount

      int getRoomCount()
      Fetches the current number of rooms on the server.
      Returns:
      the current number of rooms (integer value)
    • joinRoom

      void joinRoom(Player player, Room room, String roomPassword, int slotInRoom, boolean asSpectator)
      Allows a player to join a particular room.
      Parameters:
      player - the joining Player
      room - the current Room
      roomPassword - a String credential using for a player to join room. In case of free join, this value would be set to null
      slotInRoom - the position of player located in the room (integer value)
      asSpectator - sets by true if the player operating in the room as a spectator, otherwise sets it false
    • joinRoom

      default void joinRoom(Player player, Room room, String roomPassword)
      Allows a player to join a particular room.
      Parameters:
      player - the joining Player
      room - the current Room
      roomPassword - a String credential using for a player to join room. In case of free join, this value would be set to null
    • joinRoom

      default void joinRoom(Player player, Room room)
      Allows a player to join a particular room as the role of "participant" with the room's password is not present, and the player position in room is not considered.
      Parameters:
      player - the joining Player
      room - the current Room
      See Also:
    • switchParticipantToSpectator

      default void switchParticipantToSpectator(Player player, Room room)
      Changes the role of a player in its room, from "participant" to "spectator".
      Parameters:
      player - the checking Player
      room - the current player's Room
      Throws:
      UnsupportedOperationException - this method is not supported at the moment
    • switchSpectatorToParticipant

      default void switchSpectatorToParticipant(Player player, Room room, int targetSlot)
      Changes the role of a player in its room, from "spectator" to "participant".
      Parameters:
      player - the checking spectator (Player instance)
      room - the current spectator's Room
      targetSlot - a new position (integer value) of transformed "participant" in its room
      Throws:
      UnsupportedOperationException - this method is not supported at the moment
    • leaveRoom

      void leaveRoom(Player player, PlayerLeaveRoomMode leaveRoomMode)
      Makes a player to leave its current room.
      Parameters:
      player - the leaving Player
      leaveRoomMode - a rule (PlayerLeaveRoomMode) applied for the leaving player
    • removeRoom

      void removeRoom(Room room, RoomRemoveMode removeRoomMode)
      Removes a room from the management list, server.
      Parameters:
      room - the removing Room
      removeRoomMode - a rule (RoomRemoveMode) applied for the removing room
    • sendPublicMessage

      default void sendPublicMessage(Player sender, Room room, com.tenio.common.data.DataCollection message)
      Sends a message from a player to all recipients in a room.
      Parameters:
      sender - the sender (Player instance)
      room - all recipients in the same Room
      message - the sending DataCollection
      Throws:
      UnsupportedOperationException - the method is not supported at the moment
    • sendPrivateMessage

      default void sendPrivateMessage(Player sender, Player recipient, com.tenio.common.data.DataCollection message)
      Sends a message from a player to another recipient.
      Parameters:
      sender - the sender (Player instance)
      recipient - the receiver (Player instance)
      message - the sending DataCollection
      Throws:
      UnsupportedOperationException - the method is not supported at the moment
    • getCurrentAvailableUdpPort

      int getCurrentAvailableUdpPort()
      Retrieves the current available UDP port.
      Returns:
      an integer value of UDP port
      Since:
      0.3.0
    • getStartedTime

      long getStartedTime()
      Retrieves the time when server starts in milliseconds.
      Returns:
      started time in milliseconds
      Since:
      0.3.1
    • getUptime

      long getUptime()
      Retrieves the current uptime of server in milliseconds.
      Returns:
      the current server's uptime in milliseconds
      Since:
      0.3.1