- *
- * To register commands, either extend {@link CommandHelper} and run {@link CommandHelper#preload()} (which does nothing,
- * just makes loading look nicer lol), or use {@link CommandManager#registerCommand(Object)}.
+ *
+ * To register commands, use {@link CommandManager#registerCommand(Class)}.
*
*
* Note: if you're viewing this in IntelliJ or just see the @literal tag everywhere, please ignore that.
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Main.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Main.java
index 3c105c7..9b49fb4 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Main.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Main.java
@@ -16,5 +16,6 @@ import java.lang.annotation.Target;
@Target({ElementType.METHOD})
public @interface Main {
String description() default "";
+
int priority() default 1000;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Name.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Name.java
index ef178a0..f802697 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Name.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Name.java
@@ -16,6 +16,7 @@ import java.lang.annotation.Target;
public @interface Name {
/**
* The name of the parameter.
+ *
* @return The name of the parameter.
*/
String value();
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/SubCommand.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/SubCommand.java
index b1cf035..1bfbd53 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/SubCommand.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/SubCommand.java
@@ -16,18 +16,21 @@ import java.lang.annotation.Target;
public @interface SubCommand {
/**
* The name of the command.
+ *
* @return The name of the command.
*/
String value();
/**
* The aliases of the command.
+ *
* @return The aliases of the command.
*/
String[] aliases() default {};
/**
* The description of the command.
+ *
* @return The description of the command.
*/
String description() default "";
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/ArgumentParser.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/ArgumentParser.java
index d9d51b0..8bf811b 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/ArgumentParser.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/ArgumentParser.java
@@ -3,10 +3,36 @@ package cc.polyfrost.oneconfig.utils.commands.arguments;
import com.google.common.reflect.TypeToken;
import org.jetbrains.annotations.Nullable;
-@SuppressWarnings("unstable")
+import java.lang.reflect.Parameter;
+import java.util.Collections;
+import java.util.List;
+
+@SuppressWarnings("UnstableApiUsage")
public abstract class ArgumentParser {
- private final TypeToken type = new TypeToken(getClass()) {};
+ private final TypeToken type = new TypeToken(getClass()) {
+ };
public final Class> typeClass = type.getRawType();
+
+ /**
+ * Parses the given string into an object of the type specified by this parser.
+ * Should return null if the string cannot be parsed.
+ *
+ * @param arguments The string to parse.
+ * @return The parsed object, or null if the string cannot be parsed.
+ */
@Nullable
public abstract T parse(Arguments arguments);
+
+ /**
+ * Returns possible completions for the given arguments.
+ * Should return an empty list or null if no completions are possible.
+ *
+ * @param arguments The arguments to complete.
+ * @param parameter The parameter to complete.
+ * @return A list of possible completions, or an empty list or null if no completions are possible.
+ */
+ @Nullable
+ public List complete(Arguments arguments, Parameter parameter) {
+ return Collections.emptyList();
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/Arguments.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/Arguments.java
index 74a0840..f35cf46 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/Arguments.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/Arguments.java
@@ -1,9 +1,9 @@
package cc.polyfrost.oneconfig.utils.commands.arguments;
public class Arguments {
- private int position = 0;
public final String[] args;
public final boolean greedy;
+ private int position = 0;
public Arguments(String[] args, boolean greedy) {
this.args = args;
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/BooleanParser.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/BooleanParser.java
index dfdca2d..7411cbe 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/BooleanParser.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/BooleanParser.java
@@ -1,11 +1,31 @@
package cc.polyfrost.oneconfig.utils.commands.arguments;
+import com.google.common.collect.Lists;
import org.jetbrains.annotations.Nullable;
+import java.lang.reflect.Parameter;
+import java.util.List;
+import java.util.Locale;
+
public class BooleanParser extends ArgumentParser {
+ private static final List VALUES = Lists.newArrayList("true", "false");
+
@Override
public @Nullable Boolean parse(Arguments arguments) {
return Boolean.parseBoolean(arguments.poll());
}
+
+ @Override
+ public @Nullable List complete(Arguments arguments, Parameter parameter) {
+ String value = arguments.poll();
+ if (value != null && !value.trim().isEmpty()) {
+ for (String v : VALUES) {
+ if (v.startsWith(value.toLowerCase(Locale.ENGLISH))) {
+ return Lists.newArrayList(v);
+ }
+ }
+ }
+ return VALUES;
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/DoubleParser.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/DoubleParser.java
index 8c85849..4379e3a 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/DoubleParser.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/DoubleParser.java
@@ -5,6 +5,10 @@ import org.jetbrains.annotations.Nullable;
public class DoubleParser extends ArgumentParser {
@Override
public @Nullable Double parse(Arguments arguments) {
- return Double.parseDouble(arguments.poll());
+ try {
+ return Double.parseDouble(arguments.poll());
+ } catch (NumberFormatException e) {
+ return null;
+ }
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/FloatParser.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/FloatParser.java
index 7053fcb..08e0a45 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/FloatParser.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/FloatParser.java
@@ -6,6 +6,10 @@ public class FloatParser extends ArgumentParser {
@Override
public @Nullable Float parse(Arguments arguments) {
- return Float.parseFloat(arguments.poll());
+ try {
+ return Float.parseFloat(arguments.poll());
+ } catch (NumberFormatException e) {
+ return null;
+ }
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/IntegerParser.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/IntegerParser.java
index 6910d4b..89f4eca 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/IntegerParser.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/IntegerParser.java
@@ -3,6 +3,10 @@ package cc.polyfrost.oneconfig.utils.commands.arguments;
public class IntegerParser extends ArgumentParser {
@Override
public Integer parse(Arguments arguments) {
- return Integer.parseInt(arguments.poll());
+ try {
+ return Integer.parseInt(arguments.poll());
+ } catch (NumberFormatException e) {
+ return null;
+ }
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/hypixel/HypixelUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/hypixel/HypixelUtils.java
index d7a9b0d..a952053 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/hypixel/HypixelUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/hypixel/HypixelUtils.java
@@ -2,17 +2,17 @@ package cc.polyfrost.oneconfig.utils.hypixel;
import cc.polyfrost.oneconfig.events.EventManager;
import cc.polyfrost.oneconfig.events.event.*;
-import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
-import cc.polyfrost.oneconfig.libs.universal.UChat;
-import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
-import cc.polyfrost.oneconfig.libs.universal.wrappers.UPlayer;
-import cc.polyfrost.oneconfig.libs.universal.wrappers.message.UTextComponent;
import cc.polyfrost.oneconfig.utils.JsonUtils;
import cc.polyfrost.oneconfig.utils.Multithreading;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import gg.essential.universal.UChat;
+import gg.essential.universal.UMinecraft;
+import gg.essential.universal.wrappers.UPlayer;
+import gg.essential.universal.wrappers.message.UTextComponent;
+import me.kbrewster.eventbus.Subscribe;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
@@ -133,6 +133,7 @@ public class HypixelUtils {
/**
* Returns whether the player is in game.
+ *
* @return Whether the player is in game.
*/
public boolean isInGame() {
@@ -141,6 +142,7 @@ public class HypixelUtils {
/**
* Returns the current {@link LocrawInfo}.
+ *
* @return The current {@link LocrawInfo}.
* @see LocrawInfo
*/
@@ -150,6 +152,7 @@ public class HypixelUtils {
/**
* Returns the previous {@link LocrawInfo}.
+ *
* @return The previous {@link LocrawInfo}.
* @see LocrawInfo
*/
--
cgit