From 7694b099d66132e88423ddcbb5b46c948f905f5d Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Mon, 28 Oct 2019 10:41:47 +0100 Subject: [PATCH] Add null checks --- .../java/com/raoulvdberge/refinedstorage/apiimpl/API.java | 8 ++++++++ .../storage/disk/factory/FluidStorageDiskFactory.java | 8 ++++++++ .../storage/disk/factory/ItemStorageDiskFactory.java | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/API.java b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/API.java index 062a006c8..145d5833e 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/API.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/API.java @@ -203,12 +203,20 @@ public class API implements IRSAPI { @Override @Nonnull public IStorageDisk createDefaultItemDisk(ServerWorld world, int capacity) { + if (world == null) { + throw new IllegalArgumentException("World cannot be null"); + } + return new ItemStorageDisk(world, capacity); } @Override @Nonnull public IStorageDisk createDefaultFluidDisk(ServerWorld world, int capacity) { + if (world == null) { + throw new IllegalArgumentException("World cannot be null"); + } + return new FluidStorageDisk(world, capacity); } diff --git a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/storage/disk/factory/FluidStorageDiskFactory.java b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/storage/disk/factory/FluidStorageDiskFactory.java index e50f29db0..48107bd41 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/storage/disk/factory/FluidStorageDiskFactory.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/storage/disk/factory/FluidStorageDiskFactory.java @@ -16,6 +16,10 @@ public class FluidStorageDiskFactory implements IStorageDiskFactory @Override public IStorageDisk createFromNbt(ServerWorld world, CompoundNBT tag) { + if (world == null) { + throw new IllegalArgumentException("World cannot be null"); + } + FluidStorageDisk disk = new FluidStorageDisk(world, tag.getInt(FluidStorageDisk.NBT_CAPACITY)); ListNBT list = tag.getList(FluidStorageDisk.NBT_FLUIDS, Constants.NBT.TAG_COMPOUND); @@ -33,6 +37,10 @@ public class FluidStorageDiskFactory implements IStorageDiskFactory @Override public IStorageDisk create(ServerWorld world, int capacity) { + if (world == null) { + throw new IllegalArgumentException("World cannot be null"); + } + return new FluidStorageDisk(world, capacity); } } diff --git a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/storage/disk/factory/ItemStorageDiskFactory.java b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/storage/disk/factory/ItemStorageDiskFactory.java index 50054d0fd..abac0e336 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/storage/disk/factory/ItemStorageDiskFactory.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/storage/disk/factory/ItemStorageDiskFactory.java @@ -17,6 +17,10 @@ public class ItemStorageDiskFactory implements IStorageDiskFactory { @Override public IStorageDisk createFromNbt(ServerWorld world, CompoundNBT tag) { + if (world == null) { + throw new IllegalArgumentException("World cannot be null"); + } + ItemStorageDisk disk = new ItemStorageDisk(world, tag.getInt(ItemStorageDisk.NBT_CAPACITY)); ListNBT list = tag.getList(ItemStorageDisk.NBT_ITEMS, Constants.NBT.TAG_COMPOUND); @@ -34,6 +38,10 @@ public class ItemStorageDiskFactory implements IStorageDiskFactory { @Override public IStorageDisk create(ServerWorld world, int capacity) { + if (world == null) { + throw new IllegalArgumentException("World cannot be null"); + } + return new ItemStorageDisk(world, capacity); } }