mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Cleanup command constructors, reference GeyserCommand more
This commit is contained in:
parent
d1abeee7b8
commit
5ad0da1c06
6 changed files with 20 additions and 24 deletions
|
|
@ -59,6 +59,8 @@ import java.util.Collection;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.geysermc.geyser.command.GeyserCommand.DEFAULT_ROOT_COMMAND;
|
||||
|
||||
/**
|
||||
* Registers all built-in and extension commands to the given Cloud CommandManager.
|
||||
* <p>
|
||||
|
|
@ -78,12 +80,12 @@ public class CommandRegistry implements EventRegistrar {
|
|||
/**
|
||||
* Map of Geyser subcommands to their Commands
|
||||
*/
|
||||
private final Map<String, Command> commands = new Object2ObjectOpenHashMap<>(13);
|
||||
private final Map<String, GeyserCommand> commands = new Object2ObjectOpenHashMap<>(13);
|
||||
|
||||
/**
|
||||
* Map of Extensions to maps of their subcommands
|
||||
*/
|
||||
private final Map<Extension, Map<String, Command>> extensionCommands = new Object2ObjectOpenHashMap<>(0);
|
||||
private final Map<Extension, Map<String, GeyserCommand>> extensionCommands = new Object2ObjectOpenHashMap<>(0);
|
||||
|
||||
/**
|
||||
* Map of root commands (that are for extensions) to Extensions
|
||||
|
|
@ -103,17 +105,17 @@ public class CommandRegistry implements EventRegistrar {
|
|||
ExceptionHandlers.register(cloud);
|
||||
|
||||
// begin command registration
|
||||
HelpCommand help = new HelpCommand(geyser, "help", "geyser.commands.help.desc", "geyser.command.help", GeyserCommand.DEFAULT_ROOT_COMMAND, this.commands);
|
||||
HelpCommand help = new HelpCommand(DEFAULT_ROOT_COMMAND, "help", "geyser.commands.help.desc", "geyser.command.help", this.commands);
|
||||
registerBuiltInCommand(help);
|
||||
buildRootCommand(GEYSER_ROOT_PERMISSION, help); // build root and delegate to help
|
||||
|
||||
registerBuiltInCommand(new ListCommand(geyser, "list", "geyser.commands.list.desc", "geyser.command.list"));
|
||||
registerBuiltInCommand(new ReloadCommand(geyser, "reload", "geyser.commands.reload.desc", "geyser.command.reload"));
|
||||
registerBuiltInCommand(new OffhandCommand(geyser, "offhand", "geyser.commands.offhand.desc", "geyser.command.offhand"));
|
||||
registerBuiltInCommand(new OffhandCommand("offhand", "geyser.commands.offhand.desc", "geyser.command.offhand"));
|
||||
registerBuiltInCommand(new DumpCommand(geyser, "dump", "geyser.commands.dump.desc", "geyser.command.dump"));
|
||||
registerBuiltInCommand(new VersionCommand(geyser, "version", "geyser.commands.version.desc", "geyser.command.version"));
|
||||
registerBuiltInCommand(new SettingsCommand(geyser, "settings", "geyser.commands.settings.desc", "geyser.command.settings"));
|
||||
registerBuiltInCommand(new StatisticsCommand(geyser, "statistics", "geyser.commands.statistics.desc", "geyser.command.statistics"));
|
||||
registerBuiltInCommand(new SettingsCommand( "settings", "geyser.commands.settings.desc", "geyser.command.settings"));
|
||||
registerBuiltInCommand(new StatisticsCommand("statistics", "geyser.commands.statistics.desc", "geyser.command.statistics"));
|
||||
registerBuiltInCommand(new AdvancementsCommand("advancements", "geyser.commands.advancements.desc", "geyser.command.advancements"));
|
||||
registerBuiltInCommand(new AdvancedTooltipsCommand("tooltips", "geyser.commands.advancedtooltips.desc", "geyser.command.tooltips"));
|
||||
registerBuiltInCommand(new ConnectionTestCommand(geyser, "connectiontest", "geyser.commands.connectiontest.desc", "geyser.command.connectiontest"));
|
||||
|
|
@ -138,7 +140,7 @@ public class CommandRegistry implements EventRegistrar {
|
|||
};
|
||||
this.geyser.eventBus().fire(defineCommandsEvent);
|
||||
|
||||
for (Map.Entry<Extension, Map<String, Command>> entry : this.extensionCommands.entrySet()) {
|
||||
for (Map.Entry<Extension, Map<String, GeyserCommand>> entry : this.extensionCommands.entrySet()) {
|
||||
Extension extension = entry.getKey();
|
||||
|
||||
// Register this extension's root command
|
||||
|
|
@ -147,11 +149,10 @@ public class CommandRegistry implements EventRegistrar {
|
|||
// Register help commands for all extensions with commands
|
||||
String id = extension.description().id();
|
||||
HelpCommand extensionHelp = new HelpCommand(
|
||||
this.geyser,
|
||||
extension.rootCommand(),
|
||||
"help",
|
||||
"geyser.commands.exthelp.desc",
|
||||
"geyser.command.exthelp." + id,
|
||||
extension.rootCommand(),
|
||||
entry.getValue()); // commands it provides help for
|
||||
|
||||
registerExtensionCommand(extension, extensionHelp);
|
||||
|
|
@ -181,7 +182,7 @@ public class CommandRegistry implements EventRegistrar {
|
|||
register(command, this.extensionCommands.computeIfAbsent(extension, e -> new HashMap<>()));
|
||||
}
|
||||
|
||||
private void register(GeyserCommand command, Map<String, Command> commands) {
|
||||
private void register(GeyserCommand command, Map<String, GeyserCommand> commands) {
|
||||
command.register(cloud);
|
||||
|
||||
commands.put(command.name(), command);
|
||||
|
|
@ -252,7 +253,7 @@ public class CommandRegistry implements EventRegistrar {
|
|||
*/
|
||||
@NonNull
|
||||
public String description(@NonNull String command, @NonNull String locale) {
|
||||
if (command.equals(GeyserCommand.DEFAULT_ROOT_COMMAND)) {
|
||||
if (command.equals(DEFAULT_ROOT_COMMAND)) {
|
||||
return GeyserLocale.getPlayerLocaleString("geyser.command.root.geyser", locale);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
package org.geysermc.geyser.command.defaults;
|
||||
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.api.command.Command;
|
||||
import org.geysermc.geyser.api.util.TriState;
|
||||
import org.geysermc.geyser.command.GeyserCommand;
|
||||
|
|
@ -41,10 +40,9 @@ import java.util.Map;
|
|||
|
||||
public class HelpCommand extends GeyserCommand {
|
||||
private final String rootCommand;
|
||||
private final Collection<Command> commands;
|
||||
private final Collection<GeyserCommand> commands;
|
||||
|
||||
public HelpCommand(GeyserImpl geyser, String name, String description, String permission,
|
||||
String rootCommand, Map<String, Command> commands) {
|
||||
public HelpCommand(String rootCommand, String name, String description, String permission, Map<String, GeyserCommand> commands) {
|
||||
super(name, description, permission, TriState.TRUE);
|
||||
this.rootCommand = rootCommand;
|
||||
this.commands = commands.values();
|
||||
|
|
@ -67,7 +65,7 @@ public class HelpCommand extends GeyserCommand {
|
|||
// todo: pagination
|
||||
int page = 1;
|
||||
int maxPage = 1;
|
||||
String translationKey = this.rootCommand.equals(GeyserCommand.DEFAULT_ROOT_COMMAND) ? "geyser.commands.help.header" : "geyser.commands.extensions.header";
|
||||
String translationKey = this.rootCommand.equals(DEFAULT_ROOT_COMMAND) ? "geyser.commands.help.header" : "geyser.commands.extensions.header";
|
||||
String header = GeyserLocale.getPlayerLocaleString(translationKey, source.locale(), page, maxPage);
|
||||
source.sendMessage(header);
|
||||
|
||||
|
|
@ -76,7 +74,7 @@ public class HelpCommand extends GeyserCommand {
|
|||
.filter(cmd -> !cmd.isBedrockOnly() || bedrockPlayer) // remove bedrock only commands if not a bedrock player
|
||||
.filter(cmd -> source.hasPermission(cmd.permission()))
|
||||
.sorted(Comparator.comparing(Command::name))
|
||||
.forEach(cmd -> {
|
||||
.forEachOrdered(cmd -> {
|
||||
String description = GeyserLocale.getPlayerLocaleString(cmd.description(), source.locale());
|
||||
source.sendMessage(ChatColor.YELLOW + "/" + rootCommand + " " + cmd.name() + ChatColor.WHITE + ": " + description);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
package org.geysermc.geyser.command.defaults;
|
||||
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.api.util.TriState;
|
||||
import org.geysermc.geyser.command.GeyserCommand;
|
||||
import org.geysermc.geyser.command.GeyserCommandSource;
|
||||
|
|
@ -36,7 +35,7 @@ import java.util.Objects;
|
|||
|
||||
public class OffhandCommand extends GeyserCommand {
|
||||
|
||||
public OffhandCommand(GeyserImpl geyser, String name, String description, String permission) {
|
||||
public OffhandCommand(String name, String description, String permission) {
|
||||
super(name, description, permission, TriState.TRUE, true, true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
package org.geysermc.geyser.command.defaults;
|
||||
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.api.util.TriState;
|
||||
import org.geysermc.geyser.command.GeyserCommand;
|
||||
import org.geysermc.geyser.command.GeyserCommandSource;
|
||||
|
|
@ -37,7 +36,7 @@ import java.util.Objects;
|
|||
|
||||
public class SettingsCommand extends GeyserCommand {
|
||||
|
||||
public SettingsCommand(GeyserImpl geyser, String name, String description, String permission) {
|
||||
public SettingsCommand(String name, String description, String permission) {
|
||||
super(name, description, permission, TriState.TRUE, true, true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
package org.geysermc.geyser.command.defaults;
|
||||
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.api.util.TriState;
|
||||
import org.geysermc.geyser.command.GeyserCommand;
|
||||
import org.geysermc.geyser.command.GeyserCommandSource;
|
||||
|
|
@ -38,7 +37,7 @@ import java.util.Objects;
|
|||
|
||||
public class StatisticsCommand extends GeyserCommand {
|
||||
|
||||
public StatisticsCommand(GeyserImpl geyser, String name, String description, String permission) {
|
||||
public StatisticsCommand(String name, String description, String permission) {
|
||||
super(name, description, permission, TriState.TRUE, true, true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import java.util.Map;
|
|||
public abstract class GeyserDefineCommandsEventImpl implements GeyserDefineCommandsEvent {
|
||||
private final Map<String, Command> commands;
|
||||
|
||||
public GeyserDefineCommandsEventImpl(Map<String, Command> commands) {
|
||||
public GeyserDefineCommandsEventImpl(Map<String, ? extends Command> commands) {
|
||||
this.commands = Collections.unmodifiableMap(commands);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue