Skip to content

Commit fd0f609

Browse files
committed
Added the ability to block the commands
1 parent 5ec3cd5 commit fd0f609

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>me.petterim1.hiddencommands</groupId>
77
<artifactId>HiddenCommands</artifactId>
8-
<version>1.2.1</version>
8+
<version>1.2.2</version>
99
<properties>
1010
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1111
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

src/main/java/me.petterim1.hiddencommands/Main.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
package me.petterim1.hiddencommands;
22

33
import org.powernukkitx.event.EventHandler;
4+
import org.powernukkitx.event.EventPriority;
45
import org.powernukkitx.event.Listener;
6+
import org.powernukkitx.event.player.PlayerCommandPreprocessEvent;
57
import org.powernukkitx.event.server.PacketSendEvent;
8+
import org.powernukkitx.lang.CommandOutputContainer;
69
import org.powernukkitx.plugin.PluginBase;
710
import org.cloudburstmc.protocol.bedrock.data.command.CommandData;
811
import org.cloudburstmc.protocol.bedrock.packet.AvailableCommandsPacket;
12+
import org.powernukkitx.utils.TextFormat;
913

1014
import java.util.ArrayList;
1115
import java.util.List;
1216

1317
public class Main extends PluginBase implements Listener {
1418

1519
private boolean ignoreOPs;
20+
private boolean block;
1621
private List<String> hiddenCommands;
1722

1823
public void onEnable() {
1924
saveDefaultConfig();
2025
ignoreOPs = getConfig().getBoolean("ignoreOPs");
21-
hiddenCommands = getConfig().getStringList("hiddenCommands");
26+
block = getConfig().getBoolean("blockCommands", true);
27+
hiddenCommands = getConfig().getStringList("hiddenCommands").stream().map(String::toLowerCase).toList();
28+
if(hiddenCommands.stream().anyMatch(string -> string.equals("help"))) {
29+
getLogger().alert("You cannot block /help.");
30+
}
2231
if (!hiddenCommands.isEmpty()) {
2332
getServer().getPluginManager().registerEvents(this, this);
2433
}
@@ -39,4 +48,19 @@ public void onSendCommandData(PacketSendEvent e) {
3948
}
4049
}
4150
}
51+
52+
@EventHandler(priority = EventPriority.LOW)
53+
public void onCommand(PlayerCommandPreprocessEvent event) {
54+
if(ignoreOPs && event.getPlayer().isOp()) return;
55+
if(block) {
56+
String[] parts = event.getMessage().split("\\s+");
57+
if(parts.length >= 1) {
58+
String command = parts[0].replaceFirst("/", "").toLowerCase();
59+
if(hiddenCommands.contains(command)) {
60+
event.setCancelled();
61+
event.getPlayer().sendCommandOutput(new CommandOutputContainer(TextFormat.RED + "%commands.generic.unknown", new String[]{command}, 0));
62+
}
63+
}
64+
}
65+
}
4266
}

src/main/resources/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
ignoreOPs: true
2+
blockCommands: true
23
hiddenCommands:
34
- "hiddencommand1"
45
- "hiddencommand2"

0 commit comments

Comments
 (0)