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