From 18976b57be2b54e6b2bdde44bc1d65372a7aa478 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 15 May 2017 07:18:12 +0200 Subject: [PATCH] Fix NPE caused by lazy cleanup --- src/com/massivecraft/factions/TerritoryAccess.java | 8 ++++++-- src/com/massivecraft/factions/entity/Board.java | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/com/massivecraft/factions/TerritoryAccess.java b/src/com/massivecraft/factions/TerritoryAccess.java index f449b483..954f940a 100644 --- a/src/com/massivecraft/factions/TerritoryAccess.java +++ b/src/com/massivecraft/factions/TerritoryAccess.java @@ -80,9 +80,11 @@ public class TerritoryAccess // FIELDS: DIRECT // -------------------------------------------- // + // This method intentionally returns null if the Faction no longer exists. + // In Board we don't even return this TerritoryAccess if that is the case. public Faction getHostFaction() { - return FactionColl.get().get(this.getHostFactionId()); + return Faction.get(this.getHostFactionId()); } public Set getGrantedMPlayers() @@ -108,7 +110,9 @@ public class TerritoryAccess // Fill for (String factionId : this.getFactionIds()) { - ret.add(FactionColl.get().get(factionId)); + Faction faction = Faction.get(factionId); + if (faction == null) continue; + ret.add(faction); } // Return diff --git a/src/com/massivecraft/factions/entity/Board.java b/src/com/massivecraft/factions/entity/Board.java index 0720f628..0da9f7f4 100644 --- a/src/com/massivecraft/factions/entity/Board.java +++ b/src/com/massivecraft/factions/entity/Board.java @@ -92,7 +92,7 @@ public class Board extends Entity implements BoardInterface if (ps == null) return null; ps = ps.getChunkCoords(true); TerritoryAccess ret = this.map.get(ps); - if (ret == null) ret = TerritoryAccess.valueOf(Factions.ID_NONE); + if (ret == null || ret.getHostFaction() == null) ret = TerritoryAccess.valueOf(Factions.ID_NONE); return ret; }