mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-11-10 09:28:08 +01:00
feat: map args
This commit is contained in:
parent
7001c04915
commit
694c374eb7
5 changed files with 32 additions and 9 deletions
|
@ -6,8 +6,8 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
version = "1.20.1"
|
version = "1.20.6"
|
||||||
type = "paper"
|
type = "purpur"
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
|
|
@ -36,13 +36,14 @@ public class CommandManager {
|
||||||
public void execute(CommandSender sender, String name, String[] args) {
|
public void execute(CommandSender sender, String name, String[] args) {
|
||||||
Command command = this.commands.stream()
|
Command command = this.commands.stream()
|
||||||
.filter(cmd -> cmd.getName().equalsIgnoreCase(name) && cmd.getArgs().size() == args.length)
|
.filter(cmd -> cmd.getName().equalsIgnoreCase(name) && cmd.getArgs().size() == args.length)
|
||||||
.findFirst().orElse(null);
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
sender.sendMessage(Component.text("Command not found.")); // TODO: change
|
sender.sendMessage(Component.text("Command not found.")); // TODO: change
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
command.execute(this.plugin, sender, new Arguments(List.of(args)));
|
command.execute(this.plugin, sender, new Arguments(plugin, command, List.of(args)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.model.chat.CommandSender;
|
||||||
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
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) {
|
public void execute(LightEcoPlugin plugin, CommandSender sender, Arguments args) {
|
||||||
String childName = args.string("child");
|
String childName = args.string("child");
|
||||||
Command child = Arrays.stream(getChildren())
|
Command child = Arrays.stream(getChildren())
|
||||||
.filter(cmd -> cmd.getName().equalsIgnoreCase(childName))
|
.filter(cmd -> cmd.getName().equalsIgnoreCase(childName) && cmd.getArgs().size() == args.size() - 1)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
|
||||||
if (child == null) {
|
if (child == null) {
|
||||||
|
sender.sendMessage(Component.text("Command not found. / Parent Command"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,28 @@
|
||||||
package dev.xhyrom.lighteco.common.command.argument;
|
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.model.user.User;
|
||||||
|
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class Arguments {
|
public class Arguments {
|
||||||
|
private final LightEcoPlugin plugin;
|
||||||
|
private final Command command;
|
||||||
private final List<String> arguments;
|
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.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) {
|
public String string(String name) {
|
||||||
|
@ -35,7 +45,11 @@ public class Arguments {
|
||||||
return (String) this.arguments.get(index);
|
return (String) this.arguments.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return this.arguments.size();
|
||||||
|
}
|
||||||
|
|
||||||
public Arguments subList(int fromIndex) {
|
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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import org.spongepowered.plugin.builtin.jvm.Plugin;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Plugin("lighteco-sponge")
|
@Plugin("lighteco-sponge")
|
||||||
|
@ -60,6 +61,11 @@ public class SpongeLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<UUID> lookupUniqueId(String username) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPlayerOnline(UUID uniqueId) {
|
public boolean isPlayerOnline(UUID uniqueId) {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue