-
Notifications
You must be signed in to change notification settings - Fork 31
Region
There are many times where you need to do various things regarding a region in the world. Whether that's detecting whether a player has entered a region, iterating over the blocks in a region, or checking for certain conditions, CuboidRegion
covers almost every use case.
The basic class, CuboidRegion
, represents a cuboid region within a world. You can instantiate it by simply passing two locations to the constructor: new CuboidRegion(start, end);
. Once you've constructed it, you can check if a Location
is inside it by calling contains(Location)
. You can stream all of the blocks in the CuboidRegion
by calling region.stream()
.
There is also SpheroidRegion
for cases where you need a sphere or spheroid rather than a cuboid.
If you need to resize or move the Region
, you can do so with expand
and move
. expand(BlockFace, double)
is probably the easiest-to-use of all the expand methods, as it's fairly self-explanatory. The Region
will be expanded by the given amount in the given direction. If a negative amount is given, it will be retracted in that direction. move(int, int, int)
and move(Vector)
will simply move the Region
over a given amount.
Regions also have events, though they have to be enabled, as registering a listener every time a Region
is instantiated would result in a lot of unneeded listeners. However, simply calling enableEvents()
on a region will cause it to begin calling RegionEnterEvent
every time a player enters the region and RegionExitEvent
every time a player leaves. If you call disableEvents()
, it will stop calling these events, and it is good practice to call disableEvents()
on a region once you're done listening to its events.
You can also learn how to prevent a Region
from being modified by continuing to read on ProtectionPolicy.