Compare commits

..

8 Commits

Author SHA1 Message Date
YouHaveTrouble 1bb2c7ea6a remove workflows, update readme, added missing default in switch 2021-08-30 01:59:48 +02:00
YouHaveTrouble a935503239 bump version 2021-08-30 01:32:26 +02:00
YouHaveTrouble 2a6be9829c update depends and change help component 2021-08-30 01:25:19 +02:00
YouHaveTrouble 097b541a1f revert that I guess 2021-07-17 17:49:45 +02:00
YouHaveTrouble 5f447e07b6 comments and version bump 2021-07-17 17:46:20 +02:00
YouHaveTrouble b5e12655f9 now blocking utility mod .plugins 2021-07-17 17:42:04 +02:00
YouHaveTrouble 14f15aa754 cleanup&fixup 2021-07-17 17:41:44 +02:00
YouHaveTrouble 017011fad0 work on command completions 2021-07-06 21:31:51 +02:00
14 changed files with 104 additions and 103 deletions
-36
View File
@@ -1,36 +0,0 @@
name: Build CommandWhitelist Jar
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Git repo
uses: actions/checkout@v1
- name: Restore Maven cache
uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn package --file pom.xml
- name: Copy artifacts
uses: actions/upload-artifact@master
with:
name: CommandWhitelist
path: target/CommandWhitelist*.jar
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.0-ALPHA-2</version>
<version>2.0</version>
</parent>
<artifactId>Bukkit</artifactId>
@@ -1,10 +1,7 @@
package eu.endermite.commandwhitelist.bukkit;
import eu.endermite.commandwhitelist.bukkit.command.MainCommandExecutor;
import eu.endermite.commandwhitelist.bukkit.listeners.PacketCommandPreProcessListener;
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.*;
import eu.endermite.commandwhitelist.common.CWGroup;
import eu.endermite.commandwhitelist.common.ConfigCache;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
@@ -21,6 +18,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
public class CommandWhitelistBukkit extends JavaPlugin {
@@ -46,7 +44,13 @@ public class CommandWhitelistBukkit extends JavaPlugin {
PacketCommandPreProcessListener.protocol(this);
getLogger().info(ChatColor.AQUA + "Using ProtocolLib for command filter!");
}
try {
// Use paper's async tab completions if possible
Class.forName("com.destroystokyo.paper.event.server.AsyncTabCompleteEvent");
getServer().getPluginManager().registerEvents(new AsyncTabCompleteBlockerListener(), this);
} catch (ClassNotFoundException e) {
getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this);
}
PluginCommand command = getCommand("commandwhitelist");
if (command != null) {
@@ -26,7 +26,6 @@ public class MainCommandExecutor implements TabExecutor {
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
return true;
}
try {
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase());
switch (commandType) {
@@ -0,0 +1,29 @@
package eu.endermite.commandwhitelist.bukkit.listeners;
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.common.CommandUtil;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
public class AsyncTabCompleteBlockerListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
public void onCommandTabComplete(AsyncTabCompleteEvent event) {
if (!(event.getSender() instanceof Player)) return;
Player player = (Player) event.getSender();
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
event.setCompletions(
CommandUtil.filterSuggestions(
event.getBuffer(),
event.getCompletions(),
CommandWhitelistBukkit.getSuggestions(player)
)
);
event.setHandled(true);
}
}
+7 -7
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.0-ALPHA-2</version>
<version>2.0</version>
</parent>
<artifactId>Common</artifactId>
@@ -59,8 +59,8 @@
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
<id>pluginwiki-repo</id>
<url>https://ci.pluginwiki.us/plugin/repository/everything/</url>
</repository>
<repository>
<id>velocitypowered-repo</id>
@@ -70,9 +70,9 @@
<dependencies>
<dependency>
<groupId>com.github.Thatsmusic99</groupId>
<artifactId>ConfigurationMaster</artifactId>
<version>v2.0.0-ALPHA-3</version>
<groupId>com.github.thatsmusic99</groupId>
<artifactId>ConfigurationMaster-API</artifactId>
<version>v2.0.0-BETA-1</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -90,7 +90,7 @@
<dependency>
<groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-api</artifactId>
<version>1.16-R0.5-SNAPSHOT</version>
<version>1.17-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
@@ -3,9 +3,7 @@ package eu.endermite.commandwhitelist.common.commands;
import eu.endermite.commandwhitelist.common.CWGroup;
import eu.endermite.commandwhitelist.common.ConfigCache;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.MiniMessage;
import java.util.ArrayList;
@@ -16,8 +14,7 @@ public class CWCommand {
public static boolean addToWhitelist(ConfigCache configCache, String command, String group) {
CWGroup cwGroup = configCache.getGroupList().get(group);
if (cwGroup == null)
return false;
if (cwGroup == null) return false;
cwGroup.addCommand(command);
configCache.saveCWGroup(group, cwGroup);
return true;
@@ -35,17 +32,16 @@ public class CWCommand {
public static Component helpComponent(String baseCommand, boolean showReloadCommand, boolean showAdminCommands) {
Component component = MiniMessage.markdown().parse("<rainbow><bold>CommandWhitelist by YouHaveTrouble")
.append(Component.newline());
component = component.append(Component.text("Hover over the command to see what it does!").color(NamedTextColor.AQUA)).decoration(TextDecoration.BOLD, false).append(Component.newline());
component = component.append(Component.text("/"+baseCommand+" help").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Displays this message"))));
component = component.append(Component.text("/" + baseCommand + " help").color(NamedTextColor.AQUA).append(Component.text(" - Displays this message").color(NamedTextColor.BLUE)));
if (showReloadCommand) {
component = component.append(Component.newline());
component = component.append(Component.text("/"+baseCommand+" reload").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Reloads plugin configuration"))));
component = component.append(Component.text("/" + baseCommand + " reload").color(NamedTextColor.AQUA).append(Component.text(" - Reloads plugin configuration").color(NamedTextColor.BLUE)));
}
if (showAdminCommands) {
component = component.append(Component.newline());
component = component.append(Component.text("/"+baseCommand+" add <group> <command>").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Add a command to selected permission group"))));
component = component.append(Component.text("/" + baseCommand + " add <group> <command>").color(NamedTextColor.AQUA).append(Component.text(" - Add a command to selected permission group").color(NamedTextColor.BLUE)));
component = component.append(Component.newline());
component = component.append(Component.text("/"+baseCommand+" remove <group> <command>").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Removes a command from selected permission group"))));
component = component.append(Component.text("/" + baseCommand + " remove <group> <command>").color(NamedTextColor.AQUA).append(Component.text(" - Removes a command from selected permission group").color(NamedTextColor.BLUE)));
}
return component;
}
@@ -57,6 +53,8 @@ public class CWCommand {
public static List<String> commandSuggestions(ConfigCache config, Collection<String> serverCommands, String[] args, boolean reloadPerm, boolean adminPerm) {
List<String> list = new ArrayList<>();
switch (args.length) {
default:
case 0:
case 1:
if ("reload".startsWith(args[0]) && reloadPerm)
list.add("reload");
@@ -77,27 +75,27 @@ public class CWCommand {
case 3:
if (args[0].equalsIgnoreCase("remove")) {
if (!adminPerm) return list;
try {
for (String s : config.getGroupList().get(args[1]).getCommands()) {
CWGroup group = config.getGroupList().get(args[1]);
if (group == null) return list;
for (String s : group.getCommands()) {
if (s.startsWith(args[2]))
list.add(s);
}
} catch (NullPointerException ignored) {
}
return list;
}
if (args[0].equalsIgnoreCase("add")) {
if (!adminPerm) return list;
CWGroup group = config.getGroupList().get(args[1]);
if (group == null) return list;
for (String cmd : serverCommands) {
if (!cmd.startsWith("/")) continue;
if (cmd.startsWith("/"))
cmd = cmd.substring(1);
if (cmd.contains(":")) {
String[] cmdSplit = cmd.split(":");
if (cmdSplit.length < 2) continue;
cmd = cmd.split(":")[1];
cmd = cmdSplit[1];
}
cmd = cmd.replace("/", "");
if (config.getGroupList().get(args[1]) == null) continue;
if (config.getGroupList().get(args[1]).getCommands().contains(cmd)) continue;
if (group.getCommands().contains(cmd)) continue;
if (cmd.startsWith(args[2]))
list.add(cmd);
}
+2 -2
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.0-ALPHA-2</version>
<version>2.0</version>
</parent>
<artifactId>Velocity</artifactId>
@@ -82,7 +82,7 @@
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>1.1.0</version>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -105,10 +105,11 @@ public class CommandWhitelistVelocity {
HashMap<String, CWGroup> groups = configCache.getGroupList();
HashSet<String> commandList = new HashSet<>();
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
CWGroup group = s.getValue();
if (s.getKey().equalsIgnoreCase("default"))
commandList.addAll(s.getValue().getCommands());
else if (player.hasPermission(s.getValue().getPermission()))
commandList.addAll(s.getValue().getCommands());
commandList.addAll(group.getCommands());
else if (player.hasPermission(group.getPermission()))
commandList.addAll(group.getCommands());
}
return commandList;
}
@@ -42,11 +42,11 @@ public class VelocityMainCommand implements SimpleCommand {
}
if (args.length == 3) {
if (CWCommand.addToWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().added_to_whitelist));
sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().added_to_whitelist, args[2], args[1])));
else
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist));
sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
} else
sender.sendMessage(Component.text("/"+label+" add <group> <command>"));
sender.sendMessage(Component.text("/" + label + " add <group> <command>"));
return;
case REMOVE:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
@@ -55,11 +55,11 @@ public class VelocityMainCommand implements SimpleCommand {
}
if (args.length == 3) {
if (CWCommand.removeFromWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().removed_from_whitelist));
sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().removed_from_whitelist, args[2], args[1])));
else
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist));
sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
} else
sender.sendMessage(Component.text("/"+label+" remove <group> <command>"));
sender.sendMessage(Component.text("/" + label + " remove <group> <command>"));
return;
case HELP:
default:
@@ -77,12 +77,8 @@ public class VelocityMainCommand implements SimpleCommand {
CommandSource source = invocation.source();
String[] args = invocation.arguments();
return CompletableFuture.supplyAsync(() -> {
List<String> suggestions = new ArrayList<>();
if (args.length == 1) {
if (source.hasPermission(CWPermission.RELOAD.permission()) && "reload".startsWith(args[0]))
suggestions.add("reload");
}
return suggestions;
List<String> serverCommands = new ArrayList<>();
return CWCommand.commandSuggestions(CommandWhitelistVelocity.getConfigCache(), serverCommands, args, source.hasPermission(CWPermission.RELOAD.permission()), source.hasPermission(CWPermission.ADMIN.permission()));
});
}
}
+2 -6
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.0-ALPHA-2</version>
<version>2.0</version>
</parent>
<artifactId>Waterfall</artifactId>
@@ -68,10 +68,6 @@
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>destroystokyo-repo</id>
<url>https://repo.destroystokyo.com/repository/maven-public/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
@@ -82,7 +78,7 @@
<dependency>
<groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-api</artifactId>
<version>1.16-R0.5-SNAPSHOT</version>
<version>1.17-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -11,6 +11,10 @@ import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.TabExecutor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class BungeeMainCommand extends Command implements TabExecutor {
public BungeeMainCommand(String name) {
@@ -77,6 +81,10 @@ public class BungeeMainCommand extends Command implements TabExecutor {
@Override
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
return null;
List<String> serverCommands = new ArrayList<>();
for (Map.Entry<String, Command> command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) {
serverCommands.add(command.getValue().getName());
}
return CWCommand.commandSuggestions(CommandWhitelistWaterfall.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()),sender.hasPermission(CWPermission.ADMIN.permission()));
}
}
+2 -2
View File
@@ -6,7 +6,7 @@
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.0-ALPHA-2</version>
<version>2.0</version>
<modules>
<module>CommandWhitelistCommon</module>
<module>CommandWhitelistBukkit</module>
@@ -34,7 +34,7 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.8.0</version>
<version>4.8.1</version>
<scope>compile</scope>
</dependency>
<dependency>
+13 -7
View File
@@ -10,16 +10,22 @@ precisely what commands players can see and use.
![bStats Servers](https://img.shields.io/bstats/servers/8704?label=Proxy%20servers%20using%20CW&style=flat-square)
<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>
<li>Blocks completion and execution of specific subcommands (spigot only)</li>
<li>Lock selected commands behind permission
<li>Overwrite default "no such command" message with your branding
<li>Block tab completion</li>
<li>Block command execution</li>
<li>Block completion and execution of specified subcommands</li>
</ul>
\*This only works on Waterfall and its forks
<b>Compatible versions</b>: 1.13+
<b>Compatible software</b>:
- Bukkit-based servers (Spigot, Paper, Airplane, Purpur, etc)
- Waterfall (NOT Bungeecord!)
- Velocity
[Download latest release](https://github.com/YouHaveTrouble/CommandWhitelist/releases/latest)
Having some issues? Make sure to check out <a href="https://github.com/YouHaveTrouble/CommandWhitelist/wiki">Plugin Wiki</a>.