Class Area

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

public final class Area extends Object
An Area describes an area in the game world. It has a start and end position.

Note: If you create a new area and you don't need it anymore, call destroy() so the native resources will be released. Only do that to areas you've created using the new keyword. Do not destroy areas returned by the server (unless you really want to get rid of them).
  • Field Details

    • INFINITE

      public static final Area INFINITE
      An "infinite" area (more precisely, the largest possible area). It covers the whole world.
  • Constructor Details

    • Area

      public Area()
      Creates an "empty" area. Note: If you no longer need the area, destroy() it.
    • Area

      public Area(Area area)
      Creates an area with the same size as the provided area. Note: If you no longer need the area, destroy() it.
      Parameters:
      area - the Area you want this Area to be adapted to.
    • Area

      public Area(Vector3f startPosition, Vector3f endPosition)
      Creates a new area. Note: If you no longer need the area, destroy() it.
      Parameters:
      startPosition - the start position of the area.
      endPosition - the end position of the area.
  • Method Details

    • getID

      public long getID()
      Gets the internal unique global id of this area.
      Returns:
      the id of this area.
    • isValid

      public boolean isValid()
    • setPlayerPermission

      public void setPlayerPermission(Player player, String areaPermission)
      Sets the area permission for a player. This permission is then active for the player while he's inside the area.
      Parameters:
      player - the player you want to add to the area.
      areaPermission - the name of the area permission that should be assigned to the player.
    • setPlayerPermission

      public void setPlayerPermission(int playerDbID, String areaPermission)
      Sets the area permission for a player. This permission is then active for the player while he's inside the area. This method also works for offline players.
      Parameters:
      playerDbID - the database ID of the player.
      areaPermission - the name of the area permission that should be assigned to the player. Must not be null!
    • removePlayerPermission

      public void removePlayerPermission(Player player)
      Removes a player from the area/permissions.
      Parameters:
      player - the player you want to remove from the area.
    • removePlayerPermission

      public void removePlayerPermission(int playerDbID)
      Removes a player from the area/permissions. This method also works for offline players.
      Parameters:
      playerDbID - the database ID of the player you want to remove from the area.
    • getPlayerPermission

      public String getPlayerPermission(Player player)
      Gets the permission of a player in this area. If the player was not assigned to the area yet (see setPlayerPermission(net.risingworld.api.objects.Player, java.lang.String)), null is returned!
      Parameters:
      player - the player you want to get the area permission for.
      Returns:
      the name of the area permission for this player, or null if the player was not assigned to the area yet.
    • getPlayerPermission

      public String getPlayerPermission(int playerDbID)
      Gets the permission of a player in this area. If the player was not assigned to the area yet (see setPlayerPermission(net.risingworld.api.objects.Player, java.lang.String)), null is returned! This method also works for offline players.
      Parameters:
      playerDbID - the database ID of the player you want to get the area permission for.
      Returns:
      the name of the area permission for this player, or null if the player was not assigned to the area yet.
    • getAllPlayerPermissions

      public Map<Integer,String> getAllPlayerPermissions()
      Gets a map containing all player permissions (player database ID mapped to area permission name). If no players are assigned to this area yet, null is returned!
      Returns:
      a new map containing all players and player area permission names, or null if no players are assigned to this area yet.
      Example: Print all players/permissions assigned to an area
      1Map<Integer, String> permissions = area.getAllPlayerPermissions();
      2if (permissions != null) {
      3 //Iterate through the map
      4 for (var entry : permissions.entrySet()) {
      5 //Get player dbID and permission name
      6 int playerDbID = entry.getKey();
      7 String permission = entry.getValue();
      8
      9 //If player is online, we could use Server.getPlayerByDbID() to
      10 //get the player object. But we only want his name, so we use
      11 //this method instead (which also works for offline players)
      12 String playerName = Server.getLastKnownPlayerName(playerDbID);
      13
      14 System.out.println("Player " + playerName + " (" + playerDbID + ") : " + permission);
      15 }
      16}
    • getDefaultPermission

      public String getDefaultPermission()
      Gets the default area permission for this area.
      Returns:
      the default area permission, or null if no specific permission was assigned as default permission to this area.
    • setDefaultPermission

      public void setDefaultPermission(String areaPermission)
      Sets a default area permission for this area. This affects all players who enter the area, unless the player was added with a specific permission to that area (see setPlayerPermission(net.risingworld.api.objects.Player, java.lang.String)).
      Parameters:
      areaPermission - the name of the area permission you want to assign as default permission for this area.
    • getPriority

      public int getPriority()
      Gets the area priority. Default is 0. This is usually relevant if multiple areas are overlapping - then the permission of the area with the highest priority is used.
      Returns:
      the area priority (the higher the value, the higher the area priority).
    • setPriority

      public void setPriority(int priority)
      Changes the area priority. This is usually relevant if multiple areas are overlapping - then the permission of the area with the highest priority is used.
      Parameters:
      priority - the new priority. Default is 0.
    • getName

      public String getName()
      Gets the currently set area name. May be null (if no name is set).
      Returns:
      the optional area name, or null if no name is set.
      See Also:
    • setName

      public void setName(String name)
      Changes the area name. Area names are optional. If isNameVisible() is set, the area name will be shown to the player whenever he enters the area.
      Parameters:
      name - the new area name.
      See Also:
    • isNameVisible

      public boolean isNameVisible()
      Gets whether or not the area name should be shown to the player whenever he enters the area (shown in the lower left corner of the screen).
      Returns:
      true if the area name should be visible for the player, false if not.
      See Also:
    • setNameVisible

      public void setNameVisible(boolean set)
      Determines if the area name should be shown to the player whenever he enters the area (shown in the lower left corner of the screen).
      Parameters:
      set - true to show the area name, false to hide it.
      See Also:
    • getStartPosition

      public Vector3f getStartPosition()
      Gets the start world position of the area. In combination with the end position, this determines the area position and size.
      Returns:
      the start position.
    • getEndPosition

      public Vector3f getEndPosition()
      Gets the end world position of the area. In combination with the start position, this determines the area position and size.
      Returns:
      the end position.
    • getStartChunkPosition

      public Vector3i getStartChunkPosition()
    • getStartBlockPosition

      public Vector3i getStartBlockPosition()
    • getEndChunkPosition

      public Vector3i getEndChunkPosition()
    • getEndBlockPosition

      public Vector3i getEndBlockPosition()
    • setStartPosition

      public void setStartPosition(Vector3f startPosition)
      Sets a start position for this area (start and end position determine the area size).
      Parameters:
      startPosition - the new start position.
    • setEndPosition

      public void setEndPosition(Vector3f endPosition)
      Sets an end position for this area (start and end position determine the area size).
      Parameters:
      endPosition - the new end position.
    • set

      public void set(Vector3f startPosition, Vector3f endPosition)
      Sets a new start and end position for this area.
      Parameters:
      startPosition - the new start position.
      endPosition - the new end position.
    • getSize

      public Vector3f getSize()
    • rearrange

      public boolean rearrange()
      Rearranges the values of this area, i.e the start position will be compared with the end position, and if the start position is less than the end position, the values will be swapped.
      Note: This method is called automatically when a new area is created or when the start/end position has been changed.
      Returns:
      true if the values have been rearranged, false if rearranging was not necessary.
    • isPointInArea

      public boolean isPointInArea(Vector3f point)
      Gets whether or not the point is inside this area.
      Parameters:
      point - a global world position (as a Vector3f)
      Returns:
      true if the point is inside this area, false if not.
    • isPointInArea

      public boolean isPointInArea(float x, float y, float z)
      Gets whether or not the provided position is inside this area.
      Parameters:
      x - the global x world position.
      y - the global y world position.
      z - the global z world position.
      Returns:
      true if the position is inside this area, false if not.
    • intersects

      public boolean intersects(Area area)
      Checks whether or not the provided area intersects this area.
      Parameters:
      area - the area you want to check.
      Returns:
      true if there is an intersection between this area and the provided area, false if not.
    • destroy

      public void destroy()
      Destroys this area. This releases all native resources. It's important to call this method as soon as you don't need the area anymore. Do not use this area anymore after calling this method!
    • setAttribute

      public void setAttribute(String key, Object value)
      Stores an attribute for this area. You can store any type of object. Note that all attributes will be reset upon server restart.
      Parameters:
      key - the name of the attribute.
      value - the value/object you want to store.
    • 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.
      Parameters:
      key - the name of the attribute.
      Returns:
      the attribute that is stored for that key, or null of the key does not exists.
    • hasAttribute

      public boolean hasAttribute(String key)
      Gets whether or not the provided attribute exists.
      Parameters:
      key - the name of the attribute.
      Returns:
      true if the attribute exists, false if not.
    • deleteAttribute

      public void deleteAttribute(String key)
      Removes an attribute from this area. Does nothing if the attribute doesn't exist.
      Parameters:
      key - the name of the attribute you want to delete.
    • toString

      public String toString()
      Gets a String representation of this area (containing the global id, start and end positions).
      Overrides:
      toString in class Object
      Returns:
      a string representing the values of this area.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object