Klasse Player

java.lang.Object
net.risingworld.api.objects.Player

public final class Player extends Object
Represents a player. This only applies to players which are currently connected to the server.
  • Methodendetails

    • getID

      public int getID()
      Gets the current ID of this player. This ID will change the next time the player joins the server (or if the player leaves the server, another player might get this ID).
      Gibt zurück:
      the current player ID.
    • getUID

      public String getUID()
      Gets the globally unique ID of the player. This ID will never change, even if the player joins another server. For Steam users, this method returns the SteamID64.
      Gibt zurück:
      the globally unique player ID as a string. The game stores the UID as string because some platforms use strings to identify the account.
      Example: Display the UID of the player
      1//The UID is stored as a string
      2String playerUID = player.getUID();
      3
      4//Check if player uses Steam, then the UID is his SteamID64
      5if(player.isSteamVersion()){
      6 player.sendTextMessage("Your SteamID is " + playerUID);
      7}
      8//Otherwise it's his standalone UID
      9else{
      10 player.sendTextMessage("Your ID is " + playerUID);
      11}

      Example: Check if player uses Steam and get a link to his profile
      1//Check if player uses Steam
      2if(player.isSteamVersion()){
      3 //Get player UID (for Steam users, it's the SteamID64)
      4 String uid = player.getUID();
      5
      6 //This is the url to his Steam profile:
      7 String url = "http://steamcommunity.com/profiles/" + uid;
      8}
    • getDbID

      public int getDbID()
      Gets the database ID of the player. This ID is only unique on the current world. If the player joins another server (or loads another world), he will get a different database ID.
      The database ID is useful for database queries.
      Gibt zurück:
      the player database ID.
    • getName

      public String getName()
      Gets the name of the player.
      Gibt zurück:
      the player name.
    • setName

      public void setName(String name)
      Changes the name of the player.
      Parameter:
      name - the new player name.
    • getLastTimeOnline

      public long getLastTimeOnline()
      Gets a timestamp (i.e the number of milliseconds since 00:00:00 UTC on January 1, 1970) when the player was online on this server most recently.
      Gibt zurück:
      a timestamp (milliseconds).
    • getCurrentPlayTime

      public int getCurrentPlayTime()
      Gets the amount of time the player is connected to the server.
      Gibt zurück:
      the current play time.
    • getTotalPlayTime

      public int getTotalPlayTime()
      Gets the total amount of time the player has spent on this server (or more precisely, the amount of time the player has spent on this world).
      Gibt zurück:
      the total play time of this player (in seconds).
    • getLocalTimeZoneOffset

      public int getLocalTimeZoneOffset()
      Gets the local time zone offset (in seconds) of this player to GMT/UTC time.
      Gibt zurück:
      the offset in seconds of the local time zone of the player compared to GMT/UTC time.
    • getPermissionGroup

      public String getPermissionGroup()
      Gets the current permission group name of the player.
      Gibt zurück:
      the player permission group name or null if no group is set.
      Siehe auch:
    • setPermissionGroup

      public void setPermissionGroup(String groupName)
      Sets the permission group of the player.
      Parameter:
      groupName - the group name. Set to null to remove the player from any permission groups.
    • getActiveAreaPermission

      public String getActiveAreaPermission()
      Gets the name of the currently active area permission for this player (i.e the name of the area the player is currently inside). If the player is inside multiple, overlapping areas, the game uses the area permission with highest priority (see Area.getPriority()). If the player is not inside an area (or if this area has no permissions assigned), null is returned.
      Gibt zurück:
      the name of the currently active area permission for this player, or null if the player is not inside an area.
    • getPermissionValue

      public Object getPermissionValue(String key, boolean includeAreas)
      Gets a particular permission value (usually boolean, int, String) from the current player permission.
      Parameter:
      key - the name of the particular permission key.
      includeAreas - if true, the game returns the "resolved" permission value, i.e. taking any currently active area permissions into account. If false, only the permission value of the group permission is returned (this was the behaviour of the Java version).
      Gibt zurück:
      the permission value which belongs to the provided key, or null if the permission key does not exist.
      Example: Check if the general->keepinventory permission is set to true
      1Player player = Server.getPlayer("R2D2");
      2boolean keepinv = (boolean)player.getPermissionValue("general_keepinventory", false);
      3if(keepinv) System.out.println("Player keeps inventory after death");
      4else System.out.println("Player loses inventory upon death");

      Example: Check if player is currently allowed to fly
      1Player player = Server.getPlayer("DarthVader");
      2//Important: Set "includeAreas" to true to get the actual permission value
      3//(e.g if player is currently inside an area)
      4boolean canFly = (boolean)player.getPermissionValue("general_fly", true);
      5if(canFly) System.out.println("Player is allowed to fly");
      6else System.out.println("Player is not allowed to fly at the moment");
    • setPermissionValue

      public void setPermissionValue(String key, Object value)
      Overrides a permission value. This does not change the permission group of the player, but grants him individual permissions. These permissions, however, do not overwrite area permissions!

      Note that these changes are not permanent, i.e if the player reconnects or if the player gets assigned to another permission group ("setplayergroup"), these changes will be reverted.
      Parameter:
      key - the permission key.
      value - the value.
      Example: Disable fly mode, irrespective of the actual permission group
      1Player player = Server.getPlayer("C3PO");
      2player.setPermissionValue("general_fly", false);

      Example: Increase the max amount of uploadable custom images to 20
      1Player player = Server.getPlayer("Luke");
      2player.setPermissionValue("customimages_maxupload", 20);
    • isAdmin

      public boolean isAdmin()
      Gets wheter or not the player is an admin (according to the server.properties file).
      Gibt zurück:
      true if the player is an admin, false if not.
    • setAdmin

      public void setAdmin(boolean set)
      Gives admin rights to the player.
      Parameter:
      set - set true to give admin rights to the player, or false to revoke admin rights.
    • getInventory

      public Inventory getInventory()
      Gets the inventory of the player.
      Gibt zurück:
      the inventory of the player.
    • getEquippedItem

      public Item getEquippedItem()
      Gets the currently equipped item (i.e the item the player currently holds in his hands), or null if no item is equipped.
      Gibt zurück:
      the equipped item, or null if no item is equipped.
      Example: Check equipped item type
      1//Get equipped item
      2Item item = player.getEquippedItem();
      3
      4//Check if item is a construction element
      5if (item instanceof Item.ConstructionItem construction) {
      6 System.out.println(construction.getConstructionName()); //prints "block", for example
      7}
      8
      9//Check if item is an object
      10else if (item instanceof Item.ObjectItem object){
      11 System.out.println(object.getObjectName()); //prints "workbench", for example
      12}
      13
      14//Check if item is a garment
      15else if (item instanceof Item.ClothingItem clothing){
      16 System.out.println(clothing.getClothingName()); //prints "mininghelmet", for example
      17}
      18
      19//Check if item is a blueprint
      20else if (item instanceof Item.BlueprintItem blueprint){
      21 System.out.println(blueprint.getBlueprintName()); //prints "My summer house", for example
      22}
    • setEquippedItem

      public void setEquippedItem(int quickslot)
      Changes the equipped item (i.e the item the player currently holds in his hands).
      Parameter:
      quickslot - the quickslot focus (hotbar) which holds the desired item.
    • setEquippedItem

      public void setEquippedItem(int slot, Inventory.SlotType slotType)
      Changes the equipped item (i.e the item the player currently holds in his hands).
      Parameter:
      slot - the slot which holds the desired item.
      slotType - the according slot type.
    • getStatistic

      public int getStatistic(String name)
      Gets the value of a statistic (e.g distance walked, trees cut etc). Statistics are always stored as integer values.
      Parameter:
      name - the name of the statistic.
      Gibt zurück:
      the stat value as int, or -1 if the stat was not found.
      Siehe auch:
    • setStatistic

      public void setStatistic(String name, int value)
      Sets a new value for a statistic. This works for both built-in stats as well as custom stats. The statistic is stored persistently in the "Statistics.db" database.
      Parameter:
      name - the name of the statistic (you may use a custom name if you want to store your own stats).
      value - the associated value you want to store.
      Siehe auch:
    • sendTextMessage

      public void sendTextMessage(String message)
      Sends a text message to the player's chat. Rich text is supported, so you can define different font styles or colors for parts of the text. For example, you can use the <color> tag to change the color (e.g "<color=yellow>This is yellow text</color>) or <b> for bold text etc.
      Parameter:
      message - the message you want to send to the player.
      Example: Send a regular text message
      1player.sendTextMessage("Your name is " + player.getName());

      Example: Send a red text message
      1player.sendTextMessage("<color=red>This is a red text</color>");

      Example: Send a text message with hex color
      1player.sendTextMessage("<color=#FF0000>This is a red text</color>");

      Example: Send a multicolor text message
      1player.sendTextMessage("<color=red>This part is red, <color=green>This part is green, <color=blue>This part is blue");
    • sendYellMessage

      public void sendYellMessage(String message, float duration, boolean pulsate)
      Displays a message with big letters in the middle of the screen of the player for a few seconds (depending on the length of the message).
      Parameter:
      message - the message you want to display on the player's screen.
      duration - amount of seconds how long the message should stay visible. Use "5f" for 5 seconds, for example.
      pulsate - if true, the message will pulsate on the screen.
      Example:
      1player.sendYellMessage("Server will shutdown in 5 minutes", 5f, true);
    • showStatusMessage

      public void showStatusMessage(String message, int duration)
      Shows a status text message (centered, bottom of the screen). Status messages are used by the game to display certain information to the player, e.g status of object placement, food consume info etc.
      Parameter:
      message - the message you want to show.
      duration - the duration (seconds) how long the message will be displayed.
    • setOption

      public void setOption(String setting, Object value)
      Sets the graphics/audio/game settings for the client. This only works for settings which are also accessible from the options menu.
      Parameter:
      setting - the name of the setting (see config.properties file).
      value - the new value. Set null to reset this setting to default.
    • getOption

      public void getOption(String setting, Callback<String> callback)
      Gets a setting from the client (a setting from his config.properties file). The returned setting is always a string, so you have to parse it accordingly. If the setting is not set (i.e field in the config.properties file is blank), an empty string is returned. If the setting does not exist, null is returned.
      Since the data is queried from the client, you do not get the result as a return value, instead you have to use a callback to receive the result.
      Parameter:
      setting - the setting you want to query, e.g "input_interaction" or "graphic_fullscreen" etc.
      callback - the Callback object. It will be called once the data has been retrieved from the player. The result will be passed as a string argument (empty string if setting is not set, null if setting does not exist).
      Example: Check if player has the debug console enabled
      1player.getOption("Game_DebugConsole", (String result) -> {
      2 //The result is always a string, so we either have to parse it, or check the value directly
      3 if(result.equalsIgnoreCase("true")){
      4 System.out.println("Debug console is active!");
      5 }
      6});

      Example: Get player key mapping for inventory key, and use it for your own purposes (e.g inventory extension)
      1player.getOption("input_inventory", (String s) -> {
      2 //We have to convert the string to an integer key value,
      3 //fortunately the "KeyInput" class has a static helper function for that
      4 int key = KeyInput.fromString(s);
      5
      6 //Register the key for the player, so a "PlayerKeyEvent" event is
      7 //triggered when the player presses his inventory key
      8 player.registerKeys(key);
      9});
    • setAttribute

      public void setAttribute(String key, Object value)
      Stores an attribute for the player. You can store any type. Note that all attributes will be reset upon server restart!
      Parameter:
      key - the name of the attribute.
      value - the value/object you want to store. Set null to remove the attribute.
    • getAttribute

      public Object getAttribute(String key)
      Gets the value to which the specified key is mapped, or null if no attribute is stored for that key.
      Parameter:
      key - the name of the attribute.
      Gibt zurück:
      the attribute that is stored for that key, or null of the key does not exists.
      Example:
      1String job = "Farmer";
      2player.setAttribute("Job", job);
      3
      4//... somewhere else in your code ...
      5
      6if(player.hasAttribute("Job")){
      7 //Type-casting is necessary, since only an "Object" is returned
      8 String playerJob = (String) player.getAttribute("Job");
      9}
    • hasAttribute

      public boolean hasAttribute(String key)
      Gets whether or not the provided attribute exists.
      Parameter:
      key - the name of the attribute.
      Gibt zurück:
      true if the attribute exists, false if not.
    • hasAttribute

      public boolean hasAttribute(String key, Class type)
      Gets whether or not the provided attribute exists (also checks if it has a specific type).
      Parameter:
      key - the name of the attribute.
      type - the type of the attribute
      Gibt zurück:
      true if the attribute exists and if it has the desired type, false if not.
    • deleteAttribute

      public void deleteAttribute(String key)
      Removes a player attribute. Does nothing if the attribute doesn't exist.
      Parameter:
      key - the name of the attribute you want to delete.
    • getAttributes

      public Set<Map.Entry<String,Object>> getAttributes()
      Gets a set containing all keys and attributes.
      Be careful when modifying the set, because that affects the attributes.
      Gibt zurück:
      a set containing all keys and attributes.
      Example: Print all keys and their values
      1var attributes = player.getAttributes();
      2for(var entry : attributes){
      3 System.out.println("Entry " + entry.getKey() + " = " + entry.getValue());
      4}
    • getLanguage

      public String getLanguage()
      Gets the current ingame language of the player.
      Gibt zurück:
      the language as a string.
    • getSystemLanguage

      public String getSystemLanguage()
      Gets the current system language of the player.
      Gibt zurück:
      the language as a string.
    • getOperatingSystem

      public OS getOperatingSystem()
      Gets the operating system of the user.
      Gibt zurück:
      the operating system of the user.
    • getPlatform

      public Platform getPlatform()
      Gets the type of version the player is using, e.g standalone version, Steam version etc.
      Gibt zurück:
      the platform / version type
    • getPosition

      public Vector3f getPosition()
      Gets a Vector3f containing the current x, y and z coordinate of the player (world position).
      Gibt zurück:
      the player world position as a Vector3f (float).
    • getAltitude

      public float getAltitude()
      Gets the altitude (i.e y position) of the player. Same as getPosition().y
      Gibt zurück:
      the current player altitude (y position).
    • getPreviousPosition

      public Vector3f getPreviousPosition()
      Gets the previous position of the player (the player had the last frame).
      Gibt zurück:
      the old player position.
    • setPosition

      public void setPosition(Vector3f position)
      Sets the world position of the player.
      Parameter:
      position - the new world position you want to set.
      Example:
      1//Move player 100 units up in the sky
      2Vector3f playerPos = player.getPosition();
      3playerPos.addLocal(0f, 100f, 0f);
      4player.setPosition(playerPos);
    • setPosition

      public void setPosition(float x, float y, float z)
      Sets the world position of the player.
      Parameter:
      x - x world coordinate to set (horizontally).
      y - y world coordinate to set (vertically).
      z - z world coordinate to set (horizontally).
    • moveTo

      public void moveTo(Vector3f position, float speed)
      Moves the player (smoothly) to the target position.
      Parameter:
      position - the target position.
      speed - the speed (how long it should take to move the player to the target position).
    • moveTo

      public void moveTo(float x, float y, float z, float speed)
      Moves the player (smoothly) to the target position.
      Parameter:
      x - the target x coordinate.
      y - the target y coordinate.
      z - the target z coordinate.
      speed - the speed (how long it should take to move the player to the target position).
    • getChunkPosition

      public Vector3i getChunkPosition()
      Gets a Vector3i containing the x, y and z coordinates of the current chunk the player is in.
      Gibt zurück:
      the chunk offset as a Vector3i (int).
    • getBlockPosition

      public Vector3i getBlockPosition()
      Gets a Vector3i containing the current block position (x, y and z) of the player within the current chunk. X ranges from 0-15 (inclusive), Y ranges from 0-63 (inclusive), Z ranges from 0-15 (inclusive).
      Gibt zurück:
      the block position within the current chunk as a Vector3i (int).
    • setChunkAndBlockPosition

      public void setChunkAndBlockPosition(Vector3i chunkPosition, Vector3i blockPosition)
      Sets the chunk and block position of the player (resulting in the total global position).
      Parameter:
      chunkPosition - chunk offset as a Vector3i (int).
      blockPosition - block position within the chunk as a Vector3i (int).
    • setChunkAndBlockPosition

      public void setChunkAndBlockPosition(int cx, int cy, int cz, int bx, int by, int bz)
      Sets the chunk and block position of the player (resulting in the total global position).
      Parameter:
      cx - x chunk offset.
      cy - y chunk offset.
      cz - z chunk offset.
      bx - x block position within the chunk.
      by - y block position within the chunk.
      bz - z block position within the chunk.
    • getWorldPartPosition

      public Vector2i getWorldPartPosition()
      Gets a Vector2i containing the x and z coordinates of the current world part the player is in.
      Gibt zurück:
      the world part offset as a Vector2i (int).
    • getSectorPosition

      public Vector2i getSectorPosition()
      Gets a Vector2i containing the x and z coordinates of the current sector the player is in.
      Gibt zurück:
      the sector offset as a Vector2i (int).
    • getRotation

      public Quaternion getRotation()
      Gets the current player rotation.
      Gibt zurück:
      the player rotation as a Quaternion.
    • setRotation

      public void setRotation(Quaternion quaternion)
      Sets the player rotation.
      Parameter:
      quaternion - the quaternion which describes the desired rotation.
    • setRotation

      public void setRotation(float pitch, float yaw, float roll)
      Sets the player rotation from euler angles.
      Parameter:
      pitch - the rotation around the x axis (left axis).
      yaw - the rotation around the y axis (vertical/up axis), "heading".
      roll - the rotation around the z axis (forward axis)
    • getViewPosition

      public Vector3f getViewPosition()
      Gets the view position of the player, i.e the world position of the player eyes.
      Gibt zurück:
      the view/camera position as a Vector3f (float).
    • getViewDirection

      public Vector3f getViewDirection()
      Gets the current view direction of the player.
      Gibt zurück:
      the view direction as a Vector3f (float).
    • setViewDirection

      public void setViewDirection(Vector3f direction)
      Sets the view direction of the player. You can use this function to force the player to look into a certain direction.
      Parameter:
      direction - the new view direction as a Vector3f (float). Make sure to use a unit vector.
      Example: How to let the player look to a certain point in the world
      1//Just a random point
      2Vector3f targetPoint = new Vector3f(10.0f, 50.0f, 20.0f);
      3//Get player position
      4Vector3f playerPos = player.getPosition();
      5
      6//Vector math: target - startpoint = direction
      7targetPoint.subtractLocal(playerPos);
      8
      9//Convert to unit vector (normalize), important for directions
      10targetPoint.normalizeLocal();
      11
      12//"targetPoint" is the direction vector now
      13player.setViewDirection(targetPoint);
    • setViewDirection

      public void setViewDirection(float directionx, float directiony, float directionz)
      Sets the view direction of the player. You can use this function to force the player to look into a certain direction.
      Parameter:
      directionx - y component of the new view direction vector.
      directiony - y component of the new view direction vector.
      directionz - z component of the new view direction vector.
    • getHeading

      public float getHeading()
      Returns the heading/facing, i.e the player rotation around the y axis (vertical axis) in degrees. If the player looks exactly to north, 0 will be returned, if he looks to south, 180 (degrees) will be returned.
      Gibt zurück:
      the player heading/facing, i.e the rotation around the y axis.
    • getCardinalDirection

      public String getCardinalDirection()
      Returns the cardinal direction of the player. If the player faces towards north, this function returns "N", if he faces towards east, it returns "E", if he faces towards north-east, it returns "NE" etc.
      Gibt zurück:
      the cardinal direction. Returns either "N", "NE", "E", "SE", "S", "SW", "W" or "NW"
    • getCurrentArea

      public Area getCurrentArea()
      Gets the highest ranking (i.e most relevant) Area the player is currently inside. May be null.
      Gibt zurück:
      the area with the highest priority the player is currently inside, or null if the player is not inside an Area at the moment
    • getCurrentAreas

      public Area[] getCurrentAreas()
      Gets an array of all Areas the player is currently inside.
      Gibt zurück:
      a new array containing all Areas the player is inside.
      Example: Check all areas the player is currently inside
      1Area[] areas = player.getCurrentAreas();
      2for(Area area : areas){
      3 //do something with the "area"
      4}
      Siehe auch:
    • showLocationTicker

      public void showLocationTicker(String text, float duration)
      Shows a location ticker text in the lower left screen corner.
      Parameter:
      text - the text you want to show.
      duration - the duration (in seconds). -1 to show the text indefinitely (until it gets overridden).
    • shake

      public void shake(float intensity, float duration)
      Shakes the player screen, like an earthquake.
      Parameter:
      intensity - the intensity (default: 1.0f)
      duration - the duration, in seconds.
      Example: Simulate an earthquake for 10 seconds
      1//Intensity 1 (just try out some values)
      2player.shake(1.0f, 10.0f);
    • isSpawned

      public boolean isSpawned()
      Gets whether or not the player is already spawned, i.e if he's no longer in the loading screen.
      Gibt zurück:
      true if the player is fully spawned, false if he is still in the loading screen (loading the world or connecting to the server).
    • isInVehicle

      public boolean isInVehicle()
      Gets whether or not the player is currently inside a vehicle (either as driver or passenger).
      Gibt zurück:
      true if the player is in a vehicle (e.g boat, car, train etc), false if not.
    • isOnMount

      public boolean isOnMount()
      Gets whether or not the player is currently on a mount (e.g a horse, donkey or camel).
      Gibt zurück:
      true if the player is on a mount, false if not.
      Siehe auch:
    • isSprinting

      public boolean isSprinting()
      Gets whether or not the player is currently sprinting.
      Gibt zurück:
      true if the player is sprinting at the moment, false if not.
    • isWalking

      public boolean isWalking()
      Gets whether or not the player is currently walking slowly.
      Gibt zurück:
      true if the player is walking slowly, false if not.
    • isCrouching

      public boolean isCrouching()
      Gets whether or not the player is currently crouching.
      Gibt zurück:
      true if the player is crouching, false if not.
    • isSwimming

      public boolean isSwimming()
      Gets whether or not the player is currently swimming (i.e in water with no stable contact to ground).
      Gibt zurück:
      true if the player is swimming, false if not.
    • isLying

      public boolean isLying()
      Gets whether or not the player is currently lying in a bed, tent or shelter.
      Gibt zurück:
      true if the player is lying in a bed (or tent or shelter), false if not.
    • isSitting

      public boolean isSitting()
      Gets whether or not the player is currently sitting on a chair.
      Gibt zurück:
      true if the player is sitting on a chair, false if not.
    • getState

      public Player.State getState()
      Gets the current player state (determines if player is currently sitting, lying etc).
      Gibt zurück:
      the player Player.State.
    • isInWater

      public boolean isInWater()
      Gets whether or not the player is currently in water.
      Gibt zurück:
      true if the player is in water, false if not.
    • isUnderwater

      public boolean isUnderwater()
      Gets whether or not the player is currently under water.
      Gibt zurück:
      true if the player is under water, false if not.
    • isOnGround

      public boolean isOnGround()
      Gets whether or not the player is currently standing stable on the ground
      Gibt zurück:
      true if the player is standing stable on ground, false if not.
    • isIndoor

      public boolean isIndoor()
      Gets whether or not the player is inside a building.
      Gibt zurück:
      true if the player is inside a building, false if not.
    • isInCave

      public boolean isInCave()
      Gets whether or not the player is inside a cave. Note: If the player is inside a building in a cave, this function returns false.
      Gibt zurück:
      true if the player is currently inside a cave.
    • isSleeping

      public boolean isSleeping()
      Gets whether or not this player is currently sleeping.
      Gibt zurück:
      true if the player is currently sleeping, false if not.
      Example: Jump to next day if at least 50% of all players are sleeping
      1//Create the timer
      2Timer sleepCheck = new Timer(5, 5, -1, () -> {
      3 //We only proceed if the current time is between 10 p.m. (22) and 8 a.m. (8)
      4 Time time = Server.getGameTime();
      5 if(time.getHours() >= 22 || time.getHours() < 8){
      6 //Calculate the threshold (50 percent of current player count)
      7 int playerThreshold = Server.getPlayerCount() / 2;
      8
      9 //Now we iterate through all players, check if they're sleeping, and
      10 //increment a "sleeper" variable accordingly
      11 int sleeper = 0;
      12 for(Player p : Server.getAllPlayers()){
      13 if(p.isSleeping()) sleeper++;
      14 }
      15
      16 //If the amount of sleeping players is greater or equal to our
      17 //threshold, we will skip the night
      18 if(sleeper >= playerThreshold){
      19 //Set time to 8 a.m.
      20 Server.setGameTime(8, 0);
      21
      22 //Now we "force" all players to wake up by teleporting them to
      23 //their position (this automatically resets the sleeping state).
      24 //Since there is no "wake up" method, we have to use this "workaround"
      25 for(Player p : Server.getAllPlayers()){
      26 //Only teleport the player if he was sleeping
      27 if(p.isSleeping()){
      28 p.setPosition(p.getPosition());
      29 }
      30 }
      31 }
      32 }
      33});
      34
      35//Never forget to start the timer ;)
      36sleepCheck.start();
    • setCreativeModeEnabled

      public void setCreativeModeEnabled(boolean set)
      Enables or disables creative mode for this player.
      Parameter:
      set - set true to enable creative mode, false to disable it.
    • isCreativeModeEnabled

      public boolean isCreativeModeEnabled()
      Gets whether or not creative mode is currently enabled.
      Gibt zurück:
      true if creative mode is currently active, false if not.
    • getMaxHealth

      public int getMaxHealth()
      Gets the maximum health the player can have.
      Gibt zurück:
      the maximum possible player health (usually 100).
    • setMaxHealth

      public void setMaxHealth(int maxHealth)
    • getHealth

      public int getHealth()
      Gets the current health of the player.
      Gibt zurück:
      the current health of the player.
    • setHealth

      public void setHealth(int health)
      Sets the health of the player.
      Parameter:
      health - the new player health.
      Siehe auch:
    • addDamage

      public void addDamage(int damage)
      Causes damage to the player (reduces health, plays a hurt sound and the screen flashes red).
      Parameter:
      damage - the amount of damage you want to add to the player.
    • getArmor

      public int getArmor()
      Gets the current armor level of the player.
      Gibt zurück:
      the current armor level of the player. Returns 0 if the player has no protection.
    • getMaxArmor

      public int getMaxArmor()
      Gets the maximum armor level the player can have.
      Gibt zurück:
      the maximum possible armor level of the player.
    • getHunger

      public int getHunger()
      Gets the current hunger level of the player. 100 means the player is not hungry, 0 means the player is starving (i.e the player looses health).
      Gibt zurück:
      the current hunger level of the player.
      Example: Automatically reset hunger of the player if it is below a certain value
      1if (player.getHunger() < 10) {
      2 player.setHunger(100);
      3}
    • setHunger

      public void setHunger(int hunger)
      Sets the hunger level of the player. 100 means the player is not hungry, 0 means the player is starving (i.e the player looses health).
      Parameter:
      hunger - the new hunger level (0-100).
    • getThirst

      public int getThirst()
      Gets the current thirst level of the player. 100 means the player is not thirsty, 0 means the player is dying of dehydration (i.e the player looses health).
      Gibt zurück:
      the current thirst level of the player (0-100).
      Example: Automatically reset thirst of the player if it is below a certain value
      1if (player.getThirst() < 10) {
      2 player.setThirst(100);
      3}
    • setThirst

      public void setThirst(int thirst)
      Sets the thirst level of the player. 100 means the player is not thirsty, 0 means the player is dying of dehydration (i.e the player looses health).
      Parameter:
      thirst - the new thirst level.
    • hasBrokenBones

      public boolean hasBrokenBones()
      Gets whether the player has broken bones or not.
      Gibt zurück:
      true if the player has broken bones, false if not.
      Example: Heal broken bones if necessary
      1if (player.hasBrokenBones()) {
      2 player.setBrokenBones(false);
      3}
    • setBrokenBones

      public void setBrokenBones(boolean set)
      Sets the broken bone state of the player.
      Parameter:
      set - set true to break the bones of the player, or false to heal the broken bones.
    • hasHealedBones

      public boolean hasHealedBones()
      Gets whether the player has healed bones or not.
      Gibt zurück:
      true if the player has healed bones (after applying a splint), false if not.
    • isBleeding

      public boolean isBleeding()
      Gets whether the player is bleeding or not.
      Gibt zurück:
      true if the player is bleeding, false if not.
    • setBleeding

      public void setBleeding(boolean set)
      Sets the bleeding state of the player.
      Parameter:
      set - set true if the player should be bleeding, or false to stop bleeding.
    • getMaxStamina

      public int getMaxStamina()
      Gets the maximum stamina of the player.
      Gibt zurück:
      the maximum possible player stamina (usually 100).
    • setMaxStamina

      public void setMaxStamina(int maxStamina)
    • getStamina

      public int getStamina()
      Gets the player stamina. 0 means the player is fully exhausted (so the player cannot sprint anymore), 100 is the max value.
      Gibt zurück:
      the player stamina (0-100).
      Example: If player is exhausted, he cannot execute a certain command anymore
      1@EventMethod
      2public void onPlayerCommand(PlayerCommandEvent event){
      3Player player = event.getPlayer();
      4
      5 //Split the command
      6 String[] cmd = event.getCommand().split(" ");
      7
      8 //Just an example command...
      9 if(cmd[0].equals("/teleport")){
      10 //Check player stamina, if < 10, abort
      11 if(player.getStamina() < 10){
      12 player.sendTextMessage("You are too exhausted to use this command! Take a rest!");
      13 return;
      14 }
      15
      16 //Otherwise execute the command
      17 //...
      18 }
      19}
    • setStamina

      public void setStamina(int stamina)
      Sets a new stamina value for the player.
      Parameter:
      stamina - the new stamina level.
    • getBreath

      public int getBreath()
      Gets the player breath level. It's decreasing while the player is at a place where he can't breath (e.g underwater). 0 means the player suffocates, 100 is the max value.
      Gibt zurück:
      the current player breath level (0-100).
    • setBreath

      public void setBreath(int breath)
      Sets a new breath level for the player.
      Parameter:
      breath - the new breath level.
    • getWetness

      public int getWetness()
      Gets the current damp/wetness level of the player (0-100). The wetness level increases if the player is exposed to rain, for example, or if he's inside water etc. Otherwise the wetness level slowly decreases over time.
      Gibt zurück:
      the current player damp/wet level.
    • setWetness

      public void setWetness(int wetness)
      Sets the player damp/wetness level.
      Parameter:
      wetness - the new wetness value (0-100). 0 means player is not damp at all, 100 means the player is wet all over.
    • isFlying

      public boolean isFlying()
      Gets whether or not the player is currently flying (i.e flymode enabled).
      Gibt zurück:
      true if the player is currently flying, false if not.
    • setFlying

      public void setFlying(boolean set)
      Sets the flymode for the player.
      Parameter:
      set - true to enable flymode, false if not (be careful when the player is currently in mid-air :D)
    • isDead

      public boolean isDead()
      Gets whether or not the player is dead.
      Gibt zurück:
      true if the player is dead, false if not.
    • kill

      public void kill()
      Kills the player instantly.
    • respawn

      public boolean respawn(SpawnPointType spawnPoint)
      Respawns the player at a specific spawn point (0 for default server spawn, 1 for primary spawn point, 2 for secondary spawn point, 3 for tertiary spawn point.
      Parameter:
      spawnPoint - primary (1), secondary (2) or tertiary (3) spawn points (if available) or the default server spawn (0).
      Gibt zurück:
      true if the desired spawn point was available (and the player respawned successfully), or false if the player could not spawn at that point.
    • respawn

      public void respawn(Vector3f position, Quaternion rotation)
      Respawns the player at the given position.
      Parameter:
      position - the respawn position. You can get the default player spawn
      rotation - the respawn rotation. Use "null" if you want to use the default rotation.
    • getSpawnPosition

      public Vector3f getSpawnPosition(SpawnPointType spawnPoint)
      Gets the spawn position for this player (i.e where the player would respawn upon death).
      Parameter:
      spawnPoint - the spawn point type (default spawn, primary spawn, secondary spawn etc).
      Gibt zurück:
      the respawn position as a Vector3f, or null if the desired spawn point is not available.
    • getSpawnRotation

      public Quaternion getSpawnRotation(SpawnPointType spawnPoint)
      Gets the spawn rotation for this player (i.e where the player would respawn upon death).
      Parameter:
      spawnPoint - the spawn point type (default spawn, primary spawn, secondary spawn etc).
      Gibt zurück:
      the respawn rotation, or null if the desired spawn point is not available.
    • getSpawnName

      public String getSpawnName(SpawnPointType spawnPoint)
      Gets the optional spawn name for a spawn point of this player.
      Parameter:
      spawnPoint - the spawn point type (default spawn, primary spawn, secondary spawn etc).
      Gibt zurück:
      the optional name for the spawn point (if set).
    • setSpawnPoint

      public void setSpawnPoint(SpawnPointType spawnPoint, Vector3f position, Quaternion rotation, String name)
    • setSpawnPoint

      public void setSpawnPoint(SpawnPointType spawnPoint, Vector3f position, Quaternion rotation, String name, long relatedObjectID, int chunkPosX, int chunkPosY, int chunkPosZ)
    • getTemperature

      public int getTemperature()
      Gets the current player temperature (in celsius). Note that this is not exactly the body temperature, instead this temperature value slowly adapts to the environment temperature (depending on various factors, e.g clothing, weather etc).
      Gibt zurück:
      the current player temperature (in celsius).
    • setTemperature

      public void setTemperature(int temperature)
      Sets the player temperature (in celsius). Please note that the player temperature will still slowly adapt the environment temperature.
      Parameter:
      temperature - the player temperature (in celsius). Value must be between -100 and 100 (inclusive).
    • isInvisible

      public boolean isInvisible()
      Gets whether or not the player is sible (i.e if a plugin has set the player invisible).
      Gibt zurück:
      true if the player is invisible, false if not.
    • setInvisible

      public void setInvisible(boolean set)
      Sets the player invisible.
      Parameter:
      set - true to set the player invisible, false to make him visible again.
    • getIdleTime

      public int getIdleTime()
      Gets the player idle time in seconds.
      Gibt zurück:
      the player idle time in seconds.
    • getMount

      public Npc getMount()
      Gets the mount the player is currently riding on. If the player is not riding on an npc at the moment, this function returns null.
      Gibt zurück:
      the mount the player is currently riding on, or null if the player is not riding on any mounts.
      Example: Check if player is riding on a mount
      1//Get the mount (may be null)
      2Npc mount = player.getMount();
      3
      4//Check if the player is actually riding on a mount
      5if(mount != null){
      6 player.sendTextMessage("You're currently riding on a '" + npc.getName() + "' !");
      7}
      Siehe auch:
    • getVehicle

      public Vehicle getVehicle()
      If the player is currently passenger in a vehicle, this method returns the vehicle. Otherwise null is returned.
      Gibt zurück:
      the vehicle the player is currently a passenger of, or null if player is not in a vehicle.
    • setWalkSpeed

      public void setWalkSpeed(float speed)
      Sets the walk speed for the player. Default is 1.0
      Parameter:
      speed - the new walk speed factor.
    • setMoveSpeed

      public void setMoveSpeed(float speed)
      Sets the move speed for the player, i.e the default movement speed. Default is 1.0
      Parameter:
      speed - the new running speed factor.
    • setSprintSpeed

      public void setSprintSpeed(float speed)
      Sets the sprint speed for the player, i.e fast movement. Default is 1.0
      Parameter:
      speed - the new sprint speed factor.
    • setJumpSpeed

      public void setJumpSpeed(float speed)
      Sets the jump height for the player. Default is 1.0
      Parameter:
      speed - the new jump height.
    • setFlyingSpeed

      public void setFlyingSpeed(float speed)
      Changes the flying speed factor for this player. Default is 1.0
      Parameter:
      speed - the new flying speed factor.
    • setSwimmingSpeed

      public void setSwimmingSpeed(float speed)
      Changes the swimming speed factor for this player. Default is 1.0
      Parameter:
      speed - the new swimming speed factor.
    • setGravity

      public void setGravity(float gravity)
      Changes the gravity for this player. To get the global default gravity, see World.getDefaultGravity()
      Parameter:
      gravity - the new gravity you want to set for this player.
      Siehe auch:
    • getSkin

      public Skin getSkin()
      Gets a Skin object which represents the appearance of the character, i.e gender, haircut, skin color, hair color etc.
      Gibt zurück:
      a Skin object representing the visual appearance of the character. Never null.
      Example: Set red skin color for player once he connects to the server
      1@EventMethod
      2public void onPlayerConnect(PlayerConnectEvent event){
      3Player player = event.getPlayer();
      4
      5 //Retrieve the skin object of the player
      6 Skin skin = player.getSkin();
      7
      8 //Now set a red skin color (0xff0000), the skin gets updated automatically
      9 skin.setSkinColor(0xff0000);
      10}

      Example: Check gender of a player
      1//Get skin object of the player
      2Skin skin = player.getSkin();
      3
      4//Check gender
      5if(skin.getGender() == Skin.Gender.Female){
      6 //Player is female
      7}
      8else{
      9 //Player isn't female, so it's male
      10}
    • getClothes

      public Clothes getClothes()
      Gets a Clothes object which contains the clothes the character is currently wearing. The object is updated automatically when the player changes his clothes.
      Gibt zurück:
      a Clothes object representing the clothes of the character. Never null.
      Example: Remove all player clothes and spawn them as items in the world
      1//Get player clothes
      2Clothes clothes = player.getClothes();
      3
      4//Get all garments the player is wearing
      5Clothes.Garment[] garments = clothes.getAll();
      6
      7//Check if array is not null (i.e player not naked)
      8if (garments != null) {
      9 //Go through all garments
      10 for (Clothes.Garment garment : garments) {
      11 //Spawn new clothing item in the world (2 units in front of player)
      12 Vector3f pos = Utils.VectorUtils.getXYZInFrontOfPlayer(player, 2f);
      13 World.spawnClothingItem(garment.getID(), 0, 1, garment.getColor(), garment.getInfoID(), pos, Quaternion.IDENTITY, true);
      14 }
      15}
      16
      17//Remove all clothes from player
      18clothes.removeAll();
    • getPostProcessing

      public PostProcessing getPostProcessing()
      Gets an object representing post-processing overrides for this player.
      Gibt zurück:
      a PostProcessing object which allows you to override certain post-processing settings of this player.
    • setPostProcessing

      public void setPostProcessing(PostProcessing postProcessing)
      Applies a post-processing object to the player.
      Parameter:
      postProcessing - the post-processing object you want to apply to the player.
      Example: Change screen contrast and hue for 5 seconds
      1//Get default player post processing object
      2PostProcessing pp = player.getPostProcessing();
      3
      4//Override contrast and hue
      5pp.contrast.set(100);
      6pp.hue.set(-180);
      7
      8//Re-assign post processing object perform the update
      9player.setPostProcessing(pp);
      10
      11//After 5 seconds, we want to reset the values again,
      12//so the game takes control over them
      13executeDelayed(5f, () -> {
      14 pp.contrast.reset();
      15 pp.hue.reset();
      16
      17 //Assign post processing object again to perform the update
      18 player.setPostProcessing(pp);
      19});
    • showInventory

      public void showInventory()
    • hideInventory

      public void hideInventory()
    • showStorage

      public void showStorage(long storageID)
      Shows the content of a chest/storage.
      Parameter:
      storageID - the storage ID
    • hideStorage

      public void hideStorage()
      Hides the chest/storage content.
    • showChat

      public void showChat(boolean focus)
      Shows the chat. Optionally gains focus
      Parameter:
      focus - if true, the chat will also be focused, i.e the input field gets the focus. Otherwise, the chat simply shows up (just as if a new chat message came in)
    • showChat

      public void showChat(String text)
      Shows the chat, gains focus and also enters the provided text automatically to the input field.
      Parameter:
      text - the text that should be entered to the input field automatically (without sending it)
    • hideChat

      public void hideChat(float fadeDuration)
      Hides the chat
      Parameter:
      fadeDuration - fade-out duration (seconds). Set to 0 to hide the chat instantly
    • showBlueprints

      public void showBlueprints()
    • hideBlueprints

      public void hideBlueprints()
    • showCrafting

      public void showCrafting()
    • hideCrafting

      public void hideCrafting()
    • showContextMenu

      public void showContextMenu(String[] entries, Callback<String> callback)
      Shows a context menu with the given entries. Once the player selects an entry, the provided callback will be called (and the selected string will be passed as argument).
      Parameter:
      entries - the entries of the context menu, as a string array.
      callback - the callback which will be called once the player selects an entry. The selected entry is provided as parameter (never null). If the player just closes the context menu (i.e if he doesn't select anything), an empty string will be provided.
      Example:
      1//Set up the entries for the context menu
      2String[] entries = new String[]{"Spawn NPC", "Spawn Vehicle", "Spawn Item"};
      3
      4//Show the context menu and set up a callback to handle the player selection
      5player.showContextMenu(entries, (String entry) -> {
      6 //The selected entry is provided as parameter
      7 if(entry.equals(entries[0])){
      8 //entry 1 selected ("Spawn NPC")
      9 }
      10 else if(entry.equals(entries[1])){
      11 //entry 2 selected ("Spawn Vehicle")
      12 }
      13 else if(entry.equals(entries[2])){
      14 //entry 3 selected ("Spawn Item")
      15 }
      16});

      Example: Show context menu and use the mouse cursor to select an entry
      1//Set up the entries for the context menu
      2String[] entries = new String[]{"Selection 1", "Selection 2"};
      3
      4//Enable the mouse cursor
      5player.setMouseCursorVisible(true);
      6
      7//Show the context menu and set up a callback to handle the player selection
      8player.showContextMenu(entries, (String entry) -> {
      9 //Remember to disable the mouse cursor again
      10 player.setMouseCursorVisible(false);
      11});
    • stopInput

      public void stopInput(boolean stopMovement, boolean stopActions)
      Stops / aborts the current input actions. For example, if the player is currently digging with a pickaxe (by holding his left mouse button), and you call this method, the player will stop his actions. If he wants to continue to dig, he has to release his mouse button and press it again.
      Parameter:
      stopMovement - true if you want to stop movement input (e.g WASD). It causes the character to stop (if he's currently moving).
      stopActions - true if you want to stop interaction input, e.g primary and secondary mouse buttons and interaction key (F by default).
    • stopInput

      public void stopInput(Key key)
      Releases input from a particular key. This only affects keys registered via registerKeys(net.risingworld.api.utils.Key...). This doesn't stop input from that key entirely, it only forces the player to release the key and press it again to trigger a new PlayerKeyEvent. Calling this method triggers a PlayerKeyEvent immediately (with PlayerKeyEvent.isPressed() false). This method does not interfere with ingame input, i.e regular ingame controls are unaffected.
      Parameter:
      key - the key you want to force-release.
    • registerKeys

      public void registerKeys(Key... keys)
      Defines key inputs the client should forward to the server. Each key input will trigger a PlayerKeyEvent.

      Please note: This will accumulate with registered keys by other plugins: For example, if you register Key.A and another plugin registers Key.S, the PlayerKeyEvent will be triggered for both keys. In most cases, however, that should not cause any problems. If really necessary, you can use the method isKeyRegistered(net.risingworld.api.utils.Key, boolean) to find out if your plugin still has the key registered (but please bear in mind that this may have performance implications if used in the key input event).
      Parameter:
      keys - all keys the game should listen for.
      Example: Listen for W, A, S and D input
      1//Register keys W, A, S and D
      2player.registerKeys(Key.W, Key.A, Key.S, Key.D);
      3
      4//Set listening to true, otherwise the client will not forward any input
      5player.setListenForKeyInput(true);
      6
      7//...
      8
      9//Somewhere in your code: event method
      10@EventMethod
      11public void onPlayerKeyInputEvent(PlayerKeyEvent evt){
      12 System.out.println("Key " + evt.getKey() + " was " + (evt.isPressed() ? "pressed" : "released"));
      13}
      Siehe auch:
    • unregisterKeys

      public void unregisterKeys(Key... keys)
      Unregisters one or more keys, so the client no longer forwards input from these keys to the server.

      Please note that this does not remove keys which are still registered by other plugins, so the PlayerKeyEvent may still be triggered as long as another plugin keeps this key registered.
      Parameter:
      keys - the keys you want to unregister.
    • isKeyRegistered

      public boolean isKeyRegistered(Key key, boolean global)
      Checks if a particular key is registered, i.e the client listens for input. This is handled per plugin, so this method only checks if your plugin is still listening for input - unless the "global" parameter is set to true, then the method will check this for all plugins.
      Parameter:
      key - the key you want to check if it's registered.
      global - if true, the method will check if any plugin has this key registered. If false, this will only be checked for your plugin.
      Gibt zurück:
      true if the key is registered, false if not.
    • isKeyPressed

      public boolean isKeyPressed(Key key)
      Checks if a particular key is currently pressed. Note that this only works for keys which have been registered (see registerKeys(net.risingworld.api.utils.Key...)) and if the player is listening for key input.
      This method may be useful in the PlayerKeyEvent (if you want to implement key combos, e.g check if the shift key is also pressed etc).
      Parameter:
      key - the key you want to check if it's currently pressed.
      Gibt zurück:
      true if the key is pressed, false if not.
      Example: Check if player pressed shift + c
      1@EventMethod
      2public void onPlayerConnect(PlayerConnectEvent evt) {
      3 Player player = evt.getPlayer();
      4
      5 //It's necessary to register the keys (and set listen for input to true), otherwise
      6 //we neither get the PlayerKeyEvent nor can we check the isKeyPressed() state
      7 player.registerKeys(Key.C, Key.LeftShift);
      8 player.setListenForKeyInput(true);
      9}
      10
      11@EventMethod
      12public void onKeyInput(PlayerKeyEvent evt) {
      13 //The PlayerKeyEvent is triggered for every get that gets pressed/released,
      14 //so we just check it for key C
      15 if(evt.getKey() == Key.C && evt.getPlayer().isKeyPressed(Key.LeftShift)) {
      16 //Do something
      17 }
      18}
    • getRegisteredKeys

      public Key[] getRegisteredKeys(boolean global)
      Gets all keys that are registered by this plugin. If tue "global" parameter is set to true, this returns a list containing all keys registered by any plugins.
      Parameter:
      global - if true, the method will return all registered keys by any plugin, else it just returns the key registered by this plugin.
      Gibt zurück:
      an array (which will be created upon call) containing all keys, or null if no keys are registered.
    • setListenForKeyInput

      public void setListenForKeyInput(boolean set)
      Sets if the client should forward his key input to the server or not.

      Please note: This is handled per plugin, so if another plugin still enabled key input, the client will continue forwarding input to the server and the event will also be triggered.
      Parameter:
      set - true to forward the key inputs, false if not.
      Siehe auch:
    • isListeningForKeyInput

      public boolean isListeningForKeyInput(boolean global)
      Determines if this plugin is listening for key input.
      Parameter:
      global - if true, this method checks if any plugin is listening for key input, else this is only checked for this plugin.
      Gibt zurück:
      true if input will be forwarded to the server, false if not.
    • setListenForMouseInput

      public void setListenForMouseInput(boolean set)
      Sets if the client should forward his mouse button input to the server or not.

      Please note: This is handled per plugin, so if another plugin still enabled mouse button input, the client will continue forwarding input to the server and the event will also be triggered.
      Parameter:
      set - true to forward the mouse button inputs, false if not.
      Siehe auch:
    • isListeningForMouseInput

      public boolean isListeningForMouseInput(boolean global)
      Determines if this plugin is listening for mouse button input.
      Parameter:
      global - if true, this method checks if any plugin is listening for mouse input, else this is only checked for this plugin.
      Gibt zurück:
      true if mouse button input will be forwarded to the server, false if not.
      Siehe auch:
    • disableClientsideKeys

      public void disableClientsideKeys(Key... keys)
      Disables certain game keys for the client. That means that the game will no longer process regular input of these keys (e.g if you disable the inventory key, the player won't be able to open his inventory anymore etc). This does not affect text input like chat or console. If you want to re-enable the keys again, you can call enableClientsideKeys().

      Important: This does not interfere with keys registered by plugins (see registerKeys(net.risingworld.api.utils.Key...), so you will still receive the according input event (the keys just won't be processed any further by the client).
      Parameter:
      keys - the keys you want to disable from being processed by the client.
      Example: Disable keys W, A, S, D
      1//Note: After disabling the keys, these inputs won't be processed by the
      2//client anymore. For example, if the client uses W, A, S, D as his movement
      3//keys, he won't be able to move his character anymore
      4player.disableClientsideKeys(Key.W, Key.A, Key.S, Key.D);
      Siehe auch:
    • enableClientsideKeys

      public void enableClientsideKeys()
      Re-enables all keys which have been disabled by this plugin by calling disableClientsideKeys(net.risingworld.api.utils.Key...).

      Important: This method has nothing to do with registerKeys(net.risingworld.api.utils.Key...) or setListenForKeyInput(boolean)
    • enableClientsideKeys

      public void enableClientsideKeys(Key... keys)
      Re-enables certain keys which have been disabled by calling disableClientsideKeys(net.risingworld.api.utils.Key...). If you want to enable all keys again, call enableClientsideKeys() instead.

      Important: This method has nothing to do with registerKeys(net.risingworld.api.utils.Key...) or setListenForKeyInput(boolean)
      Parameter:
      keys - the keys you want to enable again.
      Siehe auch:
    • setMouseCursorVisible

      public void setMouseCursorVisible(boolean set)
      Toggles the visibility of the mouse cursor. Useful if any custom gui interactions are needed.
      If the cursor is set to visible, the player is unable to move anymore. You have to hide the cursor explicitly in order to unfreeze the player (in other words, the player has no chance to hide the cursor by himself).
      Parameter:
      set - true to show the mouse cursor, false to hide it.
    • setMouseCursorCoordinates

      public void setMouseCursorCoordinates(float x, float y, boolean relative)
      Moves the mouse cursor of the client to the specified xy coordinates.
      Note: This even works when the cursor isn't visible (so the cursor position will still be updated in the background).
      Parameter:
      x - the x target coordinate
      y - the y target coordinate
      relative - if set to true, relative target coordinates (0.0-1.0) will be used, otherwise the target coordinates will be treated as absolute coordinates.
    • executeCommand

      public void executeCommand(String command)
      Executes a console command for this player. The ingame console can be opened by pressing ` or ~ or # or ^ (depending on the keyboard layout).
      If a preceding slash '/' is added, the command will be treated like an API command instead - this means a PlayerCommandEvent will be invoked for all event listeners across all plugins.

      Note that this function does not override any permissions, this means if the player is not allowed to execute a certain command, you cannot execute it with this function either (first you have to change the permissions in this case).
      Parameter:
      command - the command you want to execute. It's exactly the same as if the player typed this command into his console (he even get a response in the console).
      Example: Toggle hud for a player
      1Player player = Server.getPlayer("Steve");
      2player.executeCommand("hud");

      Example: Send command from player (invoke PlayerCommandEvent) to all plugins)
      1Player player = Server.getPlayer("Steve");
      2player.executeCommand("/pnb");
    • isConnected

      public boolean isConnected()
      Gets whether or not the player is (still) connected.
      Gibt zurück:
      true if the player is connected to the server, false if not.
    • getPing

      public int getPing()
      Gets the current ping of the player, in other words, the amount of time (in milliseconds) that passes until a player packet arrives at the server. Only relevant in multiplayer.
      Gibt zurück:
      the current ping (ms) of the player.
    • getIP

      public String getIP()
      Gets the ip of the player (only relevant in multiplayer). When playing via Steam P2P, this function returns the SteamID64 of the player (e.g "76561197970685866").
      Gibt zurück:
      a string containing the ip address of the player (or the SteamID64 when playing via Steam P2P, or an empty string when playing singleplayer).
    • kick

      public void kick(String reason)
      Kicks the player from the server. The provided reason is displayed on the screen of the kicked player.
      Parameter:
      reason - a string containing the reason why the player was kicked.
    • ban

      public void ban(String reason)
      Bans the player permanently from the server. The provided reason is displayed on the screen of the banned player.
      Parameter:
      reason - a string containing the reason why the player was banned.
    • ban

      public void ban(String reason, int duration)
      Bans the player from the server for a given amount of time. The provided reason is displayed on the screen of the banned player.
      Parameter:
      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.
      Example: Ban a player for 3 days (a day has 60 * 60 * 24 seconds)
      1player.ban("Griefing and flaming", 60 * 60 * 24 * 3); //Instead you could also set 259200 directly
    • enableAreaSelectionTool

      public void enableAreaSelectionTool()
      Enables the "area selection tool" for this player. This enables the player to select an area. To stop the "area selection tool", you can call disableAreaSelectionTool(). If you want to retrieve the selection result (i.e the selected area), you can call getAreaSelectionData(net.risingworld.api.callbacks.Callback) and provide a proper Callback object.
      Example

      Example: Enable area selection tool for a player when he types a command
      1@EventMethod
      2public void onCommand(PlayerCommandEvent event){
      3 //split the command
      4 String[] cmd = event.getCommand().split(" ");
      5
      6 //now check if the command starts with "/select", for example
      7 if(cmd[0].equals("/select")){
      8 //enable selection tool for player
      9 event.getPlayer().enableAreaSelectionTool();
      10 }
      11}
      Siehe auch:
    • setAreaSelectionData

      public void setAreaSelectionData(Area area)
      Sets an area for the "area selection tool" for this player, i.e the selection tool will adapt to the position and size of the provided area.
      This only works if the area selection tool is currently active (to enable it, call enableAreaSelectionTool())
      Parameter:
      area - the area you want to adapt the selected area to. Provide null to reset the selected area (this means the player has to set a new start and end position).
    • getAreaSelectionData

      public void getAreaSelectionData(Callback<Area> callback)
      Gets the currently selected area. This only returns a proper Area if the "area selection tool" is currently enabled and if a start and end position is selected. Otherwise, null is returned.
      Since all data needs to be queried from the client, this method uses a Callback.
      Parameter:
      callback - the Callback object. It will be called once the Area object has been retrieved from the player. The particular Area will be passed as argument (or null if no area was selected).
      Example: Retrieve the selected area. Using lambda expression (Java 8))
      1player.getAreaSelectionData((Area result) -> {
      2 //if result is null, player did not select an area
      3 if(result == null){
      4 System.out.println("No area received from player! :( ");
      5 }
      6 //otherwise you can access the "Area" object
      7 else{
      8 System.out.println("Area received: "+result); //prints the area data
      9 }
      10});

      Example: Same example as above, but without using lambda expression (instead pass "old style" anonymous class)
      1player.getAreaSelectionData(new Callback<Area>(){
      2 @Override
      3 public void onCall(Area result){
      4 //if result is null, player did not select an area
      5 if(result == null){
      6 System.out.println("No area received from player!");
      7 }
      8 //otherwise you can access the "Area" object
      9 else{
      10 System.out.println("Area received: "+result);
      11 }
      12 }
      13});
      Siehe auch:
    • disableAreaSelectionTool

      public void disableAreaSelectionTool()
      Disables the "area selection tool" for this player. Does nothing if the "area selection tool" is currently not active.
      Remember to get the currently selected Area by calling getAreaSelectionData(net.risingworld.api.callbacks.Callback) first, otherwise the selected area will be discarded.
      Siehe auch:
    • raycast

      public void raycast(int layerMask, Callback<RaycastResult> callback)
      Performs a raycast from the player view position to the player view direction. The game checks the nearest collision (e.g terrain, constructions etc, this can be specified with the layer bitmask).

      Since all data needs to be queried from the client, this method uses a Callback
      Parameter:
      layerMask - the collision layer bitmask. This value specifies which colliders should be taken into account when performing the raycast. See Layer.getBitmask(int...)
      callback - the Callback object. It will be called once the RaycastResult object has been retrieved from the player. The particular RaycastResult will be passed as argument (or null if no collision was found, for example when the player looks towards the sky etc).
      Example: Find out if player looks at another player
      1player.raycast(Layer.getBitmask(Layer.REMOTEPLAYER), (RaycastResult result) -> {
      2 //If result is null, no collision was found
      3 if (result != null) {
      4 //Check the distance of the collision
      5 if (result.getDistance() < 10) {
      6 //If dist < 10 units show message
      7 p.sendYellMessage("Do not look at other players!");
      8 }
      9 }
      10});

      Example: Find collision point (on terrain, constructions or objects)
      1//Get collision bitmask: terrain, constructions and objects
      2int layerMask = Layer.getBitmask(Layer.TERRAIN, Layer.CONSTRUCTIONS, Layer.TRANSPARENT_CONSTRUCTIONS, Layer.OBJECTS);
      3
      4//Perform raycast
      5player.raycast(layerMask, (RaycastResult result) -> {
      6 //If result is null, no collision was found
      7 if (result != null) {
      8 //Get the "contact point" (i.e the position where the collision occurred)
      9 Vector3f contact = result.getCollisionPoint();
      10
      11 //Now do something with this information, e.g create a model there, teleport the player etc.
      12 player.sendTextMessage("Contact at " + contact);
      13 }
      14});
      Siehe auch:
    • raycast

      public void raycast(float distance, int layerMask, boolean includeTriggers, Callback<RaycastResult> callback)
      Performs a raycast from the player view position to the player view direction. The game checks the nearest collision (e.g terrain, constructions etc, this can be specified with the layer bitmask).

      Since all data needs to be queried from the client, this method uses a Callback
      Parameter:
      distance - the max distance you want to perform the raycast.
      layerMask - the collision layer bitmask. This value specifies which colliders should be taken into account when performing the raycast. See Layer.getBitmask(int...)
      includeTriggers - if true, trigger colliders ("ghost colliders") will also be taken into account, else the raycast will ignore them (default: false).
      callback - the Callback object. It will be called once the RaycastResult object has been retrieved from the player. The particular RaycastResult will be passed as argument (or null if no collision was found, for example when the player looks towards the sky etc).
      Siehe auch:
    • raycast

      public void raycast(Vector3f direction, float distance, int layerMask, boolean includeTriggers, Callback<RaycastResult> callback)
      Performs a raycast from the player view position to the provided direction. The game checks the nearest collision (e.g terrain, constructions etc, this can be specified with a bitmask).

      Since all data needs to be queried from the client, this method uses a Callback.

      Please keep in mind that raycasting can have a noticeable impact on the client performance (framerate), so use it with caution!
      Parameter:
      direction - the direction of the ray. If you want to use the player view direction, you can use raycast(float, int, boolean, net.risingworld.api.callbacks.Callback) instead.
      distance - the max distance you want to perform the raycast.
      layerMask - the collision layer bitmask. This value specifies which colliders should be taken into account when performing the raycast. See Layer.getBitmask(int...)
      includeTriggers - if true, trigger colliders ("ghost colliders") will also be taken into account, else the raycast will ignore them (default: false).
      callback - the Callback object. It will be called once the RaycastResult object has been retrieved from the player. The particular RaycastResult will be passed as argument (or null if no collision was found).
      Siehe auch:
    • raycastFromScreenPosition

      public void raycastFromScreenPosition(float x, float y, boolean relative, float distance, int layerMask, boolean includeTriggers, Callback<RaycastResult> callback)
      Performs a raycast from the screen xy position. In other words, the game checks the nearest collision at the given screen position (e.g terrain, constructions etc, this can be specified with a bitmask).

      Since all data needs to be queried from the client, this method uses a Callback
      Parameter:
      x - the horizontal screen position (x).
      y - the vertical screen position (y).
      relative - set to false to use absolute screen coordinates (i.e pixel coordinates), or true to use relative screen coordinates (range between 0.0 and 1.0)
      distance - the max distance you want to perform the raycast.
      layerMask - the collision layer bitmask. This value specifies which colliders should be taken into account when performing the raycast. See Layer.getBitmask(int...)
      includeTriggers - if true, trigger colliders ("ghost colliders") will also be taken into account, else the raycast will ignore them (default: false).
      callback - the Callback object. It will be called once the RaycastResult object has been retrieved from the player. The particular RaycastResult will be passed as argument (or null if no collision was found, for example when the player looks towards the sky etc).
    • raycastFromWorldPosition

      public void raycastFromWorldPosition(Vector3f position, Vector3f direction, float distance, int layerMask, boolean includeTriggers, Callback<RaycastResult> callback)
      Performs a raycast from a world position. The game checks the nearest collision (e.g terrain, constructions etc, this can be specified with a bitmask). The raycast is executed by the client (the player), so it can only take the world that's currently rendered into account (i.e you can only perfom this raycast in the proximity of the player, depending on his view settings).

      Since all data needs to be queried from the client, this method uses a Callback.

      Please keep in mind that raycasting can have a noticeable impact on the client performance (framerate), so use it with caution!
      Parameter:
      position - the origin of the ray, i.e where the world position you want to start the ray from.
      direction - the direction of the ray.
      distance - the max distance you want to perform the raycast.
      layerMask - the collision layer bitmask. This value specifies which colliders should be taken into account when performing the raycast. See Layer.getBitmask(int...)
      includeTriggers - if true, trigger colliders ("ghost colliders") will also be taken into account, else the raycast will ignore them.
      callback - the Callback object. It will be called once the RaycastResult object has been retrieved from the player. The particular RaycastResult will be passed as argument (or null if no collision was found, e.g if the player looks towards the sky etc).
    • getAreaInLineOfSight

      public void getAreaInLineOfSight(float distance, Callback<Area> callback)
      Gets the area in line-of-sight of the player (i.e the area the player is currently looking at). This is a convenience method which performs a raycast under the hood.
      Parameter:
      distance - the max allowed distance, i.e only elements within this range will be detected.
      callback - the callback that will be invoked once the result is available. It contains the area the player is currently looking at (within the distance), or null if no area was found.
    • getNpcInLineOfSight

      public void getNpcInLineOfSight(float distance, Callback<Npc> callback)
      Gets the npc in line-of-sight of the player (i.e the npc the player is currently looking at). This is a convenience method which performs a raycast under the hood.
      Parameter:
      distance - the max allowed distance, i.e only elements within this range will be detected.
      callback - the callback that will be invoked once the result is available. It contains the npc the player is currently looking at (within the distance), or null if no npc was found.
      Example: Set a name for the npc that is in front of player
      1//Get npc within 10 blocks in front of player
      2player.getNpcInLineOfSight(10, (npc) -> {
      3 //Npc could be null, so check that
      4 if (npc != null) {
      5 npc.setName("Mr. NPC");
      6 }
      7});
    • getObjectElementInLineOfSight

      public void getObjectElementInLineOfSight(float distance, Callback<ObjectElement> callback)
      Gets the object element in line-of-sight of the player (i.e the object element the player is currently looking at). This is a convenience method which performs a raycast under the hood.
      Parameter:
      distance - the max allowed distance, i.e only elements within this range will be detected.
      callback - the callback that will be invoked once the result is available. It contains the object element the player is currently looking at (within the distance), or null if no object was found.
      Example: Open door in front of player
      1//Get object within 5 blocks in front of player
      2player.getObjectElementInLineOfSight(5, (o) -> {
      3 //Check if object is not null
      4 if (o != null) {
      5 //Get object definition
      6 Objects.ObjectDefinition objectDef = o.getDefinition();
      7
      8 //Check if object is a door (determined by Type)
      9 if (objectDef.type == Objects.Type.Door) {
      10 //Open door (set status to max status from def)
      11 o.setStatus(objectDef.maxstatus);
      12 }
      13 }
      14});
    • addUIElement

      public void addUIElement(UIElement element)
      Attaches a UI element to the player's HUD.

      Note: It's not recommendable to call this method multiple times per player and element (e.g if you want to update the UI element). If you want to sync Style changes, call UIElement.updateStyle() instead, which is a lot faster. Other UI element changes are synced automatically.
      Parameter:
      element - the UI element you want to attach to this player's screen.
    • addUIElement

      public void addUIElement(UIElement element, UITarget target)
      Attaches a UI element to the player's screen (to a specific target, e.g HUD, inventory etc).

      Note: It's not recommendable to call this method multiple times per player and element (e.g if you want to update the UI element). If you want to sync Style changes, call UIElement.updateStyle() instead, which is a lot faster. Other UI element changes are synced automatically.
      Parameter:
      element - the UI element you want to attach to this player's screen.
      target - the UI target where the element should be attached to (default: UITarget.HUD)
    • removeUIElement

      public void removeUIElement(UIElement element)
      Removes a UI element from the player's screen. If the specified UI element is is not attached to the screen, nothing happens.
      Parameter:
      element - the UI element you want to remove from this player's screen.
    • getAllUIElements

      public UIElement[] getAllUIElements(boolean includeFromOtherPlugins)
      Gets all UI elements which were added to the player's screen. If no UI elements had been added to the player, null is returned.
      Parameter:
      includeFromOtherPlugins - if true, this method will include all UI elements which had been added to the player's screen, also including UI elements created by another plugin. If false, only UI elements created by this plugin will be included.
      Gibt zurück:
      a new array containing all UI elements (added by this plugin or another plugin), or null if no UI elements were added to the player.
      Example: Remove all UI elements which were added by our plugin
      1//Get all elements registered by our plugin (parameter false)
      2UIElement[] elements = player.getAllUIElements(false);
      3
      4//Check if array is not null
      5if (elements != null) {
      6 for (UIElement element : elements) {
      7 player.removeUIElement(element);
      8 }
      9}
    • getScreenResolutionX

      public int getScreenResolutionX()
      Gets the current screen width (horizontal resolution) the player set for his game.
      Gibt zurück:
      the screen width (e.g 1920 in case of FullHD)
    • getScreenResolutionY

      public int getScreenResolutionY()
      Gets the current screen height (vertical resolution) the player set for his game.
      Gibt zurück:
      the screen height (e.g 1080 in case of FullHD)
    • showMessageBox

      public void showMessageBox(MessageBoxButtons buttons, String title, String message, int timeout, Callback<Integer> callback)
      Shows a default message box to the player. When the player hits a button, the Callback will be invoked.
      Parameter:
      buttons - the message box type (determines which buttons should be visible).
      title - the title/headline of the message box.
      message - the message box text/body.
      timeout - optional timeout (seconds) when the message box should close automatically. Set to -1 for no timeout.
      callback - optional callback that will be invoked when the player hits a button. The selected button will be provided as int parameter (0 == ok/yes/accept, 1 == no/decline, 2 == cancel/timeout)
    • showInputMessageBox

      public void showInputMessageBox(String title, String message, String text, Callback<String> callback)
      Shows a text input message box to the player. When the player hits a button, the Callback will be invoked (and the String that was entered into the input field will be passed as parameter).
      Parameter:
      title - the title/headline of the message box.
      message - the message box text/body.
      text - an optional filler text for the input field (provide null for an empty field).
      callback - callback that will be invoked when the player hits a button. The entered input text will be passed as String parameter (or null if input was canceled).
    • showSuccessMessageBox

      public void showSuccessMessageBox(String title, String message)
      Shows a simple success message box to the player. It only has a single "Ok" button.
      Parameter:
      title - the title/headline of the message box.
      message - the message you want to show to the player.
    • showInfoMessageBox

      public void showInfoMessageBox(String title, String message)
      Shows a simple info message box to the player. It only has a single "Ok" button.
      Parameter:
      title - the title/headline of the message box.
      message - the message you want to show to the player.
    • showWarningMessageBox

      public void showWarningMessageBox(String title, String message)
      Shows a simple warning message box to the player. It only has a single "Ok" button.
      Parameter:
      title - the title/headline of the message box.
      message - the message you want to show to the player.
    • showErrorMessageBox

      public void showErrorMessageBox(String title, String message)
      Shows a simple error message box to the player. It only has a single "Ok" button.
      Parameter:
      title - the title/headline of the message box.
      message - the message you want to show to the player.
    • showColorPicker

      public void showColorPicker(String title, int initialColor, Callback<Integer> callback)
      Shows a color picker dialog to the player. This enables the player to select an individual RGB or HSL color.
      Parameter:
      title - the title/headline of the color picker dialog.
      initialColor - the color that is initially set, as int rgb value.
      callback - callback that will be invoked when the player hits a button. The selected color will be passed as int parameter (or null if dialog was canceled).
    • showFontDialog

      public void showFontDialog(String title, Font selectedFont, Callback<Font> callback)
      Shows a font selection dialog to the player. This enables the player to select a font (the same font selection that's used by the game for the sign editor, for example).
      Parameter:
      title - the title/headline of the font selection dialog.
      selectedFont - the font that will be pre-selected.
      callback - callback that will be invoked when the player hits a button. The selected font will be passed as parameter (or null if dialog was canceled).
    • showRadialMenu

      public void showRadialMenu(TextureAsset[] icons, String[] descriptions, String[] overrideTexts, boolean closeOnSelect, Callback<Integer> callback)
      Shows a "radial menu" or "pie menu" to the player. The menu may contain up to 13 entries. The selected entry is sent back to the API callback.
      Parameter:
      icons - an array containing icons for the individual entries. Make sure the array has the same dimension as the "descriptions" array.
      descriptions - an array containing the labels for the individual entries. Make sure the array has the same dimension as the "icons" array.
      overrideTexts - optional array to override the text that is shown for a selected entry. Set null if you just want to use the texts from the "descriptions" array. If you provide an array, make sure it has the same dimension as the "description" and "icon" array.
      closeOnSelect - if true, the radial menu closes automatically when the player selects an entry. Otherwise you have to close it manually by calling hideRadialMenu(boolean)
      callback - a callback that will be invoked once the player has selected an entry. The selected entry index is passed as parameter (e.g 0 for the first entry, 1 for the second entry etc). If nothing was selected (i.e the player just closed the radial menu), the value is -1
    • hideRadialMenu

      public void hideRadialMenu(boolean immediately)
      Hides any currently active radial menus.
      Parameter:
      immediately - true to hide the radial menu immediately, otherwise it fades out (default behaviour).
    • addGameObject

      public void addGameObject(GameObject gameObject)
      Adds the provided GameObject to the player's world.

      Note: It's not recommendable to call this method multiple times per player and object - just call this method once to register a game object with the player. Changes to the game object are then synced with all linked players automatically.
      Parameter:
      gameObject - The GameObject you want to add to the player's world.
    • removeGameObject

      public void removeGameObject(GameObject gameObject)
      Removes a GameObject from the player's world. If the specified element does not exist in the player's world, nothing happens.
      Parameter:
      gameObject - the GameObject you want to remove.
    • getAllGameObjects

      public GameObject[] getAllGameObjects(boolean includeFromOtherPlugins)
      Gets all GameObjects which were added to the player's world. If no game object had been added to the player, null is returned.
      Parameter:
      includeFromOtherPlugins - if true, this method will include all game objects which had been added to the player, also including game objects created by another plugin. If false, only game objects created by this plugin will be included.
      Gibt zurück:
      a new array containing all game objects, or null if no game objects were added to the player.
    • playSound

      public Sound playSound(SoundAsset sound)
      Plays a custom 2D sound (i.e it can be heard everywhere, but only by this player). This sound only plays once with default volume and pitch (1.0)
      Note: Make sure you use a mono sound when playing it as a 2D sound.
      Parameter:
      sound - the SoundAsset object which refers to the custom sound file.
      Gibt zurück:
      an internal ID of this new sound instance. This may be relevant when playing a loop sound, then you can stop the sound by providing this ID.
    • playSound

      public Sound playSound(SoundAsset sound, Vector3f position)
      Plays a custom 3D sound at the given position. This sound can only be heard by this player. This sound only plays once with default volume and pitch (1.0)
      Parameter:
      sound - the SoundAsset object which refers to the custom sound file.
      position - the world position of the sound. Provide null if you want to play this sound as a 2D sound instead (this means the sound has no actual position and can be heard everywhere).
      Gibt zurück:
      an internal ID of this new sound instance. This may be relevant when playing a loop sound, then you can stop the sound by providing this ID.
    • playSound

      public Sound playSound(SoundAsset sound, boolean loop, float volume, float pitch, Vector3f position)
      Plays a custom 3D sound at the given position. This sound can only be heard by this player.
      Parameter:
      sound - the SoundAsset object which refers to the custom sound file.
      loop - determines if this sound should play as a loop (i.e it repeats indefinitely). If true, the sound will only stop when calling stopSound(int).
      volume - the sound volume (default: 1.0)
      pitch - the sound pitch (default: 1.0)
      position - the world position of the sound. Provide null if you want to play a 2D sound instead (this means the sound has no actual position and can be heard everywhere).
      Gibt zurück:
      an internal ID of this new sound instance. This may be relevant when playing a loop sound, then you can stop the sound by providing this ID.
    • playSound

      public Sound playSound(SoundAsset sound, boolean loop, float volume, float pitch, float minDistance, float maxDistance, Vector3f position)
      Plays a custom 3D sound at the given position. This sound can only be heard by this player.
      Parameter:
      sound - the SoundAsset object which refers to the custom sound file.
      loop - determines if this sound should play as a loop (i.e it repeats indefinitely). If true, the sound will only stop when calling stopSound(int).
      volume - the sound volume (default: 1.0)
      pitch - the sound pitch (default: 1.0)
      minDistance - the distance that the sound emitter will cease to continue growing louder at (the further you move to the center of the sound). Within the minimum distance, the sound stays at the constant loudest possible volume (default: 1.0)
      maxDistance - the distance the sound becomes silent. The sound volume is interpolated between minDistance and maxDistance (default: 50.0). Sound uses a linear-square-rolloff (minDistance == full volume, maxDistance == silence).
      position - the world position of the sound. Provide null if you want to play a 2D sound instead (this means the sound has no actual position and can be heard everywhere).
      Gibt zurück:
      an internal ID of this new sound instance. This may be relevant when playing a loop sound, then you can stop the sound by providing this ID.
      Example: Play a loop sound for a wind mill
      1//Load the "windmill.ogg" sound from the assets folder in the plugin directory
      2SoundAsset info = SoundAsset.loadFromFile(getPath() + "/assets/windmill.ogg");
      3
      4//Get the player we want to play the sound for
      5Player player = Server.getPlayer("Testplayer");
      6
      7//Play the sound as loop at a given position, with default volume (1f) and pitch (1f)
      8player.playSound(info, true, 1f, 1f, 10f, 100f, new Vector3f(250f, 75f, -42f));
    • stopSound

      public void stopSound(Sound sound)
    • stopSound

      public void stopSound(int id)
    • enableGameMusic

      public void enableGameMusic()
      Enables the ingame music. This only has an effect if disableGameMusic() has been called previously.
    • disableGameMusic

      public void disableGameMusic()
      Disables the ingame music. This stops the currently playing (if any) music track and prevents the game from playing another music track until enableGameMusic() was called. This does not affect the main theme (which can be heared only in main menu and during the loading screen).
      Example: Disable default game music and play custom music track every 10 minutes instead
      1Note: This is a basic example! It would be more exciting if you load several music tracks, store them in a list,
      2and pick a random one when the timer triggers]
      3//Create a new sound asset which refers to the sound track.
      4//Also enable streaming - this is highly recommended for big sound files like music
      5SoundAsset soundInfo = SoundAsset.loadFromFile(getPath() + "/music/myTheme.mp3", true);
      6
      7//... somewhere in your event listener ...
      8
      9
      10//We grab the PlayerSpawnEvent, which is called when the player is fully
      11//connected to the server
      12@ EventMethod
      13public void onPlayerSpawn(PlayerSpawnEvent evt){
      14 Player player = evt.getPlayer();
      15
      16 //Disable the default game music for the player
      17 player.disableGameMusic();
      18
      19 //Create a timer which plays the music every 10 minutes, with initial delay of 1 minute.
      20 //Note: Since we want to access the timer reference from within the task (the Runnable),
      21 //we first have to set a null task, then assign the Runnable in an additional step
      22 //(otherwise you will run into a "variable might not have been initialized" error)
      23 final Timer timer = new Timer(600, 60, -1, null);
      24 timer.setTask(() -> {
      25 //If player is connected, we play the custom music track for him (provide "null" as position in order to play it as 2D sound)
      26 if(player.isConnected()){
      27 player.playSound(soundInfo, false, 1.0f, 1.0f, 10f, 100f, null);
      28 }
      29 //...otherwise, if the player isn't connected anymore, we kill this timer
      30 else{
      31 timer.kill();
      32 }
      33 });
      34
      35 //Remember to start the timer
      36 timer.start();
      37}
    • connectToOtherServer

      public void connectToOtherServer(String target, String password, Callback<Boolean> callback)
      Connects the client to another multiplayer server. Asks the client if he accepts the redirection, then the provided callback will be invoked (with a boolean parameter indicating whether or not the client accepted). NOTE: This will disconnect the player from the server (like a regular disconnect), the only difference is that the player will immediately try to connect to the other server.
      Parameter:
      target - the target ip address (and optional port)
      password - optional password (if the target server is password-protected). Set null to not provide a password
      callback - callback which will be invoked once the player accepted or declined the redirection
    • connectToTeamSpeak

      public void connectToTeamSpeak(String ip, int port, String channel)
      Connects the client to a TeamSpeak server, but only as long as TeamSpeak is installed on the client computer, and only if the client accepts to connect.

      Please note: This does only work if the client uses Windows!
      Parameter:
      ip - the target ip address of the TeamSpeak server.
      port - the target port of the TeamSpeak server.
      channel - the target channel the client should join on connect. To join a subchannel, you have to use a slash (e.g "channel/subchannel").
      Example:
      1//Connect to IP 127.0.0.1, port 9987, channel "EntranceHall"
      2player.connectToTeamSpeak("127.0.0.1", 9987, "EntranceHall");
    • connectToDiscord

      public void connectToDiscord(String url)
      Connects the client to a Discord server, or more precisely, it opens the url to the Discord server in the web browser.
      Parameter:
      url - the url to the Discord server, for example "https://discord.gg/ay21koSP" or "https://discordapp.com/invite/example" etc.
      Example:
      1player.connectToDiscord("https://discord.gg/abcdef123");
    • createScreenshot

      public void createScreenshot(float sizeFactor, float quality, boolean includeUI, Callback<BufferedImage> callback)
      Creates a screenshot of the player screen and converts it into a BufferedImage.
      Parameter:
      sizeFactor - the size factor of the image (1.0f is original width/height, 0.5f is half widht/height etc).
      quality - the quality of the image (0-1).
      includeUI - if true, the UI (HUD, active menus etc) will be visible on the screenshot.
      callback - this callback will be called once the screenshot has been uploaded to the server. The screenshot is passed as BufferedImage object. Uploading the screenshot may take a few seconds depending on the bandwidth, traffic and screenshot size.
    • createScreenshot

      public void createScreenshot(int width, int height, float quality, boolean includeUI, Callback<BufferedImage> callback)
      Creates a screenshot of the player screen with the desired resolution and converts it into a BufferedImage.
      Parameter:
      width - the width of the screenshot.
      height - the height of the screenshot.
      quality - the quality of the image (0-1).
      includeUI - if true, the UI (HUD, active menus etc) will be visible on the screenshot.
      callback - this callback will be called once the screenshot has been uploaded to the server. The screenshot is passed as BufferedImage object. Uploading the screenshot may take a few seconds depending on the bandwidth, traffic and screenshot size.
    • createScreenshot

      public void createScreenshot(Vector3f position, Vector3f direction, int width, int height, float quality, boolean includeUI, Callback<BufferedImage> callback)
      Creates a screenshot from an arbitrary world position with the desired resolution and converts it into a BufferedImage. Please note that only parts of the world which are currently generated for the player will be visible on the screenshot.
      Parameter:
      position - the world position from where the screenshot should be taken.
      direction - the view direction for the camera.
      width - the width of the screenshot.
      height - the height of the screenshot.
      quality - the quality of the image (0-1).
      includeUI - if true, the UI (HUD, active menus etc) will be visible on the screenshot.
      callback - this callback will be called once the screenshot has been uploaded to the server. The screenshot is passed as BufferedImage object. Uploading the screenshot may take a few seconds depending on the bandwidth, traffic and screenshot size.