BlueGit

timfa chestpreviews

Files

chestpreviews / src / main / java / nl / timfalken / chestpreview / BlockKey.java

BlockKey.java

BlockKey.java 1.0 KiB Download Raw
1package nl.timfalken.chestpreview;
2
3import org.bukkit.Location;
4import org.bukkit.World;
5import org.bukkit.block.Block;
6
7import java.util.Objects;
8import java.util.UUID;
9
10record BlockKey(UUID worldId, int x, int y, int z) implements Comparable<BlockKey> {
11 static BlockKey of(Block block) {
12 return new BlockKey(block.getWorld().getUID(), block.getX(), block.getY(), block.getZ());
13 }
14
15 Block getBlock() {
16 World world = org.bukkit.Bukkit.getWorld(worldId);
17 return world == null ? null : world.getBlockAt(x, y, z);
18 }
19
20 Location center() {
21 World world = org.bukkit.Bukkit.getWorld(worldId);
22 return world == null ? null : new Location(world, x + 0.5, y + 0.5, z + 0.5);
23 }
24
25 @Override
26 public int compareTo(BlockKey other) {
27 int c = worldId.compareTo(other.worldId);
28 if (c != 0) return c;
29 c = Integer.compare(x, other.x);
30 if (c != 0) return c;
31 c = Integer.compare(y, other.y);
32 if (c != 0) return c;
33 return Integer.compare(z, other.z);
34 }
35}