Package net.risingworld.api
Class Server
java.lang.Object
net.risingworld.api.Server
Represents the server object. This is basically the "core element", it will
be used to control everything related to the game context.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdds a temporaryAreato the server.static voidAdds anAreato the server.static voidBans the player with the specified UID for a given amount of time.static voidbroadcastTextMessage(String message) Broadcasts a text message, i.e send it to all players.static voidbroadcastYellMessage(String message, float duration, boolean pulsate) Broadcasts a yell message, i.e send it to all players.static PlayerfindNearestPlayer(Vector3f position) Gets the player who has the shortest distance to a particular world position.static Area[]Gets an array containing allAreasthat are currently registered with the server.static CustomImage[]Gets an array containing all custom images (creates a new array).static CustomImage[]getAllCustomImages(int playerDbID) Gets an array containing all custom images which were uploaded by a particular player.static String[]Gets all available permission group names.static Player[]Gets a new array containing all players that are currently connected to the server.static AreagetArea(long id) Gets theAreawith the provided global id.static intgetBuild()Gets the current build of the game as an int (e.g 201807210).static WeatherDefs.WeatherGets the current weather.static CustomImagegetCustomImage(long id) Gets a custom image.static InventoryGets the default spawn inventory (i.e the items you always spawn with).static Vector3fGets the global default spawn position.static QuaternionGets the default spawn rotation.static TimeDeprecated.static intgetGameTime(Time.Unit unit) Gets the current ingame time.static floatGets the game time speed.static StringgetIP()Gets the server IP is currently binded to.static StringgetLastKnownPlayerName(int playerDbID) Gets the last known name of the player with the specified database ID.static StringgetLastKnownPlayerName(String playerUID) Gets the last known name of the player with the specified UID.static String[]getLastKnownPlayerUIDs(String playerName) Gets the last known UIDs of all players who used the specified name recently.static StringGets the full file path to the log file.static intGets the maximum amount of players allowed on this server.static StringgetName()Gets the server name.static WeatherDefs.WeatherGets the next weather type.static StringGets a server option from the "server.properties" file.
Note: This method cannot be used to retrieve passwords or login names.static PlatformGets the game/server platform.static PlayergetPlayer(int playerid) Gets a player object representing the player with the provided playerid.static PlayergetPlayerByDbID(int playerDbID) Gets a player object representing the player with the provided unique database ID.static PlayergetPlayerByName(String playername) Gets a player object representing the player with the provided playername.static PlayergetPlayerByUID(String playerUID) Gets a player object representing the player with the provided unique ID (for Steam users, this is the SteamID64).static intGets the amount of players that are currently connected to this server.static StringgetPlayerUID(int playerDbID) Gets the UID of the player (irrespective of whether or not he's currently online) with the provided database ID.static intgetPort()Gets the server port.static StringTries to get the public IP of the server.static floatGets the amount of seconds that have passed since game/server start.static longGets the UID of the server.static intGets the total amount of players that were ever connected to this server in the past.static Server.TypegetType()Gets the current type of the server.static StringGets the current game version as a String (e.g "0.9.1.5").static floatGets the transition between the current weather type (0.0) and the next weather type (1.0).static booleanGets whether or not this server is password protected.static booleanisPlayerAdmin(String playerUID) Gets whether the particular player is an admin or not.static booleanisPlayerBanned(String playerUID) Gets whether the particular player (who has the provided UID) is banned or not.static booleanisPlayerConnected(int playerid) Gets whether or not this player is connected to the server.static booleanisPlayerConnected(String playername) Gets whether or not this player is connected to the server.static booleanGets whether or not the weather is enabled.static voidremoveArea(Area area) Removes anAreathat has been added to the server previously.static voidremoveCustomImage(long id, boolean destroyInstances) Deletes a custom image (and also removes all placed instances in the world).static voidrestart()Attempts to restart the server process.static voidsaveAll()Forces the server to save all pending changes (world, players, npcs, storages etc).static voidsaveNpcs()Forces the server to save all npcs.static voidForces the server to save all players and inventories.static voidForces the server to save all storages (chests etc).static voidsendInputCommand(String input) Sends an input command to the InputStream (System.in) of the server.static voidsetDefaultSpawnInventory(Inventory inventory) Sets the default spawn inventory (i.e the items you always spawn with).static voidsetDefaultSpawnPosition(float x, float y, float z) Sets the global default spawn position.static voidsetDefaultSpawnPosition(Vector3f position) Sets the global default spawn position.static voidsetDefaultSpawnRotation(float pitch, float yaw, float roll) Sets the default spawn rotation.static voidsetDefaultSpawnRotation(Quaternion quaternion) Sets the default spawn rotation.static voidsetGameTime(int hour, int min) Sets the ingame time.static voidsetGameTimeSpeed(float value) Changes the game time speed.static voidsetWeather(WeatherDefs.Weather newWeather, boolean instant) Sets the weather.static voidsetWeatherEnabled(boolean enabled) Enables or disables the weather.static voidshutdown()Forces the server to shutdown gracefully.static voidunbanPlayer(String playerUID) Unbans the player with the specified name (i.e removes him from the ban list).
-
Method Details
-
getType
Gets the current type of the server. Sometimes it's useful to find out if this server is currently a singleplayer server or a dedicated server (more precisely, it indicates if this plugin is executed in a singleplayer or multiplayer environment).- Returns:
- the current server type.
- Example: Check if the plugin is running on a dedicated server
-
getPlatform
Gets the game/server platform.- Returns:
- the game/server platform, i.e if this is a Steam version, a standalone version etc.
-
getServerUID
public static long getServerUID()Gets the UID of the server. If this is a Steam server, the SteamID64 is returned. Some platforms may not have a proper UID and return -1 in this case. If this is a singleplayer or locally hosted game, the UID of the host user is returned.- Returns:
- the UID of the server/host, or -1 if this server has no UID.
-
getName
Gets the server name.- Returns:
- the name of the server.
-
getIP
Gets the server IP is currently binded to. May a blank string if the server binds to all addresses.- Returns:
- the IP of the server. Never null.
- See Also:
-
getPublicIP
Tries to get the public IP of the server. Please note that this is not always possible.- Returns:
- the ip of the server. Never null.
-
getPort
public static int getPort()Gets the server port.- Returns:
- the port of the server.
-
isPassworded
public static boolean isPassworded()Gets whether or not this server is password protected.- Returns:
- true if players have to enter a password to enter the server, false if not (default).
-
getRunningTime
public static float getRunningTime()Gets the amount of seconds that have passed since game/server start.- Returns:
- the running time of the game/server (in seconds).
- Example: Shutdown server when it's running for more than 24 hours
-
getOption
Gets a server option from the "server.properties" file.
Note: This method cannot be used to retrieve passwords or login names.- Parameters:
key- the name of the option key.- Returns:
- a string representing the value, or null if the key was not found.
- Example: Determine if pvp is enabled (setting "settings_pvp_enabled")
-
getAllPermissionGroups
Gets all available permission group names.- Returns:
- a new array containing all permission group names.
-
getVersion
Gets the current game version as a String (e.g "0.9.1.5").- Returns:
- the current game version.
-
getBuild
public static int getBuild()Gets the current build of the game as an int (e.g 201807210). The build number always contains the year, month and day as well as an incrementing number.- Returns:
- the current build of the game.
- See Also:
-
saveAll
public static void saveAll()Forces the server to save all pending changes (world, players, npcs, storages etc). -
savePlayers
public static void savePlayers()Forces the server to save all players and inventories. -
saveStorages
public static void saveStorages()Forces the server to save all storages (chests etc). -
saveNpcs
public static void saveNpcs()Forces the server to save all npcs. -
sendInputCommand
Sends an input command to the InputStream (System.in) of the server. This only works for the dedicated server.- Parameters:
input- the input command.- Example: Send chat message
-
getLogFilePath
Gets the full file path to the log file.- Returns:
- the absolute file path to the log file.
-
shutdown
public static void shutdown()Forces the server to shutdown gracefully. This takes ~ 10 seconds. If you want to shutdown the server immediately (without removing all connections gracefully), you can useSystem.exit(0);instead. -
restart
public static void restart()Attempts to restart the server process. This first shuts down and terminates the server process, then instructs the OS to restart the process. This only works for the dedicated server (check viagetType())! You can't execute this method in singleplayer! -
setDefaultSpawnPosition
Sets the global default spawn position.- Parameters:
position- the new spawn position.
-
setDefaultSpawnPosition
public static void setDefaultSpawnPosition(float x, float y, float z) Sets the global default spawn position.- Parameters:
x- the new x coordinate.y- the new y coordinate.z- the new z coordinate.
-
getDefaultSpawnPosition
Gets the global default spawn position.- Returns:
- the spawn position as a Vector3f.
-
setDefaultSpawnRotation
Sets the default spawn rotation. ProvideQuaternion.IDENTITYif the spawn rotation should face towards north.- Parameters:
quaternion- the spawn rotation as a Quaternion.
-
setDefaultSpawnRotation
public static void setDefaultSpawnRotation(float pitch, float yaw, float roll) Sets the default spawn rotation. Builds the rotation from euler angles.- Parameters:
pitch- pitch (euler x)yaw- yaw (euler y)roll- roll (euler z)
-
getDefaultSpawnRotation
Gets the default spawn rotation.- Returns:
- the default spawn rotation as a Quaternion.
-
setDefaultSpawnInventory
Sets the default spawn inventory (i.e the items you always spawn with).- Parameters:
inventory- the default spawn inventory.
-
getDefaultSpawnInventory
Gets the default spawn inventory (i.e the items you always spawn with).- Returns:
- the default spawn inventory.
-
setGameTime
public static void setGameTime(int hour, int min) Sets the ingame time.- Parameters:
hour- hours (0-23)min- minutes (0-59)- Example: Set ingame time to 3:30 p.m. (15:30)
-
getGameTime
Gets the current ingame time.- Parameters:
unit- the time unit you want to get (e.g hours, minutes, days etc)- Returns:
- the current ingame time.
- Example:
-
getGameTime
Deprecated.Gets the internal time object which manages the ingame time and date.- Returns:
- the internal time object.
-
setGameTimeSpeed
public static void setGameTimeSpeed(float value) Changes the game time speed. The value represents the amount of realtime seconds one ingame minute should take (e.g a value of 60 indicates that one ingame minute takes 60 realtime seconds).- Parameters:
value- the amount of realtime seconds one ingame minute should take.- Example: Plugin which sets realtime time speed (1 ingame min == 60 realtime seconds)
-
getGameTimeSpeed
public static float getGameTimeSpeed()Gets the game time speed. Or more precisely, the amount of realtime seconds one ingame minute takes (e.g a value of 60 indicates that one ingame minute takes 60 realtime seconds).- Returns:
- the game time speed (realtime seconds -> ingame minutes)
-
setWeather
Sets the weather.- Parameters:
newWeather- the new weather.instant- if set to true, the weather will change instantly. Otherwise, there will be a smooth transition between the current weather type and the new weather type.- Example: Set sunny weather forever
-
getCurrentWeather
Gets the current weather.- Returns:
- the current weather type.
-
getNextWeather
Gets the next weather type. In other words, if the weather is changing, this function returns the next weather type. Otherwise, null will be returned.- Returns:
- the next weather type, or null if the weather is currently not changing.
-
setWeatherEnabled
public static void setWeatherEnabled(boolean enabled) Enables or disables the weather. If the weather is disabled, the current weather stays active until it will be changed manually. Note that if the weather is currently changing while calling this method, the transition will still be completed.- Parameters:
enabled- true to enable weather, false to disable it.
-
isWeatherEnabled
public static boolean isWeatherEnabled()Gets whether or not the weather is enabled.- Returns:
- true if the weather is enabled, false if not.
-
getWeatherTransition
public static float getWeatherTransition()Gets the transition between the current weather type (0.0) and the next weather type (1.0). If the weather is currently not changing, this function always returns 0.0, otherwise a value between 0.0 and 1.0 will be returned.- Returns:
- the transition interpolation value between the current and the next weather type. If the weather is currently not changing, this function always returns 0.0
-
getPlayerCount
public static int getPlayerCount()Gets the amount of players that are currently connected to this server.- Returns:
- the current amount of players.
-
getMaxPlayerCount
public static int getMaxPlayerCount()Gets the maximum amount of players allowed on this server.- Returns:
- the max amount of players that can play on this server simultaneously.
-
getTotalPlayerCount
public static int getTotalPlayerCount()Gets the total amount of players that were ever connected to this server in the past.- Returns:
- the total amount of entries in the player database.
-
isPlayerConnected
public static boolean isPlayerConnected(int playerid) Gets whether or not this player is connected to the server.- Parameters:
playerid- the player ID (not the database ID).- Returns:
- true if the player is online, false if not.
-
isPlayerConnected
Gets whether or not this player is connected to the server.- Parameters:
playername- the name of the player.- Returns:
- true if the player is online, false if not.
-
getPlayer
Gets a player object representing the player with the provided playerid. This function only works for players who are currently connected to the server.- Parameters:
playerid- the player ID (neither the database ID nor the unique ID)- Returns:
- the player, or null if no player with the given ID was found.
-
getPlayerByUID
Gets a player object representing the player with the provided unique ID (for Steam users, this is the SteamID64). This ID never changes for a player. This function only works for players who are currently connected to the server.- Parameters:
playerUID- the unique player ID.- Returns:
- the player, or null if no player with the given UID was found.
-
getPlayerByDbID
Gets a player object representing the player with the provided unique database ID. The database ID never changes for a player. This function only works for players who are currently connected to the server.- Parameters:
playerDbID- the player database ID (not to be confused with the regular player ID or UID)- Returns:
- the player, or null if no player with the given db ID was found.
-
getPlayerByName
Gets a player object representing the player with the provided playername. This function only works for players who are currently connected to the server.- Parameters:
playername- the name of the player.- Returns:
- the player, or null if no player was found.
-
getPlayerUID
Gets the UID of the player (irrespective of whether or not he's currently online) with the provided database ID.- Parameters:
playerDbID- the player database ID (not to be confused with the regular player ID)- Returns:
- the player UID (no matter if the player is currently online or offline), or null if no such player was found.
-
getAllPlayers
Gets a new array containing all players that are currently connected to the server.- Returns:
- a new array containing all players which are online.
- Example: Heal broken bones for all players
-
isPlayerBanned
Gets whether the particular player (who has the provided UID) is banned or not.- Parameters:
playerUID- the unique id of the player (for Steam users, it's the SteamID64).- Returns:
- true if the player is banned, false if not.
-
isPlayerAdmin
Gets whether the particular player is an admin or not.- Parameters:
playerUID- the unique id of the player (for Steam users, it's the SteamID64).- Returns:
- true if the player is an admin, false if not.
-
banPlayer
Bans the player with the specified UID for a given amount of time.- Parameters:
playerUID- the unique id of the player you want to ban (for Steam users, it's the SteamID64).reason- a string containing the reason why the player was banned.duration- the duration (in seconds) how long the player will be banned. Use '-1' to ban the player permanently.
-
unbanPlayer
Unbans the player with the specified name (i.e removes him from the ban list).- Parameters:
playerUID- the unique id of the player you want to unban (for Steam users, it's the SteamID64).
-
findNearestPlayer
Gets the player who has the shortest distance to a particular world position.- Parameters:
position- the world position.- Returns:
- the nearest player, or null if no player is currently online.
- See Also:
-
getLastKnownPlayerName
Gets the last known name of the player with the specified UID. Please note that names are not unique and can be changed by the player at any time.- Parameters:
playerUID- the unique id of the player.- Returns:
- the last known name of the player (if he ever joined the server in the past), or null if no such player data was found.
-
getLastKnownPlayerName
Gets the last known name of the player with the specified database ID. Please note that names are not unique and can be changed by the player at any time.- Parameters:
playerDbID- the unique database ID of the player.- Returns:
- the last known name of the player (if he ever joined the server in the past), or null if no such player data was found.
-
getLastKnownPlayerUIDs
Gets the last known UIDs of all players who used the specified name recently. Please note that names are not unique and can be changed by the player at any time.- Parameters:
playerName- the name of the player.- Returns:
- an array containing all UIDs of all players who used the specified name recently (as their lastest name), or null if no players were found.
-
addArea
Adds a temporaryAreato the server. Once an area is added to the server,PlayerEnterAreaEventandPlayerLeaveAreaEventevents will be triggered when a player enters/leaves an area.
Note: This area will not be stored in the area database! If you want to store the area permanently, useaddArea(net.risingworld.api.objects.Area, boolean)instead!- Parameters:
area- theAreayou want to add to the server.- See Also:
-
addArea
Adds anAreato the server. Once an area is added to the server,PlayerEnterAreaEventandPlayerLeaveAreaEventevents will be triggered when a player enters/leaves an area.- Parameters:
area- theAreayou want to add to the server.storeInDatabase- if true, the area will also be stored persistently in the database!- See Also:
-
removeArea
Removes anAreathat has been added to the server previously. Once an area is removed, events likePlayerEnterAreaEventorPlayerLeaveAreaEventwill no longer be triggered for this area.- Parameters:
area- theAreayou want to remove from the server. Note: you can still re-add the area to the server at any time.- See Also:
-
getArea
Gets theAreawith the provided global id.- Parameters:
id- the id of the area.- Returns:
- the associated area, or null if no such area was found.
-
getAllAreas
Gets an array containing allAreasthat are currently registered with the server.- Returns:
- a newly created array containing all registered areas.
- Example: Check if player is inside areas
-
getCustomImage
Gets a custom image.- Parameters:
id- the image id. For ObjectElements, this is typically stored in the "info" field.- Returns:
- the custom image, or null if the image does not exist.
-
removeCustomImage
public static void removeCustomImage(long id, boolean destroyInstances) Deletes a custom image (and also removes all placed instances in the world). If the image does not exist, nothing happens.- Parameters:
id- the image id.destroyInstances- if true, all image instances (posters) in the world using this custom image will be destroyed automatically. Otherwise they will remain in the world (without showing an image anymore).
-
getAllCustomImages
Gets an array containing all custom images (creates a new array).- Returns:
- a new array containing all images.
-
getAllCustomImages
Gets an array containing all custom images which were uploaded by a particular player. This method creates a new array.- Parameters:
playerDbID- the player database id (seePlayer.getDbID()).- Returns:
- a new array containing all images uploaded by a particular player.
-
broadcastTextMessage
Broadcasts a text message, i.e send it to all players. This is exactly the same as callingPlayer.sendTextMessage(java.lang.String)for every player.- Parameters:
message- the message you want to broadcast.- See Also:
-
broadcastYellMessage
Broadcasts a yell message, i.e send it to all players. This is exactly the same as callingPlayer.sendYellMessage(java.lang.String, float, boolean)for every player.- Parameters:
message- the yell message you want to broadcast.duration- amount of seconds how long the message should stay visible. Use "5f" for example.pulsate- if true, the message will pulsate on the screen.- See Also:
-