mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 06:26:57 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 568e7a5ca4 | |||
| 7cb94cce4b | |||
| 7f6315b6b5 | |||
| bbc0e44660 | |||
| 9e255076b0 | |||
| a91af744fd | |||
| 930f73d60a | |||
| c5fdaa95f8 | |||
| 87fc3d7da3 | |||
| 0cc2633604 | |||
| d6909b4f25 | |||
| cd3d527119 | |||
| d43bde0750 |
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>2.2.1</version>
|
<version>2.2.3</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>Bukkit</artifactId>
|
<artifactId>Bukkit</artifactId>
|
||||||
|
|||||||
+32
-7
@@ -1,7 +1,10 @@
|
|||||||
package eu.endermite.commandwhitelist.bukkit;
|
package eu.endermite.commandwhitelist.bukkit;
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.bukkit.command.MainCommandExecutor;
|
import eu.endermite.commandwhitelist.bukkit.command.MainCommandExecutor;
|
||||||
import eu.endermite.commandwhitelist.bukkit.listeners.*;
|
import eu.endermite.commandwhitelist.bukkit.listeners.AsyncTabCompleteBlockerListener;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandPreProcessListener;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandSendListener;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.listeners.TabCompleteBlockerListener;
|
||||||
import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandPreProcessListener;
|
import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandPreProcessListener;
|
||||||
import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandSendListener;
|
import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandSendListener;
|
||||||
import eu.endermite.commandwhitelist.common.CWGroup;
|
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||||
@@ -20,7 +23,6 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class CommandWhitelistBukkit extends JavaPlugin {
|
public class CommandWhitelistBukkit extends JavaPlugin {
|
||||||
@@ -67,8 +69,13 @@ public class CommandWhitelistBukkit extends JavaPlugin {
|
|||||||
|
|
||||||
private void reloadPluginConfig() {
|
private void reloadPluginConfig() {
|
||||||
File configFile = new File("plugins/CommandWhitelist/config.yml");
|
File configFile = new File("plugins/CommandWhitelist/config.yml");
|
||||||
if (configCache == null)
|
if (configCache == null) {
|
||||||
configCache = new ConfigCache(configFile, true, getSLF4JLogger());
|
try {
|
||||||
|
configCache = new ConfigCache(configFile, true, getSLF4JLogger());
|
||||||
|
} catch (NoSuchMethodError e) {
|
||||||
|
configCache = new ConfigCache(configFile, true, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
configCache.reloadConfig();
|
configCache.reloadConfig();
|
||||||
}
|
}
|
||||||
@@ -76,9 +83,11 @@ public class CommandWhitelistBukkit extends JavaPlugin {
|
|||||||
public void reloadPluginConfig(CommandSender sender) {
|
public void reloadPluginConfig(CommandSender sender) {
|
||||||
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
||||||
reloadPluginConfig();
|
reloadPluginConfig();
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
try {
|
||||||
p.updateCommands();
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
}
|
p.updateCommands();
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {}
|
||||||
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.config_reloaded));
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.config_reloaded));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -126,4 +135,20 @@ public class CommandWhitelistBukkit extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
return suggestionList;
|
return suggestionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Command denied message. Will use custom if command exists in any group.
|
||||||
|
*/
|
||||||
|
public static String getCommandDeniedMessage(String command) {
|
||||||
|
String commandDeniedMessage = configCache.command_denied;
|
||||||
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
|
for (CWGroup group : groups.values()) {
|
||||||
|
if (group.getCommands().contains(command)) {
|
||||||
|
if (group.getCommandDeniedMessage() == null || group.getCommandDeniedMessage().isEmpty()) continue;
|
||||||
|
commandDeniedMessage = group.getCommandDeniedMessage();
|
||||||
|
break; // get first message we find
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commandDeniedMessage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@ public class PlayerCommandPreProcessListener implements Listener {
|
|||||||
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
|
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
|
||||||
if (!commands.contains(label)) {
|
if (!commands.contains(label)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.command_denied));
|
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -12,6 +12,7 @@ import eu.endermite.commandwhitelist.common.CWPermission;
|
|||||||
import eu.endermite.commandwhitelist.common.CommandUtil;
|
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 net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
@@ -37,12 +38,12 @@ public class PacketCommandPreProcessListener {
|
|||||||
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||||
String label = CommandUtil.getCommandLabel(string.toLowerCase());
|
String label = CommandUtil.getCommandLabel(string.toLowerCase());
|
||||||
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
|
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
|
||||||
|
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
|
||||||
if (!commands.contains(label)) {
|
if (!commands.contains(label)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
CommandWhitelistBukkit.getAudiences().player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.command_denied));
|
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player);
|
HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player);
|
||||||
for (String bannedSubCommand : bannedSubCommands) {
|
for (String bannedSubCommand : bannedSubCommands) {
|
||||||
if (string.toLowerCase().substring(1).startsWith(bannedSubCommand)) {
|
if (string.toLowerCase().substring(1).startsWith(bannedSubCommand)) {
|
||||||
|
|||||||
+1
-2
@@ -27,8 +27,7 @@ public class PacketCommandSendListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onPacketSending(PacketEvent event) {
|
public void onPacketSending(PacketEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
if (!event.isPlayerTemporary() && player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
|
||||||
HashSet<String> commandList = CommandWhitelistBukkit.getCommands(player);
|
HashSet<String> commandList = CommandWhitelistBukkit.getCommands(player);
|
||||||
PacketContainer packet = event.getPacket();
|
PacketContainer packet = event.getPacket();
|
||||||
RootCommandNode<?> node = (RootCommandNode<?>) packet.getModifier().getValues().get(0);
|
RootCommandNode<?> node = (RootCommandNode<?>) packet.getModifier().getValues().get(0);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>2.2.1</version>
|
<version>2.2.3</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>Common</artifactId>
|
<artifactId>Common</artifactId>
|
||||||
|
|||||||
+10
-3
@@ -1,17 +1,20 @@
|
|||||||
package eu.endermite.commandwhitelist.common;
|
package eu.endermite.commandwhitelist.common;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class CWGroup {
|
public class CWGroup {
|
||||||
|
|
||||||
private final String id, permission;
|
private final String id, permission, commandDeniedMessage;
|
||||||
private final HashSet<String> commands = new HashSet<>();
|
private final HashSet<String> commands = new HashSet<>();
|
||||||
private final HashSet<String> subCommands = new HashSet<>();
|
private final HashSet<String> subCommands = new HashSet<>();
|
||||||
|
|
||||||
public CWGroup(String id, Collection<String> commands, Collection<String> subCommands) {
|
public CWGroup(String id, Collection<String> commands, Collection<String> subCommands, String custom_command_denied_message) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.permission = "commandwhitelist.group."+id;
|
this.permission = "commandwhitelist.group." + id;
|
||||||
this.commands.addAll(commands);
|
this.commands.addAll(commands);
|
||||||
|
this.commandDeniedMessage = custom_command_denied_message;
|
||||||
this.subCommands.addAll(subCommands);
|
this.subCommands.addAll(subCommands);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,6 +30,10 @@ public class CWGroup {
|
|||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable String getCommandDeniedMessage() {
|
||||||
|
return commandDeniedMessage;
|
||||||
|
}
|
||||||
|
|
||||||
public void addCommand(String command) {
|
public void addCommand(String command) {
|
||||||
commands.add(command);
|
commands.add(command);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -18,6 +18,7 @@ public enum CWPermission {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to check specific group permission
|
* Allows to check specific group permission
|
||||||
|
*
|
||||||
* @param configCache
|
* @param configCache
|
||||||
* @param groupId
|
* @param groupId
|
||||||
* @return
|
* @return
|
||||||
|
|||||||
+6
-4
@@ -17,15 +17,17 @@ public class CommandUtil {
|
|||||||
public static List<String> filterSuggestions(String buffer, Collection<String> suggestions, Collection<String> blockedSubCommands) {
|
public static List<String> filterSuggestions(String buffer, Collection<String> suggestions, Collection<String> blockedSubCommands) {
|
||||||
if (buffer.startsWith("/"))
|
if (buffer.startsWith("/"))
|
||||||
buffer = buffer.substring(1);
|
buffer = buffer.substring(1);
|
||||||
|
List<String> suggestionsList = new ArrayList<>(suggestions);
|
||||||
|
if (suggestions.isEmpty() || blockedSubCommands.isEmpty()) return suggestionsList;
|
||||||
for (String s : blockedSubCommands) {
|
for (String s : blockedSubCommands) {
|
||||||
String slast = getLastArgument(s);
|
|
||||||
String scommand = cutLastArgument(s);
|
String scommand = cutLastArgument(s);
|
||||||
if (buffer.startsWith(scommand)) {
|
if (buffer.startsWith(scommand)) {
|
||||||
while (suggestions.contains(slast))
|
String slast = getLastArgument(s);
|
||||||
suggestions.remove(slast);
|
while (suggestionsList.contains(slast))
|
||||||
|
suggestionsList.remove(slast);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ArrayList<>(suggestions);
|
return suggestionsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+15
-4
@@ -51,9 +51,11 @@ public class ConfigCache {
|
|||||||
exampleCommands.add("example");
|
exampleCommands.add("example");
|
||||||
List<String> exampleSubCommands = new ArrayList<>();
|
List<String> exampleSubCommands = new ArrayList<>();
|
||||||
exampleSubCommands.add("example of");
|
exampleSubCommands.add("example of");
|
||||||
|
String exampleCustomCommandDeniedMessage = "You don't have commandwhitelist.group.example permission.";
|
||||||
|
|
||||||
config.addExample("groups.example.commands", exampleCommands, "This is the WHITELIST of commands that players will be able to see/use in the group \"example\"");
|
config.addExample("groups.example.commands", exampleCommands, "This is the WHITELIST of commands that players will be able to see/use in the group \"example\"");
|
||||||
config.addExample("groups.example.subcommands", exampleSubCommands, "This is the BLACKLIST of subcommands that players will NOT be able to see/use in the group \"example\"");
|
config.addExample("groups.example.subcommands", exampleSubCommands, "This is the BLACKLIST of subcommands that players will NOT be able to see/use in the group \"example\"");
|
||||||
|
config.addExample("groups.example.custom_command_denied_message", exampleCustomCommandDeniedMessage, "This is a custom message that players will see if they do not have commandwhitelist.group.<group_name> permission.\ncommandwhitelist.group.example in this case\nIf you don't want to use a custom message, set custom_command_denid_message: \"\"");
|
||||||
config.addComment("groups.example", "All groups except from default require commandwhitelist.group.<group_name> permission\ncommandwhitelist.group.example in this case\n If you wish to leave the list empty, put \"commands: []\" or \"subcommands: []\"");
|
config.addComment("groups.example", "All groups except from default require commandwhitelist.group.<group_name> permission\ncommandwhitelist.group.example in this case\n If you wish to leave the list empty, put \"commands: []\" or \"subcommands: []\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +77,9 @@ public class ConfigCache {
|
|||||||
List<String> defaultSubcommands = new ArrayList<>();
|
List<String> defaultSubcommands = new ArrayList<>();
|
||||||
defaultSubcommands.add("help about");
|
defaultSubcommands.add("help about");
|
||||||
|
|
||||||
config.addDefault("groups.default", new CWGroup("default", defaultCommands, defaultSubcommands).serialize());
|
String defaultCustomCommandDeniedMessage = "";
|
||||||
|
|
||||||
|
config.addDefault("groups.default", new CWGroup("default", defaultCommands, defaultSubcommands, defaultCustomCommandDeniedMessage).serialize());
|
||||||
|
|
||||||
prefix = config.getString("messages.prefix");
|
prefix = config.getString("messages.prefix");
|
||||||
command_denied = config.getString("messages.command_denied");
|
command_denied = config.getString("messages.command_denied");
|
||||||
@@ -128,9 +132,12 @@ public class ConfigCache {
|
|||||||
if (commands.contains(cmd)) continue;
|
if (commands.contains(cmd)) continue;
|
||||||
commands.add(cmd);
|
commands.add(cmd);
|
||||||
}
|
}
|
||||||
|
List<String> subCommands = new ArrayList<>();
|
||||||
List<String> subCommands = section.getStringList(id + ".subcommands");
|
for (String subCmd : section.getStringList(id + ".subcommands")) {
|
||||||
return new CWGroup(id, commands, subCommands);
|
subCommands.add(String.valueOf(subCmd));
|
||||||
|
}
|
||||||
|
String customCommandDeniedMessage = section.getString(id + ".custom_command_denied_message");
|
||||||
|
return new CWGroup(id, commands, subCommands, customCommandDeniedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveCWGroup(String id, CWGroup group) {
|
public void saveCWGroup(String id, CWGroup group) {
|
||||||
@@ -143,6 +150,10 @@ public class ConfigCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void warn(String log) {
|
private void warn(String log) {
|
||||||
|
if (logger == null) {
|
||||||
|
System.out.println("WARNING: "+log);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (logger instanceof org.slf4j.Logger) {
|
if (logger instanceof org.slf4j.Logger) {
|
||||||
((org.slf4j.Logger) logger).warn(log);
|
((org.slf4j.Logger) logger).warn(log);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>2.2.1</version>
|
<version>2.2.3</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>Velocity</artifactId>
|
<artifactId>Velocity</artifactId>
|
||||||
|
|||||||
+3
-3
@@ -55,7 +55,7 @@ public class CommandWhitelistVelocity {
|
|||||||
public static void reloadConfig(CommandSource source) {
|
public static void reloadConfig(CommandSource source) {
|
||||||
server.getScheduler().buildTask(plugin, () -> {
|
server.getScheduler().buildTask(plugin, () -> {
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
source.sendMessage(Identity.nil(), CWCommand.miniMessage.parse(getConfigCache().prefix+getConfigCache().config_reloaded));
|
source.sendMessage(Identity.nil(), CWCommand.miniMessage.parse(getConfigCache().prefix + getConfigCache().config_reloaded));
|
||||||
}).schedule();
|
}).schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ public class CommandWhitelistVelocity {
|
|||||||
CommandMeta commandMeta = server.getCommandManager().metaBuilder("vcw").build();
|
CommandMeta commandMeta = server.getCommandManager().metaBuilder("vcw").build();
|
||||||
server.getCommandManager().register(commandMeta, new VelocityMainCommand());
|
server.getCommandManager().register(commandMeta, new VelocityMainCommand());
|
||||||
Metrics metrics = metricsFactory.make(this, 8704);
|
Metrics metrics = metricsFactory.make(this, 8704);
|
||||||
metrics.addCustomChart(new SimplePie("proxy", ()-> "Velocity"));
|
metrics.addCustomChart(new SimplePie("proxy", () -> "Velocity"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@@ -74,7 +74,7 @@ public class CommandWhitelistVelocity {
|
|||||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player);
|
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player);
|
||||||
event.getRootNode().getChildren().removeIf((commandNode) ->
|
event.getRootNode().getChildren().removeIf((commandNode) ->
|
||||||
server.getCommandManager().hasCommand(commandNode.getName())
|
server.getCommandManager().hasCommand(commandNode.getName())
|
||||||
&& !allowedCommands.contains(commandNode.getName())
|
&& !allowedCommands.contains(commandNode.getName())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"id":"commandwhitelist",
|
"id": "commandwhitelist",
|
||||||
"name":"CommandWhitelist",
|
"name": "CommandWhitelist",
|
||||||
"version":"${project.version}",
|
"version": "${project.version}",
|
||||||
"description":"You decide what commands players can use or tab complete on your server!",
|
"description": "You decide what commands players can use or tab complete on your server!",
|
||||||
"authors":["YouHaveTrouble"],
|
"authors": ["YouHaveTrouble"],
|
||||||
"dependencies":[],
|
"dependencies": [],
|
||||||
"main":"eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity"
|
"main": "eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity"
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>2.2.1</version>
|
<version>2.2.3</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>Waterfall</artifactId>
|
<artifactId>Waterfall</artifactId>
|
||||||
|
|||||||
+18
-2
@@ -8,7 +8,6 @@ import eu.endermite.commandwhitelist.waterfall.listeners.BungeeChatEventListener
|
|||||||
import eu.endermite.commandwhitelist.waterfall.listeners.BungeeTabcompleteListener;
|
import eu.endermite.commandwhitelist.waterfall.listeners.BungeeTabcompleteListener;
|
||||||
import eu.endermite.commandwhitelist.waterfall.listeners.WaterfallDefineCommandsListener;
|
import eu.endermite.commandwhitelist.waterfall.listeners.WaterfallDefineCommandsListener;
|
||||||
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
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;
|
||||||
@@ -30,7 +29,7 @@ public final class CommandWhitelistWaterfall extends Plugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
plugin = this;
|
plugin = this;
|
||||||
getLogger().info("Running on "+ ChatColor.DARK_AQUA+getProxy().getName());
|
getLogger().info("Running on " + ChatColor.DARK_AQUA + getProxy().getName());
|
||||||
loadConfig();
|
loadConfig();
|
||||||
audiences = BungeeAudiences.create(this);
|
audiences = BungeeAudiences.create(this);
|
||||||
Metrics metrics = new Metrics(this, 8704);
|
Metrics metrics = new Metrics(this, 8704);
|
||||||
@@ -53,6 +52,7 @@ public final class CommandWhitelistWaterfall extends Plugin {
|
|||||||
public static CommandWhitelistWaterfall getPlugin() {
|
public static CommandWhitelistWaterfall getPlugin() {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfigCache getConfigCache() {
|
public static ConfigCache getConfigCache() {
|
||||||
return configCache;
|
return configCache;
|
||||||
}
|
}
|
||||||
@@ -106,4 +106,20 @@ public final class CommandWhitelistWaterfall extends Plugin {
|
|||||||
}
|
}
|
||||||
return suggestionList;
|
return suggestionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Command denied message. Will use custom if command exists in any group.
|
||||||
|
*/
|
||||||
|
public static String getCommandDeniedMessage(String command) {
|
||||||
|
String commandDeniedMessage = configCache.command_denied;
|
||||||
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
|
for (CWGroup group : groups.values()) {
|
||||||
|
if (group.getCommands().contains(command)) {
|
||||||
|
if (group.getCommandDeniedMessage() == null || group.getCommandDeniedMessage().isEmpty()) continue;
|
||||||
|
commandDeniedMessage = group.getCommandDeniedMessage();
|
||||||
|
break; // get first message we find
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commandDeniedMessage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -52,7 +52,7 @@ public class BungeeMainCommand extends Command implements TabExecutor {
|
|||||||
else
|
else
|
||||||
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.group_doesnt_exist));
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.group_doesnt_exist));
|
||||||
} else
|
} else
|
||||||
audiences.sender(sender).sendMessage(Component.text("/"+label+" add <group> <command>"));
|
audiences.sender(sender).sendMessage(Component.text("/" + label + " add <group> <command>"));
|
||||||
return;
|
return;
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||||
@@ -65,7 +65,7 @@ public class BungeeMainCommand extends Command implements TabExecutor {
|
|||||||
else
|
else
|
||||||
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.group_doesnt_exist));
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.group_doesnt_exist));
|
||||||
} 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 HELP:
|
case HELP:
|
||||||
default:
|
default:
|
||||||
@@ -84,6 +84,6 @@ public class BungeeMainCommand extends Command implements TabExecutor {
|
|||||||
for (Map.Entry<String, Command> command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) {
|
for (Map.Entry<String, Command> command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) {
|
||||||
serverCommands.add(command.getValue().getName());
|
serverCommands.add(command.getValue().getName());
|
||||||
}
|
}
|
||||||
return CWCommand.commandSuggestions(CommandWhitelistWaterfall.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()),sender.hasPermission(CWPermission.ADMIN.permission()));
|
return CWCommand.commandSuggestions(CommandWhitelistWaterfall.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -6,7 +6,6 @@ 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;
|
||||||
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
@@ -33,7 +32,7 @@ public class BungeeChatEventListener implements Listener {
|
|||||||
HashSet<String> commands = CommandWhitelistWaterfall.getCommands(player);
|
HashSet<String> commands = CommandWhitelistWaterfall.getCommands(player);
|
||||||
if (!commands.contains(label)) {
|
if (!commands.contains(label)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
CommandWhitelistWaterfall.getAudiences().player(player).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.command_denied));
|
CommandWhitelistWaterfall.getAudiences().player(player).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + CommandWhitelistWaterfall.getCommandDeniedMessage(label)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -13,15 +13,13 @@ public class BungeeTabcompleteListener implements Listener {
|
|||||||
public void onTabcomplete(net.md_5.bungee.api.event.TabCompleteEvent event) {
|
public void onTabcomplete(net.md_5.bungee.api.event.TabCompleteEvent event) {
|
||||||
if (!(event.getReceiver() instanceof ProxiedPlayer)) return;
|
if (!(event.getReceiver() instanceof ProxiedPlayer)) return;
|
||||||
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||||
|
if (event.getSuggestions().isEmpty()) return;
|
||||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
|
||||||
CommandUtil.filterSuggestions(
|
CommandUtil.filterSuggestions(
|
||||||
event.getCursor(),
|
event.getCursor(),
|
||||||
event.getSuggestions(),
|
event.getSuggestions(),
|
||||||
CommandWhitelistWaterfall.getSuggestions(player)
|
CommandWhitelistWaterfall.getSuggestions(player)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -15,8 +15,7 @@ public class WaterfallDefineCommandsListener implements Listener {
|
|||||||
public void onProxyDefineCommandsEvent(io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent event) {
|
public void onProxyDefineCommandsEvent(io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent event) {
|
||||||
if (event.getReceiver() instanceof ProxiedPlayer) {
|
if (event.getReceiver() instanceof ProxiedPlayer) {
|
||||||
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||||
if (player.hasPermission(CWPermission.BYPASS.permission()))
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
return;
|
|
||||||
HashMap<String, Command> commandHashMap = new HashMap<>();
|
HashMap<String, Command> commandHashMap = new HashMap<>();
|
||||||
CommandWhitelistWaterfall.getCommands(player).forEach(cmdName ->
|
CommandWhitelistWaterfall.getCommands(player).forEach(cmdName ->
|
||||||
CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()
|
CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
name: CommandWhitelist
|
name: CommandWhitelist
|
||||||
|
author: YouHaveTrouble
|
||||||
version: ${project.version}
|
version: ${project.version}
|
||||||
main: eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall
|
main: eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall
|
||||||
description: You decide what commands players can use or tab complete on your server!
|
description: You decide what commands players can use or tab complete on your server!
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>2.2.1</version>
|
<version>2.2.3</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>CommandWhitelistCommon</module>
|
<module>CommandWhitelistCommon</module>
|
||||||
<module>CommandWhitelistBukkit</module>
|
<module>CommandWhitelistBukkit</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user