Add a commands.yml file for specifying custom command descriptions

This commit is contained in:
Camotoy 2021-12-26 14:57:17 -05:00
parent b70e2645c8
commit 3061481a1a
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
16 changed files with 123 additions and 165 deletions

View file

@ -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;
@ -119,7 +118,6 @@ public class GeyserSpongePlugin implements GeyserBootstrap {
this.geyserSpongePingPassthrough = new GeyserSpongePingPassthrough();
}
this.geyserCommandManager = new GeyserSpongeCommandManager(Sponge.getCommandManager(), geyser);
Sponge.getCommandManager().register(this, new GeyserSpongeCommandExecutor(geyser), "geyser");
}
@ -139,8 +137,8 @@ public class GeyserSpongePlugin implements GeyserBootstrap {
}
@Override
public CommandManager getGeyserCommandManager() {
return this.geyserCommandManager;
public CommandManager createGeyserCommandManager(GeyserImpl geyser) {
return new GeyserSpongeCommandManager(Sponge.getCommandManager(), geyser);
}
@Override

View file

@ -31,6 +31,8 @@ import org.spongepowered.api.Sponge;
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;
@ -41,9 +43,15 @@ public class GeyserSpongeCommandManager extends CommandManager {
}
@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;
}
}
}