2121public class WhitelistCommand
2222{
2323 private final Configuration config ;
24- private final WhitelistManager whitelistManager ;
24+ private final WhitelistManager manager ;
2525
2626 public WhitelistCommand (Configuration config , WhitelistManager whitelistManager )
2727 {
2828 this .config = config ;
29- this .whitelistManager = whitelistManager ;
29+ this .manager = whitelistManager ;
3030 }
3131
3232 @ SuppressWarnings ("deprecation" ) // Next time for sure...
33- private void registerOne (CommandManager commandManager , String [] roots , Supplier <@ Nullable PlayerList > listSupplier , Runnable listReloader )
33+ private void registerOne (CommandManager commandManager , String [] roots , Supplier <Boolean > enableStateGetter , Supplier < @ Nullable PlayerList > listSupplier , Runnable listReloader )
3434 {
3535 if (roots .length == 0 )
3636 {
@@ -39,15 +39,15 @@ private void registerOne(CommandManager commandManager, String[] roots, Supplier
3939
4040 var root = literal (roots [0 ]).
4141 requires (s -> s .hasPermission (PluginMeta .ID + ".command" )).
42- executes (c -> showPluginInfo (c .getSource ())).
42+ executes (c -> showPluginInfo (c .getSource (), listSupplier . get (), enableStateGetter . get () )).
4343 then (literal ("add" ).
4444 then (argument ("name" , word ()).
4545 executes (c -> addWhitelist (c .getSource (), listSupplier .get (), getString (c , "name" )))
4646 )
4747 ).
4848 then (literal ("remove" ).
4949 then (argument ("name" , word ()).
50- suggests ((c , sb ) -> suggestMatching (this .whitelistManager .getValuesForRemovalSuggestion (listSupplier .get ()), sb )).
50+ suggests ((c , sb ) -> suggestMatching (this .manager .getValuesForRemovalSuggestion (listSupplier .get ()), sb )).
5151 executes (c -> removeWhitelist (c .getSource (), listSupplier .get (), getString (c , "name" )))
5252 )
5353 ).
@@ -71,33 +71,38 @@ private void registerOne(CommandManager commandManager, String[] roots, Supplier
7171
7272 public void register (CommandManager commandManager )
7373 {
74- this .registerOne (commandManager , new String []{"whitelist" , "vwhitelist" }, this .whitelistManager :: getWhitelist , this .whitelistManager ::loadWhitelist );
75- this .registerOne (commandManager , new String []{"blacklist" , "vblacklist" }, this .whitelistManager :: getBlacklist , this .whitelistManager ::loadBlacklist );
74+ this .registerOne (commandManager , new String []{"whitelist" , "vwhitelist" }, this .config :: isWhitelistEnabled , this . manager :: getWhitelist , this .manager ::loadWhitelist );
75+ this .registerOne (commandManager , new String []{"blacklist" , "vblacklist" }, this .config :: isBlacklistEnabled , this . manager :: getBlacklist , this .manager ::loadBlacklist );
7676 }
7777
78- private int showPluginInfo (CommandSource source )
78+ private int showPluginInfo (CommandSource source , @ Nullable PlayerList list , boolean enabled )
7979 {
80+ if (list == null )
81+ {
82+ source .sendMessage (Component .text ("Uninitialized" ));
83+ return 0 ;
84+ }
85+
8086 source .sendMessage (Component .text (String .format ("%s v%s" , PluginMeta .NAME , PluginMeta .VERSION )));
81- source .sendMessage (Component .text (String .format ("Whitelist enabled: %s" , this .config .isWhitelistEnabled ())));
82- source .sendMessage (Component .text (String .format ("Blacklist enabled: %s" , this .config .isBlacklistEnabled ())));
83- return 0 ;
87+ source .sendMessage (Component .text (String .format ("%s enabled: %s" , list .getName (), enabled )));
88+ return enabled ? 2 : 1 ;
8489 }
8590
86- private int addWhitelist (CommandSource source , @ Nullable PlayerList list , String name )
91+ private int addWhitelist (CommandSource source , @ Nullable PlayerList list , String name )
8792 {
88- if (this .whitelistManager .addPlayer (source , list ,name ))
93+ if (this .manager .addPlayer (source , list ,name ))
8994 {
90- this .whitelistManager .saveList (list );
95+ this .manager .saveList (list );
9196 return 1 ;
9297 }
9398 return 0 ;
9499 }
95100
96101 private int removeWhitelist (CommandSource source , @ Nullable PlayerList list , String name )
97102 {
98- if (this .whitelistManager .removePlayer (source , list , name ))
103+ if (this .manager .removePlayer (source , list , name ))
99104 {
100- this .whitelistManager .saveList (list );
105+ this .manager .saveList (list );
101106 return 1 ;
102107 }
103108 return 0 ;
@@ -111,7 +116,7 @@ private int listWhitelist(CommandSource source, @Nullable PlayerList list)
111116 return 0 ;
112117 }
113118
114- var players = this .whitelistManager .getValuesForListing (list );
119+ var players = this .manager .getValuesForListing (list );
115120 source .sendMessage (Component .text (String .format ("%s size: %d" , list .getName (), players .size ())));
116121 source .sendMessage (Component .text (String .format ("%s players: %s" , list .getName (), Joiner .on (", " ).join (players ))));
117122 return players .size ();
0 commit comments