Skip to content

Commit dfb983f

Browse files
committed
Refactored pbtag command code and added a check for player. Now allows command to be run from console.
1 parent c11dafe commit dfb983f

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55

66
group = 'com.bencrow11'
7-
version = '1.0.3'
7+
version = '1.0.4'
88

99
java {
1010
archivesBaseName = 'BetterBreeding'

src/main/java/com/bencrow11/betterbreeding/CommandPokebuilder.java

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.pixelmonmod.pixelmon.command.PixelCommand;
1010
import net.minecraft.command.CommandException;
1111
import net.minecraft.command.CommandSource;
12+
import net.minecraft.entity.player.PlayerEntity;
1213
import net.minecraft.entity.player.ServerPlayerEntity;
1314
import net.minecraft.util.text.TextFormatting;
1415
import 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

Comments
 (0)