mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-29 13:17:21 +00:00
Fix targeting on Join and Remove commands
This commit is contained in:
parent
05e13d81ad
commit
efd7467a71
@ -18,6 +18,11 @@ public class JoinCommand implements CommandHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||||
|
if (targetPlayer == null) {
|
||||||
|
CommandHandler.sendMessage(sender, translate(sender, "commands.execution.need_target"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
List<Integer> avatarIds = new ArrayList<>();
|
List<Integer> avatarIds = new ArrayList<>();
|
||||||
for (String arg : args) {
|
for (String arg : args) {
|
||||||
try {
|
try {
|
||||||
@ -32,18 +37,18 @@ public class JoinCommand implements CommandHandler {
|
|||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < args.size(); i++) {
|
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) {
|
if (avatar == null) {
|
||||||
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.avatarId"));
|
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.avatarId"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (sender.getTeamManager().getCurrentTeamInfo().contains(avatar)){
|
if (targetPlayer.getTeamManager().getCurrentTeamInfo().contains(avatar)){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sender.getTeamManager().getCurrentTeamInfo().addAvatar(avatar);
|
targetPlayer.getTeamManager().getCurrentTeamInfo().addAvatar(avatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Packet
|
// Packet
|
||||||
sender.getTeamManager().updateTeamEntities(new PacketChangeMpTeamAvatarRsp(sender, sender.getTeamManager().getCurrentTeamInfo()));
|
targetPlayer.getTeamManager().updateTeamEntities(new PacketChangeMpTeamAvatarRsp(targetPlayer, targetPlayer.getTeamManager().getCurrentTeamInfo()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,11 @@ public class RemoveCommand implements CommandHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||||
|
if (targetPlayer == null) {
|
||||||
|
CommandHandler.sendMessage(sender, translate(sender, "commands.execution.need_target"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
List<Integer> avatarIndexList = new ArrayList<>();
|
List<Integer> avatarIndexList = new ArrayList<>();
|
||||||
for (String arg : args) {
|
for (String arg : args) {
|
||||||
try {
|
try {
|
||||||
@ -34,14 +39,14 @@ public class RemoveCommand implements CommandHandler {
|
|||||||
Collections.reverse(avatarIndexList);
|
Collections.reverse(avatarIndexList);
|
||||||
|
|
||||||
for (int i = 0; i < avatarIndexList.size(); i++) {
|
for (int i = 0; i < avatarIndexList.size(); i++) {
|
||||||
if (avatarIndexList.get(i) > sender.getTeamManager().getCurrentTeamInfo().getAvatars().size() || avatarIndexList.get(i) <= 0) {
|
if (avatarIndexList.get(i) > targetPlayer.getTeamManager().getCurrentTeamInfo().getAvatars().size() || avatarIndexList.get(i) <= 0) {
|
||||||
CommandHandler.sendMessage(sender, translate("commands.remove.invalid_index"));
|
CommandHandler.sendMessage(targetPlayer, translate("commands.remove.invalid_index"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sender.getTeamManager().getCurrentTeamInfo().removeAvatar(avatarIndexList.get(i) - 1);
|
targetPlayer.getTeamManager().getCurrentTeamInfo().removeAvatar(avatarIndexList.get(i) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Packet
|
// Packet
|
||||||
sender.getTeamManager().updateTeamEntities(new PacketChangeMpTeamAvatarRsp(sender, sender.getTeamManager().getCurrentTeamInfo()));
|
targetPlayer.getTeamManager().updateTeamEntities(new PacketChangeMpTeamAvatarRsp(targetPlayer, targetPlayer.getTeamManager().getCurrentTeamInfo()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user