KillCharacterCommand.java 1.71 KB
Newer Older
xtaodada's avatar
xtaodada committed
1
2
3
4
5
package emu.grasscutter.command.commands;

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.entity.EntityAvatar;
Melledy's avatar
Melledy committed
6
import emu.grasscutter.game.player.Player;
xtaodada's avatar
xtaodada committed
7
8
9
10
11
12
13
import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.LifeState;
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
import emu.grasscutter.server.packet.send.PacketLifeStateChangeNotify;

import java.util.List;

14
15
import static emu.grasscutter.utils.Language.translate;

16
@Command(label = "killcharacter", usage = "killcharacter", aliases = {"suicide", "kill"}, permission = "player.killcharacter")
xtaodada's avatar
xtaodada committed
17
18
public final class KillCharacterCommand implements CommandHandler {

19
20
21
22
23
    @Override
    public String description() {
        return translate("commands.killCharacter.description");
    }

xtaodada's avatar
xtaodada committed
24
    @Override
AnimeGitB's avatar
AnimeGitB committed
25
    public void execute(Player sender, Player targetPlayer, List<String> args) {
xtaodada's avatar
xtaodada committed
26
        if (targetPlayer == null) {
27
            CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
xtaodada's avatar
xtaodada committed
28
29
30
31
32
33
34
35
36
37
38
39
            return;
        }

        EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity();
        entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 0f);
        // Packets
        entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP));
        entity.getWorld().broadcastPacket(new PacketLifeStateChangeNotify(0, entity, LifeState.LIFE_DEAD));
        // remove
        targetPlayer.getScene().removeEntity(entity);
        entity.onDeath(0);

40
        CommandHandler.sendMessage(sender, translate("commands.killCharacter.success", targetPlayer.getNickname()));
xtaodada's avatar
xtaodada committed
41
42
    }
}