From e364094a4f4b977480c4ecbea4e0a4d121072017 Mon Sep 17 00:00:00 2001 From: tastybento Date: Wed, 15 Jul 2020 18:09:32 -0700 Subject: [PATCH] This stops BentoBox if there is an island distance mismatch. --- .../java/world/bentobox/bentobox/BentoBox.java | 18 +++++++++++++++++- .../bentobox/managers/IslandsManager.java | 11 ++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/BentoBox.java b/src/main/java/world/bentobox/bentobox/BentoBox.java index c27a7c441..abfebec10 100644 --- a/src/main/java/world/bentobox/bentobox/BentoBox.java +++ b/src/main/java/world/bentobox/bentobox/BentoBox.java @@ -1,5 +1,6 @@ package world.bentobox.bentobox; +import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -183,7 +184,22 @@ public class BentoBox extends JavaPlugin { registerListeners(); // Load islands from database - need to wait until all the worlds are loaded - islandsManager.load(); + try { + islandsManager.load(); + } catch (Exception e) { + logError("*****************CRITIAL ERROR!******************"); + Arrays.stream(e.getMessage().split("[\n\r]+")).forEach(this::logError); + logError("Could not load islands! Disabling BentoBox..."); + logError("*************************************************"); + // Stop all addons + if (addonsManager != null) { + addonsManager.disableAddons(); + } + // Do not save players or islands, just shutdown + shutdown = true; + instance.setEnabled(false); + return; + } // Save islands & players data every X minutes Bukkit.getScheduler().runTaskTimer(instance, () -> { diff --git a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java index a10ab4f81..33b4dcf5e 100644 --- a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java @@ -1,5 +1,6 @@ package world.bentobox.bentobox.managers; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -1037,8 +1038,9 @@ public class IslandsManager { /** * Clear and reload all islands from database + * @throws IOException - if a loaded island distance does not match the expected distance in config.yml */ - public void load() { + public void load() throws IOException { islandCache.clear(); quarantineCache.clear(); List toQuarantine = new ArrayList<>(); @@ -1050,12 +1052,19 @@ public class IslandsManager { plugin.logWarning("Null island when loading..."); continue; } + if (island.isDeleted()) { // These will be deleted later deletedIslands.add(island.getUniqueId()); } else if (island.isDoNotLoad() && island.getWorld() != null && island.getCenter() != null) { // Add to quarantine cache quarantineCache.computeIfAbsent(island.getOwner(), k -> new ArrayList<>()).add(island); + } // Check island distance and if incorrect stop BentoBox + else if (island.getRange() != plugin.getIWM().getIslandDistance(island.getWorld())) { + throw new IOException("Island distance mismatch!\n" + + "World '" + island.getWorld().getName() + "' distance " + plugin.getIWM().getIslandDistance(island.getWorld()) + " != island range " + island.getRange() + "!\n" + + "Island ID in database is " + island.getUniqueId() + ".\n" + + "Island distance in config.yml cannot be changed mid-game! Fix config.yml or clean database."); } else { // Fix island center if it is off fixIslandCenter(island);