11package io .github .skydynamic .quickbackupmulti .command ;
22
3+ import com .mojang .authlib .GameProfile ;
34import com .mojang .brigadier .arguments .IntegerArgumentType ;
45import com .mojang .brigadier .builder .LiteralArgumentBuilder ;
56import io .github .skydynamic .quickbackupmulti .command .permission .PermissionManager ;
89import net .minecraft .command .argument .GameProfileArgumentType ;
910import net .minecraft .server .command .CommandManager ;
1011import net .minecraft .server .command .ServerCommandSource ;
11- import net .minecraft .server .network .ServerPlayerEntity ;
12+
13+ import java .util .Collection ;
1214
1315import static io .github .skydynamic .quickbackupmulti .QbmConstant .permissionManager ;
1416import static io .github .skydynamic .quickbackupmulti .i18n .Translate .tr ;
15- import static io .github .skydynamic .quickbackupmulti .utils .QbmManager .getPlayerFromCommandSource ;
1617import static net .minecraft .server .command .CommandManager .literal ;
1718
1819public class PermissionCommand {
@@ -21,39 +22,48 @@ public class PermissionCommand {
2122 .then (literal ("set" )
2223 .then (CommandManager .argument ("player" , GameProfileArgumentType .gameProfile ())
2324 .then (CommandManager .argument ("level" , IntegerArgumentType .integer (0 , 2 ))
24- .executes (it -> setPermission (it .getSource (), IntegerArgumentType .getInteger (it , "level" )))
25+ .executes (it -> setPermission (
26+ it .getSource (),
27+ GameProfileArgumentType .getProfileArgument (it , "player" ),
28+ IntegerArgumentType .getInteger (it , "level" )
29+ ))
2530 )
2631 )
2732 )
2833 .then (literal ("get" )
2934 .then (CommandManager .argument ("player" , GameProfileArgumentType .gameProfile ())
30- .executes (it -> getPermission (it .getSource ()))
35+ .executes (it -> getPermission (
36+ it .getSource (),
37+ GameProfileArgumentType .getProfileArgument (it , "player" )
38+ ))
3139 )
3240 )
3341 .then (literal ("reload" )
3442 .executes (it -> reloadPermission (it .getSource ()))
3543 );
3644
37- private static int setPermission (ServerCommandSource commandSource , int level ) {
38- ServerPlayerEntity player = getPlayerFromCommandSource ( commandSource );
39- permissionManager .setPermissionByPermissionLevelInt (level , player );
40- Messenger .sendMessage (commandSource ,
45+ private static int setPermission (ServerCommandSource commandSource , Collection < GameProfile > players , int level ) {
46+ players . forEach ( player -> {
47+ permissionManager .setPermissionByPermissionLevelInt (level , player . getName () );
48+ Messenger .sendMessage (commandSource ,
4149 Messenger .literal (
4250 tr ("quickbackupmulti.permission.set" ,
43- player .getName (). getString () ,
51+ player .getName (),
4452 PermissionType .getByLevelInt (level ).name ()))
4553 );
54+ });
4655 return 1 ;
4756 }
4857
49- private static int getPermission (ServerCommandSource commandSource ) {
50- ServerPlayerEntity player = getPlayerFromCommandSource (commandSource );
51- Messenger .sendMessage (commandSource ,
52- Messenger .literal (
53- tr ("quickbackupmulti.permission.get" ,
54- player .getName ().getString (),
55- permissionManager .getPlayerPermission (player ).name ()))
56- );
58+ private static int getPermission (ServerCommandSource commandSource , Collection <GameProfile > players ) {
59+ players .forEach (player -> {
60+ Messenger .sendMessage (commandSource ,
61+ Messenger .literal (
62+ tr ("quickbackupmulti.permission.get" ,
63+ player .getName (),
64+ permissionManager .getPlayerPermission (player .getName ()).name ()))
65+ );
66+ });
5767 return 1 ;
5868 }
5969
0 commit comments