Class Server

java.lang.Object
net.risingworld.api.Server

public final class Server extends Object
Represents the server object. This is basically the "core element", it will be used to control everything related to the game context.
  • Method Details

    • getType

      public static Server.Type 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
      1if (Server.getType() == Type.Dedicated) {
      2 //This is a dedicated server
      3}
    • getPlatform

      public static Platform getPlatform()
    • 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

      public static String getName()
      Gets the server name.
      Returns:
      the name of the server.
    • getIP

      public static String getIP()
      Gets the server ip.
      Returns:
      the ip of the server.
    • 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
      1//Global flag somewhere in order to make sure that the shutdown
      2//procedure is only triggered once
      3public boolean shuttingdown = false;
      4
      5//24 hours == 86400 seconds
      6float runningtime = server.getRunningTime();
      7
      8//Make sure "shuttingdown" hasn't been set yet
      9if(!shuttingdown && runningtime > 86400){
      10 shuttingdown = true;
      11
      12 //Send a shutdown text and yell notification to all players
      13 Server.broadcastTextMessage("<color=red>WARNING: Server will shutdown in 1 minute!</color>");
      14 Server.broadcastYellMessage("WARNING\nServer will shutdown in 1 minute");
      15
      16 //Create a timer which only triggers once after 1 minute (60 seconds)
      17 Timer timer = new Timer(0, 60f, 0, () -> {
      18 //Save all
      19 Server.saveAll();
      20
      21 //Shutdown server (this does not restart the server!)
      22 Server.shutdown();
      23 });
      24
      25 //Start the timer (simply creating a timer does not start it automatically)
      26 timer.start();
      27}
    • getOption

      public static String getOption(String key)
      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")
      1String pvp = Server.getOption("settings_pvp_enabled");
      2if(pvp.equals("true")){
      3 System.out.println("PVP is enabled");
      4}
      5else{
      6 System.out.println("PVP is disabled");
      7}
    • getAllPermissionGroups

      public static String[] getAllPermissionGroups()
      Gets all available permission group names.
      Returns:
      a new array containing all permission group names.
    • getVersion

      public static String 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

      public static void sendInputCommand(String input)
      Sends an input command to the InputStream (System.in) of the server. This only works for the dedicated server.
      Parameters:
      input - the input command.
    • 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 use System.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 via getType())! You can't execute this method in singleplayer!
    • setDefaultSpawnPosition

      public static void setDefaultSpawnPosition(Vector3f position)
      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

      public static Vector3f getDefaultSpawnPosition()
      Gets the global default spawn position.
      Returns:
      the spawn position as a Vector3f.
    • setDefaultSpawnRotation

      public static void setDefaultSpawnRotation(Quaternion quaternion)
      Sets the default spawn rotation. Provide Quaternion.IDENTITY if 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

      public static Quaternion getDefaultSpawnRotation()
      Gets the default spawn rotation.
      Returns:
      the default spawn rotation as a Quaternion.
    • setDefaultSpawnInventory

      public static void setDefaultSpawnInventory(Inventory inventory)
      Sets the default spawn inventory (i.e the items you always spawn with).
      Parameters:
      inventory - the default spawn inventory.
    • getDefaultSpawnInventory

      public static 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)
      1Server.setGameTime(15, 30);
    • getGameTime

      public static int getGameTime(Time.Unit unit)
      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:
      1//Get current minutes (0-59)
      2int minutes = server.getGameTime(Time.Minute);
      3
      4//Get current hours (0-23)
      5int minutes = server.getGameTime(Time.Hour);
    • getGameTime

      public static Time getGameTime()
      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)
      1public class ExamplePlugin extends Plugin{
      2
      3 public static native void onEnable(){
      4 Server.setGameTimeSpeed(60);
      5 }
      6
      7 public static native void onDisable(){
      8 //...
      9 }
      10
      11}
    • 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

      public static void setWeather(WeatherDefs.Weather newWeather, boolean instant)
      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
      1//Disable weather (so it doesn't change automatically)
      2Server.setWeatherEnabled(false);
      3
      4//Change the weather to "clear" (sunny) with smooth transition
      5Server.setWeather(WeatherDefs.Clear, false);
    • getCurrentWeather

      public static WeatherDefs.Weather getCurrentWeather()
      Gets the current weather.
      Returns:
      the current weather type.
    • getNextWeather

      public static WeatherDefs.Weather 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

      public static boolean isPlayerConnected(String playername)
      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

      public static Player getPlayer(int playerid)
      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

      public static Player getPlayerByUID(String playerUID)
      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

      public static Player getPlayerByDbID(int playerDbID)
      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

      public static Player getPlayerByName(String playername)
      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

      public static String getPlayerUID(int playerDbID)
      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

      public static Player[] getAllPlayers()
      Gets a new array containing all players that are currently connected to the server.
      Returns:
      a new array containing all players.
      Example: Heal broken bones for all players
      1//Iterate through all players
      2for(Player player : Server.getAllPlayers()){
      3 //Check if player has broken bones and heal them accordingly
      4 if(player.hasBrokenBones()){
      5 player.setBrokenBones(false);
      6 }
      7}
    • isPlayerBanned

      public static boolean isPlayerBanned(String playerUID)
      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

      public static boolean isPlayerAdmin(String playerUID)
      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

      public static void banPlayer(String playerUID, String reason, int duration)
      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

      public static void unbanPlayer(String playerUID)
      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

      public static Player findNearestPlayer(Vector3f position)
      Gets the player who has the shortest distance to an arbitrary world position.
      Parameters:
      position - the world position.
      Returns:
      the nearest player, or null if no player is currently online.
    • getLastKnownPlayerName

      public static String getLastKnownPlayerName(String playerUID)
      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

      public static String getLastKnownPlayerName(int playerDbID)
      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

      public static String[] getLastKnownPlayerUIDs(String playerName)
      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

      public static void addArea(Area area)
      Adds a temporary Area to the server. Once an area is added to the server, PlayerEnterAreaEvent and PlayerLeaveAreaEvent events 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, use addArea(net.risingworld.api.objects.Area, boolean) instead!
      Parameters:
      area - the Area you want to add to the server.
      See Also:
    • addArea

      public static void addArea(Area area, boolean storeInDatabase)
      Adds an Area to the server. Once an area is added to the server, PlayerEnterAreaEvent and PlayerLeaveAreaEvent events will be triggered when a player enters/leaves an area.
      Parameters:
      area - the Area you want to add to the server.
      storeInDatabase - if true, the area will also be stored persistently in the database!
      See Also:
    • removeArea

      public static void removeArea(Area area)
      Removes an Area that has been added to the server previously. Once an area is removed, events like PlayerEnterAreaEvent or PlayerLeaveAreaEvent will no longer be triggered for this area.
      Parameters:
      area - the Area you want to remove from the server. Note: you can still re-add the area to the server at any time.
      See Also:
    • getArea

      public static Area getArea(long id)
      Gets the Area with the provided global id.
      Parameters:
      id - the id of the area.
      Returns:
      the associated area, or null if no such area was found.
    • getAllAreas

      public static Area[] getAllAreas()
      Gets an array containing all Areas that are currently registered with the server.
      Returns:
      a newly created array containing all registered areas.
      Example: Check if player is inside areas
      1//Get player position
      2Vector3f playerPosition = player.getPosition();
      3
      4//Get all areas from the server
      5Area[] areas = Server.getAllAreas();
      6
      7//Go through areas and check if player is inside
      8for (Area area : areas) {
      9 if (area.isPointInArea(playerPosition)) {
      10 System.out.println("Player is inside area " + area.getName());
      11 }
      12}
    • getCustomImage

      public static CustomImage getCustomImage(long id)
      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

      public static CustomImage[] getAllCustomImages()
      Gets an array containing all custom images (creates a new array).
      Returns:
      a new array containing all images.
    • getAllCustomImages

      public static CustomImage[] getAllCustomImages(int playerDbID)
      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 (see Player.getDbID()).
      Returns:
      a new array containing all images uploaded by a particular player.
    • broadcastTextMessage

      public static void broadcastTextMessage(String message)
      Broadcasts a text message, i.e send it to all players. This is exactly the same as calling Player.sendTextMessage(java.lang.String) for every player.
      Parameters:
      message - the message you want to broadcast.
      See Also:
    • broadcastYellMessage

      public static void broadcastYellMessage(String message, float duration, boolean pulsate)
      Broadcasts a yell message, i.e send it to all players. This is exactly the same as calling Player.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: