aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/utils
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2022-07-05 22:37:47 +0900
committerWyvest <45589059+Wyvest@users.noreply.github.com>2022-07-05 22:37:47 +0900
commit206063acf3a6e0edc0d16b07d206aa36207b42d4 (patch)
tree8d0f31d65cfa4b3f85a3d4f7f0844f6df65b2b7e /src/main/java/cc/polyfrost/oneconfig/utils
parentfecb67e07ded0d20b12d3bdb48fea3e2e50b7f88 (diff)
downloadOneConfig-206063acf3a6e0edc0d16b07d206aa36207b42d4.tar.gz
OneConfig-206063acf3a6e0edc0d16b07d206aa36207b42d4.tar.bz2
OneConfig-206063acf3a6e0edc0d16b07d206aa36207b42d4.zip
a
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/utils')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java63
2 files changed, 63 insertions, 4 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java
index a48d369..6582eaa 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java
@@ -96,7 +96,7 @@ public final class InputUtils {
* @return the current mouse X position
*/
public static int mouseX() {
- if (OneConfigGui.INSTANCE == null) return Platform.getMousePlatform().getMouseX();
+ if (OneConfigGui.INSTANCE == null) return (int) Platform.getMousePlatform().getMouseX(); //todo stop casting and actually use doubles
return (int) (Platform.getMousePlatform().getMouseX() / OneConfigGui.INSTANCE.getScaleFactor());
}
@@ -110,7 +110,7 @@ public final class InputUtils {
* @return the current mouse Y position
*/
public static int mouseY() {
- if (OneConfigGui.INSTANCE == null) return UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY());
+ if (OneConfigGui.INSTANCE == null) return (int) (UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY()));
return (int) ((UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())) / OneConfigGui.INSTANCE.getScaleFactor());
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java
index a02f4ff..1ab356c 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java
@@ -1,7 +1,66 @@
package cc.polyfrost.oneconfig.utils.commands;
+import cc.polyfrost.oneconfig.libs.universal.ChatColor;
import cc.polyfrost.oneconfig.utils.commands.annotations.Command;
+import cc.polyfrost.oneconfig.utils.commands.annotations.Name;
+import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand;
+import cc.polyfrost.oneconfig.utils.commands.arguments.ArgumentParser;
-public interface PlatformCommandManager {
- void createCommand(CommandManager.InternalCommand root, Command annotation);
+import java.lang.reflect.Parameter;
+
+public abstract class PlatformCommandManager {
+
+ //TODO: someone make the help command actually look nice lmao
+ protected String sendHelpCommand(CommandManager.InternalCommand root) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(ChatColor.GOLD).append("Help for ").append(ChatColor.BOLD).append(root.name).append(ChatColor.RESET).append(ChatColor.GOLD).append(":\n");
+ if (!root.description.isEmpty()) {
+ builder.append("\n").append(ChatColor.GOLD).append("Description: ").append(ChatColor.BOLD).append(root.description);
+ }
+ for (CommandManager.InternalCommand command : root.children) {
+ runThroughCommandsHelp(root.name, command, builder);
+ }
+ builder.append("\n").append(ChatColor.GOLD).append("Aliases: ").append(ChatColor.BOLD);
+ int index = 0;
+ for (String alias : root.aliases) {
+ ++index;
+ builder.append(alias).append(index < root.aliases.length ? ", " : "");
+ }
+ builder.append("\n");
+ return builder.toString();
+ }
+
+ protected void runThroughCommandsHelp(String append, CommandManager.InternalCommand command, StringBuilder builder) {
+ if (!command.invokers.isEmpty()) {
+ Class<?> declaringClass = command.invokers.get(0).method.getDeclaringClass();
+ if (declaringClass.isAnnotationPresent(SubCommand.class)) {
+ String description = declaringClass.getAnnotation(SubCommand.class).description();
+ if (!description.isEmpty()) {
+ builder.append("\n").append(ChatColor.GOLD).append("Description: ").append(ChatColor.BOLD).append(description);
+ }
+ }
+ }
+ for (CommandManager.InternalCommand.InternalCommandInvoker invoker : command.invokers) {
+ builder.append("\n").append(ChatColor.GOLD).append("/").append(append).append(" ").append(command.name);
+ for (Parameter parameter : invoker.method.getParameters()) {
+ String name = parameter.getName();
+ if (parameter.isAnnotationPresent(Name.class)) {
+ name = parameter.getAnnotation(Name.class).value();
+ }
+ builder.append(" <").append(name).append(">");
+ }
+ if (!command.description.trim().isEmpty()) {
+ builder.append(": ").append(ChatColor.BOLD).append(command.description);
+ }
+ }
+ for (CommandManager.InternalCommand subCommand : command.children) {
+ runThroughCommandsHelp(append + " " + command.name, subCommand, builder);
+ }
+ }
+
+ abstract void createCommand(CommandManager.InternalCommand root, Command annotation);
+
+ public void handleNewParser(ArgumentParser<?> parser, Class<?> clazz) {
+
+ }
}