|
12 | 12 | import org.bukkit.plugin.java.JavaPlugin; |
13 | 13 | import org.jetbrains.annotations.NotNull; |
14 | 14 |
|
15 | | -import java.util.Collections; |
16 | 15 | import java.util.Set; |
17 | 16 |
|
18 | | -@ConfigModule(path = "command-whitelist") |
19 | | -public final class CommandWhitelistModule extends PluginModule { |
20 | | - private static final String permission = "essentials.commandwhitelist.bypass"; |
| 17 | +@ConfigModule(path = "command-filter") |
| 18 | +public final class CommandFilterModule extends PluginModule { |
| 19 | + private enum Mode { |
| 20 | + WHITELIST, |
| 21 | + BLACKLIST |
| 22 | + } |
| 23 | + |
| 24 | + @ConfigValue(path = "command-filter.mode") |
| 25 | + private Mode mode = Mode.BLACKLIST; |
21 | 26 |
|
22 | | - @ConfigValue(path = "command-whitelist.whitelist") |
23 | | - private Set<String> whitelist = Collections.emptySet(); |
| 27 | + @ConfigValue(path = "command-filter.commands") |
| 28 | + private Set<String> commands = Set.of(); |
24 | 29 |
|
25 | | - public CommandWhitelistModule(@NotNull JavaPlugin plugin) { |
| 30 | + public CommandFilterModule(@NotNull JavaPlugin plugin) { |
26 | 31 | super(plugin); |
27 | 32 | } |
28 | 33 |
|
29 | 34 | @EventHandler(priority = EventPriority.HIGH) |
30 | 35 | public void onPlayerCommandSend(PlayerCommandSendEvent event) { |
31 | | - if (event.getPlayer().hasPermission(permission)) return; |
32 | | - event.getCommands().removeIf(command -> !whitelist.contains(command)); |
| 36 | + if (event.getPlayer().hasPermission("essentials.commandfilter.bypass")) return; |
| 37 | + event.getCommands().removeIf(command -> (mode == Mode.WHITELIST) != commands.contains(command)); |
33 | 38 | } |
34 | 39 |
|
35 | 40 | @EventHandler(priority = EventPriority.LOWEST) |
36 | 41 | public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { |
37 | 42 | final var player = event.getPlayer(); |
38 | | - if (player.hasPermission(permission)) return; |
| 43 | + if (player.hasPermission("essentials.commandfilter.bypass")) return; |
39 | 44 |
|
40 | 45 | final var message = event.getMessage(); |
41 | 46 | final var command = message.substring(1); |
42 | 47 | final var literal = command.split(" ")[0]; |
43 | | - if (whitelist.contains(literal)) return; |
| 48 | + if ((mode == Mode.WHITELIST) == commands.contains(literal)) return; |
44 | 49 |
|
45 | 50 | event.setCancelled(true); |
46 | 51 | player.sendMessage(Component.textOfChildren( |
|
0 commit comments