2D Regions

Since 1.0.0

2D regions can be created with the Region2D class, as expected, this regions are created on a two-dimensional space, where only the x and z axis are taken into account, meaning that height is ignored.

Creating 2D regions

Let's see how to create a 2D region taking the 0/0 coordinate as the center of it.

World world = Bukkit.getWorld("world");

// By coordinates: x1, z1, x2, z2
Region2D region = new Region2D(world, 5, 5, -5, -5);

// By locations: loc1, loc2
Location loc1 = new Location(world, 5, 0, 5); // Y coordinate doesn't matter.
Location loc2 = new Location(world, -5, 0, -5); // Y coordinate doesn't matter.
Region2D region = new Region2D(loc1, loc2);

Here is a representation of this region in-game

Golden block is at 0/0, top right block of the square is at 5/5, bottom left is at -5/-5

Checking if anything is inside the region

You can check whether a Location is inside of a Region2D or not, for this example we will use a player, as it's the most common use case for regions.

Contains vs overlaps

You can also check if a Region2D contains or overlaps another Region2D, but first, let's make sure we understand the difference between these two terms.

  • contains: The region is totally inside of another region

  • overlaps: The region collides with another region, even if it's only by one block.

Alright, let's see some examples then

Last updated

Was this helpful?