Skip to content
Redempt edited this page May 29, 2020 · 3 revisions

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, Region covers almost every use case.

The basic class, Region, represents a cuboid region within a world. You can instantiate it by simply passing two locations to the constructor: new Region(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 Region by calling region.stream().

If you need to resize or move the Region, you can do so with expand and move. expand(BlockFace, int) 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.

Clone this wiki locally