mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2025-01-18 19:25:26 +01:00
Fixes #36
This commit is contained in:
parent
d124c0948b
commit
a1f76bcfc2
@ -263,7 +263,7 @@ public class DropperArena implements Arena {
|
||||
* @param newLocation <p>The new spawn location</p>
|
||||
* @return <p>True if successfully updated</p>
|
||||
*/
|
||||
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 newLocation <p>The new exit location</p>
|
||||
* @return <p>True if successfully updated</p>
|
||||
*/
|
||||
public boolean setExitLocation(@NotNull Location newLocation) {
|
||||
public boolean setExitLocation(@Nullable Location newLocation) {
|
||||
if (isInvalid(newLocation)) {
|
||||
return false;
|
||||
} else {
|
||||
|
@ -356,7 +356,7 @@ public class ParkourArena implements Arena {
|
||||
* @param newLocation <p>The new spawn location</p>
|
||||
* @return <p>True if successfully updated</p>
|
||||
*/
|
||||
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 newLocation <p>The new exit location</p>
|
||||
* @return <p>True if successfully updated</p>
|
||||
*/
|
||||
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 newLocation <p>The location players have to reach</p>
|
||||
* @return <p>True if successfully changed</p>
|
||||
*/
|
||||
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 checkpoint <p>The checkpoint to add</p>
|
||||
* @return <p>True if successfully added</p>
|
||||
*/
|
||||
public boolean addCheckpoint(@NotNull Location checkpoint) {
|
||||
public boolean addCheckpoint(@Nullable Location checkpoint) {
|
||||
if (isInvalid(checkpoint)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -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 locationString <p>The location string to parse</p>
|
||||
* @return <p>The parsed location, or the player's location if not parse-able</p>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
@ -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 location <p>The location to validate</p>
|
||||
* @return <p>False if the location is valid</p>
|
||||
*/
|
||||
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 value <p>The value to check</p>
|
||||
* @return <p>True if the value can be considered as empty</p>
|
||||
*/
|
||||
public static boolean isEmptyValue(@NotNull String value) {
|
||||
return value.equalsIgnoreCase("null") || value.equalsIgnoreCase("0") ||
|
||||
value.equalsIgnoreCase("clear") || value.equalsIgnoreCase("none");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,7 +36,8 @@ public final class TabCompleteHelper {
|
||||
*
|
||||
* @return <p>All arena names</p>
|
||||
*/
|
||||
public static @NotNull List<String> getDropperArenas() {
|
||||
@NotNull
|
||||
public static List<String> getDropperArenas() {
|
||||
return getArenas(MiniGames.getInstance().getDropperArenaHandler());
|
||||
}
|
||||
|
||||
@ -45,7 +46,8 @@ public final class TabCompleteHelper {
|
||||
*
|
||||
* @return <p>All arena names</p>
|
||||
*/
|
||||
public static @NotNull List<String> getParkourArenas() {
|
||||
@NotNull
|
||||
public static List<String> getParkourArenas() {
|
||||
return getArenas(MiniGames.getInstance().getParkourArenaHandler());
|
||||
}
|
||||
|
||||
@ -54,7 +56,8 @@ public final class TabCompleteHelper {
|
||||
*
|
||||
* @return <p>All arena names</p>
|
||||
*/
|
||||
private static @NotNull List<String> getArenas(ArenaHandler<?, ?> arenaHandler) {
|
||||
@NotNull
|
||||
private static List<String> getArenas(@NotNull ArenaHandler<?, ?> arenaHandler) {
|
||||
List<String> arenaNames = new ArrayList<>();
|
||||
for (Arena arena : arenaHandler.getArenas().values()) {
|
||||
arenaNames.add(arena.getArenaName());
|
||||
@ -67,7 +70,8 @@ public final class TabCompleteHelper {
|
||||
*
|
||||
* @return <p>All arena properties</p>
|
||||
*/
|
||||
public static @NotNull List<String> getDropperArenaProperties() {
|
||||
@NotNull
|
||||
public static List<String> getDropperArenaProperties() {
|
||||
List<String> arenaProperties = new ArrayList<>();
|
||||
for (DropperArenaEditableProperty property : DropperArenaEditableProperty.values()) {
|
||||
arenaProperties.add(property.getArgumentString());
|
||||
@ -80,7 +84,8 @@ public final class TabCompleteHelper {
|
||||
*
|
||||
* @return <p>All arena properties</p>
|
||||
*/
|
||||
public static @NotNull List<String> getParkourArenaProperties() {
|
||||
@NotNull
|
||||
public static List<String> getParkourArenaProperties() {
|
||||
List<String> arenaProperties = new ArrayList<>();
|
||||
for (ParkourArenaEditableProperty property : ParkourArenaEditableProperty.values()) {
|
||||
arenaProperties.add(property.getArgumentString());
|
||||
@ -94,7 +99,8 @@ public final class TabCompleteHelper {
|
||||
* @param propertyType <p>The property type to get suggestions for</p>
|
||||
* @return <p>The suggestions produced</p>
|
||||
*/
|
||||
public static List<String> getTabCompleteSuggestions(EditablePropertyType propertyType) {
|
||||
@NotNull
|
||||
public static List<String> getTabCompleteSuggestions(@NotNull EditablePropertyType propertyType) {
|
||||
if (tabCompleteSuggestions == null) {
|
||||
tabCompleteSuggestions = new HashMap<>();
|
||||
tabCompleteSuggestions.put(EditablePropertyType.LOCATION, getLocationSuggestions());
|
||||
@ -115,6 +121,7 @@ public final class TabCompleteHelper {
|
||||
*
|
||||
* @return <p>A list of suggestions</p>
|
||||
*/
|
||||
@NotNull
|
||||
private static List<String> getDoubleSuggestions() {
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
suggestions.add("0");
|
||||
@ -133,6 +140,7 @@ public final class TabCompleteHelper {
|
||||
*
|
||||
* @return <p>A list of suggestions</p>
|
||||
*/
|
||||
@NotNull
|
||||
private static List<String> getMaterialListSuggestions() {
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
suggestions.add("LAVA,MAGMA_BLOCK");
|
||||
@ -146,6 +154,7 @@ public final class TabCompleteHelper {
|
||||
*
|
||||
* @return <p>A list of suggestions</p>
|
||||
*/
|
||||
@NotNull
|
||||
private static List<String> getCheckpointClearSuggestions() {
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
suggestions.add("true");
|
||||
@ -157,6 +166,7 @@ public final class TabCompleteHelper {
|
||||
*
|
||||
* @return <p>A list of suggestions</p>
|
||||
*/
|
||||
@NotNull
|
||||
private static List<String> getBlockTypeSuggestions() {
|
||||
List<String> materials = new ArrayList<>();
|
||||
for (Material material : Material.values()) {
|
||||
@ -172,6 +182,7 @@ public final class TabCompleteHelper {
|
||||
*
|
||||
* @return <p>A list of suggestions</p>
|
||||
*/
|
||||
@NotNull
|
||||
private static List<String> getVerticalVelocitySuggestions() {
|
||||
List<String> velocities = new ArrayList<>();
|
||||
velocities.add("0.01");
|
||||
@ -189,6 +200,7 @@ public final class TabCompleteHelper {
|
||||
*
|
||||
* @return <p>A list of suggestions</p>
|
||||
*/
|
||||
@NotNull
|
||||
private static List<String> getHorizontalVelocitySuggestions() {
|
||||
List<String> velocities = new ArrayList<>();
|
||||
velocities.add("0.01");
|
||||
@ -203,6 +215,7 @@ public final class TabCompleteHelper {
|
||||
*
|
||||
* @return <p>A list of suggestions</p>
|
||||
*/
|
||||
@NotNull
|
||||
private static List<String> getNameSuggestions() {
|
||||
List<String> locations = new ArrayList<>();
|
||||
locations.add("DropperArena1");
|
||||
@ -217,10 +230,12 @@ public final class TabCompleteHelper {
|
||||
*
|
||||
* @return <p>A list of suggestions</p>
|
||||
*/
|
||||
@NotNull
|
||||
private static List<String> getLocationSuggestions() {
|
||||
List<String> locations = new ArrayList<>();
|
||||
locations.add("here");
|
||||
locations.add("x,y,z");
|
||||
locations.add("null");
|
||||
return locations;
|
||||
}
|
||||
|
||||
@ -230,7 +245,8 @@ public final class TabCompleteHelper {
|
||||
* @param typedNode <p>The full permission node typed by the player</p>
|
||||
* @return <p>All known valid auto-complete options</p>
|
||||
*/
|
||||
public static List<String> tabCompletePermission(String typedNode) {
|
||||
@NotNull
|
||||
public static List<String> tabCompletePermission(@NotNull String typedNode) {
|
||||
if (plugins == null) {
|
||||
loadAvailablePermissions();
|
||||
}
|
||||
@ -268,7 +284,7 @@ public final class TabCompleteHelper {
|
||||
*
|
||||
* @param permissionName <p>The permission to load</p>
|
||||
*/
|
||||
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]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user