From db464d5c04df0cf26d9c7bca70c67c83814a43a7 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 9 Oct 2021 11:40:15 -0700 Subject: [PATCH] NPE protections --- .../bentobox/blueprints/BlueprintPaster.java | 10 ++++++---- .../bentobox/database/objects/Island.java | 18 ++++++------------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java index cde794edd..6528f58bd 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java @@ -109,7 +109,7 @@ public class BlueprintPaster { this.plugin = plugin; this.clipboard = clipboard; // Calculate location for pasting - this.blueprint = clipboard.getBlueprint(); + this.blueprint = Objects.requireNonNull(clipboard.getBlueprint(), "Clipboard cannot have a null Blueprint"); this.location = location; this.island = null; @@ -416,9 +416,11 @@ public class BlueprintPaster { if (island != null && !lines.isEmpty() && lines.get(0).equalsIgnoreCase(TextVariables.START_TEXT)) { // Get the addon that is operating in this world String addonName = plugin.getIWM().getAddon(island.getWorld()).map(addon -> addon.getDescription().getName().toLowerCase(Locale.ENGLISH)).orElse(""); - for (int i = 0; i < 4; i++) { - s.setLine(i, Util.translateColorCodes(plugin.getLocalesManager().getOrDefault(User.getInstance(island.getOwner()), - addonName + ".sign.line" + i,"").replace(TextVariables.NAME, name))); + if (island.getOwner() != null) { + for (int i = 0; i < 4; i++) { + s.setLine(i, Util.translateColorCodes(plugin.getLocalesManager().getOrDefault(User.getInstance(island.getOwner()), + addonName + ".sign.line" + i,"").replace(TextVariables.NAME, name))); + } } } else { // Just paste diff --git a/src/main/java/world/bentobox/bentobox/database/objects/Island.java b/src/main/java/world/bentobox/bentobox/database/objects/Island.java index 091837867..57f0a0306 100644 --- a/src/main/java/world/bentobox/bentobox/database/objects/Island.java +++ b/src/main/java/world/bentobox/bentobox/database/objects/Island.java @@ -16,7 +16,6 @@ import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.entity.Player; @@ -43,7 +42,6 @@ import world.bentobox.bentobox.database.objects.adapters.FlagSerializer; import world.bentobox.bentobox.database.objects.adapters.FlagSerializer3; import world.bentobox.bentobox.database.objects.adapters.LogEntryListAdapter; import world.bentobox.bentobox.lists.Flags; -import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.RanksManager; import world.bentobox.bentobox.util.Pair; import world.bentobox.bentobox.util.Util; @@ -1216,11 +1214,9 @@ public class Island implements DataObject, MetaDataAble { * @return {@code true} if this island has its nether island generated, {@code false} otherwise. * @since 1.5.0 */ - public boolean hasNetherIsland(){ - IslandWorldManager iwm = BentoBox.getInstance().getIWM(); - return iwm.isNetherGenerate(getWorld()) && iwm.isNetherIslands(getWorld()) && - iwm.getNetherWorld(getWorld()) != null && - !getCenter().toVector().toLocation(iwm.getNetherWorld(getWorld())).getBlock().getType().equals(Material.AIR); + public boolean hasNetherIsland() { + World nether = BentoBox.getInstance().getIWM().getNetherWorld(getWorld()); + return nether != null && !getCenter().toVector().toLocation(nether).getBlock().getType().isAir(); } /** @@ -1228,11 +1224,9 @@ public class Island implements DataObject, MetaDataAble { * @return {@code true} if this island has its end island generated, {@code false} otherwise. * @since 1.5.0 */ - public boolean hasEndIsland(){ - IslandWorldManager iwm = BentoBox.getInstance().getIWM(); - return iwm.isEndGenerate(getWorld()) && iwm.isEndIslands(getWorld()) && - iwm.getEndWorld(getWorld()) != null && - !getCenter().toVector().toLocation(iwm.getEndWorld(getWorld())).getBlock().getType().equals(Material.AIR); + public boolean hasEndIsland() { + World end = BentoBox.getInstance().getIWM().getEndWorld(getWorld()); + return end != null && !getCenter().toVector().toLocation(end).getBlock().getType().isAir(); }