Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a commands.yml file for specifying custom command descriptions #2732

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ nbdist/
### Geyser ###
run/
config.yml
commands.yml
logs/
public-key.pem
locales/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,16 @@
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.plugin.Plugin;
import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.command.CommandManager;
import org.geysermc.geyser.session.auth.AuthType;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
import org.geysermc.geyser.util.FileUtils;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.platform.bungeecord.command.GeyserBungeeCommandExecutor;
import org.geysermc.geyser.platform.bungeecord.command.GeyserBungeeCommandManager;
import org.geysermc.geyser.session.auth.AuthType;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.util.FileUtils;
import org.jetbrains.annotations.Nullable;

import java.io.File;
Expand All @@ -53,7 +51,6 @@

public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {

private GeyserBungeeCommandManager geyserCommandManager;
private GeyserBungeeConfiguration geyserConfig;
private GeyserBungeeInjector geyserInjector;
private GeyserBungeeLogger geyserLogger;
Expand Down Expand Up @@ -125,8 +122,6 @@ public void onEnable() {
this.geyserInjector = new GeyserBungeeInjector(this);
this.geyserInjector.initializeLocalChannel(this);

this.geyserCommandManager = new GeyserBungeeCommandManager(geyser);

if (geyserConfig.isLegacyPingPassthrough()) {
this.geyserBungeePingPassthrough = GeyserLegacyPingPassthrough.init(geyser);
} else {
Expand Down Expand Up @@ -156,11 +151,6 @@ public GeyserBungeeLogger getGeyserLogger() {
return geyserLogger;
}

@Override
public CommandManager getGeyserCommandManager() {
return this.geyserCommandManager;
}

@Override
public IGeyserPingPassthrough getGeyserPingPassthrough() {
return geyserBungeePingPassthrough;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import java.util.logging.Level;

public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
private GeyserSpigotCommandManager geyserCommandManager;
private GeyserSpigotConfiguration geyserConfig;
private GeyserSpigotInjector geyserInjector;
private GeyserSpigotLogger geyserLogger;
Expand Down Expand Up @@ -160,8 +159,6 @@ public void onEnable() {
this.geyserSpigotPingPassthrough = new GeyserSpigotPingPassthrough(geyserLogger);
}

this.geyserCommandManager = new GeyserSpigotCommandManager(geyser);

boolean isViaVersion = Bukkit.getPluginManager().getPlugin("ViaVersion") != null;
if (isViaVersion) {
try {
Expand Down Expand Up @@ -265,8 +262,8 @@ public GeyserSpigotLogger getGeyserLogger() {
}

@Override
public CommandManager getGeyserCommandManager() {
return this.geyserCommandManager;
public CommandManager createGeyserCommandManager(GeyserImpl geyser) {
return new GeyserSpigotCommandManager(geyser);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandManager;

import javax.annotation.Nonnull;
import java.lang.reflect.Field;

public class GeyserSpigotCommandManager extends CommandManager {
Expand All @@ -52,8 +53,14 @@ public GeyserSpigotCommandManager(GeyserImpl geyser) {
}

@Override
@Nonnull
public String getDescription(String command) {
Command cmd = COMMAND_MAP.getCommand(command.replace("/", ""));
return cmd != null ? cmd.getDescription() : "";
String description = super.getDescription(command);
if (description.isEmpty()) {
Command cmd = COMMAND_MAP.getCommand(command.replace("/", ""));
return cmd != null ? cmd.getDescription() : "";
} else {
return description;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class GeyserSpongePlugin implements GeyserBootstrap {
@ConfigDir(sharedRoot = false)
private File configDir;

private GeyserSpongeCommandManager geyserCommandManager;
private GeyserSpongeConfiguration geyserConfig;
private GeyserSpongeLogger geyserLogger;
private IGeyserPingPassthrough geyserSpongePingPassthrough;
Expand Down Expand Up @@ -119,7 +118,6 @@ public void onEnable() {
this.geyserSpongePingPassthrough = new GeyserSpongePingPassthrough();
}

this.geyserCommandManager = new GeyserSpongeCommandManager(Sponge.getCommandManager(), geyser);
Sponge.getCommandManager().register(this, new GeyserSpongeCommandExecutor(geyser), "geyser");
}

Expand All @@ -139,8 +137,8 @@ public GeyserSpongeLogger getGeyserLogger() {
}

@Override
public CommandManager getGeyserCommandManager() {
return this.geyserCommandManager;
public CommandManager createGeyserCommandManager(GeyserImpl geyser) {
return new GeyserSpongeCommandManager(Sponge.getCommandManager(), geyser);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.spongepowered.api.command.CommandMapping;
import org.spongepowered.api.text.Text;

import javax.annotation.Nonnull;

public class GeyserSpongeCommandManager extends CommandManager {
private final org.spongepowered.api.command.CommandManager handle;

Expand All @@ -41,9 +43,15 @@ public GeyserSpongeCommandManager(org.spongepowered.api.command.CommandManager h
}

@Override
@Nonnull
public String getDescription(String command) {
return handle.get(command).map(CommandMapping::getCallable)
.map(callable -> callable.getShortDescription(Sponge.getServer().getConsole()).orElse(Text.EMPTY))
.orElse(Text.EMPTY).toPlain();
String description = super.getDescription(command);
if (description.isEmpty()) {
return handle.get(command).map(CommandMapping::getCallable)
.map(callable -> callable.getShortDescription(Sponge.getServer().getConsole()).orElse(Text.EMPTY))
.orElse(Text.EMPTY).toPlain();
} else {
return description;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,16 @@
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.command.CommandManager;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.configuration.GeyserJacksonConfiguration;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
import org.geysermc.geyser.util.FileUtils;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.platform.standalone.command.GeyserCommandManager;
import org.geysermc.geyser.platform.standalone.gui.GeyserStandaloneGUI;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.util.FileUtils;

import java.io.File;
import java.io.IOException;
Expand All @@ -63,7 +61,6 @@

public class GeyserStandaloneBootstrap implements GeyserBootstrap {

private GeyserCommandManager geyserCommandManager;
private GeyserStandaloneConfiguration geyserConfig;
private GeyserStandaloneLogger geyserLogger;
private IGeyserPingPassthrough geyserPingPassthrough;
Expand Down Expand Up @@ -215,10 +212,9 @@ public void onEnable() {
logger.get().setLevel(geyserConfig.isDebugMode() ? Level.DEBUG : Level.INFO);

geyser = GeyserImpl.start(PlatformType.STANDALONE, this);
geyserCommandManager = new GeyserCommandManager(geyser);

if (gui != null) {
gui.setupInterface(geyserLogger, geyserCommandManager);
gui.setupInterface(geyserLogger, geyser.getCommandManager());
}

geyserPingPassthrough = GeyserLegacyPingPassthrough.init(geyser);
Expand Down Expand Up @@ -259,11 +255,6 @@ public GeyserStandaloneLogger getGeyserLogger() {
return geyserLogger;
}

@Override
public CommandManager getGeyserCommandManager() {
return geyserCommandManager;
}

@Override
public IGeyserPingPassthrough getGeyserPingPassthrough() {
return geyserPingPassthrough;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
package org.geysermc.geyser.platform.standalone.gui;

import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandManager;
import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.platform.standalone.GeyserStandaloneLogger;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.platform.standalone.GeyserStandaloneLogger;
import org.geysermc.geyser.platform.standalone.command.GeyserCommandManager;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
Expand Down Expand Up @@ -253,13 +253,13 @@ public void write(byte[] b) {
* Add all the Geyser commands to the commands menu, and setup the debug mode toggle
*
* @param geyserStandaloneLogger The current logger
* @param geyserCommandManager The commands manager
* @param commandManager The commands manager
*/
public void setupInterface(GeyserStandaloneLogger geyserStandaloneLogger, GeyserCommandManager geyserCommandManager) {
public void setupInterface(GeyserStandaloneLogger geyserStandaloneLogger, CommandManager commandManager) {
commandsMenu.removeAll();
optionsMenu.removeAll();

for (Map.Entry<String, GeyserCommand> command : geyserCommandManager.getCommands().entrySet()) {
for (Map.Entry<String, GeyserCommand> command : commandManager.getCommands().entrySet()) {
// Remove the offhand command and any alias commands to prevent duplicates in the list
if (!command.getValue().isExecutableOnConsole() || command.getValue().getAliases().contains(command.getKey())) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
import org.geysermc.geyser.platform.velocity.command.GeyserVelocityCommandExecutor;
import org.geysermc.geyser.platform.velocity.command.GeyserVelocityCommandManager;
import org.geysermc.geyser.session.auth.AuthType;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.util.FileUtils;
Expand All @@ -70,7 +69,6 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
@Inject
private CommandManager commandManager;

private GeyserVelocityCommandManager geyserCommandManager;
private GeyserVelocityConfiguration geyserConfig;
private GeyserVelocityInjector geyserInjector;
private GeyserVelocityLogger geyserLogger;
Expand Down Expand Up @@ -144,7 +142,6 @@ public void onEnable() {
this.geyserInjector = new GeyserVelocityInjector(proxyServer);
// Will be initialized after the proxy has been bound

this.geyserCommandManager = new GeyserVelocityCommandManager(geyser);
this.commandManager.register("geyser", new GeyserVelocityCommandExecutor(geyser));
if (geyserConfig.isLegacyPingPassthrough()) {
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(geyser);
Expand Down Expand Up @@ -173,11 +170,6 @@ public GeyserVelocityLogger getGeyserLogger() {
return geyserLogger;
}

@Override
public org.geysermc.geyser.command.CommandManager getGeyserCommandManager() {
return this.geyserCommandManager;
}

@Override
public IGeyserPingPassthrough getGeyserPingPassthrough() {
return geyserPingPassthrough;
Expand Down

This file was deleted.

10 changes: 7 additions & 3 deletions core/src/main/java/org/geysermc/geyser/GeyserBootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.geysermc.geyser.level.GeyserWorldManager;
import org.geysermc.geyser.level.WorldManager;
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
import org.jetbrains.annotations.Contract;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -68,11 +69,14 @@ public interface GeyserBootstrap {
GeyserLogger getGeyserLogger();

/**
* Returns the current CommandManager
* Creates a command manager for {@link GeyserImpl} to use.
*
* @return The current CommandManager
* @return a new CommandManager instance
*/
CommandManager getGeyserCommandManager();
@Contract("_ -> new")
default CommandManager createGeyserCommandManager(GeyserImpl geyser) {
return new CommandManager(geyser);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up that in my Sponge PR I'll have to change this javadoc to "allow" platforms to provide an existing command manager, since the sponge command manager needs to be created before the connector. There are some other things on my mind as well but they're manageable.

Also the _ in the contract infers null values are allowed as per jetbrains docs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun.

}

/**
* Returns the current PingPassthrough manager
Expand Down