KillCharacterCommand.java 1.7 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;

tester233's avatar
tester233 committed
16
@Command(label = "killcharacter", usage = "killcharacter", aliases = {"suicide", "kill"}, permission = "player.killcharacter", permissionTargeted = "player.killcharacter.others", description = "commands.killCharacter.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) {
tester233's avatar
tester233 committed
21
22
23
24
25
        if (args.isEmpty()) {
            CommandHandler.sendMessage(sender, translate(sender, "commands.killCharacter.usage"));
            return;
        }

xtaodada's avatar
xtaodada committed
26
27
28
29
30
31
32
33
34
        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);

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