Skip to content

Commit f96098c

Browse files
committed
exclude aliases on commands restriction
1 parent 8a660a6 commit f96098c

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package com.elchologamer.userlogin.listener.restriction;
22

33
import com.elchologamer.userlogin.ULPlayer;
4+
import org.bukkit.configuration.ConfigurationSection;
45
import org.bukkit.event.EventHandler;
56
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
67

8+
import java.util.ArrayList;
9+
import java.util.Arrays;
10+
import java.util.List;
11+
712
public class CommandRestriction extends BaseRestriction<PlayerCommandPreprocessEvent> {
813

914
public CommandRestriction() {
@@ -14,10 +19,21 @@ public CommandRestriction() {
1419
public void handle(PlayerCommandPreprocessEvent e) {
1520
if (!shouldRestrict(e)) return;
1621

17-
String m = e.getMessage().replaceAll("^/", "").toLowerCase();
18-
if (!m.startsWith("login") && !m.startsWith("register")) {
19-
e.setCancelled(true);
20-
ULPlayer.get(e.getPlayer()).sendMessage("messages.commands_disabled");
22+
String command = e.getMessage().replaceAll("^/", "").split("\\s+")[0];
23+
24+
List<String> allowedCommands = new ArrayList<>(Arrays.asList("login", "register"));
25+
26+
ConfigurationSection section = getPlugin().getConfig().getConfigurationSection("commandAliases");
27+
if (section != null) {
28+
allowedCommands.addAll(section.getStringList("login"));
29+
allowedCommands.addAll(section.getStringList("register"));
2130
}
31+
32+
for (String allowedCommand : allowedCommands) {
33+
if (allowedCommand.equalsIgnoreCase(command)) return;
34+
}
35+
36+
e.setCancelled(true);
37+
ULPlayer.get(e.getPlayer()).sendMessage("messages.commands_disabled");
2238
}
2339
}

0 commit comments

Comments
 (0)