1
0
Fork 0
mirror of https://github.com/xHyroM/lighteco.git synced 2024-11-10 01:18:07 +01:00

feat: some things

This commit is contained in:
Jozef Steinhübl 2024-06-30 20:21:51 +02:00
parent 694c374eb7
commit 802d90a459
No known key found for this signature in database
GPG key ID: E6BC90C91973B08F
6 changed files with 41 additions and 9 deletions

View file

@ -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()
}

View file

@ -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 {

View file

@ -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")

View file

@ -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<Command> 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)));
}
}

View file

@ -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));
}
}

View file

@ -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));
}
}