# Making cuboid regions

Discussion in 'Resources' started by CaptainUniverse, Aug 23, 2014.

Not open for further replies.
1. Offline

### CaptainUniverse

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");        }    }`

Meatiex likes this.
2. Offline

### nlthijs48

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.

#2
3. Offline

### CaptainUniverse

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

4. Offline

### viper_monster

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());}`

#4
Phasesaber and Bart like this.
5. Offline

### CaptainUniverse

Ya I guess but I felt like making my own sort of API

Panjab likes this.
6. Offline

### xTrollxDudex

Getting the world name is safer

#6
Panjab and Phasesaber like this.