I'm making a little Minigame at the moment and I'm wondering how to go about checking a player's region. The Minigame could have 100 to 200 people on it at one time, so I'm not sure if using an Event Handler for PlayerMoveEvent would be the best option, and I see no method for getting the event of when a Player enters a region in the WorldGuard source. I have also tried "WGRegionEvents" and tried to use the methods out of it, however the server fails to register the event, as blah.blah.blah.RegionEnterEvent does not exist. Would anyone have any advice on how I would go about this?
If your going to create a Mini-game I suggest not using WorldGuard, just create your own one. Also, if your going to have a lot of people on the server don't just use raw PlayerMoveEvent because it fires of when a player moves there head or hasn't even moved to a different block and this causes stress for your server, use something like: Code:java public boolean compareLocations(Location location1, Location location2){ if (location1.getBlockX() == location2.getBlockX() && location1.getBlockY() == location2.getBlockY() && location1.getBlockZ() == location2.getBlockZ()) return true; else return false; } //On move eventif (!compareLocations(event.getFrom(), event.getTo()))//Do something.
I have created a Region class in my minigame framework, which can tell if a player is in a cuboid region, hope this helps. Code:java import org.bukkit.Location; public class Region { private Location first; private Location second; public Region(Location first, Location second) { this.first = first; this.second = second; } public boolean includes(Location location) { if (location.getWorld().getUID() != first.getWorld().getUID() || location.getWorld().getUID() != second.getWorld().getUID()) return false; int x1 = first.getBlockX(); int x2 = second.getBlockX(); int y1 = first.getBlockY(); int y2 = second.getBlockY(); int z1 = first.getBlockZ(); int z2 = second.getBlockZ(); return between(location.getBlockX(), x1, x2) && between(location.getBlockY(), y1, y2) && between(location.getBlockZ(), z1, z2); } private boolean between(int target, int i, int j) { return (target < i && target > j) || (target > i && target < j); } public Location getFirst() { return first; } public void setFirst(Location first) { this.first = first; } public Location getSecond() { return second; } public void setSecond(Location second) { this.second = second; } } To create a region, use Code:java Region region = new Region(location1, location2); To test if a player is in this region, use Code:java boolean boo = region.includes(player.getLocation());