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
2cfbe781
Commit
2cfbe781
authored
Jul 18, 2022
by
AnimeGitB
Committed by
Luke H-W
Jul 22, 2022
Browse files
Refactor Command usage and description strings
parent
e9464784
Changes
40
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/Command.java
View file @
2cfbe781
...
@@ -7,12 +7,10 @@ import java.lang.annotation.RetentionPolicy;
...
@@ -7,12 +7,10 @@ import java.lang.annotation.RetentionPolicy;
public
@interface
Command
{
public
@interface
Command
{
String
label
()
default
""
;
String
label
()
default
""
;
String
usage
()
default
"commands.generic.no_usage_specified"
;
String
description
()
default
"commands.generic.no_description_specified"
;
String
[]
aliases
()
default
{};
String
[]
aliases
()
default
{};
String
[]
usage
()
default
{
""
};
String
permission
()
default
""
;
String
permission
()
default
""
;
String
permissionTargeted
()
default
""
;
String
permissionTargeted
()
default
""
;
...
...
src/main/java/emu/grasscutter/command/CommandHandler.java
View file @
2cfbe781
...
@@ -2,12 +2,11 @@ package emu.grasscutter.command;
...
@@ -2,12 +2,11 @@ package emu.grasscutter.command;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.server.event.game.CommandResponseEvent
;
import
emu.grasscutter.server.event.game.ReceiveCommandFeedbackEvent
;
import
emu.grasscutter.server.event.game.ReceiveCommandFeedbackEvent
;
import
emu.grasscutter.server.event.types.ServerEvent
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
java.util.List
;
import
java.util.List
;
import
java.util.StringJoiner
;
public
interface
CommandHandler
{
public
interface
CommandHandler
{
...
@@ -37,6 +36,42 @@ public interface CommandHandler {
...
@@ -37,6 +36,42 @@ public interface CommandHandler {
sendMessage
(
player
,
translate
(
player
,
messageKey
,
args
));
sendMessage
(
player
,
translate
(
player
,
messageKey
,
args
));
}
}
default
String
getUsageString
(
Player
player
,
String
...
args
)
{
Command
annotation
=
this
.
getClass
().
getAnnotation
(
Command
.
class
);
String
usage_prefix
=
translate
(
player
,
"commands.execution.usage_prefix"
);
String
command
=
annotation
.
label
();
for
(
String
alias
:
annotation
.
aliases
())
{
if
(
alias
.
length
()
<
command
.
length
())
command
=
alias
;
}
String
target
=
switch
(
annotation
.
targetRequirement
())
{
case
NONE
->
""
;
case
OFFLINE
->
"@<UID> "
;
// TODO: make translation keys for offline and online players
case
ONLINE
->
(
player
==
null
)
?
"@<UID> "
:
"[@<UID>] "
;
// TODO: make translation keys for offline and online players
case
PLAYER
->
(
player
==
null
)
?
"@<UID> "
:
"[@<UID>] "
;
};
String
[]
usages
=
annotation
.
usage
();
StringJoiner
joiner
=
new
StringJoiner
(
"\n\t"
);
for
(
String
usage
:
usages
)
joiner
.
add
(
usage_prefix
+
command
+
" "
+
target
+
usage
);
return
joiner
.
toString
();
}
default
void
sendUsageMessage
(
Player
player
,
String
...
args
)
{
sendMessage
(
player
,
getUsageString
(
player
,
args
));
}
default
String
getLabel
()
{
return
this
.
getClass
().
getAnnotation
(
Command
.
class
).
label
();
}
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
);
}
/**
/**
* Called when a player/console invokes a command.
* Called when a player/console invokes a command.
* @param sender The player/console that invoked the command.
* @param sender The player/console that invoked the command.
...
...
src/main/java/emu/grasscutter/command/CommandMap.java
View file @
2cfbe781
...
@@ -8,9 +8,9 @@ import java.util.*;
...
@@ -8,9 +8,9 @@ import java.util.*;
@SuppressWarnings
({
"UnusedReturnValue"
,
"unused"
})
@SuppressWarnings
({
"UnusedReturnValue"
,
"unused"
})
public
final
class
CommandMap
{
public
final
class
CommandMap
{
private
final
Map
<
String
,
CommandHandler
>
commands
=
new
HashMap
<>();
private
final
Map
<
String
,
CommandHandler
>
commands
=
new
Linked
HashMap
<>();
private
final
Map
<
String
,
CommandHandler
>
aliases
=
new
HashMap
<>();
private
final
Map
<
String
,
CommandHandler
>
aliases
=
new
Linked
HashMap
<>();
private
final
Map
<
String
,
Command
>
annotations
=
new
HashMap
<>();
private
final
Map
<
String
,
Command
>
annotations
=
new
Linked
HashMap
<>();
private
final
Map
<
String
,
Integer
>
targetPlayerIds
=
new
HashMap
<>();
private
final
Map
<
String
,
Integer
>
targetPlayerIds
=
new
HashMap
<>();
private
static
final
String
consoleId
=
"console"
;
private
static
final
String
consoleId
=
"console"
;
...
...
src/main/java/emu/grasscutter/command/commands/AccountCommand.java
View file @
2cfbe781
...
@@ -13,18 +13,24 @@ import java.util.List;
...
@@ -13,18 +13,24 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"account"
,
usage
=
"account <create|delete|resetpass> <username> [uid|password] [uid] "
,
description
=
"commands.account.description"
,
targetRequirement
=
Command
.
TargetRequirement
.
NONE
)
@Command
(
label
=
"account"
,
usage
=
{
"create <username> [<UID>]"
,
// Only with EXPERIMENTAL_RealPassword == false
"delete <username>"
,
"create <username> <password> [<UID>]"
,
// Only with EXPERIMENTAL_RealPassword == true
"resetpass <username> <password>"
},
// Only with EXPERIMENTAL_RealPassword == true
targetRequirement
=
Command
.
TargetRequirement
.
NONE
)
public
final
class
AccountCommand
implements
CommandHandler
{
public
final
class
AccountCommand
implements
CommandHandler
{
@Override
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
sender
!=
null
)
{
if
(
sender
!=
null
)
{
CommandHandler
.
send
Message
(
sender
,
translat
e
(
sender
,
"commands.generic.console_execute_error"
)
)
;
CommandHandler
.
send
TranslatedMessag
e
(
sender
,
"commands.generic.console_execute_error"
);
return
;
return
;
}
}
if
(
args
.
size
()
<
2
)
{
if
(
args
.
size
()
<
2
)
{
CommandHandler
.
send
Message
(
null
,
translat
e
(
sender
,
"commands.account.command_usage"
)
)
;
CommandHandler
.
send
TranslatedMessag
e
(
sender
,
"commands.account.command_usage"
);
return
;
return
;
}
}
...
@@ -33,17 +39,16 @@ public final class AccountCommand implements CommandHandler {
...
@@ -33,17 +39,16 @@ public final class AccountCommand implements CommandHandler {
switch
(
action
)
{
switch
(
action
)
{
default
:
default
:
CommandHandler
.
send
Message
(
null
,
translat
e
(
sender
,
"commands.account.command_usage"
)
)
;
CommandHandler
.
send
TranslatedMessag
e
(
sender
,
"commands.account.command_usage"
);
return
;
return
;
case
"create"
:
case
"create"
:
int
uid
=
0
;
int
uid
=
0
;
String
password
=
""
;
String
password
=
""
;
if
(
Configuration
.
ACCOUNT
.
EXPERIMENTAL_RealPassword
==
true
)
{
if
(
Configuration
.
ACCOUNT
.
EXPERIMENTAL_RealPassword
==
true
)
{
if
(
args
.
size
()
<
3
)
{
if
(
args
.
size
()
<
3
)
{
CommandHandler
.
sendMessage
(
null
,
"EXPERIMENTAL_RealPassword requires a password argument"
);
CommandHandler
.
sendMessage
(
sender
,
"EXPERIMENTAL_RealPassword requires a password argument"
);
CommandHandler
.
sendMessage
(
null
,
"Usage: account create <username> <password> [uid]"
);
CommandHandler
.
sendMessage
(
sender
,
"Usage: account create <username> <password> [uid]"
);
return
;
return
;
}
}
password
=
args
.
get
(
2
);
password
=
args
.
get
(
2
);
...
@@ -52,10 +57,10 @@ public final class AccountCommand implements CommandHandler {
...
@@ -52,10 +57,10 @@ public final class AccountCommand implements CommandHandler {
try
{
try
{
uid
=
Integer
.
parseInt
(
args
.
get
(
3
));
uid
=
Integer
.
parseInt
(
args
.
get
(
3
));
}
catch
(
NumberFormatException
ignored
)
{
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.invalid"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.account.invalid"
));
if
(
Configuration
.
ACCOUNT
.
EXPERIMENTAL_RealPassword
==
true
)
{
if
(
Configuration
.
ACCOUNT
.
EXPERIMENTAL_RealPassword
==
true
)
{
CommandHandler
.
sendMessage
(
null
,
"EXPERIMENTAL_RealPassword requires argument 2 to be a password, not a uid"
);
CommandHandler
.
sendMessage
(
sender
,
"EXPERIMENTAL_RealPassword requires argument 2 to be a password, not a uid"
);
CommandHandler
.
sendMessage
(
null
,
"Usage: account create <username> <password> [uid]"
);
CommandHandler
.
sendMessage
(
sender
,
"Usage: account create <username> <password> [uid]"
);
}
}
return
;
return
;
}
}
...
@@ -65,7 +70,7 @@ public final class AccountCommand implements CommandHandler {
...
@@ -65,7 +70,7 @@ public final class AccountCommand implements CommandHandler {
try
{
try
{
uid
=
Integer
.
parseInt
(
args
.
get
(
2
));
uid
=
Integer
.
parseInt
(
args
.
get
(
2
));
}
catch
(
NumberFormatException
ignored
)
{
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.invalid"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.account.invalid"
));
return
;
return
;
}
}
}
}
...
@@ -73,7 +78,7 @@ public final class AccountCommand implements CommandHandler {
...
@@ -73,7 +78,7 @@ public final class AccountCommand implements CommandHandler {
emu
.
grasscutter
.
game
.
Account
account
=
DatabaseHelper
.
createAccountWithUid
(
username
,
uid
);
emu
.
grasscutter
.
game
.
Account
account
=
DatabaseHelper
.
createAccountWithUid
(
username
,
uid
);
if
(
account
==
null
)
{
if
(
account
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.exists"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.account.exists"
));
return
;
return
;
}
else
{
}
else
{
if
(
Configuration
.
ACCOUNT
.
EXPERIMENTAL_RealPassword
==
true
)
{
if
(
Configuration
.
ACCOUNT
.
EXPERIMENTAL_RealPassword
==
true
)
{
...
@@ -82,7 +87,7 @@ public final class AccountCommand implements CommandHandler {
...
@@ -82,7 +87,7 @@ public final class AccountCommand implements CommandHandler {
account
.
addPermission
(
"*"
);
account
.
addPermission
(
"*"
);
account
.
save
();
// Save account to database.
account
.
save
();
// Save account to database.
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.create"
,
Integer
.
toString
(
account
.
getReservedPlayerUid
())));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.account.create"
,
Integer
.
toString
(
account
.
getReservedPlayerUid
())));
}
}
return
;
return
;
case
"delete"
:
case
"delete"
:
...
@@ -90,51 +95,50 @@ public final class AccountCommand implements CommandHandler {
...
@@ -90,51 +95,50 @@ public final class AccountCommand implements CommandHandler {
Account
toDelete
=
DatabaseHelper
.
getAccountByName
(
username
);
Account
toDelete
=
DatabaseHelper
.
getAccountByName
(
username
);
if
(
toDelete
==
null
)
{
if
(
toDelete
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.no_account"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.account.no_account"
));
return
;
return
;
}
}
// Get the player for the account.
// Make sure player isn't online as we delete their account.
// If that player is currently online, we kick them before proceeding with the deletion.
kickAccount
(
toDelete
);
Player
player
=
Grasscutter
.
getGameServer
().
getPlayerByAccountId
(
toDelete
.
getId
());
if
(
player
!=
null
)
{
player
.
getSession
().
close
();
}
// Finally, we do the actual deletion.
// Finally, we do the actual deletion.
DatabaseHelper
.
deleteAccount
(
toDelete
);
DatabaseHelper
.
deleteAccount
(
toDelete
);
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.delete"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.account.delete"
));
return
;
return
;
case
"resetpass"
:
case
"resetpass"
:
if
(
Configuration
.
ACCOUNT
.
EXPERIMENTAL_RealPassword
!=
true
)
{
if
(
Configuration
.
ACCOUNT
.
EXPERIMENTAL_RealPassword
!=
true
)
{
CommandHandler
.
sendMessage
(
null
,
"resetpass requires EXPERIMENTAL_RealPassword to be true."
);
CommandHandler
.
sendMessage
(
sender
,
"resetpass requires EXPERIMENTAL_RealPassword to be true."
);
return
;
return
;
}
}
if
(
args
.
size
()
!=
3
)
{
if
(
args
.
size
()
!=
3
)
{
CommandHandler
.
sendMessage
(
null
,
"Invalid Args"
);
CommandHandler
.
sendMessage
(
sender
,
"Invalid Args"
);
CommandHandler
.
sendMessage
(
null
,
"Usage: account resetpass <username> <password>"
);
CommandHandler
.
sendMessage
(
sender
,
"Usage: account resetpass <username> <password>"
);
return
;
return
;
}
}
Account
toUpdate
=
DatabaseHelper
.
getAccountByName
(
username
);
Account
toUpdate
=
DatabaseHelper
.
getAccountByName
(
username
);
if
(
toUpdate
==
null
)
{
if
(
toUpdate
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.no_account"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.account.no_account"
));
return
;
return
;
}
}
// Get the player for the account.
// Make sure player can't stay logged in with old password.
// If that player is currently online, we kick them before proceeding with the deletion.
kickAccount
(
toUpdate
);
Player
uPlayer
=
Grasscutter
.
getGameServer
().
getPlayerByAccountId
(
toUpdate
.
getId
());
if
(
uPlayer
!=
null
)
{
uPlayer
.
getSession
().
close
();
}
toUpdate
.
setPassword
(
BCrypt
.
withDefaults
().
hashToString
(
12
,
args
.
get
(
2
).
toCharArray
()));
toUpdate
.
setPassword
(
BCrypt
.
withDefaults
().
hashToString
(
12
,
args
.
get
(
2
).
toCharArray
()));
toUpdate
.
save
();
toUpdate
.
save
();
CommandHandler
.
sendMessage
(
null
,
"Password Updated."
);
CommandHandler
.
sendMessage
(
sender
,
"Password Updated."
);
return
;
return
;
}
}
}
}
private
void
kickAccount
(
Account
account
)
{
Player
player
=
Grasscutter
.
getGameServer
().
getPlayerByAccountId
(
account
.
getId
());
if
(
player
!=
null
)
{
player
.
getSession
().
close
();
}
}
}
}
src/main/java/emu/grasscutter/command/commands/AnnounceCommand.java
View file @
2cfbe781
...
@@ -13,10 +13,9 @@ import java.util.Random;
...
@@ -13,10 +13,9 @@ import java.util.Random;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"announce"
,
@Command
(
label
=
"announce"
,
usage
=
"announce|a <\"tpl\" templateId|\"refresh\"|\"
revoke
\"
templateId
|content
>"
,
usage
=
{
"<content>"
,
"refresh"
,
"(tpl|
revoke
) <
templateId>"
}
,
permission
=
"server.announce"
,
permission
=
"server.announce"
,
aliases
=
{
"a"
},
aliases
=
{
"a"
},
description
=
"commands.announce.description"
,
targetRequirement
=
Command
.
TargetRequirement
.
NONE
)
targetRequirement
=
Command
.
TargetRequirement
.
NONE
)
public
final
class
AnnounceCommand
implements
CommandHandler
{
public
final
class
AnnounceCommand
implements
CommandHandler
{
...
...
src/main/java/emu/grasscutter/command/commands/BanCommand.java
View file @
2cfbe781
...
@@ -10,8 +10,7 @@ import emu.grasscutter.server.game.GameSession;
...
@@ -10,8 +10,7 @@ import emu.grasscutter.server.game.GameSession;
@Command
(
@Command
(
label
=
"ban"
,
label
=
"ban"
,
usage
=
"ban <@player> [time] [reason]"
,
usage
=
{
"[<time> [<reason>]]"
},
description
=
"commands.ban.description"
,
permission
=
"server.ban"
,
permission
=
"server.ban"
,
targetRequirement
=
Command
.
TargetRequirement
.
PLAYER
targetRequirement
=
Command
.
TargetRequirement
.
PLAYER
)
)
...
...
src/main/java/emu/grasscutter/command/commands/ClearCommand.java
View file @
2cfbe781
...
@@ -12,10 +12,11 @@ import java.util.regex.Matcher;
...
@@ -12,10 +12,11 @@ import java.util.regex.Matcher;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
java.util.stream.Stream
;
import
java.util.stream.Stream
;
@Command
(
label
=
"clear"
,
usage
=
"clear <all|wp|art|mat> [lv<max level>] [r<max refinement>] [<max rarity>*]"
,
@Command
(
description
=
"commands.clear.description"
,
label
=
"clear"
,
aliases
=
{
"clear"
},
permission
=
"player.clearinv"
,
permissionTargeted
=
"player.clearinv.others"
)
usage
=
{
"(all|wp|art|mat) [lv<max level>] [r<max refinement>] [<max rarity>*]"
},
permission
=
"player.clearinv"
,
permissionTargeted
=
"player.clearinv.others"
)
public
final
class
ClearCommand
implements
CommandHandler
{
public
final
class
ClearCommand
implements
CommandHandler
{
private
static
Pattern
lvlRegex
=
Pattern
.
compile
(
"l(?:vl?)?(\\d+)"
);
// Java doesn't have raw string literals :(
private
static
Pattern
lvlRegex
=
Pattern
.
compile
(
"l(?:vl?)?(\\d+)"
);
// Java doesn't have raw string literals :(
private
static
Pattern
refineRegex
=
Pattern
.
compile
(
"r(\\d+)"
);
private
static
Pattern
refineRegex
=
Pattern
.
compile
(
"r(\\d+)"
);
...
...
src/main/java/emu/grasscutter/command/commands/CoopCommand.java
View file @
2cfbe781
...
@@ -9,7 +9,7 @@ import java.util.List;
...
@@ -9,7 +9,7 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"coop"
,
usage
=
"coop [
host
uid
]"
,
permission
=
"server.coop"
,
permissionTargeted
=
"server.coop.others"
,
description
=
"commands.coop.description"
)
@Command
(
label
=
"coop"
,
usage
=
{
"[<
host
UID>
]"
}
,
permission
=
"server.coop"
,
permissionTargeted
=
"server.coop.others"
)
public
final
class
CoopCommand
implements
CommandHandler
{
public
final
class
CoopCommand
implements
CommandHandler
{
@Override
@Override
...
...
src/main/java/emu/grasscutter/command/commands/EnterDungeonCommand.java
View file @
2cfbe781
...
@@ -8,7 +8,7 @@ import java.util.List;
...
@@ -8,7 +8,7 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"enterdungeon"
,
usage
=
"enterdungeon
<
dungeon
Id>"
,
aliases
=
{
"dungeon"
},
permission
=
"player.enterdungeon"
,
permissionTargeted
=
"player.enterdungeon.others"
,
description
=
"commands.enter_dungeon.description"
)
@Command
(
label
=
"enter
_
dungeon"
,
aliases
=
{
"enterdungeon
"
,
"
dungeon
"
},
usage
=
{
"
<
dungeon
Id>
"
},
permission
=
"player.enterdungeon"
,
permissionTargeted
=
"player.enterdungeon.others"
)
public
final
class
EnterDungeonCommand
implements
CommandHandler
{
public
final
class
EnterDungeonCommand
implements
CommandHandler
{
@Override
@Override
...
...
src/main/java/emu/grasscutter/command/commands/GiveCommand.java
View file @
2cfbe781
...
@@ -23,8 +23,15 @@ import java.util.List;
...
@@ -23,8 +23,15 @@ import java.util.List;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
@Command
(
label
=
"give"
,
usage
=
"give <itemId|avatarId|\"all\"|\"weapons\"|\"mats\"|\"avatars\"> [lv<level>] [r<refinement>] [x<amount>] | give <artifactId> [lv<level>] [x<amount>] [mainPropId] [<appendPropId>[,<times>]]..."
,
aliases
=
{
@Command
(
"g"
,
"item"
,
"giveitem"
},
permission
=
"player.give"
,
permissionTargeted
=
"player.give.others"
,
description
=
"commands.give.description"
)
label
=
"give"
,
aliases
=
{
"g"
,
"item"
,
"giveitem"
},
usage
=
{
"(<itemId>|<avatarId>|all|weapons|mats|avatars) [lv<level>] [r<refinement>] [x<amount>] [c<constellation>]"
,
"<artifactId> [lv<level>] [x<amount>] [<mainPropId>] [<appendPropId>[,<times>]]..."
},
permission
=
"player.give"
,
permissionTargeted
=
"player.give.others"
,
threading
=
true
)
public
final
class
GiveCommand
implements
CommandHandler
{
public
final
class
GiveCommand
implements
CommandHandler
{
private
static
Pattern
lvlRegex
=
Pattern
.
compile
(
"l(?:vl?)?(\\d+)"
);
// Java doesn't have raw string literals :(
private
static
Pattern
lvlRegex
=
Pattern
.
compile
(
"l(?:vl?)?(\\d+)"
);
// Java doesn't have raw string literals :(
private
static
Pattern
refineRegex
=
Pattern
.
compile
(
"r(\\d+)"
);
private
static
Pattern
refineRegex
=
Pattern
.
compile
(
"r(\\d+)"
);
...
...
src/main/java/emu/grasscutter/command/commands/HealCommand.java
View file @
2cfbe781
...
@@ -11,7 +11,7 @@ import java.util.List;
...
@@ -11,7 +11,7 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"heal"
,
usage
=
"heal|h"
,
aliases
=
{
"h"
},
permission
=
"player.heal"
,
permissionTargeted
=
"player.heal.others"
,
description
=
"commands.heal.description"
)
@Command
(
label
=
"heal"
,
aliases
=
{
"h"
},
permission
=
"player.heal"
,
permissionTargeted
=
"player.heal.others"
)
public
final
class
HealCommand
implements
CommandHandler
{
public
final
class
HealCommand
implements
CommandHandler
{
@Override
@Override
...
...
src/main/java/emu/grasscutter/command/commands/HelpCommand.java
View file @
2cfbe781
...
@@ -3,80 +3,80 @@ package emu.grasscutter.command.commands;
...
@@ -3,80 +3,80 @@ package emu.grasscutter.command.commands;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.command.CommandMap
;
import
emu.grasscutter.command.CommandMap
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
import
java.util.*
;
import
java.util.*
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"help"
,
usage
=
"help [
command]"
,
description
=
"commands.help.description"
,
targetRequirement
=
Command
.
TargetRequirement
.
NONE
)
@Command
(
label
=
"help"
,
usage
=
{
"[<
command
>
]"
}
,
targetRequirement
=
Command
.
TargetRequirement
.
NONE
)
public
final
class
HelpCommand
implements
CommandHandler
{
public
final
class
HelpCommand
implements
CommandHandler
{
private
final
boolean
SHOW_COMMANDS_WITHOUT_PERMISSIONS
=
false
;
// TODO: Make this into a server config key
private
void
createCommand
(
StringBuilder
builder
,
Player
player
,
Command
annotation
)
{
private
String
createCommand
(
Player
player
,
CommandHandler
command
,
List
<
String
>
args
)
{
builder
.
append
(
"\n"
).
append
(
annotation
.
label
()).
append
(
" - "
).
append
(
translate
(
player
,
annotation
.
description
()));
StringBuilder
builder
=
new
StringBuilder
(
command
.
getLabel
())
builder
.
append
(
"\n\t"
).
append
(
translate
(
player
,
"commands.help.usage"
));
.
append
(
" - "
)
if
(
annotation
.
aliases
().
length
>=
1
)
{
.
append
(
command
.
getDescriptionString
(
player
))
.
append
(
"\n\t"
)
.
append
(
command
.
getUsageString
(
player
,
args
.
toArray
(
new
String
[
0
])));
Command
annotation
=
command
.
getClass
().
getAnnotation
(
Command
.
class
);
if
(
annotation
.
aliases
().
length
>
0
)
{
builder
.
append
(
"\n\t"
).
append
(
translate
(
player
,
"commands.help.aliases"
));
builder
.
append
(
"\n\t"
).
append
(
translate
(
player
,
"commands.help.aliases"
));
for
(
String
alias
:
annotation
.
aliases
())
{
for
(
String
alias
:
annotation
.
aliases
())
{
builder
.
append
(
alias
).
append
(
" "
);
builder
.
append
(
alias
).
append
(
" "
);
}
}
}
}
builder
.
append
(
"\n\t"
).
append
(
translate
(
player
,
"commands.help.tip_need_permission"
));
builder
.
append
(
"\n\t"
).
append
(
translate
(
player
,
"commands.help.tip_need_permission"
));
if
(
annotation
.
permission
().
isEmpty
()
||
annotation
.
permission
().
isBlank
())
{
if
(!
annotation
.
permission
().
isEmpty
())
{
builder
.
append
(
translate
(
player
,
"commands.help.tip_need_no_permission"
));
}
else
{
builder
.
append
(
annotation
.
permission
());
builder
.
append
(
annotation
.
permission
());
}
else
{
builder
.
append
(
translate
(
player
,
"commands.help.tip_need_no_permission"
));
}
}
if
(!
annotation
.
permissionTargeted
().
isEmpty
()
&&
!
annotation
.
permissionTargeted
().
isBlank
()
)
{
if
(!
annotation
.
permissionTargeted
().
isEmpty
())
{
String
permissionTargeted
=
annotation
.
permissionTargeted
();
String
permissionTargeted
=
annotation
.
permissionTargeted
();
builder
.
append
(
" "
).
append
(
translate
(
player
,
"commands.help.tip_permission_targeted"
,
permissionTargeted
));
builder
.
append
(
" "
).
append
(
translate
(
player
,
"commands.help.tip_permission_targeted"
,
permissionTargeted
));
}
}
return
builder
.
toString
();
}
}
@Override
@Override
public
void
execute
(
Player
player
,
Player
targetPlayer
,
List
<
String
>
args
)
{
public
void
execute
(
Player
player
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
size
()
<
1
)
{
Account
account
=
(
player
==
null
)
?
null
:
player
.
getAccount
();
HashMap
<
String
,
CommandHandler
>
handlers
=
CommandMap
.
getInstance
().
getHandlers
();
Map
<
String
,
CommandHandler
>
handlers
=
CommandMap
.
getInstance
().
getHandlers
();
List
<
Command
>
annotations
=
new
ArrayList
<>();
List
<
String
>
commands
=
new
ArrayList
<>();
List
<
String
>
commands_no_permission
=
new
ArrayList
<>();
if
(
args
.
isEmpty
())
{
for
(
String
key
:
handlers
.
keySet
())
{
for
(
String
key
:
handlers
.
keySet
())
{
Command
an
notation
=
handlers
.
get
(
key
)
.
getClass
().
getAnnotation
(
Command
.
class
)
;
Command
H
an
dler
command
=
handlers
.
get
(
key
);
Command
annotation
=
command
.
getClass
().
getAnnotation
(
Command
.
class
);
if
(
!
Arrays
.
asList
(
annotation
.
aliases
()).
contains
(
key
))
{
if
(
player
==
null
||
account
.
hasPermission
(
annotation
.
permission
()
))
{
if
(
player
!=
null
&&
!
Objects
.
equals
(
annotation
.
permission
(),
""
)
&&
!
player
.
getAccount
().
hasPermission
(
annotation
.
permission
()
))
commands
.
add
(
createCommand
(
player
,
command
,
args
))
;
continue
;
}
else
if
(
SHOW_COMMANDS_WITHOUT_PERMISSIONS
)
{
annotat
ion
s
.
add
(
annotation
);
commands_no_permiss
ion
.
add
(
createCommand
(
player
,
command
,
args
)
);
}
}
}
}
SendAllHelpMessage
(
player
,
annotations
);
}
else
{
}
else
{
String
command
=
args
.
get
(
0
);
String
command
_str
=
args
.
remove
(
0
);
CommandHandler
handler
=
CommandMap
.
getInstance
().
getHandler
(
command
);
CommandHandler
command
=
handlers
.
get
(
command
_str
);
StringBuilder
builder
=
new
StringBuilder
(
""
);
if
(
command
==
null
)
{
if
(
handler
==
null
)
{
CommandHandler
.
sendTranslatedMessage
(
player
,
"commands.generic.command_exist_error"
);
builder
.
append
(
translate
(
player
,
"commands.generic.command_exist_error"
))
;
return
;
}
else
{
}
else
{
Command
annotation
=
handler
.
getClass
().
getAnnotation
(
Command
.
class
);
Command
annotation
=
command
.
getClass
().
getAnnotation
(
Command
.
class
);
if
(
player
==
null
||
account
.
hasPermission
(
annotation
.
permission
()))
{
this
.
createCommand
(
builder
,
player
,
annotation
);
commands
.
add
(
createCommand
(
player
,
command
,
args
));
}
else
{
if
(
player
!=
null
&&
!
Objects
.
equals
(
annotation
.
permission
(),
""
)
&&
!
player
.
getAccount
().
hasPermission
(
annotation
.
permission
()))
{
commands_no_permission
.
add
(
createCommand
(
player
,
command
,
args
));
builder
.
append
(
"\n\t"
).
append
(
translate
(
player
,
"commands.help.warn_player_has_no_permission"
));
}
}
}
}
CommandHandler
.
sendMessage
(
player
,
builder
.
toString
());
}
}
}
for
(
String
s
:
commands
)
CommandHandler
.
sendMessage
(
player
,
s
);
void
SendAllHelpMessage
(
Player
player
,
List
<
Command
>
annotations
)
{
for
(
String
s
:
commands_no_permission
)
StringBuilder
builder
=
new
StringBuilder
(
translate
(
player
,
"commands.help.available_commands"
));
CommandHandler
.
sendMessage
(
player
,
s
+
"\n\t"
+
translate
(
player
,
"commands.help.warn_player_has_no_permission"
));
annotations
.
forEach
(
annotation
->
{
this
.
createCommand
(
builder
,
player
,
annotation
);
builder
.
append
(
"\n"
);
});
CommandHandler
.
sendMessage
(
player
,
builder
.
toString
());
}
}
}
}
src/main/java/emu/grasscutter/command/commands/KickCommand.java
View file @
2cfbe781
...
@@ -6,19 +6,18 @@ import emu.grasscutter.game.player.Player;
...
@@ -6,19 +6,18 @@ import emu.grasscutter.game.player.Player;
import
java.util.List
;
import
java.util.List
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"kick"
,
aliases
=
{
"restart"
},
permissionTargeted
=
"server.kick"
)
@Command
(
label
=
"kick"
,
usage
=
"kick"
,
aliases
=
{
"restart"
},
permissionTargeted
=
"server.kick"
,
description
=
"commands.kick.description"
)
public
final
class
KickCommand
implements
CommandHandler
{
public
final
class
KickCommand
implements
CommandHandler
{
@Override
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
sender
!=
null
)
{
if
(
sender
!=
null
)
{
CommandHandler
.
send
Message
(
sender
,
translat
e
(
sender
,
"commands.kick.player_kick_player"
,
CommandHandler
.
send
TranslatedMessag
e
(
sender
,
"commands.kick.player_kick_player"
,
Integer
.
toString
(
sender
.
getUid
()),
sender
.
getAccount
().
getUsername
(),
Integer
.
toString
(
sender
.
getUid
()),
sender
.
getAccount
().
getUsername
(),
Integer
.
toString
(
targetPlayer
.
getUid
()),
targetPlayer
.
getAccount
().
getUsername
())
)
;
Integer
.
toString
(
targetPlayer
.
getUid
()),
targetPlayer
.
getAccount
().
getUsername
());
}
else
{
}
else
{
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.kick.server_kick_player"
,
Integer
.
toString
(
targetPlayer
.
getUid
()),
targetPlayer
.
getAccount
().
getUsername
()));
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.kick.server_kick_player"
,
Integer
.
toString
(
targetPlayer
.
getUid
()),
targetPlayer
.
getAccount
().
getUsername
());
}
}
targetPlayer
.
getSession
().
close
();
targetPlayer
.
getSession
().
close
();
...
...
src/main/java/emu/grasscutter/command/commands/KillAllCommand.java
View file @
2cfbe781
package
emu.grasscutter.command.commands
;
package
emu.grasscutter.command.commands
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.game.entity.EntityMonster
;
import
emu.grasscutter.game.entity.EntityMonster
;
...
@@ -12,7 +11,7 @@ import java.util.List;
...
@@ -12,7 +11,7 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"killall"
,
usage
=
"killall [
sceneId]"
,
permission
=
"server.killall"
,
permissionTargeted
=
"server.killall.others"
,
description
=
"commands.killall.description"
)
@Command
(
label
=
"killall"
,
usage
=
{
"[<
sceneId
>
]"
}
,
permission
=
"server.killall"
,
permissionTargeted
=
"server.killall.others"
)
public
final
class
KillAllCommand
implements
CommandHandler
{
public
final
class
KillAllCommand
implements
CommandHandler
{
@Override
@Override
...
...
src/main/java/emu/grasscutter/command/commands/KillCharacterCommand.java
View file @
2cfbe781
...
@@ -13,7 +13,7 @@ import java.util.List;
...
@@ -13,7 +13,7 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"kill
character"
,
usage
=
"killc
haracter"
,
aliases
=
{
"suicide"
,
"kill"
},
permission
=
"player.killcharacter"
,
permissionTargeted
=
"player.killcharacter.others"
,
description
=
"commands.killCharacter.description"
)
@Command
(
label
=
"kill
C
haracter"
,
aliases
=
{
"suicide"
,
"kill"
},
permission
=
"player.killcharacter"
,
permissionTargeted
=
"player.killcharacter.others"
)
public
final
class
KillCharacterCommand
implements
CommandHandler
{
public
final
class
KillCharacterCommand
implements
CommandHandler
{
@Override
@Override
...
...
src/main/java/emu/grasscutter/command/commands/LanguageCommand.java
View file @
2cfbe781
...
@@ -3,8 +3,6 @@ package emu.grasscutter.command.commands;
...
@@ -3,8 +3,6 @@ package emu.grasscutter.command.commands;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.database.DatabaseHelper
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.utils.Utils
;
import
emu.grasscutter.utils.Utils
;
...
@@ -13,7 +11,7 @@ import java.util.Locale;
...
@@ -13,7 +11,7 @@ import java.util.Locale;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"language"
,
usage
=
"language [
language code]"
,
description
=
"commands.language.description"
,
aliases
=
{
"lang"
},
targetRequirement
=
Command
.
TargetRequirement
.
NONE
)
@Command
(
label
=
"language"
,
usage
=
{
"[<
language code
>
]"
}
,
aliases
=
{
"lang"
},
targetRequirement
=
Command
.
TargetRequirement
.
NONE
)
public
final
class
LanguageCommand
implements
CommandHandler
{
public
final
class
LanguageCommand
implements
CommandHandler
{
@Override
@Override
...
...
src/main/java/emu/grasscutter/command/commands/ListCommand.java
View file @
2cfbe781
...
@@ -10,7 +10,7 @@ import java.util.Map;
...
@@ -10,7 +10,7 @@ import java.util.Map;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"list"
,
usage
=
"list [uid]"
,
aliases
=
{
"players"
},
description
=
"commands.list.description"
,
targetRequirement
=
Command
.
TargetRequirement
.
NONE
)
@Command
(
label
=
"list"
,
aliases
=
{
"players"
},
usage
=
{
"[<UID>]"
}
,
targetRequirement
=
Command
.
TargetRequirement
.
NONE
)
public
final
class
ListCommand
implements
CommandHandler
{
public
final
class
ListCommand
implements
CommandHandler
{
@Override
@Override
...
...
src/main/java/emu/grasscutter/command/commands/PermissionCommand.java
View file @
2cfbe781
...
@@ -11,7 +11,7 @@ import java.util.List;
...
@@ -11,7 +11,7 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"permission"
,
usage
=
"
permission <
add|remove
>
<permission>"
,
permission
=
"permission"
,
description
=
"commands.permission.description"
,
targetRequirement
=
TargetRequirement
.
PLAYER
)
@Command
(
label
=
"permission"
,
usage
=
"
(
add|remove
)
<permission>"
,
permission
=
"permission"
,
targetRequirement
=
TargetRequirement
.
PLAYER
)
public
final
class
PermissionCommand
implements
CommandHandler
{
public
final
class
PermissionCommand
implements
CommandHandler
{
@Override
@Override
...
...
src/main/java/emu/grasscutter/command/commands/PositionCommand.java
View file @
2cfbe781
...
@@ -7,16 +7,14 @@ import emu.grasscutter.utils.Position;
...
@@ -7,16 +7,14 @@ import emu.grasscutter.utils.Position;
import
java.util.List
;
import
java.util.List
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"position"
,
aliases
=
{
"pos"
})
@Command
(
label
=
"position"
,
usage
=
"position"
,
aliases
=
{
"pos"
},
description
=
"commands.position.description"
)
public
final
class
PositionCommand
implements
CommandHandler
{
public
final
class
PositionCommand
implements
CommandHandler
{
@Override
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
Position
pos
=
targetPlayer
.
getPosition
();
Position
pos
=
targetPlayer
.
getPosition
();
CommandHandler
.
send
Message
(
sender
,
translat
e
(
sender
,
"commands.position.success"
,
CommandHandler
.
send
TranslatedMessag
e
(
sender
,
"commands.position.success"
,
Float
.
toString
(
pos
.
getX
()),
Float
.
toString
(
pos
.
getY
()),
Float
.
toString
(
pos
.
getZ
()),
Float
.
toString
(
pos
.
getX
()),
Float
.
toString
(
pos
.
getY
()),
Float
.
toString
(
pos
.
getZ
()),
Integer
.
toString
(
targetPlayer
.
getSceneId
()))
)
;
Integer
.
toString
(
targetPlayer
.
getSceneId
()));
}
}
}
}
src/main/java/emu/grasscutter/command/commands/QuestCommand.java
View file @
2cfbe781
package
emu.grasscutter.command.commands
;
package
emu.grasscutter.command.commands
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
...
@@ -10,7 +9,7 @@ import java.util.List;
...
@@ -10,7 +9,7 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"quest"
,
usage
=
"quest <
add|finish
>
[questId]"
,
permission
=
"player.quest"
,
permissionTargeted
=
"player.quest.others"
,
description
=
"commands.quest.description"
)
@Command
(
label
=
"quest"
,
usage
=
{
"(
add|finish
)
[
<
questId
>
]"
}
,
permission
=
"player.quest"
,
permissionTargeted
=
"player.quest.others"
)
public
final
class
QuestCommand
implements
CommandHandler
{
public
final
class
QuestCommand
implements
CommandHandler
{
@Override
@Override
...
...
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