Created
September 26, 2021 08:49
-
-
Save hamza-cskn/39188fd868e03571b71fbbc8cfc7cbac to your computer and use it in GitHub Desktop.
Creates a cuboid that is includes all locations of a locations list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//to get main cuboid class: https://www.spigotmc.org/threads/region-cuboid.329859/ | |
public static Cuboid convertCuboid(final List<Location> locations) { | |
int firstPosX = Integer.MIN_VALUE; | |
int firstPosY = Integer.MIN_VALUE; | |
int firstPosZ = Integer.MIN_VALUE; | |
int secondPosX = Integer.MAX_VALUE; | |
int secondPosY = Integer.MAX_VALUE; | |
int secondPosZ = Integer.MAX_VALUE; | |
World world = null; | |
for (final Location loc : locations) { | |
if (loc == null || loc.getWorld() == null) continue; | |
if (world == null) world = loc.getWorld(); | |
if (world != loc.getWorld()) | |
throw new IllegalStateException("world of location can not be different! (expected: " + world.getName() + ", but found: " + loc.getWorld().getName() + ""); | |
final int x = loc.getBlockX(); | |
final int z = loc.getBlockZ(); | |
final int y = loc.getBlockY(); | |
if (firstPosX < x) firstPosX = x; | |
if (firstPosY < y) firstPosY = y; | |
if (firstPosZ < z) firstPosZ = z; | |
if (secondPosX > x) secondPosX = x; | |
if (secondPosY > y) secondPosY = y; | |
if (secondPosZ > z) secondPosZ = z; | |
} | |
if (world == null) return null; | |
return new Cuboid(new Location(world, firstPosX, firstPosY, firstPosZ), new Location(world, secondPosX, secondPosY, secondPosZ)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Red: locations which is you'll give
Light Blue: cuboid which is method'll give
Dark Blue: space