Quarantines duplicate islands so they don't load continuously

https://github.com/BentoBoxWorld/BentoBox/issues/505
This commit is contained in:
tastybento 2019-01-30 16:46:51 -08:00
parent 271d6aa5e9
commit 804d0f9878
4 changed files with 53 additions and 13 deletions

View File

@ -107,6 +107,12 @@ public class Island implements DataObject {
private int levelHandicap; private int levelHandicap;
@Expose @Expose
private Map<Environment, Location> spawnPoint = new EnumMap<>(Environment.class); private Map<Environment, Location> spawnPoint = new EnumMap<>(Environment.class);
/**
* This flag is used to quarantine islands that cannot be loaded and should be purged at some point
*/
@Expose
private boolean doNotLoad;
public Island() {} public Island() {}
@ -801,4 +807,18 @@ public class Island implements DataObject {
public void setHistory(List<LogEntry> history) { public void setHistory(List<LogEntry> history) {
this.history = history; this.history = history;
} }
/**
* @return the doNotLoad
*/
public boolean isDoNotLoad() {
return doNotLoad;
}
/**
* @param doNotLoad the doNotLoad to set
*/
public void setDoNotLoad(boolean doNotLoad) {
this.doNotLoad = doNotLoad;
}
} }

View File

@ -1,7 +1,9 @@
package world.bentobox.bentobox.managers; package world.bentobox.bentobox.managers;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
@ -22,9 +24,9 @@ import org.bukkit.entity.Monster;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.events.IslandBaseEvent; import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent; import world.bentobox.bentobox.api.events.island.IslandEvent;
@ -32,8 +34,8 @@ import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.Database; import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.database.objects.IslandDeletion;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.IslandDeletion;
import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.managers.island.IslandCache; import world.bentobox.bentobox.managers.island.IslandCache;
import world.bentobox.bentobox.util.DeleteIslandChunks; import world.bentobox.bentobox.util.DeleteIslandChunks;
@ -696,7 +698,22 @@ public class IslandsManager {
*/ */
public void load(){ public void load(){
islandCache.clear(); islandCache.clear();
handler.loadObjects().forEach(islandCache::addIsland); List<Island> toQuarantine = new ArrayList<>();
// Only load non-quarantined island
// TODO: write a purge admin command to delete these records
handler.loadObjects().stream().filter(i -> !i.isDoNotLoad()).forEach(island -> {
if (!islandCache.addIsland(island)) {
// Quarantine the offending island
toQuarantine.add(island);
}
});
if (!toQuarantine.isEmpty()) {
plugin.logError(toQuarantine.size() + " islands could not be loaded successfully; quarantining.");
toQuarantine.forEach(i -> {
i.setDoNotLoad(true);
handler.saveObject(i);
});
}
} }
/** /**

View File

@ -45,15 +45,18 @@ public class IslandCache {
if (island.getCenter() == null || island.getWorld() == null) { if (island.getCenter() == null || island.getWorld() == null) {
return false; return false;
} }
islandsByLocation.put(island.getCenter(), island); if (addToGrid(island)) {
// Make world islandsByLocation.put(island.getCenter(), island);
islandsByUUID.putIfAbsent(island.getWorld(), new HashMap<>()); // Make world
// Only add islands to this map if they are owned islandsByUUID.putIfAbsent(island.getWorld(), new HashMap<>());
if (island.getOwner() != null) { // Only add islands to this map if they are owned
islandsByUUID.get(island.getWorld()).put(island.getOwner(), island); if (island.getOwner() != null) {
island.getMemberSet().forEach(member -> islandsByUUID.get(island.getWorld()).put(member, island)); islandsByUUID.get(island.getWorld()).put(island.getOwner(), island);
island.getMemberSet().forEach(member -> islandsByUUID.get(island.getWorld()).put(member, island));
}
return true;
} }
return addToGrid(island); return false;
} }
/** /**

View File

@ -6,10 +6,10 @@ api-version: 1.13
authors: [tastybento, Poslovitch] authors: [tastybento, Poslovitch]
website: https://bentobox.world website: https://bentobox.world
softdepend: [Vault, PlaceholderAPI, MVdWPlaceholderAPI]
loadbefore: [Multiverse-Core] loadbefore: [Multiverse-Core]
softdepend: [Vault, PlaceholderAPI, MVdWPlaceholderAPI]
permissions: permissions:
bentobox.admin: bentobox.admin:
description: Allow bentobox command usage description: Allow bentobox command usage