1.0
This commit is contained in:
commit
f57af31969
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
/.idea/
|
||||
/target/
|
||||
/ElementOriginLib.iml
|
140
pom.xml
Normal file
140
pom.xml
Normal file
|
@ -0,0 +1,140 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.io.yutian.elementoriginlib</groupId>
|
||||
<artifactId>ElementOriginLib</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ElementOriginLib</name>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.5.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc-repo</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>public</id>
|
||||
<url>https://repo.aurora-pixels.com/repository/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>public-rpg</id>
|
||||
<url>https://repo.aurora-pixels.com/repository/public-rpg/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>rapture-snapshots</id>
|
||||
<url>https://repo.rapture.pw/repository/maven-snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.20.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.20.1</version>
|
||||
<classifier>nms</classifier>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mojang</groupId>
|
||||
<artifactId>authlib</artifactId>
|
||||
<version>3.3.39</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mojang</groupId>
|
||||
<artifactId>brigadier</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mojang</groupId>
|
||||
<artifactId>datafixerupper</artifactId>
|
||||
<version>4.1.27</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-compress</artifactId>
|
||||
<version>1.26.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.luben</groupId>
|
||||
<artifactId>zstd-jni</artifactId>
|
||||
<version>1.5.6-3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>4.0.3</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.46.0.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>5.1.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,21 @@
|
|||
package com.io.yutian.elementoriginlib;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class ElementOriginLib extends JavaPlugin {
|
||||
|
||||
private static ElementOriginLib instance;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
public static ElementOriginLib inst() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.io.yutian.elementoriginlib.command;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Command<S extends CommandContext> {
|
||||
|
||||
void run(S context);
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.io.yutian.elementoriginlib.command;
|
||||
|
||||
import com.io.yutian.elementoriginlib.command.argument.ArgumentValue;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandContext {
|
||||
|
||||
private String command;
|
||||
private String label;
|
||||
private CommandSender sender;
|
||||
private Map<String, ArgumentValue> argumentsValues;
|
||||
|
||||
public CommandContext(String command, String label, CommandSender sender, Map<String, ArgumentValue> argumentsValues) {
|
||||
this.command = command;
|
||||
this.label = label;
|
||||
this.sender = sender;
|
||||
this.argumentsValues = argumentsValues;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public ArgumentValue getArgumentsValue(String key) {
|
||||
return argumentsValues.getOrDefault(key, new ArgumentValue(null));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package com.io.yutian.elementoriginlib.command;
|
||||
|
||||
import com.io.yutian.elementoriginlib.command.argument.Argument;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class CommandNode {
|
||||
|
||||
private String name;
|
||||
|
||||
private List<CommandNode> childrens = new ArrayList<>();
|
||||
private List<Argument> arguments = new ArrayList<>();
|
||||
|
||||
private List<String> alias = new ArrayList<>();
|
||||
|
||||
private Predicate<CommandSender> commandSenderPredicate = (commandSender -> true);
|
||||
private Command command;
|
||||
|
||||
public CommandNode(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public CommandNode(String name, String[] alias) {
|
||||
this.name = name;
|
||||
this.alias = Arrays.asList(alias);
|
||||
}
|
||||
|
||||
public CommandNode(String name, List<String> alias) {
|
||||
this.name = name;
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
public CommandNode permission(Predicate<CommandSender> commandSenderPredicate) {
|
||||
this.commandSenderPredicate = commandSenderPredicate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<String> getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
public CommandNode setAlias(List<String> alias) {
|
||||
this.alias = alias;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandNode addAilas(String alias) {
|
||||
this.alias.add(alias);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandNode addArgument(Argument argument) {
|
||||
arguments.add(argument);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandNode addChildren(CommandNode commandNode) {
|
||||
this.childrens.add(commandNode);
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<CommandNode> getChildrens() {
|
||||
return childrens;
|
||||
}
|
||||
|
||||
public List<Argument> getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public CommandNode executes(Command command) {
|
||||
this.command = command;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Command getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static CommandNode node(String name) {
|
||||
return new CommandNode(name);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.io.yutian.elementoriginlib.command;
|
||||
|
||||
public interface IAlias {
|
||||
|
||||
String[] getAlias();
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.io.yutian.elementoriginlib.command;
|
||||
|
||||
import com.io.yutian.elementoriginlib.command.argument.Argument;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ICommand {
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
private List<CommandNode> commandNodes = new ArrayList<>();
|
||||
private List<Argument> arguments = new ArrayList<>();
|
||||
|
||||
public ICommand(String name) {
|
||||
this(name, null);
|
||||
}
|
||||
|
||||
public ICommand(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public void executes(CommandContext commandContext) {
|
||||
}
|
||||
|
||||
public boolean emptyExecutes(CommandSender commandSender) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.isOp() || sender.hasPermission(getPermissionPrefix()+"."+name);
|
||||
}
|
||||
|
||||
public String getPermissionPrefix() {
|
||||
return "command."+name;
|
||||
}
|
||||
|
||||
public ICommand addArgument(Argument argument) {
|
||||
arguments.add(argument);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ICommand addCommandNode(CommandNode commandNode) {
|
||||
this.commandNodes.add(commandNode);
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<CommandNode> getCommandNodes() {
|
||||
return commandNodes;
|
||||
}
|
||||
|
||||
public List<Argument> getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.io.yutian.elementoriginlib.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ICommandManager {
|
||||
|
||||
String getName();
|
||||
|
||||
List<ICommand> getCommands();
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.io.yutian.elementoriginlib.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface ITabCompleter {
|
||||
|
||||
List<String> onTabComplete(CommandSender commandSender, String[] args, int index, String lastArg);
|
||||
|
||||
static List<String> getPlayerList(String arg) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
String name = player.getName();
|
||||
if (arg != null && !arg.trim().equalsIgnoreCase("")) {
|
||||
if (name.toLowerCase().startsWith(arg.toLowerCase())) {
|
||||
list.add(name);
|
||||
}
|
||||
} else {
|
||||
list.add(name);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,295 @@
|
|||
package com.io.yutian.elementoriginlib.command;
|
||||
|
||||
import com.io.yutian.elementoriginlib.command.argument.Argument;
|
||||
import com.io.yutian.elementoriginlib.command.argument.ArgumentValue;
|
||||
import com.io.yutian.elementoriginlib.command.handler.CommandHandler;
|
||||
import com.io.yutian.elementoriginlib.lang.Lang;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SimpleCommandHandler extends Command {
|
||||
|
||||
private ICommand iCommand;
|
||||
|
||||
public SimpleCommandHandler(String name, ICommand iCommand) {
|
||||
super(name);
|
||||
this.iCommand = iCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
executes(sender, commandLabel, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void executes(CommandSender sender, String commandLabel, String[] args) {
|
||||
if (!iCommand.hasPermission(sender)) {
|
||||
sender.sendMessage(Lang.get("command-no-permission"));
|
||||
return;
|
||||
}
|
||||
List<CommandNode> commandNodes = iCommand.getCommandNodes();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
stringBuilder.append(args[i]);
|
||||
if (i < args.length - 1) {
|
||||
stringBuilder.append(" ");
|
||||
}
|
||||
}
|
||||
String commandString = stringBuilder.toString();
|
||||
if (commandNodes.size() == 0) {
|
||||
Map<String, ArgumentValue> map = new HashMap<>();
|
||||
if (iCommand.getArguments().size() > 0) {
|
||||
int argSize = args.length;
|
||||
List<Argument> arguments = iCommand.getArguments();
|
||||
int k = 0;
|
||||
if (arguments.get(arguments.size()-1).isOptional()) {
|
||||
k++;
|
||||
}
|
||||
if (argSize < arguments.size()-k) {
|
||||
sender.sendMessage(Lang.get("command-short-arg"));
|
||||
return;
|
||||
}
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument a = arguments.get(l);
|
||||
int index = l;
|
||||
if (index >= args.length) {
|
||||
break;
|
||||
}
|
||||
String arg = args[index];
|
||||
if (!a.getArgumentsType().test(arg)) {
|
||||
sender.sendMessage(Lang.get("command-unknown-arg", index+1, arg));
|
||||
return;
|
||||
}
|
||||
}
|
||||
map = parseArgumentValue(sender, arguments, args, -1);
|
||||
}
|
||||
iCommand.executes(new CommandContext(commandString, commandLabel, sender, map));
|
||||
return;
|
||||
}
|
||||
|
||||
int nodeSize = args.length;
|
||||
|
||||
if (commandNodes.size() > 0 && nodeSize == 0) {
|
||||
if (!iCommand.emptyExecutes(sender)) {
|
||||
sender.sendMessage(Lang.get("command-short-arg"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
String mainNode = args[0];
|
||||
|
||||
Stream<CommandNode> nodeStream = commandNodes.stream().filter((n) -> {
|
||||
return n.getName().equalsIgnoreCase(mainNode) || n.getAlias().contains(mainNode);
|
||||
});
|
||||
Optional<CommandNode> nodeOptional = nodeStream.findFirst();
|
||||
if (!nodeOptional.isPresent()) {
|
||||
sender.sendMessage(Lang.get("command-unknown-arg", 1, mainNode));
|
||||
return;
|
||||
}
|
||||
CommandNode node = nodeOptional.get();
|
||||
|
||||
if (node.getChildrens().size() > 0) {
|
||||
checkClidren(commandString, commandLabel, sender, 0, args, node);
|
||||
} else {
|
||||
if (node.getCommand() != null) {
|
||||
Map<String, ArgumentValue> map = new HashMap<>();
|
||||
if (node.getArguments().size() > 0) {
|
||||
int argSize = args.length - 1;
|
||||
List<Argument> arguments = node.getArguments();
|
||||
int k = 0;
|
||||
if (arguments.get(arguments.size()-1).isOptional()) {
|
||||
k++;
|
||||
}
|
||||
if (argSize < arguments.size()-k) {
|
||||
sender.sendMessage(Lang.get("command-short-arg"));
|
||||
return;
|
||||
}
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument a = arguments.get(l);
|
||||
int index = l + 1;
|
||||
if (index >= args.length) {
|
||||
break;
|
||||
}
|
||||
String arg = args[index];
|
||||
if (!a.getArgumentsType().test(arg)) {
|
||||
sender.sendMessage(Lang.get("command-error-arg", index+1, arg));
|
||||
return;
|
||||
}
|
||||
}
|
||||
map = parseArgumentValue(sender, node.getArguments(), args, 0);
|
||||
}
|
||||
node.getCommand().run(new CommandContext(commandString, commandLabel, sender, map));
|
||||
} else {
|
||||
sender.sendMessage(Lang.get("command-unknown-arg", 2, mainNode));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void checkClidren(String commandString, String commandLabel, CommandSender sender, int i, String[] args, CommandNode node) {
|
||||
i++;
|
||||
if (i >= args.length) {
|
||||
if (node.getCommand() == null) {
|
||||
sender.sendMessage(Lang.get("command-short-arg"));
|
||||
} else {
|
||||
node.getCommand().run(new CommandContext(commandString, commandLabel, sender, new HashMap<>()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
String s = args[i];
|
||||
Stream<CommandNode> nodeStream = node.getChildrens().stream().filter((n) -> {
|
||||
return n.getName().equalsIgnoreCase(s) || n.getAlias().contains(s);
|
||||
});
|
||||
Optional<CommandNode> nodeOptional = nodeStream.findFirst();
|
||||
if (!nodeOptional.isPresent()) {
|
||||
sender.sendMessage(Lang.get("command-unknown-arg", i+1, s));
|
||||
return;
|
||||
}
|
||||
CommandNode node1 = nodeOptional.get();
|
||||
|
||||
if (node1.getChildrens().size() > 0) {
|
||||
checkClidren(commandString, commandLabel, sender, i, args, node1);
|
||||
} else {
|
||||
if (node1.getCommand() != null) {
|
||||
Map<String, ArgumentValue> map = new HashMap<>();
|
||||
if (node1.getArguments().size() > 0) {
|
||||
int argSize = args.length - i - 1;
|
||||
List<Argument> arguments = node1.getArguments();
|
||||
int k = 0;
|
||||
if (arguments.get(arguments.size()-1).isOptional()) {
|
||||
k++;
|
||||
}
|
||||
if (argSize < arguments.size()-k) {
|
||||
sender.sendMessage(Lang.get("command-short-arg"));
|
||||
return;
|
||||
}
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument a = arguments.get(l);
|
||||
int index = i + l + 1;
|
||||
if (index >= args.length) {
|
||||
break;
|
||||
}
|
||||
String arg = args[index];
|
||||
if (!a.getArgumentsType().test(arg)) {
|
||||
sender.sendMessage(Lang.get("command-unknown-arg", index+1, arg));
|
||||
return;
|
||||
}
|
||||
}
|
||||
map = parseArgumentValue(sender, node1.getArguments(), args, i);
|
||||
}
|
||||
node1.getCommand().run(new CommandContext(commandString, commandLabel, sender, map));
|
||||
} else {
|
||||
sender.sendMessage(Lang.get("command-unknown-arg", i+1, s));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Map<String, ArgumentValue> parseArgumentValue(CommandSender commandSender, List<Argument> argumentList, String[] args, int i) {
|
||||
Map<String, ArgumentValue> map = new HashMap<>();
|
||||
List<Argument> arguments = argumentList;
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument a = arguments.get(l);
|
||||
if (i+1+l >= args.length) {
|
||||
if (a.isOptional()) {
|
||||
map.put(a.getName(), new ArgumentValue(a.getDefaultValue()));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
String arg = args[i+1+l];
|
||||
if (!a.getArgumentsType().test(arg)) {
|
||||
continue;
|
||||
}
|
||||
ArgumentValue argumentValue = new ArgumentValue(a.getArgumentsType().get(arg));
|
||||
map.put(a.getName(), argumentValue);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
||||
return onTabComplete(sender, alias, args);
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(CommandSender sender, String alias, String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
int index = args.length;
|
||||
String arg = args[index-1];
|
||||
if (!iCommand.hasPermission(sender)) {
|
||||
return list;
|
||||
}
|
||||
if (iCommand instanceof ITabCompleter) {
|
||||
ITabCompleter tabCompleter = (ITabCompleter) iCommand;
|
||||
return tabCompleter.onTabComplete(sender, args, index-1, arg);
|
||||
} else {
|
||||
Map<Integer, List<String>> map = new HashMap<>();
|
||||
if (iCommand.getCommandNodes().size() > 0) {
|
||||
List<String> list1 = new ArrayList<>();
|
||||
for (CommandNode node : iCommand.getCommandNodes()) {
|
||||
list1.add(node.getName());
|
||||
list1.addAll(node.getAlias());
|
||||
if (index >= 2) {
|
||||
if (!node.getName().equalsIgnoreCase(args[0])) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (node.getChildrens().size() > 0) {
|
||||
getTabComplete(node, 1, map);
|
||||
} else if (node.getArguments().size() > 0) {
|
||||
List<Argument> arguments = node.getArguments();
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument argument = arguments.get(l);
|
||||
if (argument.getSuggest() != null) {
|
||||
map.put(2+l, argument.getSuggest().getSuggest());
|
||||
continue;
|
||||
}
|
||||
map.put(2+l, Arrays.asList("<"+argument.getName()+">"));
|
||||
}
|
||||
}
|
||||
}
|
||||
map.put(1, list1);
|
||||
return CommandHandler.preseSuggest(map.getOrDefault(index, list), arg);
|
||||
} else if (iCommand.getArguments().size() > 0) {
|
||||
List<Argument> arguments = iCommand.getArguments();
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument argument = arguments.get(l);
|
||||
if (argument.getSuggest() != null) {
|
||||
map.put(0+l+1, argument.getSuggest().getSuggest());
|
||||
continue;
|
||||
}
|
||||
map.put(0+l+1, Arrays.asList("<"+argument.getName()+">"));
|
||||
}
|
||||
return CommandHandler.preseSuggest(map.getOrDefault(index, list), arg);
|
||||
}
|
||||
}
|
||||
return CommandHandler.preseSuggest(list, arg);
|
||||
}
|
||||
|
||||
private void getTabComplete(CommandNode node, int i, Map<Integer, List<String>> map) {
|
||||
i++;
|
||||
List<String> list = map.getOrDefault(i, new ArrayList<>());
|
||||
for (CommandNode c : node.getChildrens()) {
|
||||
list.add(c.getName());
|
||||
if (c.getChildrens().size() > 0) {
|
||||
getTabComplete(c, i, map);
|
||||
} else if (c.getArguments().size() > 0) {
|
||||
List<Argument> arguments = c.getArguments();
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument argument = arguments.get(l);
|
||||
if (argument.getSuggest() != null) {
|
||||
map.put(i+l+1, argument.getSuggest().getSuggest());
|
||||
continue;
|
||||
}
|
||||
map.put(i+l+1, Arrays.asList("<"+argument.getName()+">"));
|
||||
}
|
||||
}
|
||||
}
|
||||
map.put(i, list);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package com.io.yutian.elementoriginlib.command;
|
||||
|
||||
import com.io.yutian.elementoriginlib.command.handler.CommandHandler;
|
||||
import com.io.yutian.elementoriginlib.command.list.CommandHelp;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SimpleCommandManager implements ICommandManager {
|
||||
|
||||
protected static Map<String, Command> bukkitCommandMap = new HashMap<>();
|
||||
protected static CommandMap commandMap;
|
||||
|
||||
private final Plugin plugin;
|
||||
private final String name;
|
||||
|
||||
@NotNull
|
||||
private List<ICommand> commands;
|
||||
|
||||
|
||||
public SimpleCommandManager(Plugin plugin, String name) {
|
||||
this(plugin, name, new ArrayList<>());
|
||||
}
|
||||
|
||||
public SimpleCommandManager(Plugin plugin, String name, @NotNull List<ICommand> commands) {
|
||||
this.plugin = plugin;
|
||||
this.name = name;
|
||||
this.commands = commands;
|
||||
register(new CommandHelp(this));
|
||||
}
|
||||
|
||||
public void register(@NotNull ICommand command) {
|
||||
if (command == null) {
|
||||
return;
|
||||
}
|
||||
commands.add(command);
|
||||
if (command instanceof IAlias alias) {
|
||||
String[] array = alias.getAlias();
|
||||
for (String s : array) {
|
||||
registerPluginBukkitCommand(plugin, s, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterAll() {
|
||||
for (ICommand command : commands) {
|
||||
if (command instanceof IAlias) {
|
||||
unregister(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void unregister(ICommand command) {
|
||||
if (!(command instanceof IAlias)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Map<String, Command> map = (Map<String, Command>) commandMap.getClass().getMethod("getKnownCommands").invoke(commandMap);
|
||||
for (String name : ((IAlias) command).getAlias()) {
|
||||
map.remove(name);
|
||||
Command bukkitCommand = bukkitCommandMap.get(name);
|
||||
bukkitCommand.unregister(commandMap);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void registerPluginCommand(@NotNull Plugin plugin, String commandName) {
|
||||
Bukkit.getPluginCommand(commandName).setExecutor(new CommandHandler(plugin, this));
|
||||
}
|
||||
|
||||
protected static void registerPluginBukkitCommand(Plugin plugin, String name, ICommand command) {
|
||||
SimpleCommandHandler simpleCommandHandler = new SimpleCommandHandler(name, command);
|
||||
bukkitCommandMap.put(name, simpleCommandHandler);
|
||||
commandMap.register(plugin.getName(), simpleCommandHandler);
|
||||
}
|
||||
|
||||
public Plugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ICommand> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
Class<?> c = Bukkit.getServer().getClass();
|
||||
for (Method method : c.getDeclaredMethods()) {
|
||||
if (method.getName().equals("getCommandMap")) {
|
||||
commandMap = (CommandMap) method.invoke(Bukkit.getServer(), new Object[0]);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.io.yutian.elementoriginlib.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Suggest {
|
||||
|
||||
List<String> getSuggest();
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.io.yutian.elementoriginlib.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class Suggests {
|
||||
|
||||
public static final Suggest WORLD_LIST = ()->{
|
||||
List<String> list = new LinkedList<>();
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
list.add(world.getName());
|
||||
}
|
||||
return list;
|
||||
};
|
||||
|
||||
public static final Suggest PLAYER_LIST = ()->{
|
||||
List<String> list = new LinkedList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
list.add(player.getName());
|
||||
}
|
||||
return list;
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.io.yutian.elementoriginlib.command.argument;
|
||||
|
||||
import com.io.yutian.elementoriginlib.command.Suggest;
|
||||
|
||||
public class Argument {
|
||||
|
||||
private String name;
|
||||
|
||||
private ArgumentType argumentsType;
|
||||
|
||||
private Suggest suggest;
|
||||
|
||||
private boolean optional = false;
|
||||
private Object defaultValue = null;
|
||||
|
||||
public Argument(String name, ArgumentType argumentsType) {
|
||||
this.name = name;
|
||||
this.argumentsType = argumentsType;
|
||||
}
|
||||
|
||||
public Argument optional(Object defaultValue) {
|
||||
optional = true;
|
||||
this.defaultValue = defaultValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ArgumentType getArgumentsType() {
|
||||
return argumentsType;
|
||||
}
|
||||
|
||||
public boolean isOptional() {
|
||||
return optional;
|
||||
}
|
||||
|
||||
public Object getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public Argument suggest(Suggest suggest) {
|
||||
this.suggest = suggest;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Suggest getSuggest() {
|
||||
return suggest;
|
||||
}
|
||||
|
||||
public static Argument argument(String name, ArgumentType type) {
|
||||
return new Argument(name, type);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.io.yutian.elementoriginlib.command.argument;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ArgumentType<T> {
|
||||
|
||||
private final String name;
|
||||
|
||||
private Predicate<String> predicate;
|
||||
private Function<String, T> function;
|
||||
|
||||
public ArgumentType(String name, Predicate<String> predicate, Function<String, T> function) {
|
||||
this.name = name;
|
||||
this.predicate = predicate;
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean test(String string) {
|
||||
return predicate.test(string);
|
||||
}
|
||||
|
||||
public T get(String t) {
|
||||
return function.apply(t);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.io.yutian.elementoriginlib.command.argument;
|
||||
|
||||
import com.io.yutian.elementoriginlib.util.StringUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ArgumentTypes {
|
||||
|
||||
public static final ArgumentType<String> STRING = new ArgumentType<>("string", (s) -> true, (s) -> s);
|
||||
|
||||
public static final ArgumentType<Integer> INTEGER = new ArgumentType<>("integer", StringUtil::isInt, Integer::parseInt);
|
||||
|
||||
public static final ArgumentType<Double> DOUBLE = new ArgumentType<>("double", StringUtil::isDouble, Double::parseDouble);
|
||||
|
||||
public static final ArgumentType<UUID> UUID = new ArgumentType<>("uuid", StringUtil::isUUID, java.util.UUID::fromString);
|
||||
|
||||
public static final ArgumentType<Boolean> BOOLEAN = new ArgumentType<>("boolean", StringUtil::isBoolean, Boolean::parseBoolean);
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.io.yutian.elementoriginlib.command.argument;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ArgumentValue {
|
||||
|
||||
private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER = new HashMap<>();
|
||||
|
||||
static {
|
||||
PRIMITIVE_TO_WRAPPER.put(boolean.class, Boolean.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(byte.class, Byte.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(short.class, Short.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(char.class, Character.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(int.class, Integer.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(long.class, Long.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(float.class, Float.class);
|
||||
PRIMITIVE_TO_WRAPPER.put(double.class, Double.class);
|
||||
}
|
||||
|
||||
private Object value;
|
||||
|
||||
public ArgumentValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public <V> V get(Class<V> clazz) {
|
||||
if (PRIMITIVE_TO_WRAPPER.getOrDefault(clazz, clazz).isAssignableFrom(value.getClass())) {
|
||||
return (V) value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return (String) value;
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return (Integer) value;
|
||||
}
|
||||
|
||||
public double getDouble() {
|
||||
return (Double) value;
|
||||
}
|
||||
|
||||
public boolean getBoolean() {
|
||||
return (Boolean) value;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return (UUID) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ArgumentValue{" +
|
||||
"value=" + value +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,341 @@
|
|||
package com.io.yutian.elementoriginlib.command.handler;
|
||||
|
||||
import com.io.yutian.elementoriginlib.command.*;
|
||||
import com.io.yutian.elementoriginlib.command.argument.Argument;
|
||||
import com.io.yutian.elementoriginlib.command.argument.ArgumentValue;
|
||||
import com.io.yutian.elementoriginlib.lang.Lang;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||
|
||||
private ICommandManager commandManager;
|
||||
|
||||
public CommandHandler(Plugin plugin, ICommandManager commandManager) {
|
||||
this.commandManager = commandManager;
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, String label, String[] args) {
|
||||
if (args.length == 0) {
|
||||
execute(sender, label, new String[]{"help", "1"});
|
||||
return;
|
||||
}
|
||||
List<ICommand> commands = commandManager.getCommands();
|
||||
String command = args[0];
|
||||
Stream<ICommand> stream = commands.stream().filter((c) -> c.getName().equalsIgnoreCase(command));
|
||||
Optional<ICommand> optional = stream.findFirst();
|
||||
if (!optional.isPresent()) {
|
||||
sender.sendMessage(Lang.get("command-unknown", command));
|
||||
return;
|
||||
}
|
||||
ICommand iCommand = optional.get();
|
||||
if (!iCommand.hasPermission(sender)) {
|
||||
sender.sendMessage(Lang.get("command-no-permission"));
|
||||
return;
|
||||
}
|
||||
List<CommandNode> commandNodes = iCommand.getCommandNodes();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
stringBuilder.append(args[i]);
|
||||
if (i < args.length - 1) {
|
||||
stringBuilder.append(" ");
|
||||
}
|
||||
}
|
||||
String commandString = stringBuilder.toString();
|
||||
if (commandNodes.size() == 0) {
|
||||
Map<String, ArgumentValue> map = new HashMap<>();
|
||||
if (iCommand.getArguments().size() > 0) {
|
||||
int argSize = args.length - 1;
|
||||
List<Argument> arguments = iCommand.getArguments();
|
||||
int k = 0;
|
||||
if (arguments.get(arguments.size()-1).isOptional()) {
|
||||
k++;
|
||||
}
|
||||
if (argSize < arguments.size()-k) {
|
||||
sender.sendMessage(Lang.get("command-short-arg"));
|
||||
return;
|
||||
}
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument a = arguments.get(l);
|
||||
int index = l + 1;
|
||||
if (index >= args.length) {
|
||||
break;
|
||||
}
|
||||
String arg = args[index];
|
||||
if (!a.getArgumentsType().test(arg)) {
|
||||
sender.sendMessage(Lang.get("command-unknown-arg", index+1, arg));
|
||||
return;
|
||||
}
|
||||
}
|
||||
map = parseArgumentValue(sender, arguments, args, 0);
|
||||
}
|
||||
iCommand.executes(new CommandContext(commandString, label, sender, map));
|
||||
return;
|
||||
}
|
||||
|
||||
int nodeSize = args.length - 1;
|
||||
|
||||
if (commandNodes.size() > 0 && nodeSize == 0) {
|
||||
if (!iCommand.emptyExecutes(sender)) {
|
||||
sender.sendMessage(Lang.get("command-short-arg"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
String mainNode = args[1];
|
||||
Stream<CommandNode> nodeStream = commandNodes.stream().filter((n) -> n.getName().equalsIgnoreCase(mainNode) || n.getAlias().contains(mainNode));
|
||||
Optional<CommandNode> nodeOptional = nodeStream.findFirst();
|
||||
if (!nodeOptional.isPresent()) {
|
||||
sender.sendMessage(Lang.get("command-unknown-arg", 2, mainNode));
|
||||
return;
|
||||
}
|
||||
CommandNode node = nodeOptional.get();
|
||||
|
||||
if (node.getChildrens().size() > 0) {
|
||||
checkClidren(commandString, label, sender, 1, args, node);
|
||||
} else {
|
||||
if (node.getCommand() != null) {
|
||||
Map<String, ArgumentValue> map = new HashMap<>();
|
||||
if (node.getArguments().size() > 0) {
|
||||
int argSize = args.length - 2;
|
||||
List<Argument> arguments = node.getArguments();
|
||||
int k = 0;
|
||||
if (arguments.get(arguments.size()-1).isOptional()) {
|
||||
k++;
|
||||
}
|
||||
if (argSize < arguments.size()-k) {
|
||||
sender.sendMessage(Lang.get("command-short-arg"));
|
||||
return;
|
||||
}
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument a = arguments.get(l);
|
||||
int index = l + 1;
|
||||
if (index >= args.length) {
|
||||
break;
|
||||
}
|
||||
if (index+1 >= args.length) {
|
||||
break;
|
||||
}
|
||||
String arg = args[index+1];
|
||||
if (!a.getArgumentsType().test(arg)) {
|
||||
sender.sendMessage(Lang.get("command-error-arg", index+1, arg));
|
||||
return;
|
||||
}
|
||||
}
|
||||
map = parseArgumentValue(sender, node.getArguments(), args, 1);
|
||||
}
|
||||
node.getCommand().run(new CommandContext(commandString, label, sender, map));
|
||||
} else {
|
||||
sender.sendMessage(Lang.get("command-unknown-arg", 3, mainNode));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Map<String, ArgumentValue> parseArgumentValue(CommandSender commandSender, List<Argument> argumentList, String[] args, int i) {
|
||||
Map<String, ArgumentValue> map = new HashMap<>();
|
||||
List<Argument> arguments = argumentList;
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument a = arguments.get(l);
|
||||
if (i+1+l >= args.length) {
|
||||
if (a.isOptional()) {
|
||||
map.put(a.getName(), new ArgumentValue(a.getDefaultValue()));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
String arg = args[i+1+l];
|
||||
if (!a.getArgumentsType().test(arg)) {
|
||||
continue;
|
||||
}
|
||||
ArgumentValue argumentValue = new ArgumentValue(a.getArgumentsType().get(arg));
|
||||
map.put(a.getName(), argumentValue);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private void checkClidren(String commandString, String label, CommandSender sender, int i, String[] args, CommandNode node) {
|
||||
i++;
|
||||
if (i >= args.length) {
|
||||
if (node.getCommand() == null) {
|
||||
sender.sendMessage(Lang.get("command-short-arg"));
|
||||
} else {
|
||||
node.getCommand().run(new CommandContext(commandString, label, sender, new HashMap<>()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
String s = args[i];
|
||||
Stream<CommandNode> nodeStream = node.getChildrens().stream().filter((n) -> n.getName().equalsIgnoreCase(s) || n.getAlias().contains(s));
|
||||
Optional<CommandNode> nodeOptional = nodeStream.findFirst();
|
||||
if (!nodeOptional.isPresent()) {
|
||||
sender.sendMessage(Lang.get("command-unknown-arg", i+1, s));
|
||||
return;
|
||||
}
|
||||
CommandNode node1 = nodeOptional.get();
|
||||
|
||||
if (node1.getChildrens().size() > 0) {
|
||||
checkClidren(commandString, label, sender, i, args, node1);
|
||||
} else {
|
||||
if (node1.getCommand() != null) {
|
||||
Map<String, ArgumentValue> map = new HashMap<>();
|
||||
if (node1.getArguments().size() > 0) {
|
||||
int argSize = args.length - i - 1;
|
||||
List<Argument> arguments = node1.getArguments();
|
||||
int k = 0;
|
||||
if (arguments.get(arguments.size()-1).isOptional()) {
|
||||
k++;
|
||||
}
|
||||
if (argSize < arguments.size()-k) {
|
||||
sender.sendMessage(Lang.get("command-short-arg"));
|
||||
return;
|
||||
}
|
||||
for (int l = 0; l < arguments.size(); l++) {
|
||||
Argument a = arguments.get(l);
|
||||
int index = i + l + 1;
|
||||
if (index >= args.length) {
|
||||
break;
|
||||
}
|
||||
String arg = args[index];
|
||||
if (!a.getArgumentsType().test(arg)) {
|
||||
sender.sendMessage(Lang.get("command-unknown-arg", index+1, arg));
|
||||
return;
|
||||
}
|
||||
}
|
||||
map = parseArgumentValue(sender, node1.getArguments(), args, i);
|
||||
}
|
||||
node1.getCommand().run(new CommandContext(commandString, label, sender, map));
|
||||
} else {
|
||||
sender.sendMessage(Lang.get("command-unknown-arg", i+1, s));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
execute(sender, label, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
int index = args.length;
|
||||
String arg = args[index-1];
|
||||
List<ICommand> commands = commandManager.getCommands();
|
||||
if (index == 1) {
|
||||
List<ICommand> commandList = commands.stream().filter((c)->c.getName().startsWith(arg)).collect(Collectors.toList());
|
||||
if (commandList.size() > 0) {
|
||||
commandList.forEach(c-> {
|
||||
if (c.hasPermission(sender)) {
|
||||
list.add(c.getName());
|
||||
}
|
||||
}); |