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:
parent
694c374eb7
commit
802d90a459
6 changed files with 41 additions and 9 deletions
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue