Added types
This commit is contained in:
parent
30c775d0e3
commit
6060cbb995
17 changed files with 131 additions and 56 deletions
|
@ -3,6 +3,7 @@ package nl.iobyte.commandapi;
|
||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
||||||
import nl.iobyte.commandapi.interfaces.ICommandMiddleware;
|
import nl.iobyte.commandapi.interfaces.ICommandMiddleware;
|
||||||
|
import nl.iobyte.commandapi.objects.ArgumentCheck;
|
||||||
import nl.iobyte.commandapi.objects.CommandMap;
|
import nl.iobyte.commandapi.objects.CommandMap;
|
||||||
import nl.iobyte.commandapi.objects.CommandSyntax;
|
import nl.iobyte.commandapi.objects.CommandSyntax;
|
||||||
import nl.iobyte.commandapi.interfaces.SubCommand;
|
import nl.iobyte.commandapi.interfaces.SubCommand;
|
||||||
|
@ -111,7 +112,7 @@ public class CommandFactory implements CommandExecutor {
|
||||||
//Pre assign variables
|
//Pre assign variables
|
||||||
boolean b;
|
boolean b;
|
||||||
String str = null;
|
String str = null;
|
||||||
Pair<Boolean, Integer> pair;
|
ArgumentCheck pair;
|
||||||
List<ICommandArgument<?>> arguments;
|
List<ICommandArgument<?>> arguments;
|
||||||
List<Object> parsedArguments;
|
List<Object> parsedArguments;
|
||||||
List<CommandSyntax> syntaxList = subCommand.getApplicableSyntaxList(sender);
|
List<CommandSyntax> syntaxList = subCommand.getApplicableSyntaxList(sender);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.iobyte.commandapi.arguments;
|
package nl.iobyte.commandapi.arguments;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
|
||||||
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
||||||
|
import nl.iobyte.commandapi.objects.ArgumentCheck;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,13 +23,13 @@ public class BooleanArgument implements ICommandArgument<Boolean> {
|
||||||
* @param previousArguments Previous arguments
|
* @param previousArguments Previous arguments
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
public Pair<Boolean, Integer> checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
public ArgumentCheck checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "true":
|
case "true":
|
||||||
case "false":
|
case "false":
|
||||||
return new Pair<>(true, 1);
|
return new ArgumentCheck(true, 1);
|
||||||
default:
|
default:
|
||||||
return new Pair<>(false, 0);
|
return new ArgumentCheck(false, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.iobyte.commandapi.arguments;
|
package nl.iobyte.commandapi.arguments;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
|
||||||
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
||||||
|
import nl.iobyte.commandapi.objects.ArgumentCheck;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -30,8 +30,8 @@ public class EnumArgument implements ICommandArgument<Enum<?>> {
|
||||||
* @param previousArguments Previous arguments
|
* @param previousArguments Previous arguments
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
public Pair<Boolean, Integer> checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
public ArgumentCheck checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
||||||
return new Pair<>(Arrays.stream(validArgumentHolders).map(Enum::toString).anyMatch(args[0]::equalsIgnoreCase), 1);
|
return new ArgumentCheck(Arrays.stream(validArgumentHolders).map(Enum::toString).anyMatch(args[0]::equalsIgnoreCase), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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<Enum<?>> {
|
||||||
|
|
||||||
|
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<Object> 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<Object> previousArguments) {
|
||||||
|
return Material.getMaterial(args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,8 +1,7 @@
|
||||||
package nl.iobyte.commandapi.arguments;
|
package nl.iobyte.commandapi.arguments;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
|
||||||
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
||||||
import org.bukkit.ChatColor;
|
import nl.iobyte.commandapi.objects.ArgumentCheck;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -23,15 +22,15 @@ public class MessageArgument implements ICommandArgument<String> {
|
||||||
* @param previousArguments Previous arguments
|
* @param previousArguments Previous arguments
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
public Pair<Boolean, Integer> checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
public ArgumentCheck checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
||||||
if(!args[0].startsWith("\""))
|
if(!args[0].startsWith("\""))
|
||||||
return new Pair<>(true, 1);
|
return new ArgumentCheck(true, 1);
|
||||||
|
|
||||||
for(int i = 1; i < args.length; i++)
|
for(int i = 1; i < args.length; i++)
|
||||||
if(args[i].endsWith("\""))
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.iobyte.commandapi.arguments;
|
package nl.iobyte.commandapi.arguments;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
|
||||||
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
||||||
|
import nl.iobyte.commandapi.objects.ArgumentCheck;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -25,8 +25,8 @@ public class PlayerArgument implements ICommandArgument<Player> {
|
||||||
* @param previousArguments Previous arguments
|
* @param previousArguments Previous arguments
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
public Pair<Boolean, Integer> checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
public ArgumentCheck checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
||||||
return new Pair<>(Bukkit.getPlayer(args[0]) != null, 1);
|
return new ArgumentCheck(Bukkit.getPlayer(args[0]) != null, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.iobyte.commandapi.arguments;
|
package nl.iobyte.commandapi.arguments;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
|
||||||
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
||||||
|
import nl.iobyte.commandapi.objects.ArgumentCheck;
|
||||||
import nl.iobyte.commandapi.objects.SpigotPlayerSelector;
|
import nl.iobyte.commandapi.objects.SpigotPlayerSelector;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -25,9 +25,9 @@ public class PlayersArgument implements ICommandArgument<List<Player>> {
|
||||||
* @param previousArguments Previous arguments
|
* @param previousArguments Previous arguments
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
public Pair<Boolean, Integer> checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
public ArgumentCheck checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
||||||
List<Player> players = new SpigotPlayerSelector(args[0]).getPlayers(sender);
|
List<Player> players = new SpigotPlayerSelector(args[0]).getPlayers(sender);
|
||||||
return new Pair<>(players != null && !players.isEmpty(), 1);
|
return new ArgumentCheck(players != null && !players.isEmpty(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.iobyte.commandapi.arguments;
|
package nl.iobyte.commandapi.arguments;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
|
||||||
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
||||||
|
import nl.iobyte.commandapi.objects.ArgumentCheck;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -30,11 +30,11 @@ public class StringArgument implements ICommandArgument<String> {
|
||||||
* @param previousArguments Previous arguments
|
* @param previousArguments Previous arguments
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
public Pair<Boolean, Integer> checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
public ArgumentCheck checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
||||||
if(validArguments == null || validArguments.length == 0)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.iobyte.commandapi.arguments.array;
|
package nl.iobyte.commandapi.arguments.array;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
|
||||||
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
||||||
|
import nl.iobyte.commandapi.objects.ArgumentCheck;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -17,15 +17,15 @@ public class IntegerArrayArgument implements ICommandArgument<Integer[]> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Boolean, Integer> checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
public ArgumentCheck checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
||||||
String[] items = args[0].replace("[", "").replace("]", "").split(",");
|
String[] items = args[0].replace("[", "").replace("]", "").split(",");
|
||||||
try {
|
try {
|
||||||
for(String item : items)
|
for(String item : items)
|
||||||
Integer.parseInt(item);
|
Integer.parseInt(item);
|
||||||
|
|
||||||
return new Pair<>(true, 1);
|
return new ArgumentCheck(true, 1);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new Pair<>(false, 0);
|
return new ArgumentCheck(false, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.iobyte.commandapi.arguments.array;
|
package nl.iobyte.commandapi.arguments.array;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
|
||||||
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
||||||
|
import nl.iobyte.commandapi.objects.ArgumentCheck;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -17,11 +17,11 @@ public class StringArrayArgument implements ICommandArgument<String[]> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Boolean, Integer> checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
public ArgumentCheck checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
||||||
if(!args[0].startsWith("[\"") || !args[0].endsWith("\"]"))
|
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
|
@Override
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package nl.iobyte.commandapi.arguments.number;
|
package nl.iobyte.commandapi.arguments.number;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
|
||||||
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
||||||
|
import nl.iobyte.commandapi.objects.ArgumentCheck;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DoubleArgument implements ICommandArgument<Double> {
|
public class DoubleArgument implements ICommandArgument<Double> {
|
||||||
|
@ -24,12 +23,12 @@ public class DoubleArgument implements ICommandArgument<Double> {
|
||||||
* @param previousArguments Previous arguments
|
* @param previousArguments Previous arguments
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
public Pair<Boolean, Integer> checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
public ArgumentCheck checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
||||||
try {
|
try {
|
||||||
Double.parseDouble(args[0]);
|
Double.parseDouble(args[0]);
|
||||||
return new Pair<>(true, 1);
|
return new ArgumentCheck(true, 1);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new Pair<>(false, 0);
|
return new ArgumentCheck(false, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.iobyte.commandapi.arguments.number;
|
package nl.iobyte.commandapi.arguments.number;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
|
||||||
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
||||||
|
import nl.iobyte.commandapi.objects.ArgumentCheck;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,12 +23,12 @@ public class FloatArgument implements ICommandArgument<Float> {
|
||||||
* @param previousArguments Previous arguments
|
* @param previousArguments Previous arguments
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
public Pair<Boolean, Integer> checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
public ArgumentCheck checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
||||||
try {
|
try {
|
||||||
Float.parseFloat(args[0]);
|
Float.parseFloat(args[0]);
|
||||||
return new Pair<>(true, 1);
|
return new ArgumentCheck(true, 1);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new Pair<>(false, 0);
|
return new ArgumentCheck(false, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.iobyte.commandapi.arguments.number;
|
package nl.iobyte.commandapi.arguments.number;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
|
||||||
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
||||||
|
import nl.iobyte.commandapi.objects.ArgumentCheck;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,12 +23,12 @@ public class IntegerArgument implements ICommandArgument<Integer> {
|
||||||
* @param previousArguments Previous arguments
|
* @param previousArguments Previous arguments
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
public Pair<Boolean, Integer> checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
public ArgumentCheck checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
||||||
try {
|
try {
|
||||||
Integer.parseInt(args[0]);
|
Integer.parseInt(args[0]);
|
||||||
return new Pair<>(true, 1);
|
return new ArgumentCheck(true, 1);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new Pair<>(false, 0);
|
return new ArgumentCheck(false, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.iobyte.commandapi.arguments.number;
|
package nl.iobyte.commandapi.arguments.number;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
|
||||||
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
||||||
|
import nl.iobyte.commandapi.objects.ArgumentCheck;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,12 +23,12 @@ public class LongArgument implements ICommandArgument<Long> {
|
||||||
* @param previousArguments Previous arguments
|
* @param previousArguments Previous arguments
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
public Pair<Boolean, Integer> checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
public ArgumentCheck checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
||||||
try {
|
try {
|
||||||
Long.parseLong(args[0]);
|
Long.parseLong(args[0]);
|
||||||
return new Pair<>(true, 1);
|
return new ArgumentCheck(true, 1);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new Pair<>(false, 0);
|
return new ArgumentCheck(false, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.iobyte.commandapi.arguments.number;
|
package nl.iobyte.commandapi.arguments.number;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
|
||||||
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
import nl.iobyte.commandapi.interfaces.ICommandArgument;
|
||||||
|
import nl.iobyte.commandapi.objects.ArgumentCheck;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,12 +23,12 @@ public class ShortArgument implements ICommandArgument<Short> {
|
||||||
* @param previousArguments Previous arguments
|
* @param previousArguments Previous arguments
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
public Pair<Boolean, Integer> checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
public ArgumentCheck checkArgument(CommandSender sender, String[] args, List<Object> previousArguments) {
|
||||||
try {
|
try {
|
||||||
Short.parseShort(args[0]);
|
Short.parseShort(args[0]);
|
||||||
return new Pair<>(true, 1);
|
return new ArgumentCheck(true, 1);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new Pair<>(false, 0);
|
return new ArgumentCheck(false, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package nl.iobyte.commandapi.interfaces;
|
package nl.iobyte.commandapi.interfaces;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
import nl.iobyte.commandapi.objects.ArgumentCheck;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@ public interface ICommandArgument<T> {
|
||||||
* @param sender CommandSender
|
* @param sender CommandSender
|
||||||
* @param args Arguments passed by Command
|
* @param args Arguments passed by Command
|
||||||
* @param previousArguments Previous arguments
|
* @param previousArguments Previous arguments
|
||||||
* @return Pair<Boolean, Integer>
|
* @return ArgumentCheck
|
||||||
*/
|
*/
|
||||||
Pair<Boolean, Integer> checkArgument(CommandSender sender, String[] args, List<Object> previousArguments);
|
ArgumentCheck checkArgument(CommandSender sender, String[] args, List<Object> previousArguments);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get object of argument
|
* Get object of argument
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue