Package com.tenio.core.entity.implement
Class RoomImpl
java.lang.Object
com.tenio.core.entity.implement.RoomImpl
- All Implemented Interfaces:
Room
An implemented class is for a room using in the server.
-
Field Summary
Fields inherited from interface com.tenio.core.entity.Room
DEFAULT_SLOT, NIL_SLOT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a player to the room.void
Removes all properties of the room.boolean
containsPlayerName
(String playerName) Determines whether a player is present in the room.boolean
containsProperty
(String key) Determines whether a property is available for the room.boolean
int
Retrieves the total number of entities allowed to be in the room (participants and spectators).long
getId()
Retrieves the room's unique ID in the management list, on the server.int
Retrieves the maximum number of participants allowing in the room.int
Retrieves the maximum number of spectators allowing in the room.getName()
Retrieves the room's name.getOwner()
Retrieves the room's owner.int
Retrieves the current number of participants in the room.Retrieves the room's password.getPlayerByName
(String playerName) Retrieves a player by using its name.Retrieves an iterator for a player management list.Retrieves a player manager for the room.Retrieves a strategy to generate slot positions in the room.getProperty
(String key) Retrieves a property belongs to the room.Retrieves a read-only list of participants in a player management list.Retrieves a read-only player management list.Retrieves a read-only list of spectators in a player management list.Retrieves a strategy to validate credentials used to allow players get in the room.Retrieves the rule applied to room to remove it.int
Retrieves the current number of spectators in the room.getState()
Retrieves the current room's state.int
hashCode()
boolean
Determines whether the room is activated.boolean
isEmpty()
Determines whether the room is empty.boolean
isFull()
Determines whether the room is full.boolean
isPublic()
Determines whether the room is public which means it does not contain any credential and allowed to freely get in.static Room
Create a new instance.void
removePlayer
(Player player) Removes a player from its current room.void
removeProperty
(String key) Removes a property which belongs to the room.void
setActivated
(boolean activated) Updates the active state for the room.void
setCapacity
(int maxParticipants, int maxSpectators) Sets the limitation values for participants and spectators.void
setMaxParticipants
(int maxParticipants) Sets the maximum number of participants allowing in the room.void
setMaxSpectators
(int maxSpectators) Sets the maximum number of spectators allowing in the room.void
Sets the room's name.void
Updates the room's owner.void
setPassword
(String password) Sets the room's password.void
setPlayerManager
(PlayerManager playerManager) Sets a new player manager for the room.void
setPlayerSlotGeneratedStrategy
(RoomPlayerSlotGeneratedStrategy roomPlayerSlotGeneratedStrategy) Sets a strategy to generate slot positions in the room.void
setProperty
(String key, Object value) Sets a property belongs to the room.void
setRoomCredentialValidatedStrategy
(RoomCredentialValidatedStrategy roomCredentialValidatedStrategy) Sets a strategy to validate credentials used to allow players get in the room.void
setRoomRemoveMode
(RoomRemoveMode roomRemoveMode) Sets the rule applied to room to remove it.void
Sets a new state for the room.void
switchParticipantToSpectator
(Player player) Changes a player's role from "participant" to "spectator" in the room.void
switchSpectatorToParticipant
(Player player, int targetSlot) Changes a player's role from "spectator" to "participant" in the room.toString()
-
Constructor Details
-
RoomImpl
public RoomImpl()Constructor.
-
-
Method Details
-
newInstance
Create a new instance.- Returns:
- a new instance
-
getId
public long getId()Description copied from interface:Room
Retrieves the room's unique ID in the management list, on the server. -
getName
Description copied from interface:Room
Retrieves the room's name. -
setName
Description copied from interface:Room
Sets the room's name. -
getPassword
Description copied from interface:Room
Retrieves the room's password.- Specified by:
getPassword
in interfaceRoom
- Returns:
- a
String
value for room's password - See Also:
-
setPassword
Description copied from interface:Room
Sets the room's password.- Specified by:
setPassword
in interfaceRoom
- Parameters:
password
- aString
value for the room's password
-
getState
Description copied from interface:Room
Retrieves the current room's state. -
setState
Description copied from interface:Room
Sets a new state for the room. -
isPublic
public boolean isPublic()Description copied from interface:Room
Determines whether the room is public which means it does not contain any credential and allowed to freely get in. -
getMaxParticipants
public int getMaxParticipants()Description copied from interface:Room
Retrieves the maximum number of participants allowing in the room.- Specified by:
getMaxParticipants
in interfaceRoom
- Returns:
- the maximum number of participants (
integer
value)
-
setMaxParticipants
public void setMaxParticipants(int maxParticipants) Description copied from interface:Room
Sets the maximum number of participants allowing in the room.- Specified by:
setMaxParticipants
in interfaceRoom
- Parameters:
maxParticipants
- the maximum number of participants (integer
value)
-
getMaxSpectators
public int getMaxSpectators()Description copied from interface:Room
Retrieves the maximum number of spectators allowing in the room.- Specified by:
getMaxSpectators
in interfaceRoom
- Returns:
- the maximum number of spectators (
integer
value)
-
setMaxSpectators
public void setMaxSpectators(int maxSpectators) Description copied from interface:Room
Sets the maximum number of spectators allowing in the room.- Specified by:
setMaxSpectators
in interfaceRoom
- Parameters:
maxSpectators
- the maximum number of spectators (integer
value)
-
getOwner
Description copied from interface:Room
Retrieves the room's owner. -
setOwner
Description copied from interface:Room
Updates the room's owner. -
getPlayerManager
Description copied from interface:Room
Retrieves a player manager for the room.- Specified by:
getPlayerManager
in interfaceRoom
- Returns:
- a
PlayerManager
instance
-
setPlayerManager
Description copied from interface:Room
Sets a new player manager for the room.- Specified by:
setPlayerManager
in interfaceRoom
- Parameters:
playerManager
- aPlayerManager
instance
-
isActivated
public boolean isActivated()Description copied from interface:Room
Determines whether the room is activated.- Specified by:
isActivated
in interfaceRoom
- Returns:
true
when the room is active, otherwise returnsfalse
-
setActivated
public void setActivated(boolean activated) Description copied from interface:Room
Updates the active state for the room.- Specified by:
setActivated
in interfaceRoom
- Parameters:
activated
- sets the value totrue
to activate the room, otherwisefalse
-
getRoomRemoveMode
Description copied from interface:Room
Retrieves the rule applied to room to remove it.- Specified by:
getRoomRemoveMode
in interfaceRoom
- Returns:
- the current
RoomRemoveMode
of room
-
setRoomRemoveMode
Description copied from interface:Room
Sets the rule applied to room to remove it.- Specified by:
setRoomRemoveMode
in interfaceRoom
- Parameters:
roomRemoveMode
- the newRoomRemoveMode
of room
-
getProperty
Description copied from interface:Room
Retrieves a property belongs to the room.- Specified by:
getProperty
in interfaceRoom
- Parameters:
key
- theString
key to fetch data- Returns:
- an
Object
value if present, otherwisenull
-
setProperty
Description copied from interface:Room
Sets a property belongs to the room.- Specified by:
setProperty
in interfaceRoom
- Parameters:
key
- theString
keyvalue
- an instanceObject
of property's value
-
containsProperty
Description copied from interface:Room
Determines whether a property is available for the room.- Specified by:
containsProperty
in interfaceRoom
- Parameters:
key
- aString
key used for searching the corresponding property- Returns:
true
if the property is available, otherwise returnsfalse
-
removeProperty
Description copied from interface:Room
Removes a property which belongs to the room.- Specified by:
removeProperty
in interfaceRoom
- Parameters:
key
- theString
key
-
clearProperties
public void clearProperties()Description copied from interface:Room
Removes all properties of the room.- Specified by:
clearProperties
in interfaceRoom
-
getCapacity
public int getCapacity()Description copied from interface:Room
Retrieves the total number of entities allowed to be in the room (participants and spectators).- Specified by:
getCapacity
in interfaceRoom
- Returns:
- the total number of entities (
integer
value)
-
setCapacity
public void setCapacity(int maxParticipants, int maxSpectators) Description copied from interface:Room
Sets the limitation values for participants and spectators.- Specified by:
setCapacity
in interfaceRoom
- Parameters:
maxParticipants
- the maximum number of participants (integer
value)maxSpectators
- the maximum number of spectators (integer
value)
-
getParticipantCount
public int getParticipantCount()Description copied from interface:Room
Retrieves the current number of participants in the room.- Specified by:
getParticipantCount
in interfaceRoom
- Returns:
- the current number of participants (
integer
value)
-
getSpectatorCount
public int getSpectatorCount()Description copied from interface:Room
Retrieves the current number of spectators in the room.- Specified by:
getSpectatorCount
in interfaceRoom
- Returns:
- the current number of spectators (
integer
value)
-
containsPlayerName
Description copied from interface:Room
Determines whether a player is present in the room.- Specified by:
containsPlayerName
in interfaceRoom
- Parameters:
playerName
- a uniqueString
player name in the room's player management list- Returns:
true
when a player can be found, otherwise returnsfalse
-
getPlayerByName
Description copied from interface:Room
Retrieves a player by using its name.- Specified by:
getPlayerByName
in interfaceRoom
- Parameters:
playerName
- a uniqueString
name of player on the server- Returns:
- an instance of optional
Player
- See Also:
-
getPlayerIterator
Description copied from interface:Room
Retrieves an iterator for a player management list. This method should be used to prevent the "escape references" issue.- Specified by:
getPlayerIterator
in interfaceRoom
- Returns:
- an iterator of
Player
management list - See Also:
-
getReadonlyPlayersList
Description copied from interface:Room
Retrieves a read-only player management list. This method should be used to prevent the "escape references" issue.- Specified by:
getReadonlyPlayersList
in interfaceRoom
- Returns:
- a list of all
Player
s in the management list - See Also:
-
getReadonlyParticipantsList
Description copied from interface:Room
Retrieves a read-only list of participants in a player management list. This method should be used to prevent the "escape references" issue.- Specified by:
getReadonlyParticipantsList
in interfaceRoom
- Returns:
- a list of participants in a player management list
- See Also:
-
getReadonlySpectatorsList
Description copied from interface:Room
Retrieves a read-only list of spectators in a player management list. This method should be used to prevent the "escape references" issue.- Specified by:
getReadonlySpectatorsList
in interfaceRoom
- Returns:
- a list of spectators in a player management list
- See Also:
-
addPlayer
Description copied from interface:Room
Adds a player to the room.- Specified by:
addPlayer
in interfaceRoom
- Parameters:
player
- a joiningPlayer
password
- the password value assigned for the roomasSpectator
- sets totrue
if the player joins room as a "spectator", otherwise returnsfalse
targetSlot
- when the player join the room as role of "participants", then it can occupy a slot position (integer
value)
-
removePlayer
Description copied from interface:Room
Removes a player from its current room.- Specified by:
removePlayer
in interfaceRoom
- Parameters:
player
- the leavingPlayer
-
switchParticipantToSpectator
Description copied from interface:Room
Changes a player's role from "participant" to "spectator" in the room.- Specified by:
switchParticipantToSpectator
in interfaceRoom
- Parameters:
player
- the changingPlayer
-
switchSpectatorToParticipant
Description copied from interface:Room
Changes a player's role from "spectator" to "participant" in the room.- Specified by:
switchSpectatorToParticipant
in interfaceRoom
- Parameters:
player
- the changingPlayer
targetSlot
- a new slot position (integer
value) set to the player in the room
-
isEmpty
public boolean isEmpty()Description copied from interface:Room
Determines whether the room is empty. -
isFull
public boolean isFull()Description copied from interface:Room
Determines whether the room is full. -
equals
-
hashCode
public int hashCode() -
toString
-
getPlayerSlotGeneratedStrategy
Description copied from interface:Room
Retrieves a strategy to generate slot positions in the room.- Specified by:
getPlayerSlotGeneratedStrategy
in interfaceRoom
- Returns:
- an implementation of
RoomPlayerSlotGeneratedStrategy
, in case this value isnull
, then the default implementation will be used - See Also:
-
setPlayerSlotGeneratedStrategy
public void setPlayerSlotGeneratedStrategy(RoomPlayerSlotGeneratedStrategy roomPlayerSlotGeneratedStrategy) Description copied from interface:Room
Sets a strategy to generate slot positions in the room.- Specified by:
setPlayerSlotGeneratedStrategy
in interfaceRoom
- Parameters:
roomPlayerSlotGeneratedStrategy
- an implementation ofRoomPlayerSlotGeneratedStrategy
-
getRoomCredentialValidatedStrategy
Description copied from interface:Room
Retrieves a strategy to validate credentials used to allow players get in the room.- Specified by:
getRoomCredentialValidatedStrategy
in interfaceRoom
- Returns:
- an implementation of
RoomCredentialValidatedStrategy
, in case this value isnull
, then the default implementation will be used - See Also:
-
setRoomCredentialValidatedStrategy
public void setRoomCredentialValidatedStrategy(RoomCredentialValidatedStrategy roomCredentialValidatedStrategy) Description copied from interface:Room
Sets a strategy to validate credentials used to allow players get in the room.- Specified by:
setRoomCredentialValidatedStrategy
in interfaceRoom
- Parameters:
roomCredentialValidatedStrategy
- an implementation ofRoomCredentialValidatedStrategy
-