From 802d90a459da537eebc2aa9de2aceb8f5a5bede3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Sun, 30 Jun 2024 20:21:51 +0200 Subject: [PATCH] feat: some things --- .../main/kotlin/lighteco.base-logic.gradle.kts | 7 ++++++- bukkittest/build.gradle.kts | 9 +++++++++ common/build.gradle.kts | 6 ++++++ .../lighteco/common/command/CommandManager.java | 17 ++++++++++++----- .../command/abstraction/ParentCommand.java | 6 ++++-- .../common/command/argument/Arguments.java | 5 ++++- 6 files changed, 41 insertions(+), 9 deletions(-) diff --git a/buildSrc/src/main/kotlin/lighteco.base-logic.gradle.kts b/buildSrc/src/main/kotlin/lighteco.base-logic.gradle.kts index 3a09e7d..1471e13 100644 --- a/buildSrc/src/main/kotlin/lighteco.base-logic.gradle.kts +++ b/buildSrc/src/main/kotlin/lighteco.base-logic.gradle.kts @@ -4,7 +4,12 @@ plugins { } java { - // toolchain.languageVersion.set(JavaLanguageVersion.of(17)) + targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_17 + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } + withSourcesJar() } diff --git a/bukkittest/build.gradle.kts b/bukkittest/build.gradle.kts index e30be23..fa27896 100644 --- a/bukkittest/build.gradle.kts +++ b/bukkittest/build.gradle.kts @@ -8,6 +8,15 @@ plugins { server { version = "1.20.6" type = "purpur" + + // Minecraft 1.20.6 requires java 21 + java { + targetCompatibility = JavaVersion.VERSION_21 + sourceCompatibility = JavaVersion.VERSION_21 + toolchain { + languageVersion.set(JavaLanguageVersion.of(21)) + } + } } repositories { diff --git a/common/build.gradle.kts b/common/build.gradle.kts index a2595f9..0da0761 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -2,6 +2,10 @@ plugins { id("lighteco.shadow-logic") } +repositories { + maven("https://libraries.minecraft.net") +} + dependencies { api(project(":lighteco-api")) api("org.checkerframework:checker-qual:3.8.0") @@ -19,6 +23,8 @@ dependencies { implementation("eu.okaeri:okaeri-configs-yaml-snakeyaml:5.0.0-beta.5") implementation("eu.okaeri:okaeri-configs-validator-okaeri:5.0.0-beta.5") + implementation("com.mojang:brigadier:1.0.18") + compileOnly("com.zaxxer:HikariCP:5.0.1") compileOnly("redis.clients:jedis:5.1.0") diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/command/CommandManager.java b/common/src/main/java/dev/xhyrom/lighteco/common/command/CommandManager.java index d6e99d0..fcb2bb7 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/command/CommandManager.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/command/CommandManager.java @@ -34,16 +34,23 @@ public class CommandManager { } public void execute(CommandSender sender, String name, String[] args) { - Command command = this.commands.stream() - .filter(cmd -> cmd.getName().equalsIgnoreCase(name) && cmd.getArgs().size() == args.length) - .findFirst() - .orElse(null); + List possibleCommands = this.commands.stream() + .filter(cmd -> cmd.getName().equalsIgnoreCase(name)) + .toList(); - if (command == null) { + if (possibleCommands.isEmpty()) { sender.sendMessage(Component.text("Command not found.")); // TODO: change return; } + // get command according to args + Command command = possibleCommands.stream() + .filter(cmd -> cmd.getArgs().size() == args.length) + .findFirst() + .orElse(null); + + System.out.println("[Manager] Command: " + command.getName() + " (" + command.getClass().getName() + ")" + " / " + command.getArgs()); + command.execute(this.plugin, sender, new Arguments(plugin, command, List.of(args))); } } diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/command/abstraction/ParentCommand.java b/common/src/main/java/dev/xhyrom/lighteco/common/command/abstraction/ParentCommand.java index 2b64ae9..0ec07bd 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/command/abstraction/ParentCommand.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/command/abstraction/ParentCommand.java @@ -25,8 +25,8 @@ public class ParentCommand extends Command { public void execute(LightEcoPlugin plugin, CommandSender sender, Arguments args) { String childName = args.string("child"); Command child = Arrays.stream(getChildren()) - .filter(cmd -> cmd.getName().equalsIgnoreCase(childName) && cmd.getArgs().size() == args.size() - 1) - .findFirst() + .filter(cmd -> cmd.getName().equalsIgnoreCase(childName) && (cmd.getArgs().size() == args.size() - 1 || cmd.getArgs().size() < args.size())) + .max((cmd1, cmd2) -> Integer.compare(cmd2.getArgs().size(), cmd1.getArgs().size())) .orElse(null); if (child == null) { @@ -34,6 +34,8 @@ public class ParentCommand extends Command { return; } + System.out.println("Parent Command: " + getName() + " (" + getClass().getName() + ") " + " / Child Command: " + child.getName() + " (" + child.getClass().getName() + ")"); + child.execute(plugin, sender, args.subList(1)); } } diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/Arguments.java b/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/Arguments.java index 5720576..5a66834 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/Arguments.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/Arguments.java @@ -19,8 +19,11 @@ public class Arguments { this.command = command; this.arguments = arguments; - for (int i = 0; i < arguments.size(); i++) { + System.out.println("Arguments: " + arguments); + System.out.println("Command: " + command.getName() + " (" + command.getClass().getName() + ")" + " / " + command.getArgs()); + for (int i = 0; i < command.getArgs().size(); i++) { String arg = arguments.get(i); + System.out.println("Argument: " + arg + " / " + command.getArgs().get(i).getName()); this.mappedArguments.put(command.getArgs().get(i).getName(), (Object) command.getArgs().get(i).parse(plugin, arg)); } }