Compare commits

...

5 Commits

12 changed files with 88 additions and 19 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.9.0</version> <version>2.11.0</version>
</parent> </parent>
<artifactId>Bukkit</artifactId> <artifactId>Bukkit</artifactId>
@@ -122,13 +122,13 @@ public class CommandWhitelistBukkit extends JavaPlugin {
* @param player Bukkit Player * @param player Bukkit Player
* @return subcommands unavailable for the player * @return subcommands unavailable for the player
*/ */
public static HashSet<String> getSuggestions(org.bukkit.entity.Player player) { public static HashSet<String> getSuggestions(Player player) {
HashSet<String> suggestionList = new HashSet<>(); HashSet<String> suggestionList = new HashSet<>();
HashMap<String, CWGroup> groups = configCache.getGroupList(); HashMap<String, CWGroup> groups = configCache.getGroupList();
for (Map.Entry<String, CWGroup> s : groups.entrySet()) { for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
if (s.getKey().equalsIgnoreCase("default")) if (s.getKey().equalsIgnoreCase("default"))
suggestionList.addAll(s.getValue().getSubCommands()); suggestionList.addAll(s.getValue().getSubCommands());
if (player.hasPermission(s.getValue().getPermission())) continue; if (!player.hasPermission(s.getValue().getPermission())) continue;
suggestionList.addAll(s.getValue().getSubCommands()); suggestionList.addAll(s.getValue().getSubCommands());
} }
return suggestionList; return suggestionList;
@@ -11,12 +11,13 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.util.HashSet; import java.util.HashSet;
public class PlayerCommandPreProcessListener implements Listener { public class PlayerCommandPreProcessListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) { public void PlayerExecuteCommand(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.hasPermission(CWPermission.BYPASS.permission())) return; if (player.hasPermission(CWPermission.BYPASS.permission())) return;
String caseSensitiveLabel = CommandUtil.getCommandLabel(event.getMessage()); String caseSensitiveLabel = CommandUtil.getCommandLabel(event.getMessage());
@@ -33,7 +34,14 @@ public class PlayerCommandPreProcessListener implements Listener {
messageWithoutSlash, messageWithoutSlash,
config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label) config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label)
); );
audiences.player(player).sendMessage(message); switch (config.messageType) {
case CHAT:
audiences.player(player).sendMessage(message);
break;
case ACTIONBAR:
audiences.player(player).sendActionBar(message);
break;
}
return; return;
} }
+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.9.0</version> <version>2.11.0</version>
</parent> </parent>
<artifactId>Common</artifactId> <artifactId>Common</artifactId>
@@ -17,6 +17,7 @@ public class ConfigCache {
public String prefix, command_denied, no_permission, no_such_subcommand, config_reloaded, added_to_whitelist, public String prefix, command_denied, no_permission, no_such_subcommand, config_reloaded, added_to_whitelist,
removed_from_whitelist, group_doesnt_exist, subcommand_denied; removed_from_whitelist, group_doesnt_exist, subcommand_denied;
public boolean useProtocolLib = false; public boolean useProtocolLib = false;
public MessageType messageType = MessageType.CHAT;
public boolean debug = false; public boolean debug = false;
public ConfigCache(File configFile, boolean canDoProtocolLib, Object logger) { public ConfigCache(File configFile, boolean canDoProtocolLib, Object logger) {
@@ -56,6 +57,8 @@ public class ConfigCache {
if (canDoProtocolLib) if (canDoProtocolLib)
config.addDefault("use_protocollib", false, "Do not enable if you don't have issues with aliased commands.\nThis requires server restart to take effect."); config.addDefault("use_protocollib", false, "Do not enable if you don't have issues with aliased commands.\nThis requires server restart to take effect.");
config.addDefault("message_type", MessageType.CHAT.toString(), "Valid message types are CHAT and ACTIONBAR. Does nothing on velocity.");
if (config.isNew()) { if (config.isNew()) {
List<String> exampleCommands = new ArrayList<>(); List<String> exampleCommands = new ArrayList<>();
exampleCommands.add("example"); exampleCommands.add("example");
@@ -102,6 +105,16 @@ public class ConfigCache {
group_doesnt_exist = config.getString("messages.group_doesnt_exist"); group_doesnt_exist = config.getString("messages.group_doesnt_exist");
useProtocolLib = config.getBoolean("use_protocollib"); useProtocolLib = config.getBoolean("use_protocollib");
debug = config.getBoolean("debug", false); debug = config.getBoolean("debug", false);
try {
String chatTypeId = config.getString("message_type");
if (chatTypeId == null) {
warn("Invalid message type. Using CHAT.");
} else {
messageType = MessageType.valueOf(chatTypeId.toUpperCase(Locale.ENGLISH));
}
} catch (IllegalArgumentException e) {
warn("Invalid message type. Using CHAT.");
}
ConfigSection groupSection = config.getConfigSection("groups"); ConfigSection groupSection = config.getConfigSection("groups");
for (String key : groupSection.getKeys(false)) { for (String key : groupSection.getKeys(false)) {
@@ -0,0 +1,7 @@
package eu.endermite.commandwhitelist.common;
public enum MessageType {
CHAT, ACTIONBAR
}
+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.9.0</version> <version>2.11.0</version>
</parent> </parent>
<artifactId>Velocity</artifactId> <artifactId>Velocity</artifactId>
@@ -4,9 +4,11 @@ import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.mojang.brigadier.Command; import com.mojang.brigadier.Command;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.event.command.CommandExecuteEvent;
import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent; import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent;
import com.velocitypowered.api.event.player.TabCompleteEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
@@ -22,10 +24,7 @@ import org.bstats.velocity.Metrics;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
public class CommandWhitelistVelocity { public class CommandWhitelistVelocity {
@@ -74,7 +73,7 @@ public class CommandWhitelistVelocity {
metrics.addCustomChart(new SimplePie("proxy", () -> "Velocity")); metrics.addCustomChart(new SimplePie("proxy", () -> "Velocity"));
} }
@Subscribe @Subscribe(order = PostOrder.LAST)
@SuppressWarnings("UnstableApiUsage") @SuppressWarnings("UnstableApiUsage")
public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) { public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
@@ -95,11 +94,45 @@ public class CommandWhitelistVelocity {
// Workaround for velocity executing "/ command" as valid command // Workaround for velocity executing "/ command" as valid command
String command = event.getCommand().trim(); String command = event.getCommand().trim();
if (command.startsWith("/")) command = command.substring(1);
HashSet<String> allowedCommands = getCommands(player); HashSet<String> allowedCommands = getCommands(player);
String label = CommandUtil.getCommandLabel(command); String label = CommandUtil.getCommandLabel(command);
if (server.getCommandManager().hasCommand(label) && !allowedCommands.contains(label)) if (server.getCommandManager().hasCommand(label) && !allowedCommands.contains(label)) {
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer()); event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
return;
}
HashSet<String> bannedSubCommands = getSuggestions(player);
for (String bannedSubCommand : bannedSubCommands) {
if (command.startsWith(bannedSubCommand)) {
event.setResult(CommandExecuteEvent.CommandResult.denied());
player.sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.subcommand_denied));
return;
}
}
}
/**
* THIS IS FOR CLIENTS ON 1.12 AND BELOW, NOT GUARANTEED TO WORK, IF IT DOESN'T, PR OF GTFO
*/
@Subscribe
public void onUserTabCompleteEvent(TabCompleteEvent event) {
Player player = event.getPlayer();
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
String buffer = event.getPartialMessage();
if (event.getSuggestions().isEmpty()) return;
List<String> newSuggestions = CommandUtil.filterSuggestions(
buffer,
event.getSuggestions(),
getSuggestions(player)
);
event.getSuggestions().clear();
event.getSuggestions().addAll(newSuggestions);
} }
public ConfigCache getConfigCache() { public ConfigCache getConfigCache() {
@@ -127,12 +160,13 @@ public class CommandWhitelistVelocity {
* @param player Velocity Player * @param player Velocity Player
* @return subcommands unavailable for the player * @return subcommands unavailable for the player
*/ */
public HashSet<String> getSuggestions(Player player, HashMap<String, CWGroup> groups) { public HashSet<String> getSuggestions(Player player) {
HashSet<String> suggestionList = new HashSet<>(); HashSet<String> suggestionList = new HashSet<>();
HashMap<String, CWGroup> groups = configCache.getGroupList();
for (Map.Entry<String, CWGroup> s : groups.entrySet()) { for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
if (s.getKey().equalsIgnoreCase("default")) if (s.getKey().equalsIgnoreCase("default"))
suggestionList.addAll(s.getValue().getSubCommands()); suggestionList.addAll(s.getValue().getSubCommands());
if (player.hasPermission(s.getValue().getPermission())) continue; if (!player.hasPermission(s.getValue().getPermission())) continue;
suggestionList.addAll(s.getValue().getSubCommands()); suggestionList.addAll(s.getValue().getSubCommands());
} }
return suggestionList; return suggestionList;
+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.9.0</version> <version>2.11.0</version>
</parent> </parent>
<artifactId>Waterfall</artifactId> <artifactId>Waterfall</artifactId>
@@ -100,7 +100,7 @@ public final class CommandWhitelistWaterfall extends Plugin {
for (Map.Entry<String, CWGroup> s : groups.entrySet()) { for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
if (s.getKey().equalsIgnoreCase("default")) if (s.getKey().equalsIgnoreCase("default"))
suggestionList.addAll(s.getValue().getSubCommands()); suggestionList.addAll(s.getValue().getSubCommands());
if (player.hasPermission(s.getValue().getPermission())) continue; if (!player.hasPermission(s.getValue().getPermission())) continue;
suggestionList.addAll(s.getValue().getSubCommands()); suggestionList.addAll(s.getValue().getSubCommands());
} }
return suggestionList; return suggestionList;
@@ -38,7 +38,14 @@ public class BungeeChatEventListener implements Listener {
command, command,
configCache.prefix + CommandWhitelistWaterfall.getCommandDeniedMessage(label) configCache.prefix + CommandWhitelistWaterfall.getCommandDeniedMessage(label)
); );
audiences.player(player).sendMessage(message); switch (configCache.messageType) {
case CHAT:
audiences.player(player).sendMessage(message);
break;
case ACTIONBAR:
audiences.player(player).sendActionBar(message);
break;
}
return; return;
} }
+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.9.0</version> <version>2.11.0</version>
<modules> <modules>
<module>CommandWhitelistCommon</module> <module>CommandWhitelistCommon</module>
<module>CommandWhitelistBukkit</module> <module>CommandWhitelistBukkit</module>