diff --git a/.gitignore b/.gitignore
index 0c26c98..47bb979 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,10 +1,8 @@
-target/
-#################
-## Eclipse
-#################
-*.pydevproject
-.project
+# Created by https://www.gitignore.io/api/git,java,maven,eclipse,netbeans,java-web,intellij,intellij+iml
+
+### Eclipse ###
+
.metadata
bin/
tmp/
@@ -13,9 +11,9 @@ tmp/
*.swp
*~.nib
local.properties
-.classpath
.settings/
.loadpath
+.recommenders
# External tool builders
.externalToolBuilders/
@@ -23,142 +21,193 @@ local.properties
# Locally stored "Eclipse launch configurations"
*.launch
-# CDT-specific
+# PyDev specific (Python IDE for Eclipse)
+*.pydevproject
+
+# CDT-specific (C/C++ Development Tooling)
.cproject
-# PDT-specific
+# Java annotation processor (APT)
+.factorypath
+
+# PDT-specific (PHP Development Tools)
.buildpath
+# sbteclipse plugin
+.target
-#################
-## Visual Studio
-#################
-
-## Ignore Visual Studio temporary files, build results, and
-## files generated by popular Visual Studio add-ons.
-
-# User-specific files
-*.suo
-*.user
-*.sln.docstates
-
-# Build results
-[Dd]ebug/
-[Rr]elease/
-*_i.c
-*_p.c
-*.ilk
-*.meta
-*.obj
-*.pch
-*.pdb
-*.pgc
-*.pgd
-*.rsp
-*.sbr
-*.tlb
-*.tli
-*.tlh
-*.tmp
-*.vspscc
-.builds
-*.dotCover
-
-## TODO: If you have NuGet Package Restore enabled, uncomment this
-#packages/
-
-# Visual C++ cache files
-ipch/
-*.aps
-*.ncb
-*.opensdf
-*.sdf
-
-# Visual Studio profiler
-*.psess
-*.vsp
-
-# ReSharper is a .NET coding add-in
-_ReSharper*
-
-# Installshield output folder
-[Ee]xpress
-
-# DocProject is a documentation generator add-in
-DocProject/buildhelp/
-DocProject/Help/*.HxT
-DocProject/Help/*.HxC
-DocProject/Help/*.hhc
-DocProject/Help/*.hhk
-DocProject/Help/*.hhp
-DocProject/Help/Html2
-DocProject/Help/html
-
-# Click-Once directory
-publish
-
-# Others
-[Bb]in
-[Oo]bj
-sql
-TestResults
-*.Cache
-ClientBin
-stylecop.*
-~$*
-*.dbmdl
-Generated_Code #added for RIA/Silverlight projects
-
-# Backup & report files from converting an old project file to a newer
-# Visual Studio version. Backup files are not needed, because we have git ;-)
-_UpgradeReport_Files/
-Backup*/
-UpgradeLog*.XML
-
-
-
-############
-## Windows
-############
-
-# Windows image file caches
-Thumbs.db
-
-# Folder config file
-Desktop.ini
-
-
-#############
-## Python
-#############
-
-*.py[co]
-
-# Packages
-*.egg
-*.egg-info
-dist
-build
-eggs
-parts
-bin
-var
-sdist
-develop-eggs
-.installed.cfg
-
-# Installer logs
-pip-log.txt
-
-# Unit test / coverage reports
-.coverage
-.tox
-
-#Translations
-*.mo
-
-#Mr Developer
-.mr.developer.cfg
-
-# Mac crap
-.DS_Store
+# Tern plugin
+.tern-project
+
+# TeXlipse plugin
+.texlipse
+
+# STS (Spring Tool Suite)
+.springBeans
+
+# Code Recommenders
+.recommenders/
+
+# Scala IDE specific (Scala & Java development for Eclipse)
+.cache-main
+.scala_dependencies
+.worksheet
+
+### Eclipse Patch ###
+# Eclipse Core
+.project
+
+# JDT-specific (Eclipse Java Development Tools)
+.classpath
+
+### Git ###
+*.orig
+
+### Intellij ###
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff:
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/dictionaries
+
+# Sensitive or high-churn files:
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.xml
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+
+# Gradle:
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# CMake
+cmake-build-debug/
+
+# Mongo Explorer plugin:
+.idea/**/mongoSettings.xml
+
+## File-based project format:
+*.iws
+
+## Plugin-specific files:
+
+# IntelliJ
+/out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+### Intellij Patch ###
+# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
+
+# *.iml
+# modules.xml
+# .idea/misc.xml
+# *.ipr
+
+# Sonarlint plugin
+.idea/sonarlint
+
+### Intellij+iml ###
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff:
+
+# Sensitive or high-churn files:
+
+# Gradle:
+
+# CMake
+
+# Mongo Explorer plugin:
+
+## File-based project format:
+
+## Plugin-specific files:
+
+# IntelliJ
+
+# mpeltonen/sbt-idea plugin
+
+# JIRA plugin
+
+# Cursive Clojure plugin
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+
+### Intellij+iml Patch ###
+# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
+
+*.iml
+modules.xml
+.idea/misc.xml
+*.ipr
+
+### Java ###
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+### Java-Web ###
+## ignoring target file
+target/
+
+### Maven ###
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+
+# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
+!/.mvn/wrapper/maven-wrapper.jar
+
+### NetBeans ###
+nbproject/private/
+build/
+nbbuild/
+dist/
+nbdist/
+.nb-gradle/
+
+# End of https://www.gitignore.io/api/git,java,maven,eclipse,netbeans,java-web,intellij,intellij+iml
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..6c1d822
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+methodcommand
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..ad94b52
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index b79a480..5bd8cfc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,77 +1,87 @@
-
- 4.0.0
- se.ranzdo.bukkit
- methodcommand
- 0.2-SNAPSHOT
- MethodCommand
-
-
-
- bukkit-repo
- http://repo.bukkit.org/content/groups/public/
-
-
-
-
-
- org.bukkit
- bukkit
- 1.4.5-R0.1
- provided
-
-
+
+ 4.0.0
+ se.ranzdo.bukkit
+ methodcommand
+ 1.0.1-SNAPSHOT
+ MethodCommand
+ jar
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- 2.1
-
-
-
- MethodCommand
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-source-plugin
-
-
- attach-sources
-
- jar
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
-
-
- attach-javadocs
-
- jar
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 2.0.2
-
- 1.6
- 1.6
-
-
-
-
-
+
+
+ spigot-repo
+ https://hub.spigotmc.org/nexus/content/groups/public/
+
+ true
+
+
+ true
+
+
+
+
+
+
+ org.spigotmc
+ spigot-api
+ 1.12-pre5-SNAPSHOT
+ jar
+ provided
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 3.0.2
+
+
+
+ MethodCommand
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 3.0.1
+
+
+ attach-sources
+
+ jar
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 2.10.4
+
+
+ attach-javadocs
+
+ jar
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.6.1
+
+ 1.8
+ 1.8
+
+
+
+
diff --git a/src/main/java/se/ranzdo/bukkit/methodcommand/Arg.java b/src/main/java/se/ranzdo/bukkit/methodcommand/Arg.java
index 0dbb515..3422b8d 100644
--- a/src/main/java/se/ranzdo/bukkit/methodcommand/Arg.java
+++ b/src/main/java/se/ranzdo/bukkit/methodcommand/Arg.java
@@ -8,26 +8,35 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface Arg {
- /**The default argument to process if the argument is not defined by the user. To make it a mandatory argument define it as a space " " (as it is default).
- * When this is combined with the {@link FlagArg} annotation the default argument will only be used if the flag is not defined by the user. Flags can't have default arguments.
- */
- String def() default " ";
-
- /**The description of this argument.
- */
- String description() default "";
-
- /**The short-name of this argument. This is what will show between the [] when this argument is described to the user.
- */
- String name();
-
- /**The verifiers is a way to verify the arguments before they even execute the command.
- * For example, if you would want a integer defined by the user but it isen't allowed to be greater than 10 you can use the max verifier.
- * {@code @Arg(name="example", verifiers="max[10]")}
- * If the user input is greater than 10, it will return an predefined error message to the user.
- * You can add multiple verifiers using the | between each.
- * {@code @Arg(name="example", verifiers="min[5]|max[10]")}
- * The verifiers differs from what class the parameter have. To check which verifiers are available, see the {@linkplain ArgumentHandler} for that class.
- */
- String verifiers() default "";
+ /**
+ * The default argument to process if the argument is not defined by the user. To make it a mandatory argument
+ * define it as a space " " (as it is default).
+ * When this is combined with the {@link FlagArg} annotation the default argument will only be used if the
+ * flag is not defined by the user. Flags can't have default arguments.
+ */
+ String def() default " ";
+
+ /**
+ * The description of this argument.
+ */
+ String description() default "";
+
+ /**
+ * The short-name of this argument. This is what will show between the [] when this argument is described to the
+ * user.
+ */
+ String name();
+
+ /**
+ * The verifiers is a way to verify the arguments before they even execute the command.
+ * For example, if you would want a integer defined by the user but it isen't allowed to be greater than 10 you
+ * can use the max verifier.
+ * {@code @Arg(name="example", verifiers="max[10]")}
+ * If the user input is greater than 10, it will return an predefined error message to the user.
+ * You can add multiple verifiers using the | between each.
+ * {@code @Arg(name="example", verifiers="min[5]|max[10]")}
+ * The verifiers differs from what class the parameter have. To check which verifiers are available, see the
+ * {@linkplain ArgumentHandler} for that class.
+ */
+ String verifiers() default "";
}
diff --git a/src/main/java/se/ranzdo/bukkit/methodcommand/ArgumentHandler.java b/src/main/java/se/ranzdo/bukkit/methodcommand/ArgumentHandler.java
index 0984a68..da64246 100644
--- a/src/main/java/se/ranzdo/bukkit/methodcommand/ArgumentHandler.java
+++ b/src/main/java/se/ranzdo/bukkit/methodcommand/ArgumentHandler.java
@@ -1,160 +1,172 @@
package se.ranzdo.bukkit.methodcommand;
-import java.util.HashMap;
+import com.google.common.collect.Maps;
+import org.bukkit.command.CommandSender;
+
import java.util.Map;
import java.util.Map.Entry;
-import org.bukkit.command.CommandSender;
-
public abstract class ArgumentHandler {
- private final class Variable {
- String userFriendlyName;
- ArgumentVariable variable;
- Variable(String userFriendlyName,ArgumentVariable variable) {
- this.userFriendlyName = userFriendlyName;
- this.variable = variable;
- }
- }
-
- CommandHandler handler;
-
- private Map> verifiers = new HashMap>();
- private Map vars = new HashMap();
- private Map messageNodes = new HashMap();
-
- public ArgumentHandler() {
- //Default messages
- setMessage("include_error", "[%p] has an invalid value.");
- setMessage("exclude_error", "[%p] has an invalid value.");
- setMessage("cant_as_console", "You can't do this as console.");
-
- //Default verifiers
- addVerifier("include", new ArgumentVerifier() {
- @Override
- public void verify(CommandSender sender, CommandArgument argument, String verifyName, String[] verifyArgs, T value, String valueRaw) throws VerifyError {
- for(String include : verifyArgs) {
- try {
- if(transform(sender, argument, include) != value)
- throw new VerifyError(argument.getMessage("include_error", valueRaw));
- } catch (TransformError e) {
- throw (IllegalArgumentException) new IllegalArgumentException("Could not transform the verify argument "+include).initCause(e);
- }
- }
- }
- });
-
- addVerifier("exclude", new ArgumentVerifier() {
- @Override
- public void verify(CommandSender sender, CommandArgument argument, String verifyName, String[] verifyArgs, T value, String valueRaw) throws VerifyError {
- for(String exclude : verifyArgs) {
- try {
- if(transform(sender, argument, exclude) == value)
- throw new VerifyError(argument.getMessage("exclude_error", valueRaw));
- } catch (TransformError e) {
- throw (IllegalArgumentException) new IllegalArgumentException("Could not transform the verify argument "+exclude).initCause(e);
- }
- }
- }
- });
- }
-
- public final void addVariable(String varName, String userFriendlyName, ArgumentVariable var) {
- if(verifierExists(varName))
- throw new IllegalArgumentException("A variable with the name "+varName+" does already exist.");
-
- vars.put(varName, new Variable(userFriendlyName, var));
- }
-
- public final void addVerifier(String name, ArgumentVerifier verify) {
- if(verifierExists(name))
- throw new IllegalArgumentException("A verifier with the name "+name+" does already exist.");
-
- verifiers.put(name, verify);
- }
-
- public final CommandHandler getCommandHandler() {
- return handler;
- }
-
- public final String getMessage(String node) {
- return messageNodes.get(node);
- }
-
- public final ArgumentVariable getVariable(String varName) {
- return vars.get(varName) == null ? null : vars.get(varName).variable;
- }
-
- public final String getVariableUserFriendlyName(String varName) {
- return vars.get(varName) == null ? null : vars.get(varName).userFriendlyName;
- }
-
- public final ArgumentVerifier getVerifier(String argName) {
- return verifiers.get(argName);
- }
-
- final T handle(CommandSender sender, CommandArgument argument, String arg) throws CommandError {
- if(arg == null)
- return null;
-
- T transformed;
-
- if(arg.startsWith("?")) {
- String varName = arg.substring(1, arg.length());
- ArgumentVariable var = getVariable(varName);
- if(var == null)
- throw new IllegalArgumentException("The ArgumentVariable '"+varName+"' is not registered.");
-
- transformed = var.var(sender, argument, varName);
- }
- else if(arg.matches("^\\\\+\\?.*$")) {
- arg = arg.substring(1, arg.length());
- transformed = transform(sender, argument, arg);
- }
- else
- transformed = transform(sender, argument, arg);
-
- for(Entry verifier : argument.getVerifyArguments().entrySet()) {
- ArgumentVerifier v = this.verifiers.get(verifier.getKey());
- if(v == null)
- throw new VerifierNotRegistered(verifier.getKey());
-
- v.verify(sender, argument, verifier.getKey(), verifier.getValue(), transformed, arg);
- }
-
- return transformed;
- }
-
- public final void setMessage(String node, String def) {
- messageNodes.put(node, def);
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("ArgumentHandler -> "+getClass().getName()+"\n");
- sb.append("Set messages: \n");
- for(Entry entry : messageNodes.entrySet()) {
- sb.append(entry.getKey()+" = \""+entry.getValue()+"\";\n");
- }
- sb.append("\nAvailable verifiers: \n");
- for(Entry> entry : verifiers.entrySet()) {
- sb.append(entry.getKey()+" = \""+entry.getValue().getClass().getName()+"\";\n");
- }
- sb.append("\nAvailable variables: \n");
- for(Entry entry : vars.entrySet()) {
- sb.append(entry.getKey()+" = \""+entry.getValue().userFriendlyName+"\";\n");
- }
-
- return sb.toString();
- }
-
- public abstract T transform(CommandSender sender, CommandArgument argument, String value) throws TransformError;
-
- public final boolean variableExists(String varName) {
- return vars.get(varName) != null;
- }
-
- public final boolean verifierExists(String argName) {
- return verifiers.get(argName) != null;
- }
+ CommandHandler handler;
+ private Map> verifiers = Maps.newHashMap();
+ private Map vars = Maps.newHashMap();
+ private Map messageNodes = Maps.newHashMap();
+
+ public ArgumentHandler() {
+ //Default messages
+ setMessage("include_error", "[%p] has an invalid value.");
+ setMessage("exclude_error", "[%p] has an invalid value.");
+ setMessage("cant_as_console", "You can't do this as console.");
+
+ //Default verifiers
+ addVerifier("include", (sender, argument, verifyName, verifyArgs, value, valueRaw) -> {
+ for (String include : verifyArgs) {
+ try {
+ if (transform(sender, argument, include) != value) throw new VerifyError(
+ argument.getMessage("include_error", valueRaw)
+ );
+ } catch (TransformError e) {
+ throw new IllegalArgumentException(
+ "Could not transform the verify" + " argument " + include,
+ e
+ );
+ }
+ }
+ });
+
+ addVerifier("exclude", (sender, argument, verifyName, verifyArgs, value, valueRaw) -> {
+ for (String exclude : verifyArgs) {
+ try {
+ if (transform(sender, argument, exclude) == value) throw new VerifyError(
+ argument.getMessage("exclude_error", valueRaw)
+ );
+ } catch (TransformError e) {
+ throw new IllegalArgumentException(
+ "Could not transform the verify" + " argument " + exclude,
+ e
+ );
+ }
+ }
+ });
+ }
+
+ public final void addVariable(String varName, String userFriendlyName, ArgumentVariable var) {
+ if (verifierExists(varName)) throw new IllegalArgumentException(
+ "A variable with the name " + varName + " does already exist."
+ );
+
+ vars.put(varName, new Variable(userFriendlyName, var));
+ }
+
+ public final void addVerifier(String name, ArgumentVerifier verify) {
+ if (verifierExists(name)) throw new IllegalArgumentException(
+ "A verifier with the name " + name + " does already exist."
+ );
+
+ verifiers.put(name, verify);
+ }
+
+ public final CommandHandler getCommandHandler() {
+ return handler;
+ }
+
+ public final String getMessage(String node) {
+ return messageNodes.get(node);
+ }
+
+ public final ArgumentVariable getVariable(String varName) {
+ return vars.get(varName) == null ? null : vars.get(varName).variable;
+ }
+
+ public final String getVariableUserFriendlyName(String varName) {
+ return vars.get(varName) == null ? null : vars.get(varName).userFriendlyName;
+ }
+
+ public final ArgumentVerifier getVerifier(String argName) {
+ return verifiers.get(argName);
+ }
+
+ final T handle(CommandSender sender, CommandArgument argument, String arg) throws CommandError {
+ if (arg == null) {
+ return null;
+ }
+
+ T transformed;
+
+ if (arg.startsWith("?")) {
+ String varName = arg.substring(1, arg.length());
+ ArgumentVariable var = getVariable(varName);
+
+ if (var == null) throw new IllegalArgumentException(
+ "The ArgumentVariable '" + varName + "' is not registered."
+ );
+
+ transformed = var.var(sender, argument, varName);
+ } else if (arg.matches("^\\\\+\\?.*$")) {
+ arg = arg.substring(1, arg.length());
+ transformed = transform(sender, argument, arg);
+ } else {
+ transformed = transform(sender, argument, arg);
+ }
+
+ for (Entry verifier : argument.getVerifyArguments().entrySet()) {
+ ArgumentVerifier v = this.verifiers.get(verifier.getKey());
+ if (v == null) {
+ throw new VerifierNotRegistered(verifier.getKey());
+ }
+
+ v.verify(sender, argument, verifier.getKey(), verifier.getValue(), transformed, arg);
+ }
+
+ return transformed;
+ }
+
+ public final void setMessage(String node, String def) {
+ messageNodes.put(node, def);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("ArgumentHandler -> ").append(getClass().getName()).append("\n");
+ sb.append("Set messages: \n");
+
+ for (Entry entry : messageNodes.entrySet()) {
+ sb.append(entry.getKey()).append(" = \"").append(entry.getValue()).append("\";\n");
+ }
+
+ sb.append("\nAvailable verifiers: \n");
+
+ for (Entry> entry : verifiers.entrySet()) {
+ sb.append(entry.getKey()).append(" = \"").append(entry.getValue().getClass().getName()).append("\";\n");
+ }
+
+ sb.append("\nAvailable variables: \n");
+
+ for (Entry entry : vars.entrySet()) {
+ sb.append(entry.getKey()).append(" = \"").append(entry.getValue().userFriendlyName).append("\";\n");
+ }
+
+ return sb.toString();
+ }
+
+ public abstract T transform(CommandSender sender, CommandArgument argument, String value) throws TransformError;
+
+ public final boolean variableExists(String varName) {
+ return vars.get(varName) != null;
+ }
+
+ public final boolean verifierExists(String argName) {
+ return verifiers.get(argName) != null;
+ }
+
+ private final class Variable {
+ String userFriendlyName;
+ ArgumentVariable variable;
+
+ Variable(String userFriendlyName, ArgumentVariable variable) {
+ this.userFriendlyName = userFriendlyName;
+ this.variable = variable;
+ }
+ }
}
diff --git a/src/main/java/se/ranzdo/bukkit/methodcommand/ArgumentVariable.java b/src/main/java/se/ranzdo/bukkit/methodcommand/ArgumentVariable.java
index 1dedae1..f46976f 100644
--- a/src/main/java/se/ranzdo/bukkit/methodcommand/ArgumentVariable.java
+++ b/src/main/java/se/ranzdo/bukkit/methodcommand/ArgumentVariable.java
@@ -3,5 +3,5 @@
import org.bukkit.command.CommandSender;
public interface ArgumentVariable {
- public T var(CommandSender sender, CommandArgument argument, String varName) throws CommandError;
+ T var(CommandSender sender, CommandArgument argument, String varName) throws CommandError;
}
diff --git a/src/main/java/se/ranzdo/bukkit/methodcommand/ArgumentVerifier.java b/src/main/java/se/ranzdo/bukkit/methodcommand/ArgumentVerifier.java
index 7e9b4cb..7ef3a12 100644
--- a/src/main/java/se/ranzdo/bukkit/methodcommand/ArgumentVerifier.java
+++ b/src/main/java/se/ranzdo/bukkit/methodcommand/ArgumentVerifier.java
@@ -3,5 +3,8 @@
import org.bukkit.command.CommandSender;
public interface ArgumentVerifier {
- public void verify(CommandSender sender, CommandArgument argument, String verifyName, String[] verifyArgs, T value, String valueRaw) throws VerifyError;
+ void verify(CommandSender sender, CommandArgument argument, String verifyName,
+ String[] verifyArgs,
+ T value,
+ String valueRaw) throws VerifyError;
}
diff --git a/src/main/java/se/ranzdo/bukkit/methodcommand/Arguments.java b/src/main/java/se/ranzdo/bukkit/methodcommand/Arguments.java
index abc4810..aabdb10 100644
--- a/src/main/java/se/ranzdo/bukkit/methodcommand/Arguments.java
+++ b/src/main/java/se/ranzdo/bukkit/methodcommand/Arguments.java
@@ -1,99 +1,96 @@
package se.ranzdo.bukkit.methodcommand;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class Arguments {
- private List arguments;
- private int argCounter = 0;
-
- private Map> flags = new HashMap>();
- private Map flagCounter = new HashMap();
-
- public Arguments(String[] args, Map flags) throws CommandError {
- List largs = new ArrayList(Arrays.asList(args));
- //Find the flags
- for(Entry entry : flags.entrySet()) {
- Flag flag = entry.getValue();
-
- int flagIndex = largs.indexOf("-"+flag.getIdentifier());
- if(flagIndex == -1)
- continue;
-
- largs.remove(flagIndex);
-
- int endIndex = flag.getArguments().size()+flagIndex;
-
- if(endIndex > largs.size())
- throw new CommandError("The flag -"+flag.getIdentifier()+" does not have the required parameters.");
-
- flagCounter.put(flag, 0);
-
- List flagArgs = new ArrayList();
- this.flags.put(flag, flagArgs);
-
- for(int i = flagIndex; i < endIndex; i++) {
- flagArgs.add(largs.remove(flagIndex));
- }
- }
-
- //The rest is normal arguments
- arguments = largs;
- }
-
- public boolean flagExists(Flag flag) {
- return flags.get(flag) != null;
- }
-
- public boolean hasNext() {
- return argCounter < size();
- }
-
- public boolean hasNext(Flag flag) {
- Integer c = flagCounter.get(flag);
- if(c == null)
- return false;
-
- return c < size(flag);
- }
-
- public String nextArgument() {
- String arg = arguments.get(argCounter);
- argCounter++;
- return arg;
- }
-
- public String nextFlagArgument(Flag flag) {
- List args = flags.get(flag);
-
- if(args == null)
- return null;
-
- return args.get(flagCounter.put(flag, flagCounter.get(flag)+1));
- }
-
- public int over() {
- return size()-argCounter;
- }
-
- public int over(Flag flag) {
- return size(flag)-flagCounter.get(flag);
- }
-
- public int size() {
- return arguments.size();
- }
-
- public int size(Flag flag) {
- List args = flags.get(flag);
-
- if(args == null)
- return 0;
-
- return args.size();
- }
+ private List arguments;
+ private int argCounter = 0;
+
+ private Map> flags = Maps.newHashMap();
+ private Map flagCounter = Maps.newHashMap();
+
+ public Arguments(String[] args, Map flags) throws CommandError {
+ List largs = Lists.newArrayList(args);
+
+ //Find the flags
+ for (Entry entry : flags.entrySet()) {
+ Flag flag = entry.getValue();
+
+ int flagIndex = largs.indexOf("-" + flag.getIdentifier());
+
+ if (flagIndex == -1) {
+ continue;
+ }
+
+ largs.remove(flagIndex);
+
+ int endIndex = flag.getArguments().size() + flagIndex;
+
+ if (endIndex > largs.size()) throw new CommandError(
+ "The flag -" + flag.getIdentifier() + " does not have the required parameters."
+ );
+
+ flagCounter.put(flag, 0);
+
+ List flagArgs = Lists.newArrayList();
+ this.flags.put(flag, flagArgs);
+
+ for (int i = flagIndex; i < endIndex; i++) {
+ flagArgs.add(largs.remove(flagIndex));
+ }
+ }
+
+ //The rest is normal arguments
+ arguments = largs;
+ }
+
+ public boolean flagExists(Flag flag) {
+ return flags.get(flag) != null;
+ }
+
+ public boolean hasNext() {
+ return argCounter < size();
+ }
+
+ public boolean hasNext(Flag flag) {
+ Integer c = flagCounter.get(flag);
+
+ return c != null && c < size(flag);
+ }
+
+ public String nextArgument() {
+ String arg = arguments.get(argCounter);
+ argCounter++;
+
+ return arg;
+ }
+
+ public String nextFlagArgument(Flag flag) {
+ List args = flags.get(flag);
+
+ return args == null ? null : args.get(flagCounter.put(flag, flagCounter.get(flag) + 1));
+ }
+
+ public int over() {
+ return size() - argCounter;
+ }
+
+ public int over(Flag flag) {
+ return size(flag) - flagCounter.get(flag);
+ }
+
+ public int size() {
+ return arguments.size();
+ }
+
+ public int size(Flag flag) {
+ List args = flags.get(flag);
+
+ return args == null ? 0 : args.size();
+ }
}
diff --git a/src/main/java/se/ranzdo/bukkit/methodcommand/Command.java b/src/main/java/se/ranzdo/bukkit/methodcommand/Command.java
index c4982b1..7f973a0 100644
--- a/src/main/java/se/ranzdo/bukkit/methodcommand/Command.java
+++ b/src/main/java/se/ranzdo/bukkit/methodcommand/Command.java
@@ -1,33 +1,42 @@
package se.ranzdo.bukkit.methodcommand;
+import org.bukkit.command.CommandSender;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.bukkit.command.CommandSender;
-
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Command {
- /**The description of this command
- */
- String description() default "";
-
- /**The identifier describes what command definition this will bind to. Spliced by spaces, you can define as many sub commands as you want, as long as the first command (the root) is defined in the plugin.yml file.
- * Example: {@code @Command(identifier="root sub1 sub2")}
- * The first command "root" needs to be defined in the plugin.yml. The user will be able to access the command by writing (if the root command does not choose an alias instead):
- * {@code /root sub1 sub2}
- */
- String identifier();
-
- /**If this command can only be executed by players (default true).
- * If you turn this to false, the first parameter in the method must be the {@link CommandSender} to avoid {@link ClassCastException}
- */
- boolean onlyPlayers() default true;
-
- /**The permissions to check if the user have before execution. If it is empty the command does not require any permission.
- * If the user don't have one of the permissions, they will get an error message stating that they do not have permission to use the command.
- */
- String[] permissions() default {};
+ /**
+ * The description of this command
+ */
+ String description() default "";
+
+ /**
+ * The identifier describes what command definition this will bind to. Spliced by spaces, you can define as many
+ * sub commands as you want, as long as the first command (the root) is defined in the plugin.yml file.
+ * Example: {@code @Command(identifier="root sub1 sub2")}
+ * The first command "root" needs to be defined in the plugin.yml. The user will be able to access the command by
+ * writing (if the root command does not choose an alias instead):
+ * {@code /root sub1 sub2}
+ */
+ String identifier();
+
+ /**
+ * If this command can only be executed by players (default true).
+ * If you turn this to false, the first parameter in the method must be the {@link CommandSender} to avoid
+ * {@link ClassCastException}
+ */
+ boolean onlyPlayers() default true;
+
+ /**
+ * The permissions to check if the user have before execution. If it is empty the command does not require any
+ * permission.