mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 14:36:56 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b9db85278c | |||
| 87e59e3f2b | |||
| 292cac7415 | |||
| 7629b580ae | |||
| 7101d3d713 | |||
| 6487255d04 | |||
| c57a58eb41 | |||
| 8fac940359 | |||
| fe0b8c416d |
@@ -0,0 +1,28 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: bug
|
||||||
|
assignees: YouHaveTrouble
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: enhancement
|
||||||
|
assignees: YouHaveTrouble
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
name: Other issue
|
||||||
|
about: For other issues
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: YouHaveTrouble
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>eu.endermite</groupId>
|
<groupId>eu.endermite</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>1.4.0</version>
|
<version>1.5.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>CommandWhitelist</name>
|
<name>CommandWhitelist</name>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ precisely what commands players can see and use.
|
|||||||
<li>Overwrites default "no such command" message with your branding
|
<li>Overwrites default "no such command" message with your branding
|
||||||
<li>Blocks tab completion on spigot and bungeecord*</li>
|
<li>Blocks tab completion on spigot and bungeecord*</li>
|
||||||
<li>Blocks command execution on spigot and bungeecord</li>
|
<li>Blocks command execution on spigot and bungeecord</li>
|
||||||
|
<li>Blocks completion and execution of specific subcommands (spigot only)</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
\*This only works on Waterfall and its forks
|
\*This only works on Waterfall and its forks
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import java.util.Map;
|
|||||||
public class CommandsList {
|
public class CommandsList {
|
||||||
|
|
||||||
public static List<String> getCommands(Player player) {
|
public static List<String> getCommands(Player player) {
|
||||||
|
|
||||||
List<String> commandList = new ArrayList<>();
|
List<String> commandList = new ArrayList<>();
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
||||||
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
|
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
|
||||||
@@ -22,7 +21,6 @@ public class CommandsList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getCommands(ProxiedPlayer player) {
|
public static List<String> getCommands(ProxiedPlayer player) {
|
||||||
|
|
||||||
List<String> commandList = new ArrayList<>();
|
List<String> commandList = new ArrayList<>();
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelistBungee.getConfigCache().getPermList().entrySet()) {
|
for (Map.Entry<String, List<String>> s : CommandWhitelistBungee.getConfigCache().getPermList().entrySet()) {
|
||||||
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
|
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
|
||||||
@@ -32,4 +30,26 @@ public class CommandsList {
|
|||||||
return commandList;
|
return commandList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> getSuggestions(Player player) {
|
||||||
|
List<String> suggestionList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermSubList().entrySet()) {
|
||||||
|
if (player.hasPermission("commandwhitelist.subcommands." + s.getKey()))
|
||||||
|
continue;
|
||||||
|
suggestionList.addAll(s.getValue());
|
||||||
|
}
|
||||||
|
return suggestionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getLastArgument(String cmd) {
|
||||||
|
String[] parts = cmd.split(" ");
|
||||||
|
if (parts.length <= 1)
|
||||||
|
return "";
|
||||||
|
String last = "";
|
||||||
|
for (String part : parts) {
|
||||||
|
last = part;
|
||||||
|
}
|
||||||
|
return last;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import eu.endermite.commandwhitelist.spigot.config.ConfigCache;
|
|||||||
import eu.endermite.commandwhitelist.spigot.listeners.LegacyPlayerTabChatCompleteListener;
|
import eu.endermite.commandwhitelist.spigot.listeners.LegacyPlayerTabChatCompleteListener;
|
||||||
import eu.endermite.commandwhitelist.spigot.listeners.PlayerCommandPreProcessListener;
|
import eu.endermite.commandwhitelist.spigot.listeners.PlayerCommandPreProcessListener;
|
||||||
import eu.endermite.commandwhitelist.spigot.listeners.PlayerCommandSendListener;
|
import eu.endermite.commandwhitelist.spigot.listeners.PlayerCommandSendListener;
|
||||||
|
import eu.endermite.commandwhitelist.spigot.listeners.TabCompleteBlockerListener;
|
||||||
import eu.endermite.commandwhitelist.spigot.metrics.BukkitMetrics;
|
import eu.endermite.commandwhitelist.spigot.metrics.BukkitMetrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@@ -39,6 +40,8 @@ public class CommandWhitelist extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this);
|
||||||
|
|
||||||
getCommand("commandwhitelist").setExecutor(new MainCommand());
|
getCommand("commandwhitelist").setExecutor(new MainCommand());
|
||||||
getCommand("commandwhitelist").setTabCompleter(new MainCommand());
|
getCommand("commandwhitelist").setTabCompleter(new MainCommand());
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ public class MainCommand implements TabExecutor {
|
|||||||
}
|
}
|
||||||
if (sender.hasPermission("commandwhitelist.admin")) {
|
if (sender.hasPermission("commandwhitelist.admin")) {
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9/cw add <group> <command> &b- Add command to group"));
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9/cw add <group> <command> &b- Add command to group"));
|
||||||
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9/cw remove <group> <command> &b- Remove command from a group"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.config;
|
package eu.endermite.commandwhitelist.spigot.config;
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -11,20 +13,22 @@ public class ConfigCache {
|
|||||||
|
|
||||||
private FileConfiguration config;
|
private FileConfiguration config;
|
||||||
private HashMap<String, List<String>> permList = new HashMap<>();
|
private HashMap<String, List<String>> permList = new HashMap<>();
|
||||||
|
private HashMap<String, List<String>> permSubList = new HashMap<>();
|
||||||
private final String prefix, commandDenied, noPermission, noSubCommand, configReloaded, whitelistedCommand,
|
private final String prefix, commandDenied, noPermission, noSubCommand, configReloaded, whitelistedCommand,
|
||||||
removedWhitelistedCommand, noSuchGroup;
|
removedWhitelistedCommand, noSuchGroup, subCommandDenied;
|
||||||
private final List<String> commandDeniedList;
|
private final List<String> commandDeniedList;
|
||||||
|
|
||||||
public ConfigCache(FileConfiguration config) {
|
public ConfigCache(FileConfiguration config) {
|
||||||
|
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
prefix = config.getString("messages.prefix");
|
prefix = config.getString("messages.prefix", "");
|
||||||
commandDenied = config.getString("messages.command-denied", null);
|
commandDenied = config.getString("messages.command-denied", null);
|
||||||
commandDeniedList = config.getStringList("messages.command-denied");
|
commandDeniedList = config.getStringList("messages.command-denied");
|
||||||
noPermission = config.getString("messages.no-permission");
|
subCommandDenied = config.getString("messages.subcommand-denied", "You cannot use this subcommand");
|
||||||
noSubCommand = config.getString("messages.no-such-subcommand");
|
noPermission = config.getString("messages.no-permission", "&cYou don't have permission to do this.");
|
||||||
configReloaded = config.getString("messages.config-reloaded");
|
noSubCommand = config.getString("messages.no-such-subcommand", "&cNo subcommand by that name.");
|
||||||
|
configReloaded = config.getString("messages.config-reloaded", "&eConfiguration reloaded.");
|
||||||
whitelistedCommand = config.getString("messages.added-to-whitelist", "&eWhitelisted command &6%s &efor permission &6%s");
|
whitelistedCommand = config.getString("messages.added-to-whitelist", "&eWhitelisted command &6%s &efor permission &6%s");
|
||||||
removedWhitelistedCommand = config.getString("messages.removed-from-whitelist", "&eRemoved command &6%s &efrom permission &6%s");
|
removedWhitelistedCommand = config.getString("messages.removed-from-whitelist", "&eRemoved command &6%s &efrom permission &6%s");
|
||||||
noSuchGroup = config.getString("messages.group-doesnt-exist", "&cGroup %s doesn't exist");
|
noSuchGroup = config.getString("messages.group-doesnt-exist", "&cGroup %s doesn't exist");
|
||||||
@@ -33,16 +37,30 @@ public class ConfigCache {
|
|||||||
for (String s : perms) {
|
for (String s : perms) {
|
||||||
this.permList.put(s, config.getStringList("commands."+s));
|
this.permList.put(s, config.getStringList("commands."+s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<String> subperms = config.getConfigurationSection("tabcompletions").getKeys(false);
|
||||||
|
for (String s : subperms) {
|
||||||
|
this.permSubList.put(s, config.getStringList("tabcompletions."+s));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, List<String>> getPermList() {
|
public HashMap<String, List<String>> getPermList() {
|
||||||
return permList;
|
return permList;
|
||||||
}
|
}
|
||||||
|
public HashMap<String, List<String>> getPermSubList() {
|
||||||
|
return permSubList;
|
||||||
|
}
|
||||||
public boolean addCommand(String command, String group) {
|
public boolean addCommand(String command, String group) {
|
||||||
try {
|
try {
|
||||||
|
if (this.permList.get(group).contains(command)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
this.permList.get(group).add(command);
|
this.permList.get(group).add(command);
|
||||||
this.config.set("commands."+group, permList.get(group));
|
this.config.set("commands."+group, permList.get(group));
|
||||||
config.save(CommandWhitelist.getPlugin().getDataFolder()+"/config.yml");
|
config.save(CommandWhitelist.getPlugin().getDataFolder()+"/config.yml");
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
player.updateCommands();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -53,6 +71,9 @@ public class ConfigCache {
|
|||||||
this.permList.get(group).remove(command);
|
this.permList.get(group).remove(command);
|
||||||
this.config.set("commands."+group, permList.get(group));
|
this.config.set("commands."+group, permList.get(group));
|
||||||
config.save(CommandWhitelist.getPlugin().getDataFolder()+"/config.yml");
|
config.save(CommandWhitelist.getPlugin().getDataFolder()+"/config.yml");
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
player.updateCommands();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -75,4 +96,7 @@ public class ConfigCache {
|
|||||||
public String getNoSuchGroup() {
|
public String getNoSuchGroup() {
|
||||||
return noSuchGroup;
|
return noSuchGroup;
|
||||||
}
|
}
|
||||||
|
public String getSubCommandDenied() {
|
||||||
|
return subCommandDenied;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
-1
@@ -25,7 +25,6 @@ public class LegacyPlayerTabChatCompleteListener {
|
|||||||
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.TAB_COMPLETE) {
|
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.TAB_COMPLETE) {
|
||||||
@Override
|
@Override
|
||||||
public void onPacketSending(PacketEvent event) {
|
public void onPacketSending(PacketEvent event) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.hasPermission("commandwhitelist.bypass")) {
|
if (player.hasPermission("commandwhitelist.bypass")) {
|
||||||
|
|||||||
+15
-8
@@ -1,5 +1,6 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.listeners;
|
package eu.endermite.commandwhitelist.spigot.listeners;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.api.CommandsList;
|
||||||
import eu.endermite.commandwhitelist.api.RandomStuff;
|
import eu.endermite.commandwhitelist.api.RandomStuff;
|
||||||
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
||||||
import eu.endermite.commandwhitelist.spigot.config.ConfigCache;
|
import eu.endermite.commandwhitelist.spigot.config.ConfigCache;
|
||||||
@@ -17,28 +18,34 @@ public class PlayerCommandPreProcessListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
|
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (player.hasPermission("commandwhitelist.bypass"))
|
if (player.hasPermission("commandwhitelist.bypass"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String command = event.getMessage().toLowerCase();
|
String command = event.getMessage().toLowerCase();
|
||||||
|
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
||||||
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (String comm : s.getValue()) {
|
for (String comm : s.getValue()) {
|
||||||
comm = comm.toLowerCase();
|
comm = comm.toLowerCase();
|
||||||
if (command.equalsIgnoreCase("/" + comm))
|
if (command.equalsIgnoreCase("/" + comm) || command.startsWith("/" + comm + " ")) {
|
||||||
return;
|
String rawCmd = event.getMessage();
|
||||||
else if (command.startsWith("/" + comm + " ")) {
|
List<String> bannedSubCommands = CommandsList.getSuggestions(player);
|
||||||
|
for (String bannedSubCommand : bannedSubCommands) {
|
||||||
|
if (rawCmd.startsWith("/"+bannedSubCommand)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
ConfigCache config = CommandWhitelist.getConfigCache();
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied())));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
ConfigCache config = CommandWhitelist.getConfigCache();
|
ConfigCache config = CommandWhitelist.getConfigCache();
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getCommandDenied())));
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getCommandDenied())));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
package eu.endermite.commandwhitelist.spigot.listeners;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.api.CommandsList;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TabCompleteBlockerListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onCommandTabComplete(org.bukkit.event.server.TabCompleteEvent event) {
|
||||||
|
if (!(event.getSender() instanceof Player))
|
||||||
|
return;
|
||||||
|
Player player = (Player) event.getSender();
|
||||||
|
String buffer = event.getBuffer();
|
||||||
|
String cmd = buffer.replace(CommandsList.getLastArgument(buffer), "");
|
||||||
|
List<String> blockedCommands = CommandsList.getSuggestions(player);
|
||||||
|
List<String> suggestions = event.getCompletions();
|
||||||
|
for (String s : blockedCommands) {
|
||||||
|
String slast = CommandsList.getLastArgument(s);
|
||||||
|
String scommand = s.replace(slast, "");
|
||||||
|
cmd = cmd.replace(CommandsList.getLastArgument(cmd), "");
|
||||||
|
if (cmd.startsWith("/"+scommand+" ")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
suggestions.remove(slast);
|
||||||
|
}
|
||||||
|
event.setCompletions(suggestions);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
messages:
|
messages:
|
||||||
prefix: "CommandWhitelist > "
|
prefix: "CommandWhitelist > "
|
||||||
command-denied: "No such command."
|
command-denied: "No such command."
|
||||||
|
subcommand-denied: "You cannot use this subcommand"
|
||||||
no-permission: "&cYou don't have permission to do this."
|
no-permission: "&cYou don't have permission to do this."
|
||||||
no-such-subcommand: "&cNo subcommand by that name."
|
no-such-subcommand: "&cNo subcommand by that name."
|
||||||
config-reloaded: "&eConfiguration reloaded."
|
config-reloaded: "&eConfiguration reloaded."
|
||||||
@@ -31,3 +32,10 @@ commands:
|
|||||||
# commandwhitelist.commands.example
|
# commandwhitelist.commands.example
|
||||||
example:
|
example:
|
||||||
- example
|
- example
|
||||||
|
|
||||||
|
tabcompletions:
|
||||||
|
# This one is working as a blacklist. Player will not be able
|
||||||
|
# to see/use listed subcommands unless they have specified permission
|
||||||
|
# commandwhitelist.subcommands.example
|
||||||
|
example:
|
||||||
|
- help about
|
||||||
|
|||||||
Reference in New Issue
Block a user