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
104e04f7
Commit
104e04f7
authored
Jul 21, 2022
by
AnimeGitB
Committed by
Luke H-W
Jul 22, 2022
Browse files
Change commands to use new usage message method.
parent
2cfbe781
Changes
34
Hide whitespace changes
Inline
Side-by-side
manage_languages.py
View file @
104e04f7
...
...
@@ -90,6 +90,7 @@ class JsonHelpers:
class
LanguageManager
:
TRANSLATION_KEY
=
re
.
compile
(
r
'[Tt]ranslate.*"(\w+\.[\w\.]+)"'
)
POTENTIAL_KEY
=
re
.
compile
(
r
'"(\w+\.[\w\.]+)"'
)
COMMAND_LABEL
=
re
.
compile
(
r
'@Command\s*\([\W\w]*?label\s*=\s*"(\w+)"'
,
re
.
MULTILINE
)
# [\W\w] is a cheeky way to match everything including \n
def
__init__
(
self
):
self
.
load_jsons
()
...
...
@@ -122,6 +123,8 @@ class LanguageManager:
used
.
add
(
k
)
for
k
in
self
.
POTENTIAL_KEY
.
findall
(
data
):
potential
.
add
(
k
)
for
label
in
self
.
COMMAND_LABEL
.
findall
(
data
):
used
.
add
(
f
'commands.
{
label
}
.description'
)
return
used
|
(
potential
&
expected_keys
)
def
_lint_report_language
(
self
,
lang
:
str
,
keys
:
set
,
flattened
:
dict
,
primary_language_flattened
:
dict
)
->
None
:
...
...
src/main/java/emu/grasscutter/auth/DefaultAuthenticators.java
View file @
104e04f7
...
...
@@ -163,7 +163,7 @@ public final class DefaultAuthenticators {
}
else
{
successfulLogin
=
false
;
loggerMessage
=
translate
(
"messages.dispatch.account.login_password_storage_error"
,
address
);
responseMessage
=
translate
(
"password_storage_error"
);
responseMessage
=
translate
(
"
messages.dispatch.account.
password_storage_error"
);
}
}
else
{
loggerMessage
=
translate
(
"messages.dispatch.account.account_login_exist_error"
,
address
);
...
...
src/main/java/emu/grasscutter/command/CommandHandler.java
View file @
104e04f7
...
...
@@ -68,7 +68,6 @@ public interface CommandHandler {
default
String
getDescriptionString
(
Player
player
)
{
Command
annotation
=
this
.
getClass
().
getAnnotation
(
Command
.
class
);
String
key
=
"commands.%s.description"
.
formatted
(
annotation
.
label
());
// TODO: fallback to "commands.generic.no_description_specified"
return
translate
(
player
,
key
);
}
...
...
src/main/java/emu/grasscutter/command/CommandMap.java
View file @
104e04f7
...
...
@@ -35,6 +35,7 @@ public final class CommandMap {
*/
public
CommandMap
registerCommand
(
String
label
,
CommandHandler
command
)
{
Grasscutter
.
getLogger
().
debug
(
"Registered command: "
+
label
);
label
=
label
.
toLowerCase
();
// Get command data.
Command
annotation
=
command
.
getClass
().
getAnnotation
(
Command
.
class
);
...
...
@@ -203,7 +204,7 @@ public final class CommandMap {
// Parse message.
String
[]
split
=
rawMessage
.
split
(
" "
);
List
<
String
>
args
=
new
LinkedList
<>(
Arrays
.
asList
(
split
));
String
label
=
args
.
remove
(
0
);
String
label
=
args
.
remove
(
0
)
.
toLowerCase
()
;
String
playerId
=
(
player
==
null
)
?
consoleId
:
player
.
getAccount
().
getId
();
// Check for special cases - currently only target command.
...
...
src/main/java/emu/grasscutter/command/commands/AccountCommand.java
View file @
104e04f7
...
...
@@ -30,7 +30,7 @@ public final class AccountCommand implements CommandHandler {
}
if
(
args
.
size
()
<
2
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.account.command_usage"
);
sendUsageMessage
(
sender
);
return
;
}
...
...
@@ -39,7 +39,7 @@ public final class AccountCommand implements CommandHandler {
switch
(
action
)
{
default
:
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.account.command_usage"
);
sendUsageMessage
(
sender
);
return
;
case
"create"
:
int
uid
=
0
;
...
...
src/main/java/emu/grasscutter/command/commands/AnnounceCommand.java
View file @
104e04f7
...
...
@@ -23,14 +23,14 @@ public final class AnnounceCommand implements CommandHandler {
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
var
manager
=
Grasscutter
.
getGameServer
().
getAnnouncementSystem
();
if
(
args
.
size
()
<
1
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.announce.command_usage"
);
sendUsageMessage
(
sender
);
return
;
}
switch
(
args
.
get
(
0
))
{
case
"tpl"
:
if
(
args
.
size
()
<
2
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.announce.command_usage"
);
sendUsageMessage
(
sender
);
return
;
}
...
...
@@ -52,7 +52,7 @@ public final class AnnounceCommand implements CommandHandler {
case
"revoke"
:
if
(
args
.
size
()
<
2
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.announce.command_usage"
);
sendUsageMessage
(
sender
);
return
;
}
...
...
src/main/java/emu/grasscutter/command/commands/ClearCommand.java
View file @
104e04f7
...
...
@@ -83,7 +83,7 @@ public final class ClearCommand implements CommandHandler {
}
if
(
args
.
size
()
<
1
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.clear.command_usage"
);
sendUsageMessage
(
sender
);
return
;
}
...
...
src/main/java/emu/grasscutter/command/commands/CoopCommand.java
View file @
104e04f7
...
...
@@ -7,8 +7,6 @@ import emu.grasscutter.game.player.Player;
import
java.util.List
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"coop"
,
usage
=
{
"[<host UID>]"
},
permission
=
"server.coop"
,
permissionTargeted
=
"server.coop.others"
)
public
final
class
CoopCommand
implements
CommandHandler
{
...
...
@@ -17,25 +15,26 @@ public final class CoopCommand implements CommandHandler {
Player
host
=
sender
;
switch
(
args
.
size
())
{
case
0
:
// Summon target to self
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.coop.usage"
));
if
(
sender
==
null
)
// Console doesn't have a self to summon to
if
(
sender
==
null
)
{
// Console doesn't have a self to summon to
sendUsageMessage
(
sender
);
return
;
}
break
;
case
1
:
// Summon target to argument
try
{
int
hostId
=
Integer
.
parseInt
(
args
.
get
(
0
));
host
=
Grasscutter
.
getGameServer
().
getPlayerByUid
(
hostId
);
if
(
host
==
null
)
{
CommandHandler
.
send
Message
(
sender
,
translat
e
(
sender
,
"commands.execution.player_offline_error"
)
)
;
CommandHandler
.
send
TranslatedMessag
e
(
sender
,
"commands.execution.player_offline_error"
);
return
;
}
break
;
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
send
Message
(
sender
,
translat
e
(
sender
,
"commands.generic.invalid.uid"
)
)
;
CommandHandler
.
send
TranslatedMessag
e
(
sender
,
"commands.generic.invalid.uid"
);
return
;
}
default
:
CommandHandler
.
send
Mes
sage
(
sender
,
translate
(
sender
,
"commands.coop.usage"
)
);
send
U
sage
Message
(
sender
);
return
;
}
...
...
@@ -45,6 +44,6 @@ public final class CoopCommand implements CommandHandler {
}
host
.
getServer
().
getMultiplayerSystem
().
applyEnterMp
(
targetPlayer
,
host
.
getUid
());
targetPlayer
.
getServer
().
getMultiplayerSystem
().
applyEnterMpReply
(
host
,
targetPlayer
.
getUid
(),
true
);
CommandHandler
.
send
Message
(
sender
,
translat
e
(
sender
,
"commands.coop.success"
,
targetPlayer
.
getNickname
(),
host
.
getNickname
())
)
;
CommandHandler
.
send
TranslatedMessag
e
(
sender
,
"commands.coop.success"
,
targetPlayer
.
getNickname
(),
host
.
getNickname
());
}
}
src/main/java/emu/grasscutter/command/commands/EnterDungeonCommand.java
View file @
104e04f7
...
...
@@ -14,7 +14,7 @@ public final class EnterDungeonCommand implements CommandHandler {
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
size
()
<
1
)
{
CommandHandler
.
send
Mes
sage
(
sender
,
translate
(
sender
,
"commands.enter_dungeon.usage"
)
);
send
U
sage
Message
(
sender
);
return
;
}
...
...
@@ -33,7 +33,7 @@ public final class EnterDungeonCommand implements CommandHandler {
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.enter_dungeon.changed"
,
dungeonId
));
}
}
catch
(
Exception
e
)
{
CommandHandler
.
send
Mes
sage
(
sender
,
translate
(
sender
,
"commands.enter_dungeon.usage"
)
);
send
U
sage
Message
(
sender
);
}
}
}
src/main/java/emu/grasscutter/command/commands/GiveCommand.java
View file @
104e04f7
...
...
@@ -67,7 +67,7 @@ public final class GiveCommand implements CommandHandler {
public
GiveAllType
giveAllType
=
GiveAllType
.
NONE
;
};
private
static
GiveItemParameters
parseArgs
(
Player
sender
,
List
<
String
>
args
)
throws
IllegalArgumentException
{
private
GiveItemParameters
parseArgs
(
Player
sender
,
List
<
String
>
args
)
throws
IllegalArgumentException
{
GiveItemParameters
param
=
new
GiveItemParameters
();
// Extract any tagged arguments (e.g. "lv90", "x100", "r5")
...
...
@@ -99,7 +99,7 @@ public final class GiveCommand implements CommandHandler {
// At this point, first remaining argument MUST be itemId/avatarId
if
(
args
.
size
()
<
1
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.give.usage"
);
// Reachable if someone does `/give lv90` or similar
sendUsageMessage
(
sender
);
// Reachable if someone does `/give lv90` or similar
throw
new
IllegalArgumentException
();
}
String
id
=
args
.
remove
(
0
);
...
...
@@ -169,7 +169,7 @@ public final class GiveCommand implements CommandHandler {
throw
e
;
}
}
else
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.give.usage"
);
sendUsageMessage
(
sender
);
throw
new
IllegalArgumentException
();
}
}
...
...
@@ -180,7 +180,7 @@ public final class GiveCommand implements CommandHandler {
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
size
()
<
1
)
{
// *No args*
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.give.usage"
);
sendUsageMessage
(
sender
);
return
;
}
try
{
...
...
src/main/java/emu/grasscutter/command/commands/HelpCommand.java
View file @
104e04f7
...
...
@@ -59,8 +59,9 @@ public final class HelpCommand implements CommandHandler {
commands_no_permission
.
add
(
createCommand
(
player
,
command
,
args
));
}
}
CommandHandler
.
sendTranslatedMessage
(
player
,
"commands.help.available_commands"
);
}
else
{
String
command_str
=
args
.
remove
(
0
);
String
command_str
=
args
.
remove
(
0
)
.
toLowerCase
()
;
CommandHandler
command
=
handlers
.
get
(
command_str
);
if
(
command
==
null
)
{
CommandHandler
.
sendTranslatedMessage
(
player
,
"commands.generic.command_exist_error"
);
...
...
src/main/java/emu/grasscutter/command/commands/KillAllCommand.java
View file @
104e04f7
...
...
@@ -25,7 +25,7 @@ public final class KillAllCommand implements CommandHandler {
scene
=
targetPlayer
.
getWorld
().
getSceneById
(
Integer
.
parseInt
(
args
.
get
(
0
)));
break
;
default
:
CommandHandler
.
send
Mes
sage
(
sender
,
translate
(
sender
,
"commands.killall.usage"
)
);
send
U
sage
Message
(
sender
);
return
;
}
}
catch
(
NumberFormatException
ignored
)
{
...
...
src/main/java/emu/grasscutter/command/commands/KillCharacterCommand.java
View file @
104e04f7
...
...
@@ -18,11 +18,6 @@ public final class KillCharacterCommand implements CommandHandler {
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
isEmpty
())
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.killCharacter.usage"
));
return
;
}
EntityAvatar
entity
=
targetPlayer
.
getTeamManager
().
getCurrentAvatarEntity
();
entity
.
setFightProperty
(
FightProperty
.
FIGHT_PROP_CUR_HP
,
0
f
);
// Packets
...
...
src/main/java/emu/grasscutter/command/commands/PermissionCommand.java
View file @
104e04f7
...
...
@@ -17,7 +17,7 @@ public final class PermissionCommand implements CommandHandler {
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
size
()
!=
2
)
{
CommandHandler
.
send
Mes
sage
(
sender
,
translate
(
sender
,
"commands.permission.usage"
)
);
send
U
sage
Message
(
sender
);
return
;
}
...
...
@@ -37,7 +37,7 @@ public final class PermissionCommand implements CommandHandler {
switch
(
action
)
{
default
:
CommandHandler
.
send
Mes
sage
(
sender
,
translate
(
sender
,
"commands.permission.usage"
)
);
send
U
sage
Message
(
sender
);
break
;
case
"add"
:
if
(
account
.
addPermission
(
permission
))
{
...
...
src/main/java/emu/grasscutter/command/commands/QuestCommand.java
View file @
104e04f7
...
...
@@ -15,7 +15,7 @@ public final class QuestCommand implements CommandHandler {
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
size
()
!=
2
)
{
CommandHandler
.
send
Mes
sage
(
sender
,
translate
(
sender
,
"commands.quest.usage"
)
);
send
U
sage
Message
(
sender
);
return
;
}
...
...
@@ -53,7 +53,7 @@ public final class QuestCommand implements CommandHandler {
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.quest.finished"
,
questId
));
}
default
->
{
CommandHandler
.
send
Mes
sage
(
sender
,
translate
(
sender
,
"commands.quest.usage"
)
);
send
U
sage
Message
(
sender
);
}
}
}
...
...
src/main/java/emu/grasscutter/command/commands/ResetShopLimitCommand.java
View file @
104e04f7
...
...
@@ -14,11 +14,6 @@ public final class ResetShopLimitCommand implements CommandHandler {
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
isEmpty
())
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.resetShopLimit.usage"
));
return
;
}
targetPlayer
.
getShopLimit
().
forEach
(
x
->
x
.
setNextRefreshTime
(
0
));
targetPlayer
.
save
();
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.resetShopLimit.success"
));
...
...
src/main/java/emu/grasscutter/command/commands/SendMailCommand.java
View file @
104e04f7
...
...
@@ -43,7 +43,7 @@ public final class SendMailCommand implements CommandHandler {
MailBuilder
mailBuilder
;
switch
(
args
.
get
(
0
).
toLowerCase
())
{
case
"help"
->
{
CommandHandler
.
send
Mes
sage
(
sender
,
translate
(
sender
,
"commands.sendMail.usage"
)
);
send
U
sage
Message
(
sender
);
return
;
}
case
"all"
->
mailBuilder
=
new
MailBuilder
(
true
,
new
Mail
());
...
...
@@ -150,7 +150,7 @@ public final class SendMailCommand implements CommandHandler {
}
break
;
default
:
// *No args*
CommandHandler
.
send
Message
(
sender
,
translat
e
(
sender
,
"commands.give
.
usage"
)
)
;
CommandHandler
.
send
TranslatedMessag
e
(
sender
,
"commands.
sendMail.
give
_
usage"
);
return
;
}
mailBuilder
.
mail
.
itemList
.
add
(
new
Mail
.
MailItem
(
item
,
amount
,
lvl
));
...
...
src/main/java/emu/grasscutter/command/commands/SendMessageCommand.java
View file @
104e04f7
...
...
@@ -8,8 +8,6 @@ import emu.grasscutter.game.player.Player;
import
java.util.List
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"sendMessage"
,
aliases
=
{
"say"
,
"sendservmsg"
,
"sendservermessage"
,
"b"
,
"broadcast"
},
...
...
@@ -22,7 +20,7 @@ public final class SendMessageCommand implements CommandHandler {
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
size
()
==
0
)
{
CommandHandler
.
send
Mes
sage
(
sender
,
translate
(
sender
,
"commands.sendMessage.usage"
)
);
send
U
sage
Message
(
sender
);
return
;
}
...
...
@@ -35,6 +33,6 @@ public final class SendMessageCommand implements CommandHandler {
}
else
{
CommandHandler
.
sendMessage
(
targetPlayer
,
message
);
}
CommandHandler
.
send
Message
(
sender
,
translat
e
(
sender
,
"commands.sendMessage.success"
)
)
;
CommandHandler
.
send
TranslatedMessag
e
(
sender
,
"commands.sendMessage.success"
);
}
}
src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java
View file @
104e04f7
...
...
@@ -22,7 +22,7 @@ public final class SetFetterLevelCommand implements CommandHandler {
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
size
()
!=
1
)
{
CommandHandler
.
send
Mes
sage
(
sender
,
translate
(
sender
,
"commands.setFetterLevel.usage"
)
);
send
U
sage
Message
(
sender
);
return
;
}
...
...
src/main/java/emu/grasscutter/command/commands/SetPropCommand.java
View file @
104e04f7
...
...
@@ -10,7 +10,7 @@ import emu.grasscutter.game.player.Player;
import
emu.grasscutter.game.props.PlayerProperty
;
import
emu.grasscutter.game.tower.TowerLevelRecord
;
@Command
(
label
=
"setProp"
,
aliases
=
{
"prop"
},
usage
=
{
"<prop> <value>"
},
permission
=
"player.setprop"
,
permissionTargeted
=
"player.setprop.others"
)
@Command
(
label
=
"setProp"
,
aliases
=
{
"prop"
},
usage
=
{
"<prop> <value>"
},
permission
=
"player.setprop"
,
permissionTargeted
=
"player.setprop.others"
)
public
final
class
SetPropCommand
implements
CommandHandler
{
static
enum
PseudoProp
{
NONE
,
...
...
@@ -95,7 +95,7 @@ public final class SetPropCommand implements CommandHandler {
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
size
()
!=
2
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.setProp.usage"
);
sendUsageMessage
(
sender
);
return
;
}
String
propStr
=
args
.
get
(
0
).
toLowerCase
();
...
...
@@ -103,7 +103,7 @@ public final class SetPropCommand implements CommandHandler {
int
value
;
if
(!
props
.
containsKey
(
propStr
))
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.setProp.usage"
);
sendUsageMessage
(
sender
);
return
;
}
try
{
...
...
Prev
1
2
Next
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