mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 14:36:56 +00:00
more reorganizing and making things work
This commit is contained in:
+54
-15
@@ -2,9 +2,10 @@ package eu.endermite.commandwhitelist.velocity.command;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||
import eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -13,22 +14,60 @@ public class VelocityMainCommand implements SimpleCommand {
|
||||
|
||||
@Override
|
||||
public void execute(final Invocation invocation) {
|
||||
CommandSource source = invocation.source();
|
||||
CommandSource sender = invocation.source();
|
||||
String[] args = invocation.arguments();
|
||||
if (args.length > 0) {
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
|
||||
if (source.hasPermission("commandwhitelist.reload")) {
|
||||
CommandWhitelistVelocity.reloadConfig(source);
|
||||
} else {
|
||||
source.sendMessage(Component.text(CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
source.sendMessage(Component.text("&bCommand Whitelist by YouHaveTrouble".replaceAll("&", "§")));
|
||||
if (source.hasPermission("commandwhitelist.reload")) {
|
||||
source.sendMessage(Component.text("&9/vcw reload &b- Reload velocity plugin configuration".replaceAll("&", "§")));
|
||||
}
|
||||
String label = invocation.alias();
|
||||
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission("commandwhitelist.reload"), sender.hasPermission("commandwhitelist.admin")));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase());
|
||||
switch (commandType) {
|
||||
case RELOAD:
|
||||
if (!sender.hasPermission("commandwhitelist.reload")) {
|
||||
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||
return;
|
||||
}
|
||||
CommandWhitelistVelocity.reloadConfig(sender);
|
||||
return;
|
||||
case ADD:
|
||||
if (!sender.hasPermission("commandwhitelist.admin")) {
|
||||
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||
return;
|
||||
}
|
||||
if (args.length == 3) {
|
||||
if (CWCommand.addToWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
|
||||
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().added_to_whitelist));
|
||||
else
|
||||
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist));
|
||||
} else
|
||||
sender.sendMessage(Component.text("/"+label+" add <group> <command>"));
|
||||
return;
|
||||
case REMOVE:
|
||||
if (!sender.hasPermission("commandwhitelist.admin")) {
|
||||
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||
return;
|
||||
}
|
||||
if (args.length == 3) {
|
||||
if (CWCommand.removeFromWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
|
||||
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().removed_from_whitelist));
|
||||
else
|
||||
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist));
|
||||
} else
|
||||
sender.sendMessage(Component.text("/"+label+" remove <group> <command>"));
|
||||
return;
|
||||
case HELP:
|
||||
default:
|
||||
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission("commandwhitelist.reload"), sender.hasPermission("commandwhitelist.admin")));
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission("commandwhitelist.reload"), sender.hasPermission("commandwhitelist.admin")));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
package eu.endermite.commandwhitelist.velocity.config;
|
||||
|
||||
import com.moandjiezana.toml.Toml;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class VelocityConfigCache {
|
||||
|
||||
private HashMap<String, List<String>> permList = new HashMap<>();
|
||||
private final String noPermission, noSubCommand, configReloaded;
|
||||
|
||||
|
||||
public VelocityConfigCache(Toml config) {
|
||||
|
||||
Toml messages = config.getTable("messages");
|
||||
noPermission = messages.getString("no-permission", "&cYou don't have permission to do this.");
|
||||
noSubCommand = messages.getString("no-such-subcommand", "&cNo subcommand by that name.");
|
||||
configReloaded = messages.getString("config-reloaded", "&eConfiguration reloaded.");
|
||||
|
||||
Toml groups = config.getTable("commands");
|
||||
|
||||
for (Map.Entry<String, Object> set : groups.entrySet()) {
|
||||
this.permList.put(set.getKey(), (List<String>) set.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<String, List<String>> getPermList() {
|
||||
return permList;
|
||||
}
|
||||
public String getNoPermission() {
|
||||
return noPermission.replaceAll("&", "§");
|
||||
}
|
||||
public String getNoSubCommand() {return noSubCommand.replaceAll("&", "§");}
|
||||
public String getConfigReloaded() {return configReloaded.replaceAll("&", "§");}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user