-
Notifications
You must be signed in to change notification settings - Fork 50
Selection System
Prison-Core has a selection system similar to the WorldEdit wand system. Players can select a region using a certain tool, and you can access this region for your own use. This guide will detail how to use this simple yet effective built-in system.
In order for player selections to be recognized by the plugin, the player must use a certain tool. This ItemStack
is stored in the global variable SelectionManager.SELECTION_TOOL
. Alternatively, you could use the convenient bestowSelectionTool()
method:
Prison.get().getSelectionManager().bestowSelectionTool(myPlayer);
myPlayer.sendMessage("Left-click to select position 1, and right-click to select position 2.");
The player can then left-click to select one corner, and right-click to select the other.
Selection data is stored in a Selection
instance. To retrieve the Selection instance of a player, call the following method:
Selection selection = Prison.get().getSelectionManager().getSelection(myPlayer);
To the selection system, every player has a selection that is either complete or incomplete. As a result, this method will never return null.
So, you may ask, how do I know if the selection is complete? Answer: simply by asking it!
Selection selection = Prison.get().getSelectionManager().getSelection(myPlayer);
if(!selection.isComplete()) {
Output.get().sendError(myPlayer, "You must make a selection first!");
return;
}
Prison comes with a Bounds utility class, which contains a variety of useful methods that calculate things related to the area between two Locations. Among these methods are a within(Location)
method, which checks if a location is within the boundaries, and methods for calculating the width, height, and depth of the boundaries.
You can easily turn a Selection
into a Bounds
object by calling Selection.asBounds()
.
Selection selection = Prison.get().getSelectionManager().getSelection(myPlayer);
if(!selection.isComplete()) {
Output.get().sendError(myPlayer, "You must make a selection first!");
return;
}
Bounds bounds = selection.asBounds();
if(bounds.within(myPlayer.getLocation()) {
Output.get().sendWarn(myPlayer, "You are within the boundaries!");
}
That's all you need to know to use the built-in selection system! It's a very simple yet very useful system that will hopefully make your life a little bit easier.