Archived
0

Checking reference is not initialized

This commit is contained in:
Forwolk
2018-08-04 14:56:03 +03:00
parent eab9947aa9
commit 72989c60b7
5 changed files with 24 additions and 16 deletions

View File

@@ -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();
}

View File

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

View File

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

View File

@@ -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();
}

View File

@@ -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();
}