11package com .elchologamer .userlogin .listener .restriction ;
22
33import com .elchologamer .userlogin .ULPlayer ;
4+ import org .bukkit .configuration .ConfigurationSection ;
45import org .bukkit .event .EventHandler ;
56import org .bukkit .event .player .PlayerCommandPreprocessEvent ;
67
8+ import java .util .ArrayList ;
9+ import java .util .Arrays ;
10+ import java .util .List ;
11+
712public 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