Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
b6fedcf2
Commit
b6fedcf2
authored
Apr 25, 2022
by
xtaodada
Committed by
Melledy
Apr 25, 2022
Browse files
Support kill from console
parent
dc6702eb
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/commands/KillCharacterCommand.java
View file @
b6fedcf2
...
...
@@ -13,30 +13,41 @@ import emu.grasscutter.server.packet.send.PacketLifeStateChangeNotify;
import
java.util.List
;
@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
{
@Override
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
;
if
(
args
.
size
()
==
1
)
{
try
{
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
if
(
Grasscutter
.
getGameServer
().
getPlayerByUid
(
target
)
==
null
)
{
target
=
sender
.
getUid
();
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
;
}
}
catch
(
NumberFormatException
e
)
{
CommandHandler
.
sendMessage
(
sender
,
"Invalid
player
id.
"
);
}
else
{
CommandHandler
.
sendMessage
(
null
,
"Usage: /killcharacter [
player
Id]
"
);
return
;
}
}
else
{
target
=
sender
.
getUid
();
if
(
args
.
size
()
==
1
)
{
try
{
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
if
(
Grasscutter
.
getGameServer
().
getPlayerByUid
(
target
)
==
null
)
{
target
=
sender
.
getUid
();
}
}
catch
(
NumberFormatException
e
)
{
CommandHandler
.
sendMessage
(
sender
,
"Invalid player id."
);
return
;
}
}
else
{
target
=
sender
.
getUid
();
}
}
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerByUid
(
target
);
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
sender
,
"Player not found or offline."
);
...
...
@@ -52,6 +63,6 @@ public final class KillCharacterCommand implements CommandHandler {
targetPlayer
.
getScene
().
removeEntity
(
entity
);
entity
.
onDeath
(
0
);
sender
.
dropMessage
(
"Killed "
+
targetPlayer
.
getNickname
()
+
"
's
current
active
character."
);
CommandHandler
.
sendMessage
(
sender
,
"Killed "
+
targetPlayer
.
getNickname
()
+
" current character."
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment