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
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/Command.java
View file @
2cfbe781
...
...
@@ -7,14 +7,12 @@ import java.lang.annotation.RetentionPolicy;
public
@interface
Command
{
String
label
()
default
""
;
String
usage
()
default
"commands.generic.no_usage_specified"
;
String
description
()
default
"commands.generic.no_description_specified"
;
String
[]
aliases
()
default
{};
String
[]
usage
()
default
{
""
};
String
permission
()
default
""
;
String
permissionTargeted
()
default
""
;
public
enum
TargetRequirement
{
...
...
src/main/java/emu/grasscutter/command/CommandHandler.java
View file @
2cfbe781
...
...
@@ -2,12 +2,11 @@ package emu.grasscutter.command;
import
emu.grasscutter.Grasscutter
;
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.types.ServerEvent
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
java.util.List
;
import
java.util.StringJoiner
;
public
interface
CommandHandler
{
...
...
@@ -37,6 +36,42 @@ public interface CommandHandler {
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.
* @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.*;
@SuppressWarnings
({
"UnusedReturnValue"
,
"unused"
})
public
final
class
CommandMap
{
private
final
Map
<
String
,
CommandHandler
>
commands
=
new
HashMap
<>();
private
final
Map
<
String
,
CommandHandler
>
aliases
=
new
HashMap
<>();
private
final
Map
<
String
,
Command
>
annotations
=
new
HashMap
<>();
private
final
Map
<
String
,
CommandHandler
>
commands
=
new
Linked
HashMap
<>();
private
final
Map
<
String
,
CommandHandler
>
aliases
=
new
Linked
HashMap
<>();
private
final
Map
<
String
,
Command
>
annotations
=
new
Linked
HashMap
<>();
private
final
Map
<
String
,
Integer
>
targetPlayerIds
=
new
HashMap
<>();
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;
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
{
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
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
;
}
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
;
}
...
...
@@ -33,17 +39,16 @@ public final class AccountCommand implements CommandHandler {
switch
(
action
)
{
default
:
CommandHandler
.
send
Message
(
null
,
translat
e
(
sender
,
"commands.account.command_usage"
)
)
;
CommandHandler
.
send
TranslatedMessag
e
(
sender
,
"commands.account.command_usage"
);
return
;
case
"create"
:
int
uid
=
0
;
String
password
=
""
;
if
(
Configuration
.
ACCOUNT
.
EXPERIMENTAL_RealPassword
==
true
)
{
if
(
args
.
size
()
<
3
)
{
CommandHandler
.
sendMessage
(
null
,
"EXPERIMENTAL_RealPassword requires a password argument"
);
CommandHandler
.
sendMessage
(
null
,
"Usage: account create <username> <password> [uid]"
);
if
(
Configuration
.
ACCOUNT
.
EXPERIMENTAL_RealPassword
==
true
)
{
if
(
args
.
size
()
<
3
)
{
CommandHandler
.
sendMessage
(
sender
,
"EXPERIMENTAL_RealPassword requires a password argument"
);
CommandHandler
.
sendMessage
(
sender
,
"Usage: account create <username> <password> [uid]"
);
return
;
}
password
=
args
.
get
(
2
);
...
...
@@ -52,10 +57,10 @@ public final class AccountCommand implements CommandHandler {
try
{
uid
=
Integer
.
parseInt
(
args
.
get
(
3
));
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.invalid"
));
if
(
Configuration
.
ACCOUNT
.
EXPERIMENTAL_RealPassword
==
true
)
{
CommandHandler
.
sendMessage
(
null
,
"EXPERIMENTAL_RealPassword requires argument 2 to be a password, not a uid"
);
CommandHandler
.
sendMessage
(
null
,
"Usage: account create <username> <password> [uid]"
);
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.account.invalid"
));
if
(
Configuration
.
ACCOUNT
.
EXPERIMENTAL_RealPassword
==
true
)
{
CommandHandler
.
sendMessage
(
sender
,
"EXPERIMENTAL_RealPassword requires argument 2 to be a password, not a uid"
);
CommandHandler
.
sendMessage
(
sender
,
"Usage: account create <username> <password> [uid]"
);
}
return
;
}
...
...
@@ -65,7 +70,7 @@ public final class AccountCommand implements CommandHandler {
try
{
uid
=
Integer
.
parseInt
(
args
.
get
(
2
));
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.invalid"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.account.invalid"
));
return
;
}
}
...
...
@@ -73,7 +78,7 @@ public final class AccountCommand implements CommandHandler {
emu
.
grasscutter
.
game
.
Account
account
=
DatabaseHelper
.
createAccountWithUid
(
username
,
uid
);
if
(
account
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.exists"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.account.exists"
));
return
;
}
else
{
if
(
Configuration
.
ACCOUNT
.
EXPERIMENTAL_RealPassword
==
true
)
{
...
...
@@ -82,7 +87,7 @@ public final class AccountCommand implements CommandHandler {
account
.
addPermission
(
"*"
);
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
;
case
"delete"
:
...
...
@@ -90,51 +95,50 @@ public final class AccountCommand implements CommandHandler {
Account
toDelete
=
DatabaseHelper
.
getAccountByName
(
username
);
if
(
toDelete
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.no_account"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.account.no_account"
));
return
;
}
// Get the player for the account.
// If that player is currently online, we kick them before proceeding with the deletion.
Player
player
=
Grasscutter
.
getGameServer
().
getPlayerByAccountId
(
toDelete
.
getId
());
if
(
player
!=
null
)
{
player
.
getSession
().
close
();
}
// Make sure player isn't online as we delete their account.
kickAccount
(
toDelete
);
// Finally, we do the actual deletion.
DatabaseHelper
.
deleteAccount
(
toDelete
);
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.delete"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.account.delete"
));
return
;
case
"resetpass"
:
if
(
Configuration
.
ACCOUNT
.
EXPERIMENTAL_RealPassword
!=
true
)
{
CommandHandler
.
sendMessage
(
null
,
"resetpass requires EXPERIMENTAL_RealPassword to be true."
);
if
(
Configuration
.
ACCOUNT
.
EXPERIMENTAL_RealPassword
!=
true
)
{
CommandHandler
.
sendMessage
(
sender
,
"resetpass requires EXPERIMENTAL_RealPassword to be true."
);
return
;
}
if
(
args
.
size
()
!=
3
)
{
CommandHandler
.
sendMessage
(
null
,
"Invalid Args"
);
CommandHandler
.
sendMessage
(
null
,
"Usage: account resetpass <username> <password>"
);
if
(
args
.
size
()
!=
3
)
{
CommandHandler
.
sendMessage
(
sender
,
"Invalid Args"
);
CommandHandler
.
sendMessage
(
sender
,
"Usage: account resetpass <username> <password>"
);
return
;
}
Account
toUpdate
=
DatabaseHelper
.
getAccountByName
(
username
);
if
(
toUpdate
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.no_account"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.account.no_account"
));
return
;
}
// Get the player for the account.
// If that player is currently online, we kick them before proceeding with the deletion.
Player
uPlayer
=
Grasscutter
.
getGameServer
().
getPlayerByAccountId
(
toUpdate
.
getId
());
if
(
uPlayer
!=
null
)
{
uPlayer
.
getSession
().
close
();
}
// Make sure player can't stay logged in with old password.
kickAccount
(
toUpdate
);
toUpdate
.
setPassword
(
BCrypt
.
withDefaults
().
hashToString
(
12
,
args
.
get
(
2
).
toCharArray
()));
toUpdate
.
save
();
CommandHandler
.
sendMessage
(
null
,
"Password Updated."
);
CommandHandler
.
sendMessage
(
sender
,
"Password Updated."
);
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;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"announce"
,
usage
=
"announce|a <\"tpl\" templateId|\"refresh\"|\"
revoke
\"
templateId
|content
>"
,
usage
=
{
"<content>"
,
"refresh"
,
"(tpl|
revoke
) <
templateId>"
}
,
permission
=
"server.announce"
,
aliases
=
{
"a"
},
description
=
"commands.announce.description"
,
targetRequirement
=
Command
.
TargetRequirement
.
NONE
)
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;
@Command
(
label
=
"ban"
,
usage
=
"ban <@player> [time] [reason]"
,
description
=
"commands.ban.description"
,
usage
=
{
"[<time> [<reason>]]"
},
permission
=
"server.ban"
,
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;
import
java.util.regex.Pattern
;
import
java.util.stream.Stream
;
@Command
(
label
=
"clear"
,
usage
=
"clear <all|wp|art|mat> [lv<max level>] [r<max refinement>] [<max rarity>*]"
,
description
=
"commands.clear.description"
,
aliases
=
{
"clear"
},
permission
=
"player.clearinv"
,
permissionTargeted
=
"player.clearinv.others"
)
@Command
(
label
=
"clear"
,
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
{
private
static
Pattern
lvlRegex
=
Pattern
.
compile
(
"l(?:vl?)?(\\d+)"
);
// Java doesn't have raw string literals :(
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;
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
{
@Override
...
...
src/main/java/emu/grasscutter/command/commands/EnterDungeonCommand.java
View file @
2cfbe781
...
...
@@ -8,7 +8,7 @@ import java.util.List;
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
{
@Override
...
...
src/main/java/emu/grasscutter/command/commands/GiveCommand.java
View file @
2cfbe781
...
...
@@ -23,8 +23,15 @@ import java.util.List;
import
java.util.regex.Matcher
;
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
=
{
"g"
,
"item"
,
"giveitem"
},
permission
=
"player.give"
,
permissionTargeted
=
"player.give.others"
,
description
=
"commands.give.description"
)
@Command
(
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
{
private
static
Pattern
lvlRegex
=
Pattern
.
compile
(
"l(?:vl?)?(\\d+)"
);
// Java doesn't have raw string literals :(
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;
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
{
@Override
...
...
src/main/java/emu/grasscutter/command/commands/HelpCommand.java
View file @
2cfbe781
...
...
@@ -3,80 +3,80 @@ package emu.grasscutter.command.commands;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.command.CommandMap
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.player.Player
;
import
java.util.*
;
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
{
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
)
{
builder
.
append
(
"\n"
).
append
(
annotation
.
label
()).
append
(
" - "
).
append
(
translate
(
player
,
annotation
.
description
()));
builder
.
append
(
"\n\t"
).
append
(
translate
(
player
,
"commands.help.usage"
));
if
(
annotation
.
aliases
().
length
>=
1
)
{
private
String
createCommand
(
Player
player
,
CommandHandler
command
,
List
<
String
>
args
)
{
StringBuilder
builder
=
new
StringBuilder
(
command
.
getLabel
())
.
append
(
" - "
)
.
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"
));
for
(
String
alias
:
annotation
.
aliases
())
{
builder
.
append
(
alias
).
append
(
" "
);
}
}
builder
.
append
(
"\n\t"
).
append
(
translate
(
player
,
"commands.help.tip_need_permission"
));
if
(
annotation
.
permission
().
isEmpty
()
||
annotation
.
permission
().
isBlank
())
{
builder
.
append
(
translate
(
player
,
"commands.help.tip_need_no_permission"
));
}
else
{
if
(!
annotation
.
permission
().
isEmpty
())
{
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
();
builder
.
append
(
" "
).
append
(
translate
(
player
,
"commands.help.tip_permission_targeted"
,
permissionTargeted
));
}
return
builder
.
toString
();
}
@Override
public
void
execute
(
Player
player
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
size
()
<
1
)
{
HashMap
<
String
,
CommandHandler
>
handlers
=
CommandMap
.
getInstance
().
getHandlers
();
List
<
Command
>
annotations
=
new
ArrayList
<>();
Account
account
=
(
player
==
null
)
?
null
:
player
.
getAccount
();
Map
<
String
,
CommandHandler
>
handlers
=
CommandMap
.
getInstance
().
getHandlers
();
List
<
String
>
commands
=
new
ArrayList
<>();
List
<
String
>
commands_no_permission
=
new
ArrayList
<>();
if
(
args
.
isEmpty
())
{
for
(
String
key
:
handlers
.
keySet
())
{
Command
an
notation
=
handlers
.
get
(
key
)
.
getClass
().
getAnnotation
(
Command
.
class
)
;
if
(
!
Arrays
.
asList
(
annotation
.
aliases
()).
contains
(
key
))
{
if
(
player
!=
null
&&
!
Objects
.
equals
(
annotation
.
permission
(),
""
)
&&
!
player
.
getAccount
().
hasPermission
(
annotation
.
permission
()
))
continue
;
annotat
ion
s
.
add
(
annotation
);
Command
H
an
dler
command
=
handlers
.
get
(
key
);
Command
annotation
=
command
.
getClass
().
getAnnotation
(
Command
.
class
);
if
(
player
==
null
||
account
.
hasPermission
(
annotation
.
permission
()
))
{
commands
.
add
(
createCommand
(
player
,
command
,
args
))
;
}
else
if
(
SHOW_COMMANDS_WITHOUT_PERMISSIONS
)
{
commands_no_permiss
ion
.
add
(
createCommand
(
player
,
command
,
args
)
);
}
}
SendAllHelpMessage
(
player
,
annotations
);
}
else
{
String
command
=
args
.
get
(
0
);
CommandHandler
handler
=
CommandMap
.
getInstance
().
getHandler
(
command
);
StringBuilder
builder
=
new
StringBuilder
(
""
);
if
(
handler
==
null
)
{
builder
.
append
(
translate
(
player
,
"commands.generic.command_exist_error"
))
;
String
command
_str
=
args
.
remove
(
0
);
CommandHandler
command
=
handlers
.
get
(
command
_str
);
if
(
command
==
null
)
{
CommandHandler
.
sendTranslatedMessage
(
player
,
"commands.generic.command_exist_error"
);
return
;
}
else
{
Command
annotation
=
handler
.
getClass
().
getAnnotation
(
Command
.
class
);
this
.
createCommand
(
builder
,
player
,
annotation
);
if
(
player
!=
null
&&
!
Objects
.
equals
(
annotation
.
permission
(),
""
)
&&
!
player
.
getAccount
().
hasPermission
(
annotation
.
permission
()))
{
builder
.
append
(
"\n\t"
).
append
(
translate
(
player
,
"commands.help.warn_player_has_no_permission"
));
Command
annotation
=
command
.
getClass
().
getAnnotation
(
Command
.
class
);
if
(
player
==
null
||
account
.
hasPermission
(
annotation
.
permission
()))
{
commands
.
add
(
createCommand
(
player
,
command
,
args
));
}
else
{
commands_no_permission
.
add
(
createCommand
(
player
,
command
,
args
));
}
}
CommandHandler
.
sendMessage
(
player
,
builder
.
toString
());
}
}
void
SendAllHelpMessage
(
Player
player
,
List
<
Command
>
annotations
)
{
StringBuilder
builder
=
new
StringBuilder
(
translate
(
player
,
"commands.help.available_commands"
));
annotations
.
forEach
(
annotation
->
{
this
.
createCommand
(
builder
,
player
,
annotation
);
builder
.
append
(
"\n"
);
});
CommandHandler
.
sendMessage
(
player
,
builder
.
toString
());
for
(
String
s
:
commands
)
CommandHandler
.
sendMessage
(
player
,
s
);
for
(
String
s
:
commands_no_permission
)
CommandHandler
.
sendMessage
(
player
,
s
+
"\n\t"
+
translate
(
player
,
"commands.help.warn_player_has_no_permission"
));
}
}
src/main/java/emu/grasscutter/command/commands/KickCommand.java
View file @
2cfbe781
...
...
@@ -6,19 +6,18 @@ import emu.grasscutter.game.player.Player;
import
java.util.List
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"kick"
,
usage
=
"kick"
,
aliases
=
{
"restart"
},
permissionTargeted
=
"server.kick"
,
description
=
"commands.kick.description"
)
@Command
(
label
=
"kick"
,
aliases
=
{
"restart"
},
permissionTargeted
=
"server.kick"
)
public
final
class
KickCommand
implements
CommandHandler
{
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
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
(
targetPlayer
.
getUid
()),
targetPlayer
.
getAccount
().
getUsername
())
)
;
Integer
.
toString
(
targetPlayer
.
getUid
()),
targetPlayer
.
getAccount
().
getUsername
());
}
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
();
...
...
src/main/java/emu/grasscutter/command/commands/KillAllCommand.java
View file @
2cfbe781
package
emu.grasscutter.command.commands
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.game.entity.EntityMonster
;
...
...
@@ -12,7 +11,7 @@ import java.util.List;
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
{
@Override
...
...
src/main/java/emu/grasscutter/command/commands/KillCharacterCommand.java
View file @
2cfbe781
...
...
@@ -13,7 +13,7 @@ import java.util.List;
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
{
@Override
...
...
src/main/java/emu/grasscutter/command/commands/LanguageCommand.java
View file @
2cfbe781
...
...
@@ -3,8 +3,6 @@ package emu.grasscutter.command.commands;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.database.DatabaseHelper
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.utils.Utils
;
...
...
@@ -13,7 +11,7 @@ import java.util.Locale;
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
{
@Override
...
...
src/main/java/emu/grasscutter/command/commands/ListCommand.java
View file @
2cfbe781
...
...
@@ -10,7 +10,7 @@ import java.util.Map;
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
{
@Override
...
...
src/main/java/emu/grasscutter/command/commands/PermissionCommand.java
View file @
2cfbe781
...
...
@@ -11,7 +11,7 @@ import java.util.List;
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
{
@Override
...
...
src/main/java/emu/grasscutter/command/commands/PositionCommand.java
View file @
2cfbe781
...
...
@@ -7,16 +7,14 @@ import emu.grasscutter.utils.Position;
import
java.util.List
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"position"
,
usage
=
"position"
,
aliases
=
{
"pos"
},
description
=
"commands.position.description"
)
@Command
(
label
=
"position"
,
aliases
=
{
"pos"
})
public
final
class
PositionCommand
implements
CommandHandler
{
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
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
()),
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
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.game.player.Player
;
...
...
@@ -10,7 +9,7 @@ import java.util.List;
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
{
@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