Compare commits

...

6 Commits

Author SHA1 Message Date
YouHaveTrouble 2c7a089fae bump version 2022-05-01 15:22:00 +02:00
YouHaveTrouble 41ff6d9d3e don't replace config. whops 2022-05-01 15:20:00 +02:00
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
YouHaveTrouble 8b45057544 make <newline> work 2022-03-21 17:11:46 +01:00
13 changed files with 148 additions and 39 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.3.0</version> <version>2.4.1</version>
</parent> </parent>
<artifactId>Bukkit</artifactId> <artifactId>Bukkit</artifactId>
@@ -1,6 +1,6 @@
package eu.endermite.commandwhitelist.bukkit; 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.AsyncTabCompleteBlockerListener;
import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandPreProcessListener; import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandPreProcessListener;
import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandSendListener; import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandSendListener;
@@ -17,13 +17,12 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.help.HelpTopic;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.*;
import java.util.HashSet;
import java.util.Map;
public class CommandWhitelistBukkit extends JavaPlugin { public class CommandWhitelistBukkit extends JavaPlugin {
@@ -59,7 +58,7 @@ public class CommandWhitelistBukkit extends JavaPlugin {
PluginCommand command = getCommand("commandwhitelist"); PluginCommand command = getCommand("commandwhitelist");
if (command != null) { if (command != null) {
MainCommandExecutor executor = new MainCommandExecutor(); BukkitCommandExecutor executor = new BukkitCommandExecutor();
command.setExecutor(executor); command.setExecutor(executor);
command.setTabCompleter(executor); command.setTabCompleter(executor);
} }
@@ -151,4 +150,18 @@ public class CommandWhitelistBukkit extends JavaPlugin {
} }
return commandDeniedMessage; 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.bukkit.CommandWhitelistBukkit;
import eu.endermite.commandwhitelist.common.CWPermission; import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.common.CommandUtil;
import eu.endermite.commandwhitelist.common.commands.CWCommand; import eu.endermite.commandwhitelist.common.commands.CWCommand;
import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.bukkit.help.HelpTopic;
import java.util.ArrayList; import java.io.File;
import java.util.HashSet;
import java.util.List; import java.util.List;
public class MainCommandExecutor implements TabExecutor { public class BukkitCommandExecutor implements TabExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@@ -62,6 +60,18 @@ public class MainCommandExecutor implements TabExecutor {
} else } else
audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>")); audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>"));
return true; 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/command_dump.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: case HELP:
default: default:
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()))); 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 @Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> serverCommands; return CWCommand.commandSuggestions(
try { CommandWhitelistBukkit.getConfigCache(),
serverCommands = new ArrayList<>(Bukkit.getCommandMap().getKnownCommands().keySet()); CommandWhitelistBukkit.getServerCommands(),
} catch (NoSuchMethodError error) { args,
HashSet<String> commands = new HashSet<>(); sender.hasPermission(CWPermission.RELOAD.permission()),
for (HelpTopic topic : Bukkit.getHelpMap().getHelpTopics()) { sender.hasPermission(CWPermission.ADMIN.permission()),
String cmd = topic.getName(); CWCommand.ImplementationType.BUKKIT
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);
} }
} }
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.3.0</version> <version>2.4.1</version>
</parent> </parent>
<artifactId>Common</artifactId> <artifactId>Common</artifactId>
@@ -1,5 +1,9 @@
package eu.endermite.commandwhitelist.common; 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.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -63,4 +67,31 @@ public class CommandUtil {
return parts[0]; 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;
}
} }
@@ -22,6 +22,9 @@ public class CWCommand {
.resolver(StandardTags.reset()) .resolver(StandardTags.reset())
.resolver(StandardTags.rainbow()) .resolver(StandardTags.rainbow())
.resolver(StandardTags.translatable()) .resolver(StandardTags.translatable())
.resolver(StandardTags.newline())
.resolver(StandardTags.clickEvent())
.resolver(StandardTags.keybind())
.build() .build()
).build(); ).build();
@@ -60,7 +63,7 @@ public class CWCommand {
} }
public enum CommandType { public enum CommandType {
ADD, REMOVE, HELP, RELOAD ADD, REMOVE, HELP, RELOAD, DUMP
} }
public enum ImplementationType { public enum ImplementationType {
@@ -85,6 +88,7 @@ public class CWCommand {
if (adminPerm) { if (adminPerm) {
list.add("add"); list.add("add");
list.add("remove"); list.add("remove");
list.add("dump");
} }
} }
return list; return list;
@@ -97,6 +101,8 @@ public class CWCommand {
list.add("add"); list.add("add");
if ("remove".startsWith(args[0]) && adminPerm) if ("remove".startsWith(args[0]) && adminPerm)
list.add("remove"); list.add("remove");
if ("dump".startsWith(args[0]) && adminPerm)
list.add("dump");
return list; return list;
case 2: case 2:
if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("remove")) { if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("remove")) {
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.3.0</version> <version>2.4.1</version>
</parent> </parent>
<artifactId>Velocity</artifactId> <artifactId>Velocity</artifactId>
@@ -22,6 +22,7 @@ import org.slf4j.Logger;
import javax.inject.Inject; import javax.inject.Inject;
import java.io.File; import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
@@ -97,6 +98,10 @@ public class CommandWhitelistVelocity {
return configCache; return configCache;
} }
public static Path getConfigPath() {
return folder;
}
/** /**
* @param player Velocity Player * @param player Velocity Player
* @return commands available to the player * @return commands available to the player
@@ -129,4 +134,8 @@ public class CommandWhitelistVelocity {
return suggestionList; 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.CommandSource;
import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.command.SimpleCommand;
import eu.endermite.commandwhitelist.common.CWPermission; import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.common.CommandUtil;
import eu.endermite.commandwhitelist.common.commands.CWCommand; import eu.endermite.commandwhitelist.common.commands.CWCommand;
import eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity; import eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@@ -60,6 +62,18 @@ public class VelocityMainCommand implements SimpleCommand {
} else } else
sender.sendMessage(Component.text("/" + label + " remove <group> <command>")); sender.sendMessage(Component.text("/" + label + " remove <group> <command>"));
return; 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: case HELP:
default: default:
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()))); 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(); CommandSource source = invocation.source();
String[] args = invocation.arguments(); String[] args = invocation.arguments();
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
List<String> serverCommands = new ArrayList<>(); 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); 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> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.3.0</version> <version>2.4.1</version>
</parent> </parent>
<artifactId>Waterfall</artifactId> <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.ChatColor;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer; 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 net.md_5.bungee.api.plugin.Plugin;
import org.bstats.bungeecord.Metrics; import org.bstats.bungeecord.Metrics;
import org.bstats.charts.SimplePie; import org.bstats.charts.SimplePie;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.*;
import java.util.HashSet;
import java.util.Map;
public final class CommandWhitelistWaterfall extends Plugin { public final class CommandWhitelistWaterfall extends Plugin {
@@ -122,4 +121,12 @@ public final class CommandWhitelistWaterfall extends Plugin {
} }
return commandDeniedMessage; 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; package eu.endermite.commandwhitelist.waterfall.command;
import eu.endermite.commandwhitelist.common.CWPermission; import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.common.CommandUtil;
import eu.endermite.commandwhitelist.common.ConfigCache; import eu.endermite.commandwhitelist.common.ConfigCache;
import eu.endermite.commandwhitelist.common.commands.CWCommand; import eu.endermite.commandwhitelist.common.commands.CWCommand;
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall; 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.Command;
import net.md_5.bungee.api.plugin.TabExecutor; import net.md_5.bungee.api.plugin.TabExecutor;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -67,6 +69,18 @@ public class BungeeMainCommand extends Command implements TabExecutor {
} else } else
audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>")); audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>"));
return; 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/command_dump.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: case HELP:
default: default:
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()))); 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 @Override
public Iterable<String> onTabComplete(CommandSender sender, String[] args) { public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
List<String> serverCommands = new ArrayList<>(); return CWCommand.commandSuggestions(
for (Map.Entry<String, Command> command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) { CommandWhitelistWaterfall.getConfigCache(),
serverCommands.add(command.getValue().getName()); CommandWhitelistWaterfall.getServerCommands(),
} args,
return CWCommand.commandSuggestions(CommandWhitelistWaterfall.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()), CWCommand.ImplementationType.WATERFALL); 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> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.3.0</version> <version>2.4.1</version>
<modules> <modules>
<module>CommandWhitelistCommon</module> <module>CommandWhitelistCommon</module>
<module>CommandWhitelistBukkit</module> <module>CommandWhitelistBukkit</module>