Class RegionMap<T>

java.lang.Object
redempt.redlib.region.RegionMap<T>
Type Parameters:
T - The type mapped by this RegionMap

public class RegionMap<T> extends Object
Represents a spatial mapping which can retrieve objects by approximate location in O(1)
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a RegionMap with scale 100
    RegionMap(int scale)
    Constructs a RegionMap with the specified scale
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears all data from this RegionMap
    get(org.bukkit.Location location)
    Gets all objects mapped to an approximate location
     
    getNearby(org.bukkit.Location location, int radius)
    Gets all objects mapped near the given location
    int
     
    void
    remove(org.bukkit.Location loc, T object)
    Removes a mapping by location
    void
    remove(CuboidRegion region, T object)
    Removes a mapping by region
    void
    set(org.bukkit.Location loc, T object)
    Maps a Location to an object
    void
    set(CuboidRegion region, T object)
    Maps a Region to an object

    Methods inherited from class java.lang.Object

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

    • RegionMap

      public RegionMap()
      Constructs a RegionMap with scale 100
    • RegionMap

      public RegionMap(int scale)
      Constructs a RegionMap with the specified scale
      Parameters:
      scale - The distance between things being stored in the internal map. Higher values use less memory but more CPU time. If the regions being used to store objects in this RegionMap are especially large, use a larger scale. If they are very small and there are a lot of them, use a smaller scale.
  • Method Details

    • getScale

      public int getScale()
      Returns:
      The scale of this RegionMap
    • set

      public void set(CuboidRegion region, T object)
      Maps a Region to an object
      Parameters:
      region - The Region to map the object to
      object - The object to set
    • set

      public void set(org.bukkit.Location loc, T object)
      Maps a Location to an object
      Parameters:
      loc - The location to map the object to
      object - The object to put at this approximate location
    • remove

      public void remove(CuboidRegion region, T object)
      Removes a mapping by region
      Parameters:
      region - The region to remove the mapping from
      object - The object to remove
    • remove

      public void remove(org.bukkit.Location loc, T object)
      Removes a mapping by location
      Parameters:
      loc - The location to remove the mapping from
      object - The object to remove
    • get

      public Set<T> get(org.bukkit.Location location)
      Gets all objects mapped to an approximate location
      Parameters:
      location - The location to check nearby objects for
      Returns:
      A set of objects mapped near the given location
    • getNearby

      public Set<T> getNearby(org.bukkit.Location location, int radius)
      Gets all objects mapped near the given location
      Parameters:
      location - The location to check centered on
      radius - The radius to check
      Returns:
      A set of all objects mapped near the given location Note: The radius is not exact, no distance checks are made. Make sure you do your own distance checks if needed.
    • getAll

      public Set<T> getAll()
      Returns:
      All objects mapped with this RegionMap
    • clear

      public void clear()
      Clears all data from this RegionMap