Skip to content

World Management

Kamil Więczaszek edited this page Jun 11, 2023 · 3 revisions

Area

Info

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 on PlayerMoveEvent)
  • 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.

Usage

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

Info

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.

Usage

Declaration

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 areas

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

Info

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 area y size and ellipsoid as base of radiuses suitable with area x and z size

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.

Usage

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

Info

GameMap interface represents a game map that can be loaded to the world using MapManager.

Usage

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

Info

MapManager class has a simple task of loading and unloading the map from the world and storing the current one

Usage

Declaration

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

Loading a map object happens by .loadMap function accepting GameMap object.

mapManager.loadMap(gameMap);

Technical info

  • Java version: 8
  • Build: Maven
  • Minecraft version: 1.8.8+
  • License: Apache 2.0

⚠️ Repository in development state. ⚠️

Clone this wiki locally