99import com .pixelmonmod .pixelmon .command .PixelCommand ;
1010import net .minecraft .command .CommandException ;
1111import net .minecraft .command .CommandSource ;
12+ import net .minecraft .entity .player .PlayerEntity ;
1213import net .minecraft .entity .player .ServerPlayerEntity ;
1314import net .minecraft .util .text .TextFormatting ;
1415import net .minecraftforge .fml .server .ServerLifecycleHooks ;
@@ -35,33 +36,39 @@ public List<String> getAliases() {
3536
3637 @ Override
3738 public void execute (CommandSource sender , String [] args ) throws CommandException , CommandSyntaxException {
38- // Checks for permission to use the command
39- if (!PermissionAPI .hasPermission (sender .asPlayer (), "pokebuilder.admin" )) {
40- CommandChatHandler .sendChat (sender , TextFormatting .RED + "You do not have permission for this command!" );
41- } else {
42- // checks arg amount is correct
39+
40+ // checks for a player running the command
41+ if (sender .getEntity () != null ) {
42+ // Checks the player has the permission
43+ if (!PermissionAPI .hasPermission (sender .asPlayer (), "pokebuilder.admin" )) {
44+ CommandChatHandler .sendChat (sender , TextFormatting .RED + "You do not have permission for this command!" );
45+ return ;
46+ }
47+
48+ // Checks the arg lenth is correct
4349 if (args .length != 2 ) {
4450 CommandChatHandler .sendChat (sender , TextFormatting .RED + "Usage: /pbtag <player> <slot>" );
45- } else {
46- try {
47- // gets the player given
48- ServerPlayerEntity player =
49- ServerLifecycleHooks .getCurrentServer ().getPlayerList ().getPlayerByUsername (args [0 ]);
51+ return ;
52+ }
53+ }
5054
51- // gets the slot from the args
52- int slot = Integer .parseInt (args [1 ]);
55+ try {
56+ // gets the player given
57+ ServerPlayerEntity player =
58+ ServerLifecycleHooks .getCurrentServer ().getPlayerList ().getPlayerByUsername (args [0 ]);
5359
54- assert player != null ;
55- PartyStorage storage = StorageProxy . getParty ( player . getUniqueID () );
60+ // gets the slot from the args
61+ int slot = Integer . parseInt ( args [ 1 ] );
5662
57- // adds the tag pokebuilder tag to the pokemon in the specified slot
58- Objects .requireNonNull (storage .get (slot - 1 )).addFlag ("Pokebuilder" );
59- Objects .requireNonNull (storage .get (slot - 1 )).addFlag ("unbreedable" );
60- Objects .requireNonNull (storage .get (slot - 1 )).getPersistentData ().remove ("currentOwner" );
61- } catch (Exception error ) {
62- CommandChatHandler .sendChat (sender , TextFormatting .RED + "Usage: /pbtag <player> <slot>" );
63- }
64- }
63+ assert player != null ;
64+ PartyStorage storage = StorageProxy .getParty (player .getUniqueID ());
65+
66+ // adds the tag pokebuilder tag to the pokemon in the specified slot
67+ Objects .requireNonNull (storage .get (slot - 1 )).addFlag ("Pokebuilder" );
68+ Objects .requireNonNull (storage .get (slot - 1 )).addFlag ("unbreedable" );
69+ Objects .requireNonNull (storage .get (slot - 1 )).getPersistentData ().remove ("currentOwner" );
70+ } catch (Exception error ) {
71+ CommandChatHandler .sendChat (sender , TextFormatting .RED + "Usage: /pbtag <player> <slot>" );
6572 }
6673 }
6774}
0 commit comments