From 67d58a6b817235953ddb3624d35e74ee02948d50 Mon Sep 17 00:00:00 2001 From: Pierre Maurice Schwang Date: Sun, 23 Apr 2023 14:54:51 +0200 Subject: [PATCH] fix: Ensure PlotAreaBuilder#plotAreaType returns non-null value --- .../com/plotsquared/core/setup/PlotAreaBuilder.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/setup/PlotAreaBuilder.java b/Core/src/main/java/com/plotsquared/core/setup/PlotAreaBuilder.java index b32e8c265..edbdfa8ce 100644 --- a/Core/src/main/java/com/plotsquared/core/setup/PlotAreaBuilder.java +++ b/Core/src/main/java/com/plotsquared/core/setup/PlotAreaBuilder.java @@ -25,11 +25,17 @@ import com.plotsquared.core.plot.PlotAreaTerrainType; import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.util.SetupUtils; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Objects; public class PlotAreaBuilder { private String generatorName; private String plotManager; + @Nullable private PlotAreaType plotAreaType; private PlotAreaTerrainType terrainType; private String worldName; @@ -85,8 +91,10 @@ public class PlotAreaBuilder { return this.plotManager; } + @NotNull + @Contract(" -> !null") public PlotAreaType plotAreaType() { - return this.plotAreaType; + return Objects.requireNonNullElse(this.plotAreaType, PlotAreaType.NORMAL); } public PlotAreaTerrainType terrainType() { @@ -127,7 +135,8 @@ public class PlotAreaBuilder { return this; } - public PlotAreaBuilder plotAreaType(PlotAreaType plotAreaType) { + public PlotAreaBuilder plotAreaType(@NotNull PlotAreaType plotAreaType) { + Objects.requireNonNull(plotAreaType, "PlotAreaType must not be null"); this.plotAreaType = plotAreaType; return this; }