mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-24 01:21:30 +00:00
Support kill from console
This commit is contained in:
parent
76e2fa59d8
commit
dbb7350f6f
@ -13,17 +13,26 @@ import emu.grasscutter.server.packet.send.PacketLifeStateChangeNotify;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Command(label = "killcharacter", usage = "killcharacter [playerId]", aliases = {"suicide", "kill"},
|
@Command(label = "killcharacter", usage = "killcharacter [playerId]", aliases = {"suicide", "kill"},
|
||||||
description = "Directly kill a player's current active character", permission = "player.killcharacter")
|
description = "Kills the players current character", permission = "player.killcharacter")
|
||||||
public final class KillCharacterCommand implements CommandHandler {
|
public final class KillCharacterCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(GenshinPlayer sender, List<String> args) {
|
public void execute(GenshinPlayer sender, List<String> args) {
|
||||||
if (sender == null) {
|
|
||||||
CommandHandler.sendMessage(null, "Run this command in-game.");
|
|
||||||
return; // TODO: kill a player's current active character from console
|
|
||||||
}
|
|
||||||
|
|
||||||
int target;
|
int target;
|
||||||
|
if (sender == null) {
|
||||||
|
// from console
|
||||||
|
if (args.size() == 1) {
|
||||||
|
try {
|
||||||
|
target = Integer.parseInt(args.get(0));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
CommandHandler.sendMessage(null, "Invalid player id.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
CommandHandler.sendMessage(null, "Usage: /killcharacter [playerId]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (args.size() == 1) {
|
if (args.size() == 1) {
|
||||||
try {
|
try {
|
||||||
target = Integer.parseInt(args.get(0));
|
target = Integer.parseInt(args.get(0));
|
||||||
@ -37,6 +46,8 @@ public final class KillCharacterCommand implements CommandHandler {
|
|||||||
} else {
|
} else {
|
||||||
target = sender.getUid();
|
target = sender.getUid();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
|
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
|
||||||
if (targetPlayer == null) {
|
if (targetPlayer == null) {
|
||||||
CommandHandler.sendMessage(sender, "Player not found or offline.");
|
CommandHandler.sendMessage(sender, "Player not found or offline.");
|
||||||
@ -52,6 +63,6 @@ public final class KillCharacterCommand implements CommandHandler {
|
|||||||
targetPlayer.getScene().removeEntity(entity);
|
targetPlayer.getScene().removeEntity(entity);
|
||||||
entity.onDeath(0);
|
entity.onDeath(0);
|
||||||
|
|
||||||
sender.dropMessage("Killed " + targetPlayer.getNickname() + "'s current active character.");
|
CommandHandler.sendMessage(sender, "Killed " + targetPlayer.getNickname() + " current character.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user