KillCharacterCommand.java 1.68 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", permissionTargeted = "player.killcharacter.others", description = "commands.list.description")
xtaodada's avatar
xtaodada committed
17
18
19
public final class KillCharacterCommand implements CommandHandler {

    @Override
AnimeGitB's avatar
AnimeGitB committed
20
    public void execute(Player sender, Player targetPlayer, List<String> args) {
xtaodada's avatar
xtaodada committed
21
        if (targetPlayer == null) {
22
            CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
xtaodada's avatar
xtaodada committed
23
24
25
26
27
28
29
30
31
32
33
34
            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);

35
        CommandHandler.sendMessage(sender, translate("commands.killCharacter.success", targetPlayer.getNickname()));
xtaodada's avatar
xtaodada committed
36
37
    }
}