Package com.tenio.core.api
Interface ServerApi
- All Known Implementing Classes:
ServerApiImpl
public interface ServerApi
This class provides all supported APIs working with the server.
-
Method Summary
Modifier and TypeMethodDescriptionaddRoom(Room room, InitialRoomSetting roomSetting, Player roomOwner) Adds a new room to the server.default voidbanPlayer(Player player, String message, PlayerBanMode banMode, int durationInMinutes, int delayInSeconds) Prevents a player from logging on the server.default RoomcreateRoom(InitialRoomSetting roomSetting) Creates a new room on the server without an owner.createRoom(InitialRoomSetting roomSetting, Player roomOwner) Creates a new room on the server.intRetrieves the current available UDP port.getPlayerByName(String playerName) Retrieves a player on the server by using its name.intFetches the current number of players activating on the server.Retrieves an iterator for the global player management list on the server.Retrieves a read-only global player management list on the server.Retrieves a read-only global room management list on the server.getRoomById(long roomId) Retrieves a room instance by using its ID.intFetches the current number of rooms on the server.Retrieves an iterator for the room management list on the server.longRetrieves the time when server starts in milliseconds.longRetrieves the current uptime of server in milliseconds.default voidAllows 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.default voidAllows a player to join a particular room.voidAllows a player to join a particular room.default voidkickPlayer(Player player, String message, int delayInSeconds) Removes a player manually from the server.voidleaveRoom(Player player, PlayerLeaveRoomMode leaveRoomMode) Makes a player to leave its current room.voidAllows creating an instance of a player on the server which could be a custom one.voidAllows creating an instance of a player in the server.voidAllows creating an instance of a player in the server.voidlogout(Player player, ConnectionDisconnectMode connectionDisconnectMode, PlayerDisconnectMode playerDisconnectMode) Removes a player from the management list and from the server as well.voidremoveRoom(Room room, RoomRemoveMode removeRoomMode) Removes a room from the management list, server.default voidsendPrivateMessage(Player sender, Player recipient, com.tenio.common.data.DataCollection message) Sends a message from a player to another recipient.default voidsendPublicMessage(Player sender, Room room, com.tenio.common.data.DataCollection message) Sends a message from a player to all recipients in a room.default voidswitchParticipantToSpectator(Player player, Room room) Changes the role of a player in its room, from "participant" to "spectator".default voidswitchSpectatorToParticipant(Player player, Room room, int targetSlot) Changes the role of a player in its room, from "spectator" to "participant".
-
Method Details
-
login
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 (Stringvalue) on the server- See Also:
-
login
Allows creating an instance of a player in the server. -
login
Allows creating an instance of a player on the server which could be a custom one.- Parameters:
player- aPlayerwho 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 methodResponse.writeThenClose()- Parameters:
player- the currentPlayerin the management list, on the serverconnectionDisconnectMode-ConnectionDisconnectModesession disconnected reasonplayerDisconnectMode-PlayerDisconnectModeplayer disconnected reason- Since:
- 0.5.0
- See Also:
-
kickPlayer
Removes a player manually from the server.- Parameters:
player- thePlayerneeds to be removedmessage- aStringtext delivered to the player before it leavesdelayInSeconds- a countdown time in seconds (integervalue) for removing the player. In case the player has to be out immediately, this value should be set to0- 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- thePlayerneeds to be bannedmessage- a text (Stringvalue) delivered to the player before it is bannedbanMode- a rule (PlayerBanMode) applied for the playerdurationInMinutes- how long the player takes punishment calculated in minutes (integervalue)delayInSeconds- a countdown time in seconds (integervalue) for banning the player. In case the player has to be banned immediately, this value should be set to0- Throws:
UnsupportedOperationException- this method is not supported at the moment
-
createRoom
Creates a new room on the server without an owner.- Parameters:
roomSetting- all roomInitialRoomSettingat the time its created- Returns:
- a new instance of
Roomif available, otherwisenull
-
createRoom
Creates a new room on the server.- Parameters:
roomSetting- all roomInitialRoomSettingat the time its createdroomOwner- aPlayerowner of this room, owner can also be declared bynullvalue- Returns:
- a new instance of
Roomif available, otherwisenull
-
addRoom
Adds a new room to the server.- Parameters:
room- an instance ofRoomroomSetting- all settings created by aInitialRoomSettingbuilderroomOwner- aPlayeras 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
Retrieves a player on the server by using its name. -
getPlayerCount
int getPlayerCount()Fetches the current number of players activating on the server.- Returns:
- the current number of players (
integervalue) - Since:
- 0.5.0
-
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
Playermanagement list - See Also:
-
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
Retrieves a room instance by using its ID. -
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
Roomin the management list on the server - See Also:
-
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
Roomin 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 (
integervalue)
-
joinRoom
Allows a player to join a particular room.- Parameters:
player- the joiningPlayerroom- the currentRoomroomPassword- aStringcredential using for a player to join room. In case of free join, this value would be set tonullslotInRoom- the position of player located in the room (integervalue)asSpectator- sets bytrueif the player operating in the room as a spectator, otherwise sets itfalse
-
joinRoom
Allows a player to join a particular room. -
joinRoom
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. -
switchParticipantToSpectator
Changes the role of a player in its room, from "participant" to "spectator".- Parameters:
player- the checkingPlayerroom- the current player'sRoom- Throws:
UnsupportedOperationException- this method is not supported at the moment
-
switchSpectatorToParticipant
Changes the role of a player in its room, from "spectator" to "participant".- Parameters:
player- the checking spectator (Playerinstance)room- the current spectator'sRoomtargetSlot- a new position (integervalue) of transformed "participant" in its room- Throws:
UnsupportedOperationException- this method is not supported at the moment
-
leaveRoom
Makes a player to leave its current room.- Parameters:
player- the leavingPlayerleaveRoomMode- a rule (PlayerLeaveRoomMode) applied for the leaving player
-
removeRoom
Removes a room from the management list, server.- Parameters:
room- the removingRoomremoveRoomMode- 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 (Playerinstance)room- all recipients in the sameRoommessage- the sendingDataCollection- 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 (Playerinstance)recipient- the receiver (Playerinstance)message- the sendingDataCollection- Throws:
UnsupportedOperationException- the method is not supported at the moment
-
getCurrentAvailableUdpPort
int getCurrentAvailableUdpPort()Retrieves the current available UDP port.- Returns:
- an
integervalue 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
-