diff --git a/.gitignore b/.gitignore
index fe5b3b35..b6be78b8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
*.class
-
+.DS_Store
# Mobile Tools for Java (J2ME)
.mtj.tmp/
diff --git a/bukkit/acf-bukkit.iml b/bukkit/acf-bukkit.iml
index 579fdd23..8bc7831e 100644
--- a/bukkit/acf-bukkit.iml
+++ b/bukkit/acf-bukkit.iml
@@ -19,8 +19,6 @@
-
-
diff --git a/bungee/acf-bungee.iml b/bungee/acf-bungee.iml
index 1314a2c7..fcb9ee95 100644
--- a/bungee/acf-bungee.iml
+++ b/bungee/acf-bungee.iml
@@ -18,13 +18,11 @@
-
-
-
-
-
-
-
+
+
+
+
+
diff --git a/core/acf-core.iml b/core/acf-core.iml
index f609017e..d7675d1b 100644
--- a/core/acf-core.iml
+++ b/core/acf-core.iml
@@ -16,8 +16,6 @@
-
-
diff --git a/core/src/main/java/co/aikar/commands/CommandContexts.java b/core/src/main/java/co/aikar/commands/CommandContexts.java
index 81173e13..af8923ad 100644
--- a/core/src/main/java/co/aikar/commands/CommandContexts.java
+++ b/core/src/main/java/co/aikar/commands/CommandContexts.java
@@ -29,6 +29,7 @@ import co.aikar.commands.annotation.Values;
import co.aikar.commands.contexts.ContextResolver;
import co.aikar.commands.contexts.IssuerAwareContextResolver;
import co.aikar.commands.contexts.IssuerOnlyContextResolver;
+import co.aikar.commands.contexts.OptionalContextResolver;
import com.google.common.collect.Maps;
import java.util.List;
@@ -145,6 +146,24 @@ public class CommandContexts {
+ String first = c.getFirstArg();
+ int page = 1;
+ List search = null;
+ if (first != null && ACFUtil.isInteger(first)) {
+ c.popFirstArg();
+ page = ACFUtil.parseInt(first);
+ if (!c.getArgs().isEmpty()) {
+ search = c.getArgs();
+ }
+ } else if (first != null && !c.getArgs().isEmpty()) {
+ search = c.getArgs();
+ }
+ CommandHelp commandHelp = manager.generateCommandHelp();
+ commandHelp.setPage(page);
+ commandHelp.setSearch(search);
+ return commandHelp;
+ });
}
/**
@@ -175,6 +194,14 @@ public class CommandContexts void registerOptionalContext(Class context, OptionalContextResolver supplier) {
+ contextMap.put(context, supplier);
+ }
+
/**
* Registers a context that requires input from the command issuer to resolve. This resolver should always
* call {@link CommandExecutionContext#popFirstArg()}
diff --git a/core/src/main/java/co/aikar/commands/CommandExecutionContext.java b/core/src/main/java/co/aikar/commands/CommandExecutionContext.java
index 06ae90d1..cbda835e 100644
--- a/core/src/main/java/co/aikar/commands/CommandExecutionContext.java
+++ b/core/src/main/java/co/aikar/commands/CommandExecutionContext.java
@@ -176,4 +176,11 @@ public class CommandExecutionContext getFlags() {
return this.flags;
}
+
+ public String joinArgs() {
+ return ACFUtil.join(args, " ");
+ }
+ public String joinArgs(String sep) {
+ return ACFUtil.join(args, sep);
+ }
}
diff --git a/core/src/main/java/co/aikar/commands/CommandHelp.java b/core/src/main/java/co/aikar/commands/CommandHelp.java
index d709c66d..66a0426c 100644
--- a/core/src/main/java/co/aikar/commands/CommandHelp.java
+++ b/core/src/main/java/co/aikar/commands/CommandHelp.java
@@ -28,12 +28,15 @@ import com.google.common.collect.SetMultimap;
import org.jetbrains.annotations.NotNull;
import java.util.*;
+import java.util.regex.Pattern;
@SuppressWarnings("WeakerAccess")
public class CommandHelp {
private final CommandManager manager;
private final CommandIssuer issuer;
private final List helpEntries = new ArrayList<>();
+ private int page;
+ private List search;
public CommandHelp(CommandManager manager, RootCommand rootCommand, CommandIssuer issuer) {
this.manager = manager;
@@ -46,6 +49,7 @@ public class CommandHelp {
if (key.equals("__default") || key.equals("__unknown")){
return;
}
+
RegisteredCommand regCommand = e.getValue();
if (regCommand.hasPermission(issuer) && !seen.contains(regCommand)) {
this.helpEntries.add(new HelpEntry(regCommand));
@@ -54,6 +58,23 @@ public class CommandHelp {
});
}
+ private boolean matchesSearch(HelpEntry help) {
+ if (this.search == null) {
+ return true;
+ }
+ final RegisteredCommand cmd = help.getRegisteredCommand();
+
+ for (String word : this.search) {
+ Pattern pattern = Pattern.compile(Pattern.quote(word));
+ if (pattern.matcher(cmd.command).matches()) {
+ return true;
+ } else if (pattern.matcher(help.getDescription()).matches()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public CommandManager getManager() {
return manager;
}
@@ -68,6 +89,9 @@ public class CommandHelp {
public void showHelp(CommandIssuer issuer, MessageKeyProvider format) {
getHelpEntries().forEach(e -> {
+ if (!matchesSearch(e)) {
+ return;
+ }
String formatted = this.manager.formatMessage(issuer, MessageType.HELP, format, getFormatReplacements(e));
for (String msg : ACFPatterns.NEWLINE.split(formatted)) {
issuer.sendMessageInternal(ACFUtil.rtrim(msg));
@@ -94,4 +118,12 @@ public class CommandHelp {
public List getHelpEntries() {
return helpEntries;
}
+
+ public void setPage(int page) {
+ this.page = page;
+ }
+
+ public void setSearch(List search) {
+ this.search = search;
+ }
}
diff --git a/core/src/main/java/co/aikar/commands/HelpEntry.java b/core/src/main/java/co/aikar/commands/HelpEntry.java
index c0f6137b..7bd41cb3 100644
--- a/core/src/main/java/co/aikar/commands/HelpEntry.java
+++ b/core/src/main/java/co/aikar/commands/HelpEntry.java
@@ -31,6 +31,10 @@ public class HelpEntry {
this.command = command;
}
+ RegisteredCommand getRegisteredCommand() {
+ return this.command;
+ }
+
public String getCommand(){
return "/" + this.command.command;
diff --git a/core/src/main/java/co/aikar/commands/contexts/OptionalContextResolver.java b/core/src/main/java/co/aikar/commands/contexts/OptionalContextResolver.java
new file mode 100644
index 00000000..cb734c1e
--- /dev/null
+++ b/core/src/main/java/co/aikar/commands/contexts/OptionalContextResolver.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package co.aikar.commands.contexts;
+
+import co.aikar.commands.CommandExecutionContext;
+import co.aikar.commands.CommandIssuer;
+
+/**
+ * Context Resolver that can accept null input
+ */
+public interface OptionalContextResolver > extends ContextResolver {}
diff --git a/example/acf-example.iml b/example/acf-example.iml
index f108849d..a6b5d1a6 100644
--- a/example/acf-example.iml
+++ b/example/acf-example.iml
@@ -21,8 +21,6 @@
-
-
diff --git a/paper/acf-paper.iml b/paper/acf-paper.iml
index 07830e2c..7a65e2aa 100644
--- a/paper/acf-paper.iml
+++ b/paper/acf-paper.iml
@@ -18,8 +18,6 @@
-
-
diff --git a/sponge/acf-sponge.iml b/sponge/acf-sponge.iml
index ee0aaf6f..7817f18b 100644
--- a/sponge/acf-sponge.iml
+++ b/sponge/acf-sponge.iml
@@ -18,8 +18,6 @@
-
-