HealCommand.java 1.46 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;

14
@Command(label = "heal", usage = "heal|h", aliases = {"h"}, permission = "player.heal", permissionTargeted = "player.heal.others", description = "commands.heal.description")
KingRainbow44's avatar
KingRainbow44 committed
15
public final class HealCommand implements CommandHandler {
16

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
        targetPlayer.getTeamManager().getActiveTeam().forEach(entity -> {
fengyuecanzhu's avatar
fengyuecanzhu committed
20
21
22
23
24
25
26
27
28
29
            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()));
            }
        });
Secretboy's avatar
Secretboy committed
30
        CommandHandler.sendMessage(sender, translate(sender, "commands.heal.success"));
fengyuecanzhu's avatar
fengyuecanzhu committed
31
32
    }
}