Archived
0

Checking on unloading

This commit is contained in:
Forwolk
2018-08-04 14:31:43 +03:00
parent 610981b7b8
commit eab9947aa9
5 changed files with 39 additions and 3 deletions

View File

@@ -5,15 +5,17 @@
package mc.core;
import lombok.Data;
import mc.core.exception.ResourceUnloadException;
import mc.core.world.World;
import java.io.Serializable;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
@Data
public class Location implements Serializable{
private double x, y, z;
private WeakReference<World> world;
private Reference<World> world;
private static int floor_double(double value) {
int i = (int)value;
@@ -53,6 +55,7 @@ public class Location implements Serializable{
public Location(long compactValue, World world) {
set(compactValue);
this.world = new WeakReference<>(world);
}
public void set(Location location) {
@@ -95,6 +98,9 @@ public class Location implements Serializable{
}
public World getWorld () {
if (world.get() == null) {
throw new ResourceUnloadException("You're trying to get unloaded world");
}
return this.world.get();
}

View File

@@ -0,0 +1,12 @@
package mc.core.exception;
public abstract class McCoreUncheckedException extends RuntimeException {
public McCoreUncheckedException() {
super();
}
public McCoreUncheckedException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,8 @@
package mc.core.exception;
public class ResourceUnloadException extends McCoreUncheckedException {
public ResourceUnloadException(String msg) {
super(msg);
}
}