Compare commits

..

3 Commits

Author SHA1 Message Date
YouHaveTrouble 9e13c7b2f1 bump version 2022-04-19 20:35:01 +02:00
YouHaveTrouble 0716514787 add full commands list dump command 2022-04-19 20:33:47 +02:00
YouHaveTrouble 428ee93996 make keybind and clickevent work 2022-04-01 20:44:48 +02:00
13 changed files with 147 additions and 39 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.3.1</version>
<version>2.4.0</version>
</parent>
<artifactId>Bukkit</artifactId>
@@ -1,6 +1,6 @@
package eu.endermite.commandwhitelist.bukkit;
import eu.endermite.commandwhitelist.bukkit.command.MainCommandExecutor;
import eu.endermite.commandwhitelist.bukkit.command.BukkitCommandExecutor;
import eu.endermite.commandwhitelist.bukkit.listeners.AsyncTabCompleteBlockerListener;
import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandPreProcessListener;
import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandSendListener;
@@ -17,13 +17,12 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.help.HelpTopic;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.*;
public class CommandWhitelistBukkit extends JavaPlugin {
@@ -59,7 +58,7 @@ public class CommandWhitelistBukkit extends JavaPlugin {
PluginCommand command = getCommand("commandwhitelist");
if (command != null) {
MainCommandExecutor executor = new MainCommandExecutor();
BukkitCommandExecutor executor = new BukkitCommandExecutor();
command.setExecutor(executor);
command.setTabCompleter(executor);
}
@@ -151,4 +150,18 @@ public class CommandWhitelistBukkit extends JavaPlugin {
}
return commandDeniedMessage;
}
public static ArrayList<String> getServerCommands() {
try {
return new ArrayList<>(Bukkit.getCommandMap().getKnownCommands().keySet());
} catch (NoSuchMethodError error) {
HashSet<String> commands = new HashSet<>();
for (HelpTopic topic : Bukkit.getHelpMap().getHelpTopics()) {
String cmd = topic.getName();
if (Character.isUpperCase(cmd.charAt(0))) continue;
commands.add(topic.getName());
}
return new ArrayList<>(commands);
}
}
}
@@ -2,20 +2,18 @@ package eu.endermite.commandwhitelist.bukkit.command;
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.common.CommandUtil;
import eu.endermite.commandwhitelist.common.commands.CWCommand;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.help.HelpTopic;
import java.util.ArrayList;
import java.util.HashSet;
import java.io.File;
import java.util.List;
public class MainCommandExecutor implements TabExecutor {
public class BukkitCommandExecutor implements TabExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@@ -62,6 +60,18 @@ public class MainCommandExecutor implements TabExecutor {
} else
audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>"));
return true;
case DUMP:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
return true;
}
audiences.sender(sender).sendMessage(Component.text("Dumping all available commands to a file..."));
if (CommandUtil.dumpAllBukkitCommands(CommandWhitelistBukkit.getServerCommands(), new File("plugins/CommandWhitelist/config.yml"))) {
audiences.sender(sender).sendMessage(Component.text("Commands dumped to command_dump.yml"));
} else {
audiences.sender(sender).sendMessage(Component.text("Failed to save the file."));
}
return true;
case HELP:
default:
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
@@ -74,18 +84,13 @@ public class MainCommandExecutor implements TabExecutor {
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> serverCommands;
try {
serverCommands = new ArrayList<>(Bukkit.getCommandMap().getKnownCommands().keySet());
} catch (NoSuchMethodError error) {
HashSet<String> commands = new HashSet<>();
for (HelpTopic topic : Bukkit.getHelpMap().getHelpTopics()) {
String cmd = topic.getName();
if (Character.isUpperCase(cmd.charAt(0))) continue;
commands.add(topic.getName());
}
serverCommands = new ArrayList<>(commands);
}
return CWCommand.commandSuggestions(CommandWhitelistBukkit.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()), CWCommand.ImplementationType.BUKKIT);
return CWCommand.commandSuggestions(
CommandWhitelistBukkit.getConfigCache(),
CommandWhitelistBukkit.getServerCommands(),
args,
sender.hasPermission(CWPermission.RELOAD.permission()),
sender.hasPermission(CWPermission.ADMIN.permission()),
CWCommand.ImplementationType.BUKKIT
);
}
}
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.3.1</version>
<version>2.4.0</version>
</parent>
<artifactId>Common</artifactId>
@@ -1,5 +1,9 @@
package eu.endermite.commandwhitelist.common;
import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -63,4 +67,31 @@ public class CommandUtil {
return parts[0];
}
/**
* Dumps command list to a file
*
* @param serverCommands Commands to dump
* @return True on successful file save
*/
public static boolean dumpAllBukkitCommands(ArrayList<String> serverCommands, File file) {
try {
File parent = new File(file.getParent());
if (!parent.exists())
parent.mkdir();
if (!file.exists())
file.createNewFile();
} catch (IOException e) {
return false;
}
ConfigFile dumpFile = ConfigFile.loadConfig(file);
dumpFile.set("commands", serverCommands);
try {
dumpFile.save();
} catch (IOException e) {
return false;
}
return true;
}
}
@@ -23,6 +23,8 @@ public class CWCommand {
.resolver(StandardTags.rainbow())
.resolver(StandardTags.translatable())
.resolver(StandardTags.newline())
.resolver(StandardTags.clickEvent())
.resolver(StandardTags.keybind())
.build()
).build();
@@ -61,7 +63,7 @@ public class CWCommand {
}
public enum CommandType {
ADD, REMOVE, HELP, RELOAD
ADD, REMOVE, HELP, RELOAD, DUMP
}
public enum ImplementationType {
@@ -86,6 +88,7 @@ public class CWCommand {
if (adminPerm) {
list.add("add");
list.add("remove");
list.add("dump");
}
}
return list;
@@ -98,6 +101,8 @@ public class CWCommand {
list.add("add");
if ("remove".startsWith(args[0]) && adminPerm)
list.add("remove");
if ("dump".startsWith(args[0]) && adminPerm)
list.add("dump");
return list;
case 2:
if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("remove")) {
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.3.1</version>
<version>2.4.0</version>
</parent>
<artifactId>Velocity</artifactId>
@@ -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
);
});
}
}
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.3.1</version>
<version>2.4.0</version>
</parent>
<artifactId>Waterfall</artifactId>
@@ -11,14 +11,13 @@ import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.Plugin;
import org.bstats.bungeecord.Metrics;
import org.bstats.charts.SimplePie;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.*;
public final class CommandWhitelistWaterfall extends Plugin {
@@ -122,4 +121,12 @@ public final class CommandWhitelistWaterfall extends Plugin {
}
return commandDeniedMessage;
}
public static ArrayList<String> getServerCommands() {
ArrayList<String> serverCommands = new ArrayList<>();
for (Map.Entry<String, Command> command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) {
serverCommands.add(command.getValue().getName());
}
return serverCommands;
}
}
@@ -1,6 +1,7 @@
package eu.endermite.commandwhitelist.waterfall.command;
import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.common.CommandUtil;
import eu.endermite.commandwhitelist.common.ConfigCache;
import eu.endermite.commandwhitelist.common.commands.CWCommand;
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
@@ -10,6 +11,7 @@ import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.TabExecutor;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -67,6 +69,18 @@ public class BungeeMainCommand extends Command implements TabExecutor {
} else
audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>"));
return;
case DUMP:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().no_permission));
return;
}
audiences.sender(sender).sendMessage(Component.text("Dumping all available commands to a file..."));
if (CommandUtil.dumpAllBukkitCommands(CommandWhitelistWaterfall.getServerCommands(), new File("plugins/CommandWhitelist/config.yml"))) {
audiences.sender(sender).sendMessage(Component.text("Commands dumped to command_dump.yml"));
} else {
audiences.sender(sender).sendMessage(Component.text("Failed to save the file."));
}
return;
case HELP:
default:
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
@@ -80,10 +94,13 @@ public class BungeeMainCommand extends Command implements TabExecutor {
@Override
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
List<String> serverCommands = new ArrayList<>();
for (Map.Entry<String, Command> command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) {
serverCommands.add(command.getValue().getName());
}
return CWCommand.commandSuggestions(CommandWhitelistWaterfall.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()), CWCommand.ImplementationType.WATERFALL);
return CWCommand.commandSuggestions(
CommandWhitelistWaterfall.getConfigCache(),
CommandWhitelistWaterfall.getServerCommands(),
args,
sender.hasPermission(CWPermission.RELOAD.permission()),
sender.hasPermission(CWPermission.ADMIN.permission()),
CWCommand.ImplementationType.WATERFALL
);
}
}
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.3.1</version>
<version>2.4.0</version>
<modules>
<module>CommandWhitelistCommon</module>
<module>CommandWhitelistBukkit</module>