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

KingRainbow44's avatar
KingRainbow44 committed
12
13
14
@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
15
    @Override
16
    public void execute(Player sender, List<String> args) {
fengyuecanzhu's avatar
fengyuecanzhu committed
17
18
19
20
        if (sender == null) {
            CommandHandler.sendMessage(null, "Run this command in-game.");
            return;
        }
KingRainbow44's avatar
KingRainbow44 committed
21
        
fengyuecanzhu's avatar
fengyuecanzhu committed
22
23
24
25
26
27
28
29
30
31
32
        sender.getTeamManager().getActiveTeam().forEach(entity -> {
            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()));
            }
        });
KingRainbow44's avatar
KingRainbow44 committed
33
        CommandHandler.sendMessage(sender, "All characters have been healed.");
fengyuecanzhu's avatar
fengyuecanzhu committed
34
35
    }
}