diff --git a/src/main/java/net/knarcraft/minigames/arena/dropper/DropperArena.java b/src/main/java/net/knarcraft/minigames/arena/dropper/DropperArena.java index 88e5d68..2e659b8 100644 --- a/src/main/java/net/knarcraft/minigames/arena/dropper/DropperArena.java +++ b/src/main/java/net/knarcraft/minigames/arena/dropper/DropperArena.java @@ -263,7 +263,7 @@ public class DropperArena implements Arena { * @param newLocation
The new spawn location
* @returnTrue if successfully updated
*/ - public boolean setSpawnLocation(@NotNull Location newLocation) { + public boolean setSpawnLocation(@Nullable Location newLocation) { if (isInvalid(newLocation)) { return false; } else { @@ -279,7 +279,7 @@ public class DropperArena implements Arena { * @param newLocationThe new exit location
* @returnTrue if successfully updated
*/ - public boolean setExitLocation(@NotNull Location newLocation) { + public boolean setExitLocation(@Nullable Location newLocation) { if (isInvalid(newLocation)) { return false; } else { diff --git a/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourArena.java b/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourArena.java index 3b4bbaa..b97d712 100644 --- a/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourArena.java +++ b/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourArena.java @@ -356,7 +356,7 @@ public class ParkourArena implements Arena { * @param newLocationThe new spawn location
* @returnTrue if successfully updated
*/ - public boolean setSpawnLocation(@NotNull Location newLocation) { + public boolean setSpawnLocation(@Nullable Location newLocation) { if (isInvalid(newLocation)) { return false; } else { @@ -372,7 +372,7 @@ public class ParkourArena implements Arena { * @param newLocationThe new exit location
* @returnTrue if successfully updated
*/ - public boolean setExitLocation(@NotNull Location newLocation) { + public boolean setExitLocation(@Nullable Location newLocation) { if (isInvalid(newLocation)) { return false; } else { @@ -425,13 +425,18 @@ public class ParkourArena implements Arena { * @param newLocationThe location players have to reach
* @returnTrue if successfully changed
*/ - public boolean setWinLocation(@NotNull Location newLocation) { - if (isInvalid(newLocation)) { - return false; - } else { + public boolean setWinLocation(@Nullable Location newLocation) { + if (newLocation == null) { + // Un-set the win location, and fall back to the win block type + this.winLocation = null; + this.saveArena(); + return true; + } else if (!isInvalid(newLocation)) { this.winLocation = newLocation.clone(); this.saveArena(); return true; + } else { + return false; } } @@ -485,7 +490,7 @@ public class ParkourArena implements Arena { * @param checkpointThe checkpoint to add
* @returnTrue if successfully added
*/ - public boolean addCheckpoint(@NotNull Location checkpoint) { + public boolean addCheckpoint(@Nullable Location checkpoint) { if (isInvalid(checkpoint)) { return false; } diff --git a/src/main/java/net/knarcraft/minigames/command/parkour/EditParkourArenaCommand.java b/src/main/java/net/knarcraft/minigames/command/parkour/EditParkourArenaCommand.java index 7762c06..95524f0 100644 --- a/src/main/java/net/knarcraft/minigames/command/parkour/EditParkourArenaCommand.java +++ b/src/main/java/net/knarcraft/minigames/command/parkour/EditParkourArenaCommand.java @@ -5,6 +5,7 @@ import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.arena.parkour.ParkourArena; import net.knarcraft.minigames.arena.parkour.ParkourArenaEditableProperty; import net.knarcraft.minigames.config.MiniGameMessage; +import net.knarcraft.minigames.util.InputValidationHelper; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.command.Command; @@ -12,6 +13,7 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.HashSet; import java.util.List; @@ -109,7 +111,7 @@ public class EditParkourArenaCommand implements CommandExecutor { * @param locationStringThe location string to parse
* @returnThe parsed location, or the player's location if not parse-able
*/ - private @NotNull Location parseLocation(Player player, String locationString) { + private @Nullable Location parseLocation(Player player, String locationString) { if ((locationString.trim() + ",").matches("([0-9]+.?[0-9]*,){3}")) { String[] parts = locationString.split(","); Location newLocation = player.getLocation().clone(); @@ -117,6 +119,8 @@ public class EditParkourArenaCommand implements CommandExecutor { newLocation.setY(Double.parseDouble(parts[1].trim())); newLocation.setZ(Double.parseDouble(parts[2].trim())); return newLocation; + } else if (InputValidationHelper.isEmptyValue(locationString)) { + return null; } else { return player.getLocation().clone(); } diff --git a/src/main/java/net/knarcraft/minigames/util/InputValidationHelper.java b/src/main/java/net/knarcraft/minigames/util/InputValidationHelper.java index 9e68afd..ee841ca 100644 --- a/src/main/java/net/knarcraft/minigames/util/InputValidationHelper.java +++ b/src/main/java/net/knarcraft/minigames/util/InputValidationHelper.java @@ -2,6 +2,8 @@ package net.knarcraft.minigames.util; import org.bukkit.Location; import org.bukkit.World; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * A helper class for validating whether given input is valid @@ -18,9 +20,23 @@ public final class InputValidationHelper { * @param locationThe location to validate
* @returnFalse if the location is valid
*/ - public static boolean isInvalid(Location location) { + public static boolean isInvalid(@Nullable Location location) { + if (location == null) { + return true; + } World world = location.getWorld(); return world == null || !world.getWorldBorder().isInside(location); } + /** + * Checks whether the given value can be considered "empty" + * + * @param valueThe value to check
+ * @returnTrue if the value can be considered as empty
+ */ + public static boolean isEmptyValue(@NotNull String value) { + return value.equalsIgnoreCase("null") || value.equalsIgnoreCase("0") || + value.equalsIgnoreCase("clear") || value.equalsIgnoreCase("none"); + } + } diff --git a/src/main/java/net/knarcraft/minigames/util/TabCompleteHelper.java b/src/main/java/net/knarcraft/minigames/util/TabCompleteHelper.java index 213b515..9d46c0b 100644 --- a/src/main/java/net/knarcraft/minigames/util/TabCompleteHelper.java +++ b/src/main/java/net/knarcraft/minigames/util/TabCompleteHelper.java @@ -36,7 +36,8 @@ public final class TabCompleteHelper { * * @returnAll arena names
*/ - public static @NotNull ListAll arena names
*/ - public static @NotNull ListAll arena names
*/ - private static @NotNull ListAll arena properties
*/ - public static @NotNull ListAll arena properties
*/ - public static @NotNull ListThe property type to get suggestions for
* @returnThe suggestions produced
*/ - public static ListA list of suggestions
*/ + @NotNull private static ListA list of suggestions
*/ + @NotNull private static ListA list of suggestions
*/ + @NotNull private static ListA list of suggestions
*/ + @NotNull private static ListA list of suggestions
*/ + @NotNull private static ListA list of suggestions
*/ + @NotNull private static ListA list of suggestions
*/ + @NotNull private static ListA list of suggestions
*/ + @NotNull private static ListThe full permission node typed by the player
* @returnAll known valid auto-complete options
*/ - public static ListThe permission to load
*/ - private static void loadPermission(String permissionName) { + private static void loadPermission(@NotNull String permissionName) { String[] permissionParts = permissionName.split("\\."); if (permissionParts.length == 1 && !plugins.contains(permissionParts[0])) { plugins.add(permissionParts[0]);