Compare commits

..

22 Commits

Author SHA1 Message Date
youhavetrouble ca18d17c13 1.8 - 1.12 support 2020-08-02 21:28:12 +02:00
youhavetrouble d7e461cb89 fixing waterfall depend 2020-08-02 14:03:11 +02:00
youhavetrouble 14d0384de0 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	readme.md
2020-08-02 12:58:18 +02:00
YouHaveTrouble 4edaffaa09 fixing typo 2020-08-02 12:58:09 +02:00
youhavetrouble 8a431470a2 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	readme.md
2020-08-02 12:56:28 +02:00
youhavetrouble 1362080878 create readme.md 2020-08-02 12:56:09 +02:00
youhavetrouble c23fd43a70 create readme.md 2020-08-02 12:55:36 +02:00
youhavetrouble 9db227e493 reload command for bungee 2020-08-01 02:07:23 +02:00
youhavetrouble 55ec366804 bungee tabcomplete blocker for waterfall 2020-08-01 01:14:29 +02:00
youhavetrouble 6d2eb27ef3 bungee command blocker (no tab complete block yet) 2020-07-31 15:32:43 +02:00
youhavetrouble 86faeb8aeb version bump 2020-07-27 22:15:07 +02:00
youhavetrouble d246654fa9 ????? 2020-07-27 22:03:29 +02:00
youhavetrouble 5d2fe19586 reload command 2020-07-27 18:00:00 +02:00
youhavetrouble ac8f1b403a f 2020-07-27 17:23:12 +02:00
youhavetrouble 023d9b57fe downgraded to 1.13 api version 2020-07-26 17:22:46 +02:00
youhavetrouble eb13e174e9 Merge remote-tracking branch 'origin/master' 2020-07-22 19:46:16 +02:00
youhavetrouble c2dd36d13b Merge remote-tracking branch 'origin/master' 2020-07-22 19:46:09 +02:00
youhavetrouble be4d8d21c0 Merge remote-tracking branch 'origin/master' 2020-07-22 19:45:36 +02:00
youhavetrouble 26b05aef7b improved command execution check 2020-07-22 19:45:27 +02:00
youhavetrouble 687fd0867b improved command execution check 2020-07-22 19:44:55 +02:00
youhavetrouble 733b556166 messed up priorities 2020-07-12 16:36:05 +02:00
youhavetrouble 97f0403b2e better command check 2020-07-11 17:46:55 +02:00
19 changed files with 647 additions and 91 deletions
+26 -1
View File
@@ -6,7 +6,7 @@
<groupId>eu.endermite</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.3.0</version>
<packaging>jar</packaging>
<name>CommandWhitelist</name>
@@ -62,6 +62,14 @@
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
</repository>
</repositories>
<dependencies>
@@ -71,5 +79,22 @@
<version>1.16.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.15-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-api</artifactId>
<version>1.15-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.5.0</version>
</dependency>
</dependencies>
</project>
+17
View File
@@ -0,0 +1,17 @@
Command Whitelist is a plugin that allows you to control
precisely what commands players can see and use.
<h3>Plugin Features</h3>
<ul>
<li>You can lock certain commands behind permission
<li>Overwrites default "no such command" message with your branding
<li>Blocks tab completion on spigot and bungeecord*</li>
<li>Blocks command execution on spigot and bungeecord</li>
</ul>
\*This only works on Waterfall and its forks
Having some issues? Make sure to check out <a href="https://github.com/YouHaveTrouble/CommandWhitelist/wiki">Plugin Wiki</a>.
Found a bug or you think plugin is missing an important feature? <a href="https://github.com/YouHaveTrouble/CommandWhitelist/issues">Create an issue</a>.
@@ -1,36 +0,0 @@
package eu.endermite.commandwhitelist;
import eu.endermite.commandwhitelist.config.ConfigCache;
import eu.endermite.commandwhitelist.listeners.PlayerCommandPreProcess;
import eu.endermite.commandwhitelist.listeners.PlayerCommandSend;
import org.bukkit.plugin.java.JavaPlugin;
public final class CommandWhitelist extends JavaPlugin {
private static CommandWhitelist commandWhitelist;
private static ConfigCache configCache;
@Override
public void onEnable() {
commandWhitelist = this;
reloadPluginConfig();
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcess(), this);
getServer().getPluginManager().registerEvents(new PlayerCommandSend(), this);
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
public void reloadPluginConfig() {
saveDefaultConfig();
configCache = new ConfigCache(this.getConfig());
}
public static CommandWhitelist getPlugin() {return commandWhitelist;}
public static ConfigCache getConfigCache() {return configCache;}
}
@@ -0,0 +1,83 @@
package eu.endermite.commandwhitelist.bungee;
import com.google.common.io.ByteStreams;
import eu.endermite.commandwhitelist.bungee.command.BungeeMainCommand;
import eu.endermite.commandwhitelist.bungee.config.BungeeConfigCache;
import eu.endermite.commandwhitelist.bungee.listeners.BungeeChatEventListener;
import eu.endermite.commandwhitelist.bungee.listeners.BungeeTabCompleteListener;
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public final class CommandWhitelistBungee extends Plugin {
private static CommandWhitelistBungee plugin;
private static BungeeConfigCache configCache;
@Override
public void onEnable() {
plugin = this;
getLogger().info("Running on "+ ChatColor.DARK_AQUA+getProxy().getName());
loadConfig();
this.getProxy().getPluginManager().registerListener(this, new BungeeChatEventListener());
if (this.getProxy().getName().contains("Waterfall") || getProxy().getName().contains("FlameCord")) {
this.getProxy().getPluginManager().registerListener(this, new BungeeTabCompleteListener());
} else {
getLogger().info("Bungee tab completion requires Waterfall, FlameCord or other Waterfall fork.");
}
getProxy().getPluginManager().registerCommand(this, new BungeeMainCommand());
}
public static CommandWhitelistBungee getPlugin() {
return plugin;
}
public static BungeeConfigCache getConfigCache() {
return configCache;
}
public void loadConfig() {
try {
if (!getDataFolder().exists()) {
getDataFolder().mkdir();
}
File file = new File(getDataFolder(), "config.yml");
if (!file.exists()) {
file.createNewFile();
try (InputStream in = getResourceAsStream("bungeeconfig.yml");
OutputStream out = new FileOutputStream(file)) {
ByteStreams.copy(in, out);
}
}
final Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, new File(getDataFolder(), "config.yml"));
configCache = new BungeeConfigCache(config);
} catch (Exception e) {
e.printStackTrace();
}
}
public void loadConfigAsync(CommandSender sender) {
getProxy().getScheduler().runAsync(this, () -> {
loadConfig();
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getConfigReloaded()));
});
}
}
@@ -0,0 +1,34 @@
package eu.endermite.commandwhitelist.bungee.command;
import eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command;
public class BungeeMainCommand extends Command {
public BungeeMainCommand() {
super("bungeecommandwhitelist", "none", "bcw");
}
@Override
public void execute(CommandSender sender, String[] args) {
if (args.length > 0) {
if (args[0].equalsIgnoreCase("reload")) {
if (sender.hasPermission("commandwhitelist.reload")) {
CommandWhitelistBungee.getPlugin().loadConfigAsync(sender);
} else {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getNoPermission()));
}
} else {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getNoSubCommand()));
}
} else {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bCommand Whitelist by YouHaveTrouble"));
if (sender.hasPermission("commandwhitelist.reload")) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9/bcw reload &b- Reload bungee plugin configuration"));
}
}
}
}
@@ -0,0 +1,38 @@
package eu.endermite.commandwhitelist.bungee.config;
import net.md_5.bungee.config.Configuration;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
public class BungeeConfigCache {
private HashMap<String, List<String>> permList = new HashMap<>();
private String prefix, commandDenied, noPermission, noSubCommand, configReloaded;
public BungeeConfigCache(Configuration config) {
prefix = config.getString("messages.prefix");
commandDenied = config.getString("messages.command-denied");
noPermission = config.getString("messages.no-permission");
noSubCommand = config.getString("messages.no-such-subcommand");
configReloaded = config.getString("messages.config-reloaded");
Collection<String> perms = config.getSection("commands").getKeys();
for (String s : perms) {
this.permList.put(s, config.getStringList("commands."+s));
}
}
public HashMap<String, List<String>> getPermList() {
return permList;
}
public String getPrefix() {return prefix;}
public String getCommandDenied() {return commandDenied;}
public String getNoPermission() {return noPermission;}
public String getNoSubCommand() {return noSubCommand;}
public String getConfigReloaded() {return configReloaded;}
}
@@ -0,0 +1,46 @@
package eu.endermite.commandwhitelist.bungee.listeners;
import eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import java.util.List;
import java.util.Map;
public class BungeeChatEventListener implements Listener {
@EventHandler
public void onChatEvent(net.md_5.bungee.api.event.ChatEvent event) {
if (!event.isCancelled() && event.getSender() instanceof ProxiedPlayer) {
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
if (event.isProxyCommand()) {
if (player.hasPermission("commandwhitelist.bypass")) {
return;
}
String command = event.getMessage().toLowerCase();
boolean found = false;
for (Map.Entry<String, List<String>> s : CommandWhitelistBungee.getConfigCache().getPermList().entrySet()) {
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
for (String comm : s.getValue()) {
comm = comm.toLowerCase();
if (command.equalsIgnoreCase("/"+comm)) {
found = true;
break;
}
else if (command.startsWith("/" + comm + " ")) {
found = true;
break;
}
}
}
}
if (!found) {
event.setCancelled(true);
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getCommandDenied()));
}
}
}
}
}
@@ -0,0 +1,46 @@
package eu.endermite.commandwhitelist.bungee.listeners;
import eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BungeeTabCompleteListener implements Listener {
@EventHandler
public void onProxyDefineCommandsEvent(io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent event) {
if (event.getReceiver() instanceof ProxiedPlayer) {
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
if (player.hasPermission("commandwhitelist.bypass")) {
return;
}
List<String> commandList = new ArrayList<>();
for (Map.Entry<String, List<String>> entry : CommandWhitelistBungee.getConfigCache().getPermList().entrySet()) {
if (player.hasPermission("commandwhitelist.commands."+entry.getKey())) {
commandList.addAll(entry.getValue());
}
}
HashMap<String, Command> commandHashMap = new HashMap<>();
for (String s : commandList) {
for (Map.Entry<String, Command> command : CommandWhitelistBungee.getPlugin().getProxy().getPluginManager().getCommands()) {
if (s.equalsIgnoreCase(command.getValue().getName())) {
commandHashMap.put(command.getKey(), command.getValue());
}
}
}
event.getCommands().values().removeIf((cmd) -> !commandHashMap.containsValue(cmd));
}
}
}
@@ -1,35 +0,0 @@
package eu.endermite.commandwhitelist.config;
import eu.endermite.commandwhitelist.CommandWhitelist;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
public class ConfigCache {
private final HashMap<String, List<String>> permList = new HashMap<>();
private final String prefix;
private final String commandDenied;
public ConfigCache(FileConfiguration yamlConfiguration) {
Set<String> perms = yamlConfiguration.getConfigurationSection("commands").getKeys(false);
for (String s : perms) {
this.permList.put(s, CommandWhitelist.getPlugin().getConfig().getStringList("commands."+s));
}
this.prefix = CommandWhitelist.getPlugin().getConfig().getString("messages.prefix");
this.commandDenied = CommandWhitelist.getPlugin().getConfig().getString("messages.command-denied");
}
public HashMap<String, List<String>> getPermList() {
return permList;
}
public List<String> getPerm(String s) {
return permList.get(s);
}
public String getPrefix() {return prefix;}
public String getCommandDenied() {return commandDenied;}
}
@@ -0,0 +1,100 @@
package eu.endermite.commandwhitelist.spigot;
import com.comphenix.protocol.ProtocolLib;
import com.comphenix.protocol.ProtocolLibrary;
import eu.endermite.commandwhitelist.spigot.command.MainCommand;
import eu.endermite.commandwhitelist.spigot.config.ConfigCache;
import eu.endermite.commandwhitelist.spigot.listeners.LegacyPlayerTabChatCompleteListener;
import eu.endermite.commandwhitelist.spigot.listeners.PlayerCommandPreProcessListener;
import eu.endermite.commandwhitelist.spigot.listeners.PlayerCommandSendListener;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class CommandWhitelist extends JavaPlugin {
private static CommandWhitelist commandWhitelist;
private static ConfigCache configCache;
private static boolean isLegacy;
@Override
public void onEnable() {
commandWhitelist = this;
isLegacy = checkLegacy();
reloadPluginConfig();
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
if (!isLegacy) {
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
} else {
getLogger().info(ChatColor.AQUA+"Running in legacy mode...");
if (getServer().getPluginManager().getPlugin("ProtocolLib") != null) {
LegacyPlayerTabChatCompleteListener.protocol(this);
} else {
getLogger().info(ChatColor.YELLOW+"ProtocolLib is required for tab completion blocking!");
}
}
getCommand("commandwhitelist").setExecutor(new MainCommand());
getCommand("commandwhitelist").setTabCompleter(new MainCommand());
}
public void reloadPluginConfig() {
saveDefaultConfig();
reloadConfig();
configCache = new ConfigCache();
}
public void reloadPluginConfig(CommandSender sender) {
getServer().getScheduler().runTaskAsynchronously(this, () -> {
reloadPluginConfig();
if (!isLegacy()) {
for (Player p : Bukkit.getOnlinePlayers()) {
p.updateCommands();
}
}
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getConfigReloaded()));
});
}
public boolean isLegacy() {
return isLegacy;
}
private boolean checkLegacy() {
String version = getServer().getVersion();
if (version.contains("1.8")) {
return true;
} else if (version.contains("1.9")) {
return true;
} else if (version.contains("1.10")) {
return true;
} else if (version.contains("1.11")) {
return true;
} else if (version.contains("1.12")) {
return true;
} else if (version.contains("1.13")) {
return false;
} else if (version.contains("1.14")) {
return false;
} else if (version.contains("1.15")) {
return false;
} else if (version.contains("1.16")) {
return false;
}
return false;
}
public static CommandWhitelist getPlugin() {return commandWhitelist;}
public static ConfigCache getConfigCache() {return configCache;}
}
@@ -0,0 +1,49 @@
package eu.endermite.commandwhitelist.spigot.command;
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import java.util.ArrayList;
import java.util.List;
public class MainCommand implements TabExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length > 0) {
if (args[0].equalsIgnoreCase("reload")) {
if (sender.hasPermission("commandwhitelist.reload")) {
CommandWhitelist.getPlugin().reloadPluginConfig(sender);
} else {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getNoPermission()));
}
} else {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getNoSubCommand()));
}
} else {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bCommand Whitelist by YouHaveTrouble"));
if (sender.hasPermission("commandwhitelist.reload")) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9/cw reload &b- Reload plugin configuration"));
}
}
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> list = new ArrayList<>();
if(args.length == 1) {
if ("restart".startsWith(args[0]) && sender.hasPermission("commandwhitelist.reload")) {
list.add("reload");
}
}
return list;
}
}
@@ -0,0 +1,43 @@
package eu.endermite.commandwhitelist.spigot.config;
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
import org.bukkit.configuration.Configuration;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
public class ConfigCache {
private HashMap<String, List<String>> permList = new HashMap<>();
private String prefix, commandDenied, noPermission, noSubCommand, configReloaded;
public ConfigCache() {
Configuration config = CommandWhitelist.getPlugin().getConfig();
prefix = config.getString("messages.prefix");
commandDenied = config.getString("messages.command-denied");
noPermission = config.getString("messages.no-permission");
noSubCommand = config.getString("messages.no-such-subcommand");
configReloaded = config.getString("messages.config-reloaded");
Set<String> perms = config.getConfigurationSection("commands").getKeys(false);
for (String s : perms) {
this.permList.put(s, config.getStringList("commands."+s));
}
}
public HashMap<String, List<String>> getPermList() {
return permList;
}
public List<String> getPerm(String s) {
return permList.get(s);
}
public String getPrefix() {return prefix;}
public String getCommandDenied() {return commandDenied;}
public String getNoPermission() {return noPermission;}
public String getNoSubCommand() {return noSubCommand;}
public String getConfigReloaded() {return configReloaded;}
}
@@ -0,0 +1,110 @@
package eu.endermite.commandwhitelist.spigot.listeners;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class LegacyPlayerTabChatCompleteListener {
public static void protocol(CommandWhitelist plugin) {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
tabCompleteServerBound(protocolManager, plugin);
tabCompleteClientBound(protocolManager, plugin);
}
public static void tabCompleteServerBound(ProtocolManager protocolManager, Plugin plugin) {
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.TAB_COMPLETE) {
@Override
public void onPacketSending(PacketEvent event) {
try {
Player player = event.getPlayer();
if (player.hasPermission("commandwhitelist.bypass")) {
return;
}
PacketContainer packet = event.getPacket();
String[] message = packet.getSpecificModifier(String[].class).read(0);
List<String> commandList = new ArrayList<>();
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
commandList.addAll(s.getValue());
}
}
List<String> finalList = new ArrayList<>();
int components = 0;
for (String cmd : message) {
for (String cmdFromList : commandList) {
if (cmd.equalsIgnoreCase("/" + cmdFromList) || !cmd.startsWith("/")) {
finalList.add(components++, cmd);
break;
}
}
}
String[] toWrite = new String[components];
int counter = 0;
for (String cmd : finalList) {
toWrite[counter++] = cmd;
}
packet.getSpecificModifier(String[].class).write(0, toWrite);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public static void tabCompleteClientBound(ProtocolManager protocolManager, Plugin plugin) {
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.TAB_COMPLETE) {
@Override
public void onPacketReceiving(PacketEvent event) {
try {
Player player = event.getPlayer();
if (player.hasPermission("commandwhitelist.bypass")) {
return;
}
PacketContainer packet = event.getPacket();
String command = packet.getSpecificModifier(String.class).read(0);
System.out.println(command);
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
for (String comm : s.getValue()) {
comm = comm.toLowerCase();
if (command.equalsIgnoreCase("/"+comm))
return;
else if (command.startsWith("/" + comm + " ")) {
return;
}
}
}
}
event.setCancelled(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
@@ -1,18 +1,17 @@
package eu.endermite.commandwhitelist.listeners;
package eu.endermite.commandwhitelist.spigot.listeners;
import eu.endermite.commandwhitelist.CommandWhitelist;
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import java.util.List;
import java.util.Map;
public class PlayerCommandPreProcess implements Listener {
public class PlayerCommandPreProcessListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
@EventHandler(priority = EventPriority.HIGHEST)
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
@@ -20,20 +19,22 @@ public class PlayerCommandPreProcess implements Listener {
return;
}
String command = event.getMessage();
String command = event.getMessage().toLowerCase();
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
for (String comm : s.getValue()) {
if (command.startsWith("/" + comm)) {
comm = comm.toLowerCase();
if (command.equalsIgnoreCase("/"+comm))
return;
else if (command.startsWith("/" + comm + " ")) {
return;
}
}
}
}
event.setCancelled(true);
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + " " + CommandWhitelist.getConfigCache().getCommandDenied()));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getCommandDenied()));
}
}
@@ -1,20 +1,19 @@
package eu.endermite.commandwhitelist.listeners;
package eu.endermite.commandwhitelist.spigot.listeners;
import eu.endermite.commandwhitelist.CommandWhitelist;
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import java.util.*;
public class PlayerCommandSend implements Listener {
public class PlayerCommandSendListener implements Listener {
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGHEST)
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) {
Player player = event.getPlayer();
if (player.hasPermission("commandwhitelist.bypass:")) {
if (player.hasPermission("commandwhitelist.bypass")) {
return;
}
@@ -30,4 +29,6 @@ public class PlayerCommandSend implements Listener {
}
}
+4
View File
@@ -0,0 +1,4 @@
name: CommandWhitelistBungee
version: ${project.version}
main: eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee
author: YouHaveTrouble
+20
View File
@@ -0,0 +1,20 @@
# This is bungeecord version of the config.
messages:
prefix: "CommandWhitelist > "
command-denied: "No such command."
no-permission: "&cYou don't have permission to do this."
no-such-subcommand: "&cNo subcommand by that name."
config-reloaded: "&eConfiguration reloaded."
commands:
# Permissions that control what commands players can use
# you can add unlimited amount of whitelists
# commandwhitelist.commands.default
# this will be automatically given to players by default
default:
- glist
- server
# commandwhitelist.commands.example
example:
- example
+3 -1
View File
@@ -1,6 +1,9 @@
messages:
prefix: "CommandWhitelist > "
command-denied: "No such command."
no-permission: "&cYou don't have permission to do this."
no-such-subcommand: "&cNo subcommand by that name."
config-reloaded: "&eConfiguration reloaded."
commands:
# Permissions that control what commands players can use
@@ -9,7 +12,6 @@ commands:
# commandwhitelist.commands.default
# this will be automatically given to players by default
default:
- ?
- help
- spawn
- bal
+10 -2
View File
@@ -1,10 +1,18 @@
name: CommandWhitelist
version: ${project.version}
main: eu.endermite.commandwhitelist.CommandWhitelist
api-version: 1.16
main: eu.endermite.commandwhitelist.spigot.CommandWhitelist
authors: [YouHaveTrouble]
softdepend:
- ProtocolLib
description: Control what commands players can use
commands:
commandwhitelist:
aliases:
- cw
usage: /commandwhitelist [args]
permissions:
commandwhitelist.reload:
default: OP
commandwhitelist.bypass:
default: OP
commandwhitelist.commands.default: