/
OfflineBlock.java
72 lines (63 loc) · 1.7 KB
/
OfflineBlock.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package net.ME1312.SubServers.Client.Bukkit.Library.Compatibility;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import java.util.Objects;
import java.util.UUID;
/**
* Offline Block Location Class
*/
public class OfflineBlock {
public final UUID world;
public final int x, y, z;
/**
* Convert an existing location object
*
* @param location Location
*/
public OfflineBlock(Location location) {
this(location.getWorld().getUID(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
/**
* Store location data
*
* @param world World ID
* @param x X position
* @param y Y position
* @param z Z position
*/
public OfflineBlock(UUID world, int x, int y, int z) {
this.world = world;
this.x = x;
this.y = y;
this.z = z;
}
/**
* Find the World if loaded
*
* @return World (or null if unavailable)
*/
public World world() {
return Bukkit.getWorld(this.world);
}
/**
* Find the Location if loaded
*
* @return Location (or null if unavailable)
*/
public Location load() {
World world = Bukkit.getWorld(this.world);
return (world == null)? null : new Location(world, x, y, z);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
OfflineBlock that = (OfflineBlock) o;
return x == that.x && y == that.y && z == that.z && Objects.equals(world, that.world);
}
@Override
public int hashCode() {
return Objects.hash(world, x, y, z);
}
}