Skip to content

Commit 7bf7aa7

Browse files
committed
change command whitelist module to command filter module
1 parent 8e93bbd commit 7bf7aa7

4 files changed

Lines changed: 28 additions & 18 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ commands and features.
1212
- **Custom Chat Formatting**
1313
- **Custom Join and Quit Messages**
1414
- **Custom Death Messages**
15-
- **Custom Command Whitelist**
15+
- **Custom Command Filter**
1616

1717
| MOTD | Chat | Tab List |
1818
|-------------------------------------|-------------------------------------|-----------------------------------|

src/main/java/com/uravgcode/modernessentials/module/CommandWhitelistModule.java renamed to src/main/java/com/uravgcode/modernessentials/module/CommandFilterModule.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,40 @@
1212
import org.bukkit.plugin.java.JavaPlugin;
1313
import org.jetbrains.annotations.NotNull;
1414

15-
import java.util.Collections;
1615
import java.util.Set;
1716

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;
2126

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();
2429

25-
public CommandWhitelistModule(@NotNull JavaPlugin plugin) {
30+
public CommandFilterModule(@NotNull JavaPlugin plugin) {
2631
super(plugin);
2732
}
2833

2934
@EventHandler(priority = EventPriority.HIGH)
3035
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));
3338
}
3439

3540
@EventHandler(priority = EventPriority.LOWEST)
3641
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
3742
final var player = event.getPlayer();
38-
if (player.hasPermission(permission)) return;
43+
if (player.hasPermission("essentials.commandfilter.bypass")) return;
3944

4045
final var message = event.getMessage();
4146
final var command = message.substring(1);
4247
final var literal = command.split(" ")[0];
43-
if (whitelist.contains(literal)) return;
48+
if ((mode == Mode.WHITELIST) == commands.contains(literal)) return;
4449

4550
event.setCancelled(true);
4651
player.sendMessage(Component.textOfChildren(

src/main/java/com/uravgcode/modernessentials/module/PluginModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public void disable() {
7676
case List<?> list when type == String.class -> list.stream().map(Object::toString).collect(Collectors.joining("\n"));
7777
case List<?> list when type == Set.class -> Set.copyOf(list);
7878
case String string when type == List.class -> List.of(string);
79+
case String string when type.isEnum() -> Enum.valueOf(type.asSubclass(Enum.class), string.toUpperCase());
7980
default -> value;
8081
};
8182
}

src/main/resources/config.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,20 @@ death-message:
9191
format: "<gray>☠ <white><message>"
9292

9393
# =========================
94-
# Command Whitelist
94+
# Command Filter
9595
# =========================
96-
command-whitelist:
97-
# Enables command whitelist module
96+
command-filter:
97+
# Enables command filter module
9898
enabled: false
9999

100-
# List of whitelisted commands
101-
whitelist:
100+
# whitelist or blacklist
101+
mode: blacklist
102+
103+
# Commands affected by the filter
104+
# Bypass permission: essentials.commandfilter.bypass
105+
commands:
102106
- help
103-
- msg
107+
- plugins
104108

105109
# =========================
106110
# Commands

0 commit comments

Comments
 (0)