From 206063acf3a6e0edc0d16b07d206aa36207b42d4 Mon Sep 17 00:00:00 2001 From: Wyvest <45589059+Wyvest@users.noreply.github.com> Date: Tue, 5 Jul 2022 22:37:47 +0900 Subject: a --- .../cc/polyfrost/oneconfig/utils/InputUtils.java | 4 +- .../utils/commands/PlatformCommandManager.java | 63 +++++++++++++++++++++- 2 files changed, 63 insertions(+), 4 deletions(-) (limited to 'src/main/java/cc/polyfrost/oneconfig/utils') 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) { + + } } -- cgit