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
91e4a087
Commit
91e4a087
authored
Apr 19, 2022
by
SpikeHD
Browse files
fix conventions to match other commands
parent
21a15032
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/commands/PlayerCommands.java
View file @
91e4a087
...
@@ -3,6 +3,7 @@ package emu.grasscutter.commands;
...
@@ -3,6 +3,7 @@ package emu.grasscutter.commands;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GenshinData
;
import
emu.grasscutter.data.GenshinData
;
import
emu.grasscutter.data.def.ItemData
;
import
emu.grasscutter.data.def.ItemData
;
import
emu.grasscutter.data.def.AvatarData
;
import
emu.grasscutter.data.def.MonsterData
;
import
emu.grasscutter.data.def.MonsterData
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.World
;
import
emu.grasscutter.game.World
;
...
@@ -177,32 +178,107 @@ public final class PlayerCommands {
...
@@ -177,32 +178,107 @@ public final class PlayerCommands {
}
}
}
}
@Command
(
label
=
"givechar"
,
aliases
=
{
"givec"
},
usage
=
"Usage: givechar
[
avatar
id]
[level]"
)
@Command
(
label
=
"givechar"
,
aliases
=
{
"givec"
},
usage
=
"Usage: givechar
<playerId> <
avatar
Id>
[level]"
)
public
static
class
GiveCharCommand
implements
CommandHandler
{
public
static
class
GiveCharCommand
implements
CommandHandler
{
@Override
public
void
execute
(
GenshinPlayer
player
,
List
<
String
>
args
)
{
int
target
,
avatarID
,
level
=
1
;
@Override
if
(
args
.
size
()
<
2
)
{
public
void
execute
(
GenshinPlayer
player
,
List
<
String
>
args
)
{
CommandHandler
.
sendMessage
(
null
,
"Usage: give <player> <avatarId> [level]"
);
int
avatarID
=
Integer
.
parseInt
(
args
.
get
(
0
));
return
;
int
level
=
Integer
.
parseInt
(
args
.
get
(
1
));
}
switch
(
args
.
size
())
{
default
:
CommandHandler
.
sendMessage
(
null
,
"Usage: give <player> <avatarId> [level]"
);
return
;
case
1
:
try
{
avatarID
=
Integer
.
parseInt
(
args
.
get
(
0
));
target
=
player
.
getAccount
().
getPlayerId
();
}
catch
(
NumberFormatException
ignored
)
{
// TODO: Parse from avatar name using GM Handbook.
CommandHandler
.
sendMessage
(
player
,
"Invalid avatar id."
);
return
;
}
break
;
case
2
:
try
{
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
if
(
Grasscutter
.
getGameServer
().
getPlayerById
(
target
)
==
null
)
{
target
=
player
.
getId
();
level
=
Integer
.
parseInt
(
args
.
get
(
1
));
avatarID
=
Integer
.
parseInt
(
args
.
get
(
0
));
}
else
{
avatarID
=
Integer
.
parseInt
(
args
.
get
(
1
));
}
}
catch
(
NumberFormatException
ignored
)
{
// TODO: Parse from avatar name using GM Handbook.
CommandHandler
.
sendMessage
(
player
,
"Invalid avatar or player ID."
);
return
;
}
break
;
case
3
:
try
{
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
if
(
Grasscutter
.
getGameServer
().
getPlayerById
(
target
)
==
null
)
{
CommandHandler
.
sendMessage
(
player
,
"Invalid player ID."
);
return
;
}
if
(
player
==
null
)
{
avatarID
=
Integer
.
parseInt
(
args
.
get
(
1
));
level
=
Integer
.
parseInt
(
args
.
get
(
2
));
}
catch
(
NumberFormatException
ignored
)
{
// TODO: Parse from avatar name using GM Handbook.
CommandHandler
.
sendMessage
(
player
,
"Invalid avatar or player ID."
);
return
;
}
break
;
}
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerById
(
target
);
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Player not found."
);
return
;
CommandHandler
.
sendMessage
(
null
,
"Player not found."
);
return
;
}
}
AvatarData
avatarData
=
GenshinData
.
getAvatarDataMap
().
get
(
avatarID
);
AvatarData
avatarData
=
GenshinData
.
getAvatarDataMap
().
get
(
avatarID
);
if
(
avatarData
==
null
)
{
if
(
avatarData
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Invalid avatar id."
);
return
;
CommandHandler
.
sendMessage
(
null
,
"Invalid avatar id."
);
return
;
}
}
if
(
args
.
size
()
==
0
)
{
CommandHandler
.
sendMessage
(
player
,
"Usage: givechar [avatar id] [level]"
);
return
;
}
GenshinAvatar
avatar
=
new
GenshinAvatar
(
avatarID
);
GenshinAvatar
avatar
=
new
GenshinAvatar
(
avatarID
);
avatar
.
setLevel
(
level
);
avatar
.
setLevel
(
level
);
targetPlayer
.
addAvatar
(
avatar
);
}
player
.
addAvatar
(
avatar
);
@Override
public
void
execute
(
List
<
String
>
args
)
{
if
(
args
.
size
()
<
2
)
{
CommandHandler
.
sendMessage
(
null
,
"Usage: give <player> <itemId|itemName> [amount]"
);
return
;
}
try
{
int
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
int
avatarID
=
Integer
.
parseInt
(
args
.
get
(
1
));
int
level
=
1
;
if
(
args
.
size
()
>
2
)
level
=
Integer
.
parseInt
(
args
.
get
(
2
));
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerById
(
target
);
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Player not found."
);
return
;
}
AvatarData
avatarData
=
GenshinData
.
getAvatarDataMap
().
get
(
avatarID
);
if
(
avatarData
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Invalid avatar id."
);
return
;
}
GenshinAvatar
avatar
=
new
GenshinAvatar
(
avatarID
);
avatar
.
setLevel
(
level
);
targetPlayer
.
addAvatar
(
avatar
);
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
null
,
"Invalid item or player ID."
);
}
}
}
}
}
...
...
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