11package pro .cloudnode .smp .cloudnodemsg .command ;
22
3+ import org .bukkit .OfflinePlayer ;
34import org .bukkit .command .CommandSender ;
45import org .bukkit .entity .Player ;
56import org .jetbrains .annotations .NotNull ;
1314
1415import java .util .List ;
1516import java .util .Objects ;
17+ import java .util .Optional ;
1618
1719public class ToggleMessageCommand extends Command {
1820 public static final @ NotNull String usage = "<player>" ;
@@ -21,18 +23,19 @@ public class ToggleMessageCommand extends Command {
2123 public boolean run (@ NotNull CommandSender sender , @ NotNull String label , @ NotNull String [] args ) {
2224 if (!sender .hasPermission (Permission .TOGGLE ) || (args .length == 1 && !sender .hasPermission (Permission .TOGGLE_OTHER ))) return new NoPermissionError ().send (sender );
2325 if (args .length == 1 ) {
24- final @ NotNull Player recipient = Objects . requireNonNull ( CloudnodeMSG .getInstance ().getServer ().getPlayer (args [0 ]) );
26+ final @ NotNull OfflinePlayer recipient = CloudnodeMSG .getInstance ().getServer ().getOfflinePlayer (args [0 ]);
2527
26- if (Message .isIncomeEnabled (recipient )) {
27- Message .incomeDisable (recipient );
28- sendMessage (sender , CloudnodeMSG .getInstance ().config ().toggleDisableOther (Objects .requireNonNull (recipient .getName ())));
2928 if (recipient .getPlayer () == null ) return new NeverJoinedError (Optional .ofNullable (recipient .getName ()).orElse ("Unknown Player" )).send (sender );
3029
30+ if (Message .isIncomeEnabled (recipient .getPlayer ())) {
31+ Message .incomeDisable (recipient .getPlayer ());
32+ sendMessage (sender , CloudnodeMSG .getInstance ().config ().toggleDisableOther (Optional .of (recipient .getPlayer ().getName ()).orElse ("Unknown Player" )));
33+
3134 return true ;
3235 }
3336
34- Message .incomeEnable (recipient );
35- sendMessage (sender , CloudnodeMSG .getInstance ().config ().toggleEnableOther (Objects . requireNonNull (recipient .getName ())));
37+ Message .incomeEnable (recipient . getPlayer () );
38+ sendMessage (sender , CloudnodeMSG .getInstance ().config ().toggleEnableOther (Optional . of (recipient .getPlayer (). getName ()). orElse ( "Unknown Player" )));
3639
3740 return true ;
3841 }
0 commit comments