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
a46d58e5
Commit
a46d58e5
authored
May 08, 2022
by
方块君
Committed by
Melledy
May 08, 2022
Browse files
Add command description multilingual
parent
257a92f3
Changes
40
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/Command.java
View file @
a46d58e5
...
...
@@ -9,8 +9,6 @@ public @interface Command {
String
usage
()
default
"No usage specified"
;
String
description
()
default
"No description specified"
;
String
[]
aliases
()
default
{};
String
permission
()
default
""
;
...
...
src/main/java/emu/grasscutter/command/CommandHandler.java
View file @
a46d58e5
...
...
@@ -6,6 +6,9 @@ import emu.grasscutter.game.player.Player;
import
java.util.List
;
public
interface
CommandHandler
{
String
description
();
/**
* Send a message to the target.
*
...
...
src/main/java/emu/grasscutter/command/CommandMap.java
View file @
a46d58e5
...
...
@@ -85,6 +85,14 @@ public final class CommandMap {
return
new
LinkedHashMap
<>(
this
.
annotations
);
}
public
HashMap
<
CommandHandler
,
Command
>
getHandlersAndAnnotations
()
{
HashMap
<
CommandHandler
,
Command
>
hashMap
=
new
HashMap
<>();
this
.
commands
.
forEach
((
key
,
handler
)
->
{
hashMap
.
put
(
handler
,
this
.
annotations
.
get
(
key
));
});
return
hashMap
;
}
/**
* Returns a list of all registered commands.
*
...
...
src/main/java/emu/grasscutter/command/commands/AccountCommand.java
View file @
a46d58e5
...
...
@@ -9,9 +9,14 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"account"
,
usage
=
"account <create|delete> <username> [uid]"
,
description
=
"Modify user accounts"
)
@Command
(
label
=
"account"
,
usage
=
"account <create|delete> <username> [uid]"
)
public
final
class
AccountCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.account.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
sender
!=
null
)
{
...
...
src/main/java/emu/grasscutter/command/commands/BroadcastCommand.java
View file @
a46d58e5
...
...
@@ -9,10 +9,14 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"broadcast"
,
usage
=
"broadcast <message>"
,
description
=
"Sends a message to all the players"
,
aliases
=
{
"b"
},
permission
=
"server.broadcast"
)
@Command
(
label
=
"broadcast"
,
usage
=
"broadcast <message>"
,
aliases
=
{
"b"
},
permission
=
"server.broadcast"
)
public
final
class
BroadcastCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.broadcast.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
size
()
<
1
)
{
...
...
src/main/java/emu/grasscutter/command/commands/ChangeSceneCommand.java
View file @
a46d58e5
...
...
@@ -8,9 +8,13 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"changescene"
,
usage
=
"changescene <scene id>"
,
description
=
"Changes your scene"
,
aliases
=
{
"scene"
},
permission
=
"player.changescene"
)
@Command
(
label
=
"changescene"
,
usage
=
"changescene <scene id>"
,
aliases
=
{
"scene"
},
permission
=
"player.changescene"
)
public
final
class
ChangeSceneCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.changescene.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
...
...
src/main/java/emu/grasscutter/command/commands/ClearCommand.java
View file @
a46d58e5
...
...
@@ -13,11 +13,15 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"clear"
,
usage
=
"clear <all|wp|art|mat>"
,
//Merged /clearartifacts and /clearweapons to /clear <args> [uid]
description
=
"Deletes unequipped unlocked items, including yellow rarity ones from your inventory"
,
aliases
=
{
"clear"
},
permission
=
"player.clearinv"
)
public
final
class
ClearCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.clear.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
...
...
src/main/java/emu/grasscutter/command/commands/CoopCommand.java
View file @
a46d58e5
...
...
@@ -9,9 +9,13 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"coop"
,
usage
=
"coop [host UID]"
,
description
=
"Forces someone to join the world of others"
,
permission
=
"server.coop"
)
@Command
(
label
=
"coop"
,
usage
=
"coop [host UID]"
,
permission
=
"server.coop"
)
public
final
class
CoopCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.coop.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
...
...
src/main/java/emu/grasscutter/command/commands/DropCommand.java
View file @
a46d58e5
...
...
@@ -13,10 +13,14 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"drop"
,
usage
=
"drop <itemId|itemName> [amount]"
,
description
=
"Drops an item near you"
,
aliases
=
{
"d"
,
"dropitem"
},
permission
=
"server.drop"
)
@Command
(
label
=
"drop"
,
usage
=
"drop <itemId|itemName> [amount]"
,
aliases
=
{
"d"
,
"dropitem"
},
permission
=
"server.drop"
)
public
final
class
DropCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.drop.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
...
...
src/main/java/emu/grasscutter/command/commands/EnterDungeonCommand.java
View file @
a46d58e5
...
...
@@ -8,9 +8,13 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"enterdungeon"
,
usage
=
"enterdungeon <dungeon id>"
,
description
=
"Enter a dungeon"
,
aliases
=
{
"dungeon"
},
permission
=
"player.enterdungeon"
)
@Command
(
label
=
"enterdungeon"
,
usage
=
"enterdungeon <dungeon id>"
,
aliases
=
{
"dungeon"
},
permission
=
"player.enterdungeon"
)
public
final
class
EnterDungeonCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.enter_dungeon.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
...
...
src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java
View file @
a46d58e5
...
...
@@ -15,10 +15,14 @@ import java.util.*;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"giveall"
,
usage
=
"giveall [amount]"
,
description
=
"Gives all items"
,
aliases
=
{
"givea"
},
permission
=
"player.giveall"
,
threading
=
true
)
@Command
(
label
=
"giveall"
,
usage
=
"giveall [amount]"
,
aliases
=
{
"givea"
},
permission
=
"player.giveall"
,
threading
=
true
)
public
final
class
GiveAllCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.giveAll.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
...
...
src/main/java/emu/grasscutter/command/commands/GiveArtifactCommand.java
View file @
a46d58e5
...
...
@@ -16,8 +16,13 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"giveart"
,
usage
=
"giveart <artifactId> <mainPropId> [<appendPropId>[,<times>]]... [level]"
,
description
=
"Gives the player a specified artifact"
,
aliases
=
{
"gart"
},
permission
=
"player.giveart"
)
@Command
(
label
=
"giveart"
,
usage
=
"giveart <artifactId> <mainPropId> [<appendPropId>[,<times>]]... [level]"
,
aliases
=
{
"gart"
},
permission
=
"player.giveart"
)
public
final
class
GiveArtifactCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.giveArtifact.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
...
...
src/main/java/emu/grasscutter/command/commands/GiveCharCommand.java
View file @
a46d58e5
...
...
@@ -12,10 +12,14 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"givechar"
,
usage
=
"givechar <avatarId> [level]"
,
description
=
"Gives the player a specified character"
,
aliases
=
{
"givec"
},
permission
=
"player.givechar"
)
@Command
(
label
=
"givechar"
,
usage
=
"givechar <avatarId> [level]"
,
aliases
=
{
"givec"
},
permission
=
"player.givechar"
)
public
final
class
GiveCharCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.giveChar.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
...
...
src/main/java/emu/grasscutter/command/commands/GiveCommand.java
View file @
a46d58e5
package
emu.grasscutter.command.commands
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.data.GameData
;
...
...
@@ -12,12 +11,12 @@ import emu.grasscutter.game.props.ActionReason;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.regex.Pattern
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"give"
,
usage
=
"give <itemId|itemName> [amount] [level]"
,
description
=
"Gives an item to you or the specified player"
,
aliases
=
{
@Command
(
label
=
"give"
,
usage
=
"give <itemId|itemName> [amount] [level]"
,
aliases
=
{
"g"
,
"item"
,
"giveitem"
},
permission
=
"player.give"
)
public
final
class
GiveCommand
implements
CommandHandler
{
Pattern
lvlRegex
=
Pattern
.
compile
(
"l(?:vl?)?(\\d+)"
);
// Java is a joke of a proglang that doesn't have raw string literals
...
...
@@ -32,6 +31,11 @@ public final class GiveCommand implements CommandHandler {
return
-
1
;
}
@Override
public
String
description
()
{
return
translate
(
"commands.give.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
...
...
src/main/java/emu/grasscutter/command/commands/GodModeCommand.java
View file @
a46d58e5
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
;
...
...
@@ -9,10 +8,14 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"godmode"
,
usage
=
"godmode [on|off|toggle]"
,
description
=
"Prevents you from taking damage. Defaults to toggle."
,
permission
=
"player.godmode"
)
@Command
(
label
=
"godmode"
,
usage
=
"godmode [on|off|toggle]"
,
permission
=
"player.godmode"
)
public
final
class
GodModeCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.godmode.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
...
...
src/main/java/emu/grasscutter/command/commands/HealCommand.java
View file @
a46d58e5
...
...
@@ -11,9 +11,13 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"heal"
,
usage
=
"heal|h"
,
aliases
=
{
"h"
},
description
=
"Heal all characters in your current team."
,
permission
=
"player.heal"
)
@Command
(
label
=
"heal"
,
usage
=
"heal|h"
,
aliases
=
{
"h"
},
permission
=
"player.heal"
)
public
final
class
HealCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.heal.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
...
...
src/main/java/emu/grasscutter/command/commands/HelpCommand.java
View file @
a46d58e5
...
...
@@ -10,22 +10,26 @@ import java.util.*;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"help"
,
usage
=
"help [command]"
,
description
=
"Sends the help message or shows information about a specified command"
)
@Command
(
label
=
"help"
,
usage
=
"help [command]"
)
public
final
class
HelpCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.help.description"
);
}
@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
<>();
HashMap
<
Command
,
CommandHandler
>
annotations
=
new
HashMap
<>();
for
(
String
key
:
handlers
.
keySet
())
{
Command
annotation
=
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
;
annotations
.
add
(
annotation
);
annotations
.
put
(
annotation
,
handlers
.
get
(
key
)
);
}
}
...
...
@@ -39,7 +43,7 @@ public final class HelpCommand implements CommandHandler {
}
else
{
Command
annotation
=
handler
.
getClass
().
getAnnotation
(
Command
.
class
);
builder
.
append
(
" "
).
append
(
an
notation
.
description
()).
append
(
"\n"
);
builder
.
append
(
" "
).
append
(
h
an
dler
.
description
()).
append
(
"\n"
);
builder
.
append
(
translate
(
"commands.help.usage"
)).
append
(
annotation
.
usage
());
if
(
annotation
.
aliases
().
length
>=
1
)
{
builder
.
append
(
"\n"
).
append
(
translate
(
"commands.help.aliases"
));
...
...
@@ -56,12 +60,12 @@ public final class HelpCommand implements CommandHandler {
}
}
void
SendAllHelpMessage
(
Player
player
,
List
<
Command
>
annotations
)
{
void
SendAllHelpMessage
(
Player
player
,
HashMap
<
Command
,
CommandHandler
>
annotations
)
{
if
(
player
==
null
)
{
StringBuilder
builder
=
new
StringBuilder
(
"\n"
+
translate
(
"commands.help.available_commands"
)
+
"\n"
);
annotations
.
forEach
(
annotation
->
{
annotations
.
forEach
(
(
annotation
,
handler
)
->
{
builder
.
append
(
annotation
.
label
()).
append
(
"\n"
);
builder
.
append
(
" "
).
append
(
an
notation
.
description
()).
append
(
"\n"
);
builder
.
append
(
" "
).
append
(
h
an
dler
.
description
()).
append
(
"\n"
);
builder
.
append
(
translate
(
"commands.help.usage"
)).
append
(
annotation
.
usage
());
if
(
annotation
.
aliases
().
length
>=
1
)
{
builder
.
append
(
"\n"
).
append
(
translate
(
"commands.help.aliases"
));
...
...
@@ -76,9 +80,9 @@ public final class HelpCommand implements CommandHandler {
CommandHandler
.
sendMessage
(
null
,
builder
.
toString
());
}
else
{
CommandHandler
.
sendMessage
(
player
,
translate
(
"commands.help.available_commands"
));
annotations
.
forEach
(
annotation
->
{
annotations
.
forEach
(
(
annotation
,
handler
)
->
{
StringBuilder
builder
=
new
StringBuilder
(
annotation
.
label
()).
append
(
"\n"
);
builder
.
append
(
" "
).
append
(
an
notation
.
description
()).
append
(
"\n"
);
builder
.
append
(
" "
).
append
(
h
an
dler
.
description
()).
append
(
"\n"
);
builder
.
append
(
translate
(
"commands.help.usage"
)).
append
(
annotation
.
usage
());
if
(
annotation
.
aliases
().
length
>=
1
)
{
builder
.
append
(
"\n"
).
append
(
translate
(
"commands.help.aliases"
));
...
...
src/main/java/emu/grasscutter/command/commands/KickCommand.java
View file @
a46d58e5
...
...
@@ -8,10 +8,14 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"kick"
,
usage
=
"kick"
,
description
=
"Kicks the specified player from the server (WIP)"
,
permission
=
"server.kick"
)
@Command
(
label
=
"kick"
,
usage
=
"kick"
,
permission
=
"server.kick"
)
public
final
class
KickCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.kick.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
...
...
src/main/java/emu/grasscutter/command/commands/KillAllCommand.java
View file @
a46d58e5
...
...
@@ -12,10 +12,14 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"killall"
,
usage
=
"killall [sceneId]"
,
description
=
"Kill all entities"
,
permission
=
"server.killall"
)
@Command
(
label
=
"killall"
,
usage
=
"killall [sceneId]"
,
permission
=
"server.killall"
)
public
final
class
KillAllCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.kill.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
...
...
src/main/java/emu/grasscutter/command/commands/KillCharacterCommand.java
View file @
a46d58e5
...
...
@@ -13,10 +13,14 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"killcharacter"
,
usage
=
"killcharacter"
,
aliases
=
{
"suicide"
,
"kill"
},
description
=
"Kills the players current character"
,
permission
=
"player.killcharacter"
)
@Command
(
label
=
"killcharacter"
,
usage
=
"killcharacter"
,
aliases
=
{
"suicide"
,
"kill"
},
permission
=
"player.killcharacter"
)
public
final
class
KillCharacterCommand
implements
CommandHandler
{
@Override
public
String
description
()
{
return
translate
(
"commands.killCharacter.description"
);
}
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
...
...
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