diff --git a/src/main/java/world/bentobox/bentobox/database/json/adapters/FlagTypeAdapter.java b/src/main/java/world/bentobox/bentobox/database/json/adapters/FlagTypeAdapter.java index 0eb0caba9..2b283ae93 100644 --- a/src/main/java/world/bentobox/bentobox/database/json/adapters/FlagTypeAdapter.java +++ b/src/main/java/world/bentobox/bentobox/database/json/adapters/FlagTypeAdapter.java @@ -1,6 +1,9 @@ package world.bentobox.bentobox.database.json.adapters; import java.io.IOException; +import java.util.UUID; + +import org.bukkit.Material; import com.google.gson.TypeAdapter; import com.google.gson.stream.JsonReader; @@ -34,6 +37,13 @@ public class FlagTypeAdapter extends TypeAdapter { reader.nextNull(); return null; } - return plugin.getFlagsManager().getFlag(reader.nextString()).orElse(null); + String id = reader.nextString(); + Flag f = plugin.getFlagsManager().getFlag(id).orElse(null); + // Flags can end up null if an addon that created one is removed or if a flag name was changed + if (f == null) { + // Create a temporary flag with a unique key. It will be immediately deleted after loading + f = new Flag.Builder("NULL_FLAG_"+ UUID.randomUUID().toString(), Material.STONE).build(); + } + return f; } } \ No newline at end of file diff --git a/src/main/java/world/bentobox/bentobox/lists/Flags.java b/src/main/java/world/bentobox/bentobox/lists/Flags.java index ca9b5f28b..90f9661a0 100644 --- a/src/main/java/world/bentobox/bentobox/lists/Flags.java +++ b/src/main/java/world/bentobox/bentobox/lists/Flags.java @@ -412,26 +412,25 @@ public final class Flags { /** * Protects against visitors dying stuff, like sheep or signs - * + * * @since 1.5.0 * @see DyeListener */ public static final Flag DYE = new Flag.Builder("DYE", Material.LIGHT_BLUE_DYE).type(Type.PROTECTION).listener(new DyeListener()).build(); - + /** * Provides a list of all the Flag instances contained in this class using reflection. * @return List of all the flags in this class */ public static List values() { return Arrays.stream(Flags.class.getFields()) - .filter(field -> field.getAnnotation(Deprecated.class) == null) // Ensures it is not deprecated .map(field -> { - try { - return (Flag)field.get(null); - } catch (IllegalArgumentException | IllegalAccessException e) { - Bukkit.getLogger().severe("Could not get Flag values " + e.getMessage()); - } - return null; - }).collect(Collectors.toList()); + try { + return (Flag)field.get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { + Bukkit.getLogger().severe("Could not get Flag values " + e.getMessage()); + } + return null; + }).collect(Collectors.toList()); } } diff --git a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java index b17b46d07..997496834 100644 --- a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java @@ -774,6 +774,10 @@ public class IslandsManager { } else if (island.isSpawn()) { // Success, set spawn if this is the spawn island. this.setSpawn(island); + } else { + // Successful load + // Clean any null flags out of the island - these can occur for various reasons + island.getFlags().keySet().removeIf(f -> f.getID().startsWith("NULL_FLAG")); } }