From efd7467a710fbe56542117f8c4f4bf3921c2fc62 Mon Sep 17 00:00:00 2001 From: AnimeGitB Date: Sun, 15 May 2022 17:18:11 +0930 Subject: [PATCH] Fix targeting on Join and Remove commands --- .../grasscutter/command/commands/JoinCommand.java | 13 +++++++++---- .../grasscutter/command/commands/RemoveCommand.java | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/JoinCommand.java b/src/main/java/emu/grasscutter/command/commands/JoinCommand.java index 0024403f4..84258a2f2 100644 --- a/src/main/java/emu/grasscutter/command/commands/JoinCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/JoinCommand.java @@ -18,6 +18,11 @@ public class JoinCommand implements CommandHandler { @Override public void execute(Player sender, Player targetPlayer, List args) { + if (targetPlayer == null) { + CommandHandler.sendMessage(sender, translate(sender, "commands.execution.need_target")); + return; + } + List avatarIds = new ArrayList<>(); for (String arg : args) { try { @@ -32,18 +37,18 @@ public class JoinCommand implements CommandHandler { for (int i = 0; i < args.size(); i++) { - Avatar avatar = sender.getAvatars().getAvatarById(avatarIds.get(i)); + Avatar avatar = targetPlayer.getAvatars().getAvatarById(avatarIds.get(i)); if (avatar == null) { CommandHandler.sendMessage(sender, translate("commands.generic.invalid.avatarId")); return; } - if (sender.getTeamManager().getCurrentTeamInfo().contains(avatar)){ + if (targetPlayer.getTeamManager().getCurrentTeamInfo().contains(avatar)){ continue; } - sender.getTeamManager().getCurrentTeamInfo().addAvatar(avatar); + targetPlayer.getTeamManager().getCurrentTeamInfo().addAvatar(avatar); } // Packet - sender.getTeamManager().updateTeamEntities(new PacketChangeMpTeamAvatarRsp(sender, sender.getTeamManager().getCurrentTeamInfo())); + targetPlayer.getTeamManager().updateTeamEntities(new PacketChangeMpTeamAvatarRsp(targetPlayer, targetPlayer.getTeamManager().getCurrentTeamInfo())); } } diff --git a/src/main/java/emu/grasscutter/command/commands/RemoveCommand.java b/src/main/java/emu/grasscutter/command/commands/RemoveCommand.java index 2d850e505..c30bad4b3 100644 --- a/src/main/java/emu/grasscutter/command/commands/RemoveCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/RemoveCommand.java @@ -19,6 +19,11 @@ public class RemoveCommand implements CommandHandler { @Override public void execute(Player sender, Player targetPlayer, List args) { + if (targetPlayer == null) { + CommandHandler.sendMessage(sender, translate(sender, "commands.execution.need_target")); + return; + } + List avatarIndexList = new ArrayList<>(); for (String arg : args) { try { @@ -34,14 +39,14 @@ public class RemoveCommand implements CommandHandler { Collections.reverse(avatarIndexList); for (int i = 0; i < avatarIndexList.size(); i++) { - if (avatarIndexList.get(i) > sender.getTeamManager().getCurrentTeamInfo().getAvatars().size() || avatarIndexList.get(i) <= 0) { - CommandHandler.sendMessage(sender, translate("commands.remove.invalid_index")); + if (avatarIndexList.get(i) > targetPlayer.getTeamManager().getCurrentTeamInfo().getAvatars().size() || avatarIndexList.get(i) <= 0) { + CommandHandler.sendMessage(targetPlayer, translate("commands.remove.invalid_index")); return; } - sender.getTeamManager().getCurrentTeamInfo().removeAvatar(avatarIndexList.get(i) - 1); + targetPlayer.getTeamManager().getCurrentTeamInfo().removeAvatar(avatarIndexList.get(i) - 1); } // Packet - sender.getTeamManager().updateTeamEntities(new PacketChangeMpTeamAvatarRsp(sender, sender.getTeamManager().getCurrentTeamInfo())); + targetPlayer.getTeamManager().updateTeamEntities(new PacketChangeMpTeamAvatarRsp(targetPlayer, targetPlayer.getTeamManager().getCurrentTeamInfo())); } }