Bladeren bron

add null check

mastercake10 1 jaar geleden
bovenliggende
commit
58515138ea
2 gewijzigde bestanden met toevoegingen van 10 en 8 verwijderingen
  1. 2 2
      pom.xml
  2. 8 6
      src/main/java/xyz/spaceio/hooks/HookPlotSquared.java

+ 2 - 2
pom.xml

@@ -4,7 +4,7 @@
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>xyz.spaceio</groupId>
 	<artifactId>CustomOreGen</artifactId>
-	<version>1.3.33-SNAPSHOT</version>
+	<version>1.3.34-SNAPSHOT</version>
 	<repositories>
 		<!-- Spigot repository -->
 		<repository>
@@ -104,7 +104,7 @@
 		<dependency>
 		    <groupId>com.plotsquared</groupId>
 		    <artifactId>PlotSquared-Bukkit</artifactId>
-		    <version>6.1.4</version>
+		    <version>6.8.1</version>
 		    <scope>provided</scope>
 		</dependency>
  		<!-- PlotSquared Legacy -->

+ 8 - 6
src/main/java/xyz/spaceio/hooks/HookPlotSquared.java

@@ -1,9 +1,11 @@
 package xyz.spaceio.hooks;
 
+import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
 import java.util.UUID;
 
+import com.plotsquared.core.plot.PlotArea;
 import org.bukkit.Location;
 import org.bukkit.block.Block;
 
@@ -26,15 +28,15 @@ public class HookPlotSquared implements SkyblockAPIHook {
 
 	@Override
 	public Optional<UUID> getIslandOwner(Location loc) {
-		Optional<UUID> optional = Optional.empty();
-
-		if(api.getPlotSquared().getPlotAreaManager().getApplicablePlotArea(getPSLocation(loc)).getPlotCount() > 0) {
-			Set<UUID> owners = api.getPlotSquared().getPlotAreaManager().getApplicablePlotArea(getPSLocation(loc)).getPlots().iterator().next().getOwners();
+		PlotArea plotArea = api.getPlotSquared().getPlotAreaManager().getApplicablePlotArea(getPSLocation(loc));
+		if(plotArea != null && plotArea.getPlotCount() > 0) {
+			Set<UUID> owners = Objects.requireNonNull(api.getPlotSquared().getPlotAreaManager().
+					getApplicablePlotArea(getPSLocation(loc))).getPlots().iterator().next().getOwners();
 			if(!owners.isEmpty()) {
-				Optional.of(owners.iterator().next());
+				return Optional.of(owners.iterator().next());
 			}
 		}
-		return optional;
+		return Optional.empty();
 	}
 
 	@Override