add full commands list dump command

This commit is contained in:
2022-04-19 20:33:47 +02:00
parent 428ee93996
commit 0716514787
8 changed files with 140 additions and 34 deletions
@@ -22,6 +22,7 @@ import org.slf4j.Logger;
import javax.inject.Inject;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -97,6 +98,10 @@ public class CommandWhitelistVelocity {
return configCache;
}
public static Path getConfigPath() {
return folder;
}
/**
* @param player Velocity Player
* @return commands available to the player
@@ -129,4 +134,8 @@ public class CommandWhitelistVelocity {
return suggestionList;
}
public static ArrayList<String> getServerCommands() {
return new ArrayList<>(server.getCommandManager().getAliases());
}
}
@@ -3,10 +3,12 @@ package eu.endermite.commandwhitelist.velocity.command;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.common.CommandUtil;
import eu.endermite.commandwhitelist.common.commands.CWCommand;
import eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity;
import net.kyori.adventure.text.Component;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -60,6 +62,18 @@ public class VelocityMainCommand implements SimpleCommand {
} else
sender.sendMessage(Component.text("/" + label + " remove <group> <command>"));
return;
case DUMP:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
sender.sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
return;
}
sender.sendMessage(Component.text("Dumping all available commands to a file..."));
if (CommandUtil.dumpAllBukkitCommands(CommandWhitelistVelocity.getServerCommands(), new File(String.valueOf(CommandWhitelistVelocity.getConfigPath()), "command_dump.yml"))) {
sender.sendMessage(Component.text("Commands dumped to command_dump.yml"));
} else {
sender.sendMessage(Component.text("Failed to save the file."));
}
return;
case HELP:
default:
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
@@ -76,8 +90,15 @@ public class VelocityMainCommand implements SimpleCommand {
CommandSource source = invocation.source();
String[] args = invocation.arguments();
return CompletableFuture.supplyAsync(() -> {
List<String> serverCommands = new ArrayList<>();
return CWCommand.commandSuggestions(CommandWhitelistVelocity.getConfigCache(), serverCommands, args, source.hasPermission(CWPermission.RELOAD.permission()), source.hasPermission(CWPermission.ADMIN.permission()), CWCommand.ImplementationType.VELOCITY);
List<String> serverCommands = CommandWhitelistVelocity.getServerCommands();
return CWCommand.commandSuggestions(
CommandWhitelistVelocity.getConfigCache(),
serverCommands,
args,
source.hasPermission(CWPermission.RELOAD.permission()),
source.hasPermission(CWPermission.ADMIN.permission()),
CWCommand.ImplementationType.VELOCITY
);
});
}
}