-
Notifications
You must be signed in to change notification settings - Fork 0
World Management
Area class is used to define the area of specific size, location and shape and check the player presence in it. With proper event listeners it allows to create truly interactive world. It has three abstract methods handling three major events for the particular area:
-
.onEnter- runs when player enters the area -
.onMove- runs when the player moves inside of area (called onPlayerMoveEvent) -
onLeave- runs when player leaves the area
Area class has a PlainArea subclass which simply overrides the abstract methods with empty block of code, simultaneously applying no functionality to these handler methods.
Area objects are defined using the constructor which defies area center, size in three dimensions and shape.
Creating 6x8x10 area with shape of cuboid:
Area area = new PlainArea(location, 3, 4, 5, AreaShape.CUBOID);As Area constructor overload accepts the supplier of location, the area center can be dependant from e.g. player's location.
Creating a sphere area with radius equal 10 and center in player's location:
Area personalArea = new PlainArea(player::getLocation, 10, 10, 10, AreaShape.SPHERE);AreaController is the controller used to operate on Area objects and predicate if certain location, thus also certain entity, is within the bounds of any area. Controller will pick the area of the highest priority.
AreaController object is created using constructor accepting the plugin object.
AreaController controller = new AreaController(this);
controller.addArea(area, 1);Note: It may also accept the predefined
<Area, Integer>priority map.
Adding Area objects to AreaController can be done using AreaController.addArea(Area, int) function. The integer value is the priority of Area object considered while picking one.
Area priorArea = controller.getArea(location);Note: If the controller encounters two or more overlapping areas with same priority on picking one for location within each one of these, it will throw
AreaPickEquivocationException.
Every area the specified location is in, can be obtained as a HashSet<Area> object by AreaController.getAreas(location) function:
HashSet<Area> allAreas = controller.getAreas(location);AreaShape interface specifies the shape basing on Area object. It provides some predefined shapes such as:
-
CUBOID- cuboid of doubled area sizes;3x4x5=6x8x10 -
SPHERE- ellipsoid of three radiuses suitable with area sizes -
CYLINDER- elliptic cylinder of height equal to doubled areaysize and ellipsoid as base of radiuses suitable with areaxandzsize
The abstract function accepts the Area object the shape is applied to, and Location object representing any location to be checked. AreaShape.compute(Area,Location) returns the true if the location is within the bounds of the shape.
As AreaShape interface is a functional interface, it can be declared with lambda expression. This the declaration of AreaShape.CUBOID field:
AreaShape CUBOID = (area, pos) -> {
Location center = area.getCenter();
Point3D centerPoint = new Point3D(center.getX(), center.getY(), center.getZ());
Point3D posPoint = new Point3D(pos.getX(), pos.getY(), pos.getZ());
Point3D diff = centerPoint.subtract(posPoint);
return Math.abs(diff.getX()) <= area.getSizeX() && Math.abs(diff.getY()) <= area.getSizeY() && Math.abs(diff.getZ()) <= area.getSizeZ();
};GameMap interface represents a game map that can be loaded to the world using MapManager.
GameMap object can be created by instantiating a class implementing the following interface, or be obtained using MapManager.createMap function.
GameMap gameMap = mapManager.createMap("maps/custom/myMap", true);Note: Directory location specified in first parameter is relative to main directory of MapManager object.
MapManager class has a simple task of loading and unloading the map from the world and storing the current one
MapManager object is create using a constructor accepting a directory file or path, which will be the default directory that maps will be taken from.
MapManager mapManager = new MapManager(getPluginFolder());Loading a map object happens by .loadMap function accepting GameMap object.
mapManager.loadMap(gameMap);© 2023 Kamil Więczaszek under Apache 2.0
- Java version: 8
- Build: Maven
- Minecraft version: 1.8.8+
- License: Apache 2.0