diff --git a/src/main/java/nl/iobyte/commandapi/CommandFactory.java b/src/main/java/nl/iobyte/commandapi/CommandFactory.java index 7fc6715..5fde1fa 100644 --- a/src/main/java/nl/iobyte/commandapi/CommandFactory.java +++ b/src/main/java/nl/iobyte/commandapi/CommandFactory.java @@ -3,6 +3,7 @@ package nl.iobyte.commandapi; import javafx.util.Pair; import nl.iobyte.commandapi.interfaces.ICommandArgument; import nl.iobyte.commandapi.interfaces.ICommandMiddleware; +import nl.iobyte.commandapi.objects.ArgumentCheck; import nl.iobyte.commandapi.objects.CommandMap; import nl.iobyte.commandapi.objects.CommandSyntax; import nl.iobyte.commandapi.interfaces.SubCommand; @@ -111,7 +112,7 @@ public class CommandFactory implements CommandExecutor { //Pre assign variables boolean b; String str = null; - Pair pair; + ArgumentCheck pair; List> arguments; List parsedArguments; List syntaxList = subCommand.getApplicableSyntaxList(sender); diff --git a/src/main/java/nl/iobyte/commandapi/arguments/BooleanArgument.java b/src/main/java/nl/iobyte/commandapi/arguments/BooleanArgument.java index 3dfad77..c886de4 100644 --- a/src/main/java/nl/iobyte/commandapi/arguments/BooleanArgument.java +++ b/src/main/java/nl/iobyte/commandapi/arguments/BooleanArgument.java @@ -1,7 +1,7 @@ package nl.iobyte.commandapi.arguments; -import javafx.util.Pair; import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.objects.ArgumentCheck; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import java.util.List; @@ -23,13 +23,13 @@ public class BooleanArgument implements ICommandArgument { * @param previousArguments Previous arguments * @return Boolean */ - public Pair checkArgument(CommandSender sender, String[] args, List previousArguments) { + public ArgumentCheck checkArgument(CommandSender sender, String[] args, List previousArguments) { switch (args[0].toLowerCase()) { case "true": case "false": - return new Pair<>(true, 1); + return new ArgumentCheck(true, 1); default: - return new Pair<>(false, 0); + return new ArgumentCheck(false, 0); } } diff --git a/src/main/java/nl/iobyte/commandapi/arguments/EnumArgument.java b/src/main/java/nl/iobyte/commandapi/arguments/EnumArgument.java index 6d31a37..4aca067 100644 --- a/src/main/java/nl/iobyte/commandapi/arguments/EnumArgument.java +++ b/src/main/java/nl/iobyte/commandapi/arguments/EnumArgument.java @@ -1,7 +1,7 @@ package nl.iobyte.commandapi.arguments; -import javafx.util.Pair; import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.objects.ArgumentCheck; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import java.util.Arrays; @@ -30,8 +30,8 @@ public class EnumArgument implements ICommandArgument> { * @param previousArguments Previous arguments * @return Boolean */ - public Pair checkArgument(CommandSender sender, String[] args, List previousArguments) { - return new Pair<>(Arrays.stream(validArgumentHolders).map(Enum::toString).anyMatch(args[0]::equalsIgnoreCase), 1); + public ArgumentCheck checkArgument(CommandSender sender, String[] args, List previousArguments) { + return new ArgumentCheck(Arrays.stream(validArgumentHolders).map(Enum::toString).anyMatch(args[0]::equalsIgnoreCase), 1); } /** diff --git a/src/main/java/nl/iobyte/commandapi/arguments/MaterialArgument.java b/src/main/java/nl/iobyte/commandapi/arguments/MaterialArgument.java new file mode 100644 index 0000000..62b35cd --- /dev/null +++ b/src/main/java/nl/iobyte/commandapi/arguments/MaterialArgument.java @@ -0,0 +1,55 @@ +package nl.iobyte.commandapi.arguments; + +import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.objects.ArgumentCheck; +import org.bukkit.Material; +import org.bukkit.command.CommandSender; +import java.util.Arrays; +import java.util.List; + +public class MaterialArgument implements ICommandArgument> { + + private final Material[] validArgumentHolders; + + public MaterialArgument(Material... validArgumentHolders) { + this.validArgumentHolders = validArgumentHolders; + } + + /** + * Message to display when giving an error + * @return String + */ + public String getMessage(String[] args) { + return "No material with name: "+args[0]; + } + + /** + * Check if argument is valid Material + * @param sender CommandSender + * @param args Arguments passed by Command + * @param previousArguments Previous arguments + * @return Boolean + */ + public ArgumentCheck checkArgument(CommandSender sender, String[] args, List previousArguments) { + Material material = Material.getMaterial(args[0]); + if(material == null) + return new ArgumentCheck(false, 0); + + if(validArgumentHolders == null || validArgumentHolders.length == 0) + return new ArgumentCheck(true, 1); + + return new ArgumentCheck(Arrays.stream(validArgumentHolders).anyMatch(m -> m == material), 1); + } + + /** + * Get Material passed by command + * @param sender CommandSender + * @param args Arguments passed by Command + * @param previousArguments Previous arguments + * @return Material + */ + public Material getArgument(CommandSender sender, String[] args, List previousArguments) { + return Material.getMaterial(args[0]); + } + +} diff --git a/src/main/java/nl/iobyte/commandapi/arguments/MessageArgument.java b/src/main/java/nl/iobyte/commandapi/arguments/MessageArgument.java index 6ec73bd..bb9df1e 100644 --- a/src/main/java/nl/iobyte/commandapi/arguments/MessageArgument.java +++ b/src/main/java/nl/iobyte/commandapi/arguments/MessageArgument.java @@ -1,8 +1,7 @@ package nl.iobyte.commandapi.arguments; -import javafx.util.Pair; import nl.iobyte.commandapi.interfaces.ICommandArgument; -import org.bukkit.ChatColor; +import nl.iobyte.commandapi.objects.ArgumentCheck; import org.bukkit.command.CommandSender; import java.util.List; @@ -23,15 +22,15 @@ public class MessageArgument implements ICommandArgument { * @param previousArguments Previous arguments * @return Boolean */ - public Pair checkArgument(CommandSender sender, String[] args, List previousArguments) { + public ArgumentCheck checkArgument(CommandSender sender, String[] args, List previousArguments) { if(!args[0].startsWith("\"")) - return new Pair<>(true, 1); + return new ArgumentCheck(true, 1); for(int i = 1; i < args.length; i++) if(args[i].endsWith("\"")) - return new Pair<>(true, i + 1); + return new ArgumentCheck(true, i + 1); - return new Pair<>(true, args.length); + return new ArgumentCheck(true, args.length); } /** diff --git a/src/main/java/nl/iobyte/commandapi/arguments/PlayerArgument.java b/src/main/java/nl/iobyte/commandapi/arguments/PlayerArgument.java index 24d1bf8..0805896 100644 --- a/src/main/java/nl/iobyte/commandapi/arguments/PlayerArgument.java +++ b/src/main/java/nl/iobyte/commandapi/arguments/PlayerArgument.java @@ -1,7 +1,7 @@ package nl.iobyte.commandapi.arguments; -import javafx.util.Pair; import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.objects.ArgumentCheck; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -25,8 +25,8 @@ public class PlayerArgument implements ICommandArgument { * @param previousArguments Previous arguments * @return Boolean */ - public Pair checkArgument(CommandSender sender, String[] args, List previousArguments) { - return new Pair<>(Bukkit.getPlayer(args[0]) != null, 1); + public ArgumentCheck checkArgument(CommandSender sender, String[] args, List previousArguments) { + return new ArgumentCheck(Bukkit.getPlayer(args[0]) != null, 1); } /** diff --git a/src/main/java/nl/iobyte/commandapi/arguments/PlayersArgument.java b/src/main/java/nl/iobyte/commandapi/arguments/PlayersArgument.java index 57df97e..3e20dfc 100644 --- a/src/main/java/nl/iobyte/commandapi/arguments/PlayersArgument.java +++ b/src/main/java/nl/iobyte/commandapi/arguments/PlayersArgument.java @@ -1,7 +1,7 @@ package nl.iobyte.commandapi.arguments; -import javafx.util.Pair; import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.objects.ArgumentCheck; import nl.iobyte.commandapi.objects.SpigotPlayerSelector; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -25,9 +25,9 @@ public class PlayersArgument implements ICommandArgument> { * @param previousArguments Previous arguments * @return Boolean */ - public Pair checkArgument(CommandSender sender, String[] args, List previousArguments) { + public ArgumentCheck checkArgument(CommandSender sender, String[] args, List previousArguments) { List players = new SpigotPlayerSelector(args[0]).getPlayers(sender); - return new Pair<>(players != null && !players.isEmpty(), 1); + return new ArgumentCheck(players != null && !players.isEmpty(), 1); } /** diff --git a/src/main/java/nl/iobyte/commandapi/arguments/StringArgument.java b/src/main/java/nl/iobyte/commandapi/arguments/StringArgument.java index b1eeb0a..8219472 100644 --- a/src/main/java/nl/iobyte/commandapi/arguments/StringArgument.java +++ b/src/main/java/nl/iobyte/commandapi/arguments/StringArgument.java @@ -1,7 +1,7 @@ package nl.iobyte.commandapi.arguments; -import javafx.util.Pair; import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.objects.ArgumentCheck; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import java.util.Arrays; @@ -30,11 +30,11 @@ public class StringArgument implements ICommandArgument { * @param previousArguments Previous arguments * @return Boolean */ - public Pair checkArgument(CommandSender sender, String[] args, List previousArguments) { + public ArgumentCheck checkArgument(CommandSender sender, String[] args, List previousArguments) { if(validArguments == null || validArguments.length == 0) - return new Pair<>(true, 1); + return new ArgumentCheck(true, 1); - return new Pair<>(Arrays.stream(validArguments).anyMatch(args[0]::equalsIgnoreCase), 1); + return new ArgumentCheck(Arrays.stream(validArguments).anyMatch(args[0]::equalsIgnoreCase), 1); } /** diff --git a/src/main/java/nl/iobyte/commandapi/arguments/array/IntegerArrayArgument.java b/src/main/java/nl/iobyte/commandapi/arguments/array/IntegerArrayArgument.java index 7079098..3c1bed9 100644 --- a/src/main/java/nl/iobyte/commandapi/arguments/array/IntegerArrayArgument.java +++ b/src/main/java/nl/iobyte/commandapi/arguments/array/IntegerArrayArgument.java @@ -1,7 +1,7 @@ package nl.iobyte.commandapi.arguments.array; -import javafx.util.Pair; import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.objects.ArgumentCheck; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import java.util.List; @@ -17,15 +17,15 @@ public class IntegerArrayArgument implements ICommandArgument { } @Override - public Pair checkArgument(CommandSender sender, String[] args, List previousArguments) { + public ArgumentCheck checkArgument(CommandSender sender, String[] args, List previousArguments) { String[] items = args[0].replace("[", "").replace("]", "").split(","); try { for(String item : items) Integer.parseInt(item); - return new Pair<>(true, 1); + return new ArgumentCheck(true, 1); } catch (Exception e) { - return new Pair<>(false, 0); + return new ArgumentCheck(false, 0); } } diff --git a/src/main/java/nl/iobyte/commandapi/arguments/array/StringArrayArgument.java b/src/main/java/nl/iobyte/commandapi/arguments/array/StringArrayArgument.java index 042a61a..cb79b82 100644 --- a/src/main/java/nl/iobyte/commandapi/arguments/array/StringArrayArgument.java +++ b/src/main/java/nl/iobyte/commandapi/arguments/array/StringArrayArgument.java @@ -1,7 +1,7 @@ package nl.iobyte.commandapi.arguments.array; -import javafx.util.Pair; import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.objects.ArgumentCheck; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import java.util.List; @@ -17,11 +17,11 @@ public class StringArrayArgument implements ICommandArgument { } @Override - public Pair checkArgument(CommandSender sender, String[] args, List previousArguments) { + public ArgumentCheck checkArgument(CommandSender sender, String[] args, List previousArguments) { if(!args[0].startsWith("[\"") || !args[0].endsWith("\"]")) - return new Pair<>(false, 0); + return new ArgumentCheck(false, 0); - return new Pair<>(true, 1); + return new ArgumentCheck(true, 1); } @Override diff --git a/src/main/java/nl/iobyte/commandapi/arguments/number/DoubleArgument.java b/src/main/java/nl/iobyte/commandapi/arguments/number/DoubleArgument.java index cae705a..84ad511 100644 --- a/src/main/java/nl/iobyte/commandapi/arguments/number/DoubleArgument.java +++ b/src/main/java/nl/iobyte/commandapi/arguments/number/DoubleArgument.java @@ -1,10 +1,9 @@ package nl.iobyte.commandapi.arguments.number; -import javafx.util.Pair; import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.objects.ArgumentCheck; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; - import java.util.List; public class DoubleArgument implements ICommandArgument { @@ -24,12 +23,12 @@ public class DoubleArgument implements ICommandArgument { * @param previousArguments Previous arguments * @return Boolean */ - public Pair checkArgument(CommandSender sender, String[] args, List previousArguments) { + public ArgumentCheck checkArgument(CommandSender sender, String[] args, List previousArguments) { try { Double.parseDouble(args[0]); - return new Pair<>(true, 1); + return new ArgumentCheck(true, 1); } catch (Exception e) { - return new Pair<>(false, 0); + return new ArgumentCheck(false, 0); } } diff --git a/src/main/java/nl/iobyte/commandapi/arguments/number/FloatArgument.java b/src/main/java/nl/iobyte/commandapi/arguments/number/FloatArgument.java index 601a22b..7f3e600 100644 --- a/src/main/java/nl/iobyte/commandapi/arguments/number/FloatArgument.java +++ b/src/main/java/nl/iobyte/commandapi/arguments/number/FloatArgument.java @@ -1,7 +1,7 @@ package nl.iobyte.commandapi.arguments.number; -import javafx.util.Pair; import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.objects.ArgumentCheck; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import java.util.List; @@ -23,12 +23,12 @@ public class FloatArgument implements ICommandArgument { * @param previousArguments Previous arguments * @return Boolean */ - public Pair checkArgument(CommandSender sender, String[] args, List previousArguments) { + public ArgumentCheck checkArgument(CommandSender sender, String[] args, List previousArguments) { try { Float.parseFloat(args[0]); - return new Pair<>(true, 1); + return new ArgumentCheck(true, 1); } catch (Exception e) { - return new Pair<>(false, 0); + return new ArgumentCheck(false, 0); } } diff --git a/src/main/java/nl/iobyte/commandapi/arguments/number/IntegerArgument.java b/src/main/java/nl/iobyte/commandapi/arguments/number/IntegerArgument.java index 181be6d..da6935d 100644 --- a/src/main/java/nl/iobyte/commandapi/arguments/number/IntegerArgument.java +++ b/src/main/java/nl/iobyte/commandapi/arguments/number/IntegerArgument.java @@ -1,7 +1,7 @@ package nl.iobyte.commandapi.arguments.number; -import javafx.util.Pair; import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.objects.ArgumentCheck; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import java.util.List; @@ -23,12 +23,12 @@ public class IntegerArgument implements ICommandArgument { * @param previousArguments Previous arguments * @return Boolean */ - public Pair checkArgument(CommandSender sender, String[] args, List previousArguments) { + public ArgumentCheck checkArgument(CommandSender sender, String[] args, List previousArguments) { try { Integer.parseInt(args[0]); - return new Pair<>(true, 1); + return new ArgumentCheck(true, 1); } catch (Exception e) { - return new Pair<>(false, 0); + return new ArgumentCheck(false, 0); } } diff --git a/src/main/java/nl/iobyte/commandapi/arguments/number/LongArgument.java b/src/main/java/nl/iobyte/commandapi/arguments/number/LongArgument.java index b252952..0f3e9f0 100644 --- a/src/main/java/nl/iobyte/commandapi/arguments/number/LongArgument.java +++ b/src/main/java/nl/iobyte/commandapi/arguments/number/LongArgument.java @@ -1,7 +1,7 @@ package nl.iobyte.commandapi.arguments.number; -import javafx.util.Pair; import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.objects.ArgumentCheck; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import java.util.List; @@ -23,12 +23,12 @@ public class LongArgument implements ICommandArgument { * @param previousArguments Previous arguments * @return Boolean */ - public Pair checkArgument(CommandSender sender, String[] args, List previousArguments) { + public ArgumentCheck checkArgument(CommandSender sender, String[] args, List previousArguments) { try { Long.parseLong(args[0]); - return new Pair<>(true, 1); + return new ArgumentCheck(true, 1); } catch (Exception e) { - return new Pair<>(false, 0); + return new ArgumentCheck(false, 0); } } diff --git a/src/main/java/nl/iobyte/commandapi/arguments/number/ShortArgument.java b/src/main/java/nl/iobyte/commandapi/arguments/number/ShortArgument.java index 7323231..079f2d2 100644 --- a/src/main/java/nl/iobyte/commandapi/arguments/number/ShortArgument.java +++ b/src/main/java/nl/iobyte/commandapi/arguments/number/ShortArgument.java @@ -1,7 +1,7 @@ package nl.iobyte.commandapi.arguments.number; -import javafx.util.Pair; import nl.iobyte.commandapi.interfaces.ICommandArgument; +import nl.iobyte.commandapi.objects.ArgumentCheck; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import java.util.List; @@ -23,12 +23,12 @@ public class ShortArgument implements ICommandArgument { * @param previousArguments Previous arguments * @return Boolean */ - public Pair checkArgument(CommandSender sender, String[] args, List previousArguments) { + public ArgumentCheck checkArgument(CommandSender sender, String[] args, List previousArguments) { try { Short.parseShort(args[0]); - return new Pair<>(true, 1); + return new ArgumentCheck(true, 1); } catch (Exception e) { - return new Pair<>(false, 0); + return new ArgumentCheck(false, 0); } } diff --git a/src/main/java/nl/iobyte/commandapi/interfaces/ICommandArgument.java b/src/main/java/nl/iobyte/commandapi/interfaces/ICommandArgument.java index 5e2f11f..b0fd7e8 100644 --- a/src/main/java/nl/iobyte/commandapi/interfaces/ICommandArgument.java +++ b/src/main/java/nl/iobyte/commandapi/interfaces/ICommandArgument.java @@ -1,6 +1,6 @@ package nl.iobyte.commandapi.interfaces; -import javafx.util.Pair; +import nl.iobyte.commandapi.objects.ArgumentCheck; import org.bukkit.command.CommandSender; import java.util.List; @@ -17,9 +17,9 @@ public interface ICommandArgument { * @param sender CommandSender * @param args Arguments passed by Command * @param previousArguments Previous arguments - * @return Pair + * @return ArgumentCheck */ - Pair checkArgument(CommandSender sender, String[] args, List previousArguments); + ArgumentCheck checkArgument(CommandSender sender, String[] args, List previousArguments); /** * Get object of argument diff --git a/src/main/java/nl/iobyte/commandapi/objects/ArgumentCheck.java b/src/main/java/nl/iobyte/commandapi/objects/ArgumentCheck.java new file mode 100644 index 0000000..9f9e1fc --- /dev/null +++ b/src/main/java/nl/iobyte/commandapi/objects/ArgumentCheck.java @@ -0,0 +1,21 @@ +package nl.iobyte.commandapi.objects; + +public class ArgumentCheck { + + private final boolean key; + private final int value; + + public ArgumentCheck(boolean key, int value) { + this.key = key; + this.value = value; + } + + public boolean getKey() { + return key; + } + + public int getValue() { + return value; + } + +}