1
0
Fork 0
mirror of https://github.com/xHyroM/lighteco.git synced 2024-12-22 20:41:05 +01:00

feat: map args

This commit is contained in:
Jozef Steinhübl 2024-06-24 22:50:58 +02:00
parent 7001c04915
commit 694c374eb7
No known key found for this signature in database
GPG key ID: E6BC90C91973B08F
5 changed files with 32 additions and 9 deletions

View file

@ -6,8 +6,8 @@ plugins {
}
server {
version = "1.20.1"
type = "paper"
version = "1.20.6"
type = "purpur"
}
repositories {

View file

@ -36,13 +36,14 @@ 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);
.findFirst()
.orElse(null);
if (command == null) {
sender.sendMessage(Component.text("Command not found.")); // TODO: change
return;
}
command.execute(this.plugin, sender, new Arguments(List.of(args)));
command.execute(this.plugin, sender, new Arguments(plugin, command, List.of(args)));
}
}

View file

@ -5,6 +5,7 @@ import dev.xhyrom.lighteco.common.command.argument.type.StringArgument;
import dev.xhyrom.lighteco.common.model.chat.CommandSender;
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
import lombok.Getter;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -24,11 +25,12 @@ 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))
.filter(cmd -> cmd.getName().equalsIgnoreCase(childName) && cmd.getArgs().size() == args.size() - 1)
.findFirst()
.orElse(null);
if (child == null) {
sender.sendMessage(Component.text("Command not found. / Parent Command"));
return;
}

View file

@ -1,18 +1,28 @@
package dev.xhyrom.lighteco.common.command.argument;
import dev.xhyrom.lighteco.common.command.abstraction.Command;
import dev.xhyrom.lighteco.common.model.user.User;
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Arguments {
private final LightEcoPlugin plugin;
private final Command command;
private final List<String> arguments;
private final Map<String, ?> mappedArguments;
private final Map<String, Object> mappedArguments = new HashMap<>();
public Arguments(List<String> arguments) {
public Arguments(LightEcoPlugin plugin, Command command, List<String> arguments) {
this.plugin = plugin;
this.command = command;
this.arguments = arguments;
this.mappedArguments = Map.of();
for (int i = 0; i < arguments.size(); i++) {
String arg = arguments.get(i);
this.mappedArguments.put(command.getArgs().get(i).getName(), (Object) command.getArgs().get(i).parse(plugin, arg));
}
}
public String string(String name) {
@ -35,7 +45,11 @@ public class Arguments {
return (String) this.arguments.get(index);
}
public int size() {
return this.arguments.size();
}
public Arguments subList(int fromIndex) {
return new Arguments(this.arguments.subList(fromIndex, this.arguments.size()));
return new Arguments(this.plugin, this.command, this.arguments.subList(fromIndex, this.arguments.size()));
}
}

View file

@ -12,6 +12,7 @@ import org.spongepowered.plugin.builtin.jvm.Plugin;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Plugin("lighteco-sponge")
@ -60,6 +61,11 @@ public class SpongeLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
return null;
}
@Override
public Optional<UUID> lookupUniqueId(String username) {
return Optional.empty();
}
@Override
public boolean isPlayerOnline(UUID uniqueId) {
return false;