Package redempt.redlib.region
Class RegionMap<T>
java.lang.Object
redempt.redlib.region.RegionMap<T>
- Type Parameters:
T
- The type mapped by this RegionMap
Represents a spatial mapping which can retrieve objects by approximate location in O(1)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears all data from this RegionMapget
(org.bukkit.Location location) Gets all objects mapped to an approximate locationgetAll()
getNearby
(org.bukkit.Location location, int radius) Gets all objects mapped near the given locationint
getScale()
void
Removes a mapping by locationvoid
remove
(CuboidRegion region, T object) Removes a mapping by regionvoid
Maps a Location to an objectvoid
set
(CuboidRegion region, T object) Maps a Region to an object
-
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
Maps a Region to an object- Parameters:
region
- The Region to map the object toobject
- The object to set
-
set
Maps a Location to an object- Parameters:
loc
- The location to map the object toobject
- The object to put at this approximate location
-
remove
Removes a mapping by region- Parameters:
region
- The region to remove the mapping fromobject
- The object to remove
-
remove
Removes a mapping by location- Parameters:
loc
- The location to remove the mapping fromobject
- The object to remove
-
get
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
Gets all objects mapped near the given location- Parameters:
location
- The location to check centered onradius
- 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
- Returns:
- All objects mapped with this RegionMap
-
clear
public void clear()Clears all data from this RegionMap
-