NPE protections

This commit is contained in:
tastybento 2021-10-09 11:40:15 -07:00
parent f37226b115
commit db464d5c04
2 changed files with 12 additions and 16 deletions

View File

@ -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

View File

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