mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 06:26:57 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b4fda1cb9e | |||
| a42f546e4d | |||
| 7222b910e5 | |||
| e3c6103ec7 |
@@ -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.10.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>Bukkit</artifactId>
|
<artifactId>Bukkit</artifactId>
|
||||||
|
|||||||
+2
-2
@@ -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;
|
||||||
|
|||||||
+2
-1
@@ -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());
|
||||||
|
|||||||
@@ -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.10.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>Common</artifactId>
|
<artifactId>Common</artifactId>
|
||||||
|
|||||||
@@ -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.10.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>Velocity</artifactId>
|
<artifactId>Velocity</artifactId>
|
||||||
|
|||||||
+42
-8
@@ -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;
|
||||||
|
|||||||
@@ -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.10.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>Waterfall</artifactId>
|
<artifactId>Waterfall</artifactId>
|
||||||
|
|||||||
+1
-1
@@ -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;
|
||||||
|
|||||||
@@ -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.10.0</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>CommandWhitelistCommon</module>
|
<module>CommandWhitelistCommon</module>
|
||||||
<module>CommandWhitelistBukkit</module>
|
<module>CommandWhitelistBukkit</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user