From 76a3e441ac4187dcde707d2b6e5765b7ed2159a3 Mon Sep 17 00:00:00 2001 From: xsmeths Date: Wed, 3 Apr 2024 08:02:25 +0100 Subject: [PATCH 1/2] this should fix dynmap related error reported on discord try/catch to handle possible NoSuchElementException when iterating claimed regions and added null check in DynmapManager --- .../com/craftaro/ultimateclaims/claim/Claim.java | 14 ++++++-------- .../ultimateclaims/dynmap/DynmapManager.java | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/craftaro/ultimateclaims/claim/Claim.java b/src/main/java/com/craftaro/ultimateclaims/claim/Claim.java index c66f4c3..c2920ae 100644 --- a/src/main/java/com/craftaro/ultimateclaims/claim/Claim.java +++ b/src/main/java/com/craftaro/ultimateclaims/claim/Claim.java @@ -27,13 +27,7 @@ import org.bukkit.boss.BossBar; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.concurrent.ThreadLocalRandom; public class Claim { @@ -91,7 +85,11 @@ public int getId() { } public ClaimedChunk getFirstClaimedChunk() { - return this.claimedRegions.iterator().next().getFirstClaimedChunk(); + try { + return this.claimedRegions.iterator().next().getFirstClaimedChunk(); + } catch (NoSuchElementException handled) { + return null; + } } public String getName() { diff --git a/src/main/java/com/craftaro/ultimateclaims/dynmap/DynmapManager.java b/src/main/java/com/craftaro/ultimateclaims/dynmap/DynmapManager.java index 494ef57..8a5600a 100644 --- a/src/main/java/com/craftaro/ultimateclaims/dynmap/DynmapManager.java +++ b/src/main/java/com/craftaro/ultimateclaims/dynmap/DynmapManager.java @@ -56,8 +56,8 @@ public void refresh() { if (this.plugin.getClaimManager() != null) { for (Claim claim : this.plugin.getClaimManager().getRegisteredClaims()) { - if (Bukkit.getWorld(claim.getFirstClaimedChunk().getWorld()) == null) { - continue; + if (claim.getFirstClaimedChunk() != null && Bukkit.getWorld(claim.getFirstClaimedChunk().getWorld()) == null) { + continue; } if (claim.getCorners() != null) { From c29aeda0c096b77114f985561888f07da4b6c8be Mon Sep 17 00:00:00 2001 From: xsmeths Date: Wed, 3 Apr 2024 10:16:39 +0100 Subject: [PATCH 2/2] attempt to make requested changes replaced try/catch with if/else and import explicitly --- .../com/craftaro/ultimateclaims/claim/Claim.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/craftaro/ultimateclaims/claim/Claim.java b/src/main/java/com/craftaro/ultimateclaims/claim/Claim.java index c2920ae..9568adb 100644 --- a/src/main/java/com/craftaro/ultimateclaims/claim/Claim.java +++ b/src/main/java/com/craftaro/ultimateclaims/claim/Claim.java @@ -27,7 +27,13 @@ import org.bukkit.boss.BossBar; import org.bukkit.entity.Player; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import java.util.Collections; + import java.util.concurrent.ThreadLocalRandom; public class Claim { @@ -85,9 +91,9 @@ public int getId() { } public ClaimedChunk getFirstClaimedChunk() { - try { + if (!this.claimedRegions.isEmpty()) { return this.claimedRegions.iterator().next().getFirstClaimedChunk(); - } catch (NoSuchElementException handled) { + } else { return null; } }