HealCommand.java 1.59 KB
Newer Older
fengyuecanzhu's avatar
fengyuecanzhu committed
1
2
3
4
package emu.grasscutter.command.commands;

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
Melledy's avatar
Melledy committed
5
import emu.grasscutter.game.player.Player;
fengyuecanzhu's avatar
fengyuecanzhu committed
6
7
8
9
10
11
import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify;
import emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify;

import java.util.List;

12
13
import static emu.grasscutter.utils.Language.translate;

KingRainbow44's avatar
KingRainbow44 committed
14
15
16
@Command(label = "heal", usage = "heal|h", aliases = {"h"},
        description = "Heal all characters in your current team.", permission = "player.heal")
public final class HealCommand implements CommandHandler {
fengyuecanzhu's avatar
fengyuecanzhu committed
17
    @Override
AnimeGitB's avatar
AnimeGitB committed
18
    public void execute(Player sender, Player targetPlayer, List<String> args) {
AnimeGitB's avatar
AnimeGitB committed
19
        if (targetPlayer == null) {
20
            CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
fengyuecanzhu's avatar
fengyuecanzhu committed
21
22
            return;
        }
KingRainbow44's avatar
KingRainbow44 committed
23
        
AnimeGitB's avatar
AnimeGitB committed
24
        targetPlayer.getTeamManager().getActiveTeam().forEach(entity -> {
fengyuecanzhu's avatar
fengyuecanzhu committed
25
26
27
28
29
30
31
32
33
34
            boolean isAlive = entity.isAlive();
            entity.setFightProperty(
                    FightProperty.FIGHT_PROP_CUR_HP,
                    entity.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP)
            );
            entity.getWorld().broadcastPacket(new PacketAvatarFightPropUpdateNotify(entity.getAvatar(), FightProperty.FIGHT_PROP_CUR_HP));
            if (!isAlive) {
                entity.getWorld().broadcastPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar()));
            }
        });
35
        CommandHandler.sendMessage(sender, translate("commands.heal.success"));
fengyuecanzhu's avatar
fengyuecanzhu committed
36
37
    }
}