From 60b06e1728181ece132eefc88ea90f75931ce484 Mon Sep 17 00:00:00 2001 From: LlmDl Date: Wed, 7 Aug 2024 08:38:29 -0500 Subject: [PATCH] - Fix potential NPE thrown in outpost name tab completer, caused by outposts in non-existent worlds. --- .../com/palmergames/bukkit/towny/TownyAPI.java | 7 ++++++- .../palmergames/bukkit/towny/object/Town.java | 17 +++++++++++------ Towny/src/main/resources/ChangeLog.txt | 3 ++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/TownyAPI.java b/Towny/src/main/java/com/palmergames/bukkit/towny/TownyAPI.java index 3355e67250..10d8abeb49 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/TownyAPI.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/TownyAPI.java @@ -638,7 +638,12 @@ public List getTownsWithoutNation() { */ @Nullable public TownBlock getTownBlock(Location location) { - WorldCoord worldCoord = WorldCoord.parseWorldCoord(location); + WorldCoord worldCoord; + try { + worldCoord = WorldCoord.parseWorldCoord(location); + } catch (IllegalArgumentException ignored) { + return null; + } return worldCoord.getTownBlockOrNull(); } diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/object/Town.java b/Towny/src/main/java/com/palmergames/bukkit/towny/object/Town.java index 61d3e608ef..026501ec8e 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/object/Town.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/object/Town.java @@ -1044,13 +1044,18 @@ public List getOutpostNames() { for (Location loc : getAllOutpostSpawns()) { i++; TownBlock tboutpost = TownyAPI.getInstance().getTownBlock(loc); - if (tboutpost != null) { - String name = !tboutpost.hasPlotObjectGroup() ? tboutpost.getName() : tboutpost.getPlotObjectGroup().getName(); - if (!name.isEmpty()) - outpostNames.add(name); - else - outpostNames.add(String.valueOf(i)); + + if (tboutpost == null) { + removeOutpostSpawn(loc); + save(); + continue; } + + String name = !tboutpost.hasPlotObjectGroup() ? tboutpost.getName() : tboutpost.getPlotObjectGroup().getName(); + if (!name.isEmpty()) + outpostNames.add(name); + else + outpostNames.add(String.valueOf(i)); } return outpostNames; } diff --git a/Towny/src/main/resources/ChangeLog.txt b/Towny/src/main/resources/ChangeLog.txt index 638dc213e4..3669f4c125 100644 --- a/Towny/src/main/resources/ChangeLog.txt +++ b/Towny/src/main/resources/ChangeLog.txt @@ -9958,4 +9958,5 @@ v0.92.0.11: - Support custom biomes with the unwanted biomes feature, courtesy of Warrior with PR #7540. - Fix worldcoord upper corners being in another worldcoord, courtesy of Warrior with PR #7539. - Fix possible ConcurrentModificationException when using /ta plot claim {residentname} - - Fix potential NPE thrown by PlayerMoveEvent and PlayerTeleportEvents with a null destination location. \ No newline at end of file + - Fix potential NPE thrown by PlayerMoveEvent and PlayerTeleportEvents with a null destination location. + - Fix potential NPE thrown in outpost name tab completer, caused by outposts in non-existent worlds. \ No newline at end of file