Class LocationUtil

java.lang.Object
net.mathias2246.buildmc.util.LocationUtil

public final class LocationUtil extends Object
A Utility class for Bukkit Locations.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    calculateChunkArea(int chunkX1, int chunkZ1, int chunkX2, int chunkZ2)
    Calculates the Area in chunks between these chunk coordinates.
    static int
    calculateChunkArea(@NotNull org.bukkit.Location pos1, @NotNull org.bukkit.Location pos2)
    Calculates the number of chunks covered by the area defined by two positions.
    static @NotNull org.bukkit.Location
    Deserialize a String back into a Location.
    static org.bukkit.util.Vector[]
    Returns the min and max block coordinates of a claim.
    static String
    serialize(org.bukkit.Location location)
    Serialize a Location into a String.
    static @Nullable org.bukkit.Location
    Deserialize a String back into a Location.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LocationUtil

      public LocationUtil()
  • Method Details

    • serialize

      public static String serialize(org.bukkit.Location location)
      Serialize a Location into a String. Format: world,x,y,z,yaw,pitch
      Parameters:
      location - the Location to serialize
      Returns:
      serialized String
    • deserialize

      @Contract(value="null -> fail; _ -> new;", pure=true) @NotNull public static @NotNull org.bukkit.Location deserialize(String data)
      Deserialize a String back into a Location. Must match the format from serialize()
      Parameters:
      data - the serialized string
      Returns:
      Location object
    • tryDeserialize

      @Contract(value="_ -> _", pure=true) @Nullable public static @Nullable org.bukkit.Location tryDeserialize(String data)
      Deserialize a String back into a Location. Must match the format from serialize()
      Parameters:
      data - the serialized string
      Returns:
      Location object, or null is failed
    • calculateChunkArea

      @Contract(pure=true) public static int calculateChunkArea(@NotNull @NotNull org.bukkit.Location pos1, @NotNull @NotNull org.bukkit.Location pos2)
      Calculates the number of chunks covered by the area defined by two positions. Both positions must be in the same world.
      Parameters:
      pos1 - First corner location
      pos2 - Second corner location
      Returns:
      Number of chunks in the rectangular selection
    • calculateChunkArea

      @Contract(pure=true) public static int calculateChunkArea(int chunkX1, int chunkZ1, int chunkX2, int chunkZ2)
      Calculates the Area in chunks between these chunk coordinates.
      Parameters:
      chunkX1 - the smallest chunk X coordinate
      chunkZ1 - the smallest chunk Z coordinate
      chunkX2 - the largest chunk X coordinate
      chunkZ2 - the largest chunk Z coordinate
      Returns:
      The Area in chunks
    • getBlockCorners

      @Contract(pure=true) public static org.bukkit.util.Vector[] getBlockCorners(Claim claim)
      Returns the min and max block coordinates of a claim. Always sorted: x1 <= x2, z1 <= z2
      Parameters:
      claim - The claim
      Returns:
      Vector array: [minCorner, maxCorner]