package nl.timfalken.chestpreview; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Block; import java.util.Objects; import java.util.UUID; record BlockKey(UUID worldId, int x, int y, int z) implements Comparable { static BlockKey of(Block block) { return new BlockKey(block.getWorld().getUID(), block.getX(), block.getY(), block.getZ()); } Block getBlock() { World world = org.bukkit.Bukkit.getWorld(worldId); return world == null ? null : world.getBlockAt(x, y, z); } Location center() { World world = org.bukkit.Bukkit.getWorld(worldId); return world == null ? null : new Location(world, x + 0.5, y + 0.5, z + 0.5); } @Override public int compareTo(BlockKey other) { int c = worldId.compareTo(other.worldId); if (c != 0) return c; c = Integer.compare(x, other.x); if (c != 0) return c; c = Integer.compare(y, other.y); if (c != 0) return c; return Integer.compare(z, other.z); } }