Checking reference is not initialized
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
package mc.core;
|
package mc.core;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import mc.core.exception.ResourceUnloadException;
|
import mc.core.exception.ResourceUnloadedException;
|
||||||
import mc.core.world.World;
|
import mc.core.world.World;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@@ -98,8 +98,11 @@ public class Location implements Serializable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public World getWorld () {
|
public World getWorld () {
|
||||||
|
if (world == null) {
|
||||||
|
throw new IllegalStateException("World is not initialized");
|
||||||
|
}
|
||||||
if (world.get() == null) {
|
if (world.get() == null) {
|
||||||
throw new ResourceUnloadException("You're trying to get unloaded world");
|
throw new ResourceUnloadedException("You're trying to get unloaded world");
|
||||||
}
|
}
|
||||||
return this.world.get();
|
return this.world.get();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
package mc.core.exception;
|
|
||||||
|
|
||||||
public class ResourceUnloadException extends McCoreUncheckedException {
|
|
||||||
|
|
||||||
public ResourceUnloadException(String msg) {
|
|
||||||
super(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package mc.core.exception;
|
||||||
|
|
||||||
|
public class ResourceUnloadedException extends McCoreUncheckedException {
|
||||||
|
|
||||||
|
public ResourceUnloadedException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ package mc.world.generated_world.chunk;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import mc.core.block.Block;
|
import mc.core.block.Block;
|
||||||
import mc.core.block.BlockType;
|
import mc.core.block.BlockType;
|
||||||
import mc.core.exception.ResourceUnloadException;
|
import mc.core.exception.ResourceUnloadedException;
|
||||||
import mc.core.world.Biome;
|
import mc.core.world.Biome;
|
||||||
import mc.core.world.Chunk;
|
import mc.core.world.Chunk;
|
||||||
import mc.core.world.Region;
|
import mc.core.world.Region;
|
||||||
@@ -111,8 +111,11 @@ public class ChunkImpl implements Chunk{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Region getRegion() {
|
public Region getRegion() {
|
||||||
|
if (region == null) {
|
||||||
|
throw new IllegalStateException("Region is not initialized");
|
||||||
|
}
|
||||||
if (region.get() == null) {
|
if (region.get() == null) {
|
||||||
throw new ResourceUnloadException("Region is unloaded");
|
throw new ResourceUnloadedException("Region is unloaded");
|
||||||
}
|
}
|
||||||
return region.get();
|
return region.get();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
package mc.world.generated_world.region;
|
package mc.world.generated_world.region;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import mc.core.exception.ResourceUnloadException;
|
import mc.core.exception.ResourceUnloadedException;
|
||||||
import mc.core.serialization.IRegionReaderWriter;
|
import mc.core.serialization.IRegionReaderWriter;
|
||||||
import mc.core.serialization.Serializer;
|
import mc.core.serialization.Serializer;
|
||||||
import mc.core.world.*;
|
import mc.core.world.*;
|
||||||
import mc.world.generated_world.chunk.InMemoryCacheChunkLoader;
|
|
||||||
import mc.world.generated_world.chunk.ChunkImpl;
|
import mc.world.generated_world.chunk.ChunkImpl;
|
||||||
import mc.world.generated_world.chunk.ChunkProxy;
|
import mc.world.generated_world.chunk.ChunkProxy;
|
||||||
|
import mc.world.generated_world.chunk.InMemoryCacheChunkLoader;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -81,8 +80,11 @@ public class RegionImpl implements Region{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
|
if (world == null) {
|
||||||
|
throw new IllegalStateException("World is not initialized");
|
||||||
|
}
|
||||||
if (world.get() == null) {
|
if (world.get() == null) {
|
||||||
throw new ResourceUnloadException("World is unloaded");
|
throw new ResourceUnloadedException("World is unloaded");
|
||||||
}
|
}
|
||||||
return world.get();
|
return world.get();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user