This stops BentoBox if there is an island distance mismatch.

This commit is contained in:
tastybento 2020-07-15 18:09:32 -07:00
parent d67bf05f5d
commit e364094a4f
2 changed files with 27 additions and 2 deletions

View File

@ -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, () -> {

View File

@ -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<Island> 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);