Hello guys I have recently made a simple Boolean to tell weather a player is in a location. This is a very simple method with no loops what so ever and it is not very long too. This doesn't only work for players it can be any Location of any block. It also has IlligalArgumentExceptions on if the location being sent is in another world, weather the two corners are identical, and if the two corners are in seperate worlds. Well here you guys go. Cube Class Boolean Code:java public static boolean isInside(Location loc, Location corner, Location corner2) {if (corner == corner2) throw new IllegalArgumentException("Can not be the Same location for corner and corner2");if (corner.getWorld() != corner2.getWorld()) throw new IllegalArgumentException("Can not be in another world");if (loc.getWorld() != corner.getWorld())return false;boolean jon = new Boolean(false);int locx = loc.getBlockX();int locz = loc.getBlockZ();int BigX = 0;int BigZ = 0;int SmallX = 0;int SmallZ = 0;if (corner.getBlockX() > corner2.getBlockX()) {BigX = corner.getBlockX();SmallX = corner2.getBlockX();}else if (corner2.getBlockX() > corner.getBlockX()) {BigX = corner2.getBlockX();SmallX = corner.getBlockX();}if (corner.getBlockZ() > corner2.getBlockZ()) {BigZ = corner.getBlockZ();SmallZ = corner2.getBlockZ();}else if (corner2.getBlockZ() > corner.getBlockZ()) {BigZ = corner2.getBlockZ();SmallZ = corner.getBlockZ();}if (locx > BigX || locx < SmallX || locz > BigZ || locz < SmallZ) {jon = new Boolean(false);}if (locx <= BigX && locx >= SmallX && locz <= BigZ && locz >= SmallZ) {jon = new Boolean(true);}return jon;} ExampleClass Code:java @EventHandler public void onMove(PlayerMoveEvent e) { Location loc = e.getFrom(); if (Cube.isInside(loc, new Location(Bukkit.getWorld("world"), 144,3,98), new Location(Bukkit.getWorld("world"),143,3,99))) { e.getPlayer().sendMessage("You are in the cube"); } }
CaptainUniverse Why are you using this? Code:java jon = new Boolean(true); You can just use the following: Code:java jon = true; Edit: It is not smart to compare World objects by using ==, you have to use .equals() for that.
I'm not actually sure It's cause I'm new with booleans and I thought you had to do it that way but anyway thanks for the advice nlthijs48
CaptainUniverse Isn't this simpler? Code:java public static boolean isInside(Location location, Location min, Location max) { return location.toVector().isInAABB(min.toVector(), max.toVector());}