I've seen some people struggling to make zone plugins, so I figured I'd help them out a little bit. You can download the library here: http://www.bytecraft.info/zoneLib.zip view on github And here's how to use it For 3D zones/areas For this example, we're going to imagine two HashMap<String, Location>'s have been set, as a way to select the two points, and in the main plugin file there's a List<Cube> to store cubes. (you can store the points to config and load later, however we wont for the example) Code:java HashMap<String, Location> map1 = plugin.getMap1();HashMap<String, Location> map2 = plugin.getMap2(); //check if players name is in both maps! Location l1 = map1.get(player.getName());Location l2 = map2.get(player.getName()); Point point1 = new Point(l1.getBlockX(), l1.getBlockY(), l1.getBlockZ());Point point2 = new Point(l2.getBlockX(), l2.getBlockY(), l2.getBlockZ());//now we have two points, we can create a cube Cube cube = new Cube(point1, point2); plugin.addCube(cube); //now to actually use it, very badly public void onBreak(BlockBreakEvent event){ Block block = event.getBlock(); //Create a new point for the block Point p = new Point(block.getX(), block.getY(), block.getZ()); for(Cube cube: plugin.getCubes()){//this is very bad, dont do it exactly like this! if(cube.contains(p)){ player.sendMessage("You broke a block inside a cube"); } }} You can do the same thing with Plane's, except the Y-Axis doesn't come into play when checking if it contains a point. So how do you use it? Well thats up to you. Just download the .zip, extract it to your plugin, and you can start using it. Let me know what you think, or if anything doesn't work exactly how its supposed to. //EDIT: Updated to suggestion by kumpelblase2
You should evaluate the highest and lowest point on cube creation, not on the contains check. Because now you'd need to re-evaluate the highest and lowest point every time the method gets called, which is pretty resource intensive after a certain amount.
Thanks, I wasnt sure what to put it under. Alright, thanks for the tip. I'll get right on that I've added a method to Plane and Cube to check intersections EDIT by Moderator: merged posts, please use the edit button instead of double posting.