3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-19 14:30:17 +01:00

Extensions have their own command

Dieser Commit ist enthalten in:
Camotoy 2022-07-10 20:58:48 -04:00
Ursprung 897c4dcfec
Commit 83ba6b5ab5
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
16 geänderte Dateien mit 101 neuen und 116 gelöschten Zeilen

Datei anzeigen

@ -33,7 +33,9 @@ import org.geysermc.geyser.api.event.connection.ConnectionEvent;
import java.util.Set; import java.util.Set;
/** /**
* Called when the downstream server defines the commands available on the server. * Called when the Java server defines the commands available on the server.
* <br>
* This event is mapped to the existence of Brigadier on the server.
*/ */
public class ServerDefineCommandsEvent extends ConnectionEvent implements Cancellable { public class ServerDefineCommandsEvent extends ConnectionEvent implements Cancellable {
private final Set<? extends CommandInfo> commands; private final Set<? extends CommandInfo> commands;

Datei anzeigen

@ -1,42 +0,0 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.api.event.lifecycle;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.api.command.CommandManager;
import org.geysermc.geyser.api.event.Event;
import java.util.Map;
/**
* Called when commands are defined within Geyser.
*
* @param commandManager the command manager
* @param commands an immutable view of the default commands
*/
public record GeyserDefineCommandsEvent(@NonNull CommandManager commandManager, @NonNull Map<String, Command> commands) implements Event {
}

Datei anzeigen

@ -86,7 +86,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
InetSocketAddress javaAddr = listener.getHost(); InetSocketAddress javaAddr = listener.getHost();
// By default this should be localhost but may need to be changed in some circumstances // By default this should be localhost but may need to be changed in some circumstances
if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) { if (this.geyserConfig.getRemote().address().equalsIgnoreCase("auto")) {
this.geyserConfig.setAutoconfiguredRemote(true); this.geyserConfig.setAutoconfiguredRemote(true);
// Don't use localhost if not listening on all interfaces // Don't use localhost if not listening on all interfaces
if (!javaAddr.getHostString().equals("0.0.0.0") && !javaAddr.getHostString().equals("")) { if (!javaAddr.getHostString().equals("0.0.0.0") && !javaAddr.getHostString().equals("")) {
@ -109,7 +109,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
return; return;
} }
if (geyserConfig.getRemote().getAuthType() == AuthType.FLOODGATE && getProxy().getPluginManager().getPlugin("floodgate") == null) { if (geyserConfig.getRemote().authType() == AuthType.FLOODGATE && getProxy().getPluginManager().getPlugin("floodgate") == null) {
geyserLogger.severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.disabling")); geyserLogger.severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.disabling"));
return; return;
} else if (geyserConfig.isAutoconfiguredRemote() && getProxy().getPluginManager().getPlugin("floodgate") != null) { } else if (geyserConfig.isAutoconfiguredRemote() && getProxy().getPluginManager().getPlugin("floodgate") != null) {
@ -134,7 +134,8 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
this.geyserBungeePingPassthrough = new GeyserBungeePingPassthrough(getProxy()); this.geyserBungeePingPassthrough = new GeyserBungeePingPassthrough(getProxy());
} }
this.getProxy().getPluginManager().registerCommand(this, new GeyserBungeeCommandExecutor(geyser)); this.getProxy().getPluginManager().registerCommand(this, new GeyserBungeeCommandExecutor("geyser", geyser, geyserCommandManager.getCommands()));
this.getProxy().getPluginManager().registerCommand(this, new GeyserBungeeCommandExecutor("geyserext", geyser, geyserCommandManager.commands()));
} }
@Override @Override

Datei anzeigen

@ -37,14 +37,15 @@ import org.geysermc.geyser.text.GeyserLocale;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Map;
public class GeyserBungeeCommandExecutor extends Command implements TabExecutor { public class GeyserBungeeCommandExecutor extends Command implements TabExecutor {
private final GeyserCommandExecutor commandExecutor; private final GeyserCommandExecutor commandExecutor;
public GeyserBungeeCommandExecutor(GeyserImpl geyser) { public GeyserBungeeCommandExecutor(String name, GeyserImpl geyser, Map<String, org.geysermc.geyser.api.command.Command> commands) {
super("geyser"); super(name);
this.commandExecutor = new GeyserCommandExecutor(geyser); this.commandExecutor = new GeyserCommandExecutor(geyser, commands);
} }
@Override @Override

Datei anzeigen

@ -170,8 +170,8 @@ public class GeyserSpigotInjector extends GeyserInjector {
*/ */
private void workAroundWeirdBug(GeyserBootstrap bootstrap) { private void workAroundWeirdBug(GeyserBootstrap bootstrap) {
MinecraftProtocol protocol = new MinecraftProtocol(); MinecraftProtocol protocol = new MinecraftProtocol();
LocalSession session = new LocalSession(bootstrap.getGeyserConfig().getRemote().getAddress(), LocalSession session = new LocalSession(bootstrap.getGeyserConfig().getRemote().address(),
bootstrap.getGeyserConfig().getRemote().getPort(), this.serverSocketAddress, bootstrap.getGeyserConfig().getRemote().port(), this.serverSocketAddress,
InetAddress.getLoopbackAddress().getHostAddress(), protocol, protocol.createHelper()); InetAddress.getLoopbackAddress().getHostAddress(), protocol, protocol.createHelper());
session.connect(); session.connect();
} }

Datei anzeigen

@ -43,7 +43,6 @@ import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.adapters.spigot.SpigotAdapters; import org.geysermc.geyser.adapters.spigot.SpigotAdapters;
import org.geysermc.geyser.api.command.Command; import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.api.network.AuthType; import org.geysermc.geyser.api.network.AuthType;
import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.command.GeyserCommandManager; import org.geysermc.geyser.command.GeyserCommandManager;
import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.dump.BootstrapDumpInfo; import org.geysermc.geyser.dump.BootstrapDumpInfo;
@ -125,7 +124,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
} }
// By default this should be localhost but may need to be changed in some circumstances // By default this should be localhost but may need to be changed in some circumstances
if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) { if (this.geyserConfig.getRemote().address().equalsIgnoreCase("auto")) {
geyserConfig.setAutoconfiguredRemote(true); geyserConfig.setAutoconfiguredRemote(true);
// Don't use localhost if not listening on all interfaces // Don't use localhost if not listening on all interfaces
if (!Bukkit.getIp().equals("0.0.0.0") && !Bukkit.getIp().equals("")) { if (!Bukkit.getIp().equals("0.0.0.0") && !Bukkit.getIp().equals("")) {
@ -148,7 +147,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
return; return;
} }
if (geyserConfig.getRemote().getAuthType() == AuthType.FLOODGATE && Bukkit.getPluginManager().getPlugin("floodgate") == null) { if (geyserConfig.getRemote().authType() == AuthType.FLOODGATE && Bukkit.getPluginManager().getPlugin("floodgate") == null) {
geyserLogger.severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.disabling")); geyserLogger.severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.disabling"));
this.getPluginLoader().disablePlugin(this); this.getPluginLoader().disablePlugin(this);
return; return;
@ -249,8 +248,10 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
geyserLogger.debug("Using default world manager: " + this.geyserWorldManager.getClass()); geyserLogger.debug("Using default world manager: " + this.geyserWorldManager.getClass());
} }
PluginCommand pluginCommand = this.getCommand("geyser"); PluginCommand geyserCommand = this.getCommand("geyser");
pluginCommand.setExecutor(new GeyserSpigotCommandExecutor(geyser)); geyserCommand.setExecutor(new GeyserSpigotCommandExecutor(geyser, geyserCommandManager.getCommands()));
PluginCommand geyserExtCommand = this.getCommand("geyserext");
geyserExtCommand.setExecutor(new GeyserSpigotCommandExecutor(geyser, geyserCommandManager.getCommands()));
if (!INITIALIZED) { if (!INITIALIZED) {
// Register permissions so they appear in, for example, LuckPerms' UI // Register permissions so they appear in, for example, LuckPerms' UI
@ -277,7 +278,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
boolean brigadierSupported = CommodoreProvider.isSupported(); boolean brigadierSupported = CommodoreProvider.isSupported();
geyserLogger.debug("Brigadier supported? " + brigadierSupported); geyserLogger.debug("Brigadier supported? " + brigadierSupported);
if (brigadierSupported) { if (brigadierSupported) {
GeyserBrigadierSupport.loadBrigadier(this, pluginCommand); GeyserBrigadierSupport.loadBrigadier(this, geyserCommand);
} }
// Check to ensure the current setup can support the protocol version Geyser uses // Check to ensure the current setup can support the protocol version Geyser uses

Datei anzeigen

@ -38,11 +38,12 @@ import org.geysermc.geyser.text.GeyserLocale;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
public class GeyserSpigotCommandExecutor extends GeyserCommandExecutor implements TabExecutor { public class GeyserSpigotCommandExecutor extends GeyserCommandExecutor implements TabExecutor {
public GeyserSpigotCommandExecutor(GeyserImpl geyser) { public GeyserSpigotCommandExecutor(GeyserImpl geyser, Map<String, org.geysermc.geyser.api.command.Command> commands) {
super(geyser); super(geyser, commands);
} }
@Override @Override

Datei anzeigen

@ -9,3 +9,6 @@ commands:
geyser: geyser:
description: The main command for Geyser. description: The main command for Geyser.
usage: /geyser <subcommand> usage: /geyser <subcommand>
geyserext:
description: The command any extensions can register to.
usage: /geyserext <subcommand>

Datei anzeigen

@ -99,14 +99,14 @@ public class GeyserSpongePlugin implements GeyserBootstrap {
// Don't change the ip if its listening on all interfaces // Don't change the ip if its listening on all interfaces
// By default this should be 127.0.0.1 but may need to be changed in some circumstances // By default this should be 127.0.0.1 but may need to be changed in some circumstances
if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) { if (this.geyserConfig.getRemote().address().equalsIgnoreCase("auto")) {
this.geyserConfig.setAutoconfiguredRemote(true); this.geyserConfig.setAutoconfiguredRemote(true);
geyserConfig.getRemote().setPort(javaAddr.getPort()); geyserConfig.getRemote().setPort(javaAddr.getPort());
} }
} }
if (geyserConfig.getBedrock().isCloneRemotePort()) { if (geyserConfig.getBedrock().isCloneRemotePort()) {
geyserConfig.getBedrock().setPort(geyserConfig.getRemote().getPort()); geyserConfig.getBedrock().setPort(geyserConfig.getRemote().port());
} }
this.geyserLogger = new GeyserSpongeLogger(logger, geyserConfig.isDebugMode()); this.geyserLogger = new GeyserSpongeLogger(logger, geyserConfig.isDebugMode());
@ -121,7 +121,8 @@ public class GeyserSpongePlugin implements GeyserBootstrap {
this.geyserCommandManager = new GeyserSpongeCommandManager(Sponge.getCommandManager(), geyser); this.geyserCommandManager = new GeyserSpongeCommandManager(Sponge.getCommandManager(), geyser);
this.geyserCommandManager.init(); this.geyserCommandManager.init();
Sponge.getCommandManager().register(this, new GeyserSpongeCommandExecutor(geyser), "geyser"); Sponge.getCommandManager().register(this, new GeyserSpongeCommandExecutor(geyser, geyserCommandManager.getCommands()), "geyser");
Sponge.getCommandManager().register(this, new GeyserSpongeCommandExecutor(geyser, geyserCommandManager.commands()), "geyserext");
} }
@Override @Override

Datei anzeigen

@ -26,6 +26,7 @@
package org.geysermc.geyser.platform.sponge.command; package org.geysermc.geyser.platform.sponge.command;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.command.GeyserCommandExecutor; import org.geysermc.geyser.command.GeyserCommandExecutor;
import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.command.GeyserCommandSource;
@ -40,15 +41,12 @@ import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.World;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Arrays; import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
public class GeyserSpongeCommandExecutor extends GeyserCommandExecutor implements CommandCallable { public class GeyserSpongeCommandExecutor extends GeyserCommandExecutor implements CommandCallable {
public GeyserSpongeCommandExecutor(GeyserImpl geyser) { public GeyserSpongeCommandExecutor(GeyserImpl geyser, Map<String, Command> commands) {
super(geyser); super(geyser, commands);
} }
@Override @Override

Datei anzeigen

@ -102,7 +102,7 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
InetSocketAddress javaAddr = proxyServer.getBoundAddress(); InetSocketAddress javaAddr = proxyServer.getBoundAddress();
// By default this should be localhost but may need to be changed in some circumstances // By default this should be localhost but may need to be changed in some circumstances
if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) { if (this.geyserConfig.getRemote().address().equalsIgnoreCase("auto")) {
this.geyserConfig.setAutoconfiguredRemote(true); this.geyserConfig.setAutoconfiguredRemote(true);
// Don't use localhost if not listening on all interfaces // Don't use localhost if not listening on all interfaces
if (!javaAddr.getHostString().equals("0.0.0.0") && !javaAddr.getHostString().equals("")) { if (!javaAddr.getHostString().equals("0.0.0.0") && !javaAddr.getHostString().equals("")) {
@ -128,7 +128,7 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
} catch (ClassNotFoundException ignored) { } catch (ClassNotFoundException ignored) {
} }
if (geyserConfig.getRemote().getAuthType() == AuthType.FLOODGATE && proxyServer.getPluginManager().getPlugin("floodgate").isEmpty()) { if (geyserConfig.getRemote().authType() == AuthType.FLOODGATE && proxyServer.getPluginManager().getPlugin("floodgate").isEmpty()) {
geyserLogger.severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " " geyserLogger.severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " "
+ GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.disabling")); + GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.disabling"));
return; return;
@ -148,7 +148,8 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
this.geyserCommandManager = new GeyserVelocityCommandManager(geyser); this.geyserCommandManager = new GeyserVelocityCommandManager(geyser);
this.geyserCommandManager.init(); this.geyserCommandManager.init();
this.commandManager.register("geyser", new GeyserVelocityCommandExecutor(geyser)); this.commandManager.register("geyser", new GeyserVelocityCommandExecutor(geyser, geyserCommandManager.getCommands()));
this.commandManager.register("geyserext", new GeyserVelocityCommandExecutor(geyser, geyserCommandManager.commands()));
if (geyserConfig.isLegacyPingPassthrough()) { if (geyserConfig.isLegacyPingPassthrough()) {
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(geyser); this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(geyser);
} else { } else {

Datei anzeigen

@ -27,6 +27,7 @@ package org.geysermc.geyser.platform.velocity.command;
import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.command.SimpleCommand;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.command.GeyserCommandExecutor; import org.geysermc.geyser.command.GeyserCommandExecutor;
import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.command.GeyserCommandSource;
@ -37,11 +38,12 @@ import org.geysermc.geyser.text.GeyserLocale;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
public class GeyserVelocityCommandExecutor extends GeyserCommandExecutor implements SimpleCommand { public class GeyserVelocityCommandExecutor extends GeyserCommandExecutor implements SimpleCommand {
public GeyserVelocityCommandExecutor(GeyserImpl geyser) { public GeyserVelocityCommandExecutor(GeyserImpl geyser, Map<String, Command> commands) {
super(geyser); super(geyser, commands);
} }
@Override @Override

Datei anzeigen

@ -37,15 +37,16 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* Represents helper functions for listening to {@code /geyser} commands. * Represents helper functions for listening to {@code /geyser} or {@code /geyserext} commands.
*/ */
@AllArgsConstructor @AllArgsConstructor
public class GeyserCommandExecutor { public class GeyserCommandExecutor {
protected final GeyserImpl geyser; protected final GeyserImpl geyser;
private final Map<String, Command> commands;
public GeyserCommand getCommand(String label) { public GeyserCommand getCommand(String label) {
return (GeyserCommand) geyser.commandManager().commands().get(label); return (GeyserCommand) commands.get(label);
} }
@Nullable @Nullable
@ -78,7 +79,6 @@ public class GeyserCommandExecutor {
} }
List<String> availableCommands = new ArrayList<>(); List<String> availableCommands = new ArrayList<>();
Map<String, Command> commands = geyser.commandManager().getCommands();
// Only show commands they have permission to use // Only show commands they have permission to use
for (Map.Entry<String, Command> entry : commands.entrySet()) { for (Map.Entry<String, Command> entry : commands.entrySet()) {

Datei anzeigen

@ -25,6 +25,7 @@
package org.geysermc.geyser.command; package org.geysermc.geyser.command;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
@ -34,7 +35,6 @@ import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.api.command.CommandExecutor; import org.geysermc.geyser.api.command.CommandExecutor;
import org.geysermc.geyser.api.command.CommandManager; import org.geysermc.geyser.api.command.CommandManager;
import org.geysermc.geyser.api.command.CommandSource; import org.geysermc.geyser.api.command.CommandSource;
import org.geysermc.geyser.api.event.lifecycle.GeyserDefineCommandsEvent;
import org.geysermc.geyser.command.defaults.*; import org.geysermc.geyser.command.defaults.*;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;
@ -42,91 +42,104 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
@RequiredArgsConstructor @RequiredArgsConstructor
public abstract class GeyserCommandManager extends CommandManager { public abstract class GeyserCommandManager extends CommandManager {
@Getter @Getter
private final Map<String, Command> commands = new HashMap<>(); private final Map<String, Command> commands = new Object2ObjectOpenHashMap<>(12);
private final Map<String, Command> extensionCommands = new Object2ObjectOpenHashMap<>(0);
private final GeyserImpl geyser; private final GeyserImpl geyser;
public void init() { public void init() {
register(new HelpCommand(geyser, "help", "geyser.commands.help.desc", "geyser.command.help")); registerBuiltInCommand(new HelpCommand(geyser, "help", "geyser.commands.help.desc", "geyser.command.help", "geyser", commands));
register(new ListCommand(geyser, "list", "geyser.commands.list.desc", "geyser.command.list")); registerBuiltInCommand(new ListCommand(geyser, "list", "geyser.commands.list.desc", "geyser.command.list"));
register(new ReloadCommand(geyser, "reload", "geyser.commands.reload.desc", "geyser.command.reload")); registerBuiltInCommand(new ReloadCommand(geyser, "reload", "geyser.commands.reload.desc", "geyser.command.reload"));
register(new OffhandCommand(geyser, "offhand", "geyser.commands.offhand.desc", "geyser.command.offhand")); registerBuiltInCommand(new OffhandCommand(geyser, "offhand", "geyser.commands.offhand.desc", "geyser.command.offhand"));
register(new DumpCommand(geyser, "dump", "geyser.commands.dump.desc", "geyser.command.dump")); registerBuiltInCommand(new DumpCommand(geyser, "dump", "geyser.commands.dump.desc", "geyser.command.dump"));
register(new VersionCommand(geyser, "version", "geyser.commands.version.desc", "geyser.command.version")); registerBuiltInCommand(new VersionCommand(geyser, "version", "geyser.commands.version.desc", "geyser.command.version"));
register(new SettingsCommand(geyser, "settings", "geyser.commands.settings.desc", "geyser.command.settings")); registerBuiltInCommand(new SettingsCommand(geyser, "settings", "geyser.commands.settings.desc", "geyser.command.settings"));
register(new StatisticsCommand(geyser, "statistics", "geyser.commands.statistics.desc", "geyser.command.statistics")); registerBuiltInCommand(new StatisticsCommand(geyser, "statistics", "geyser.commands.statistics.desc", "geyser.command.statistics"));
register(new AdvancementsCommand("advancements", "geyser.commands.advancements.desc", "geyser.command.advancements")); registerBuiltInCommand(new AdvancementsCommand("advancements", "geyser.commands.advancements.desc", "geyser.command.advancements"));
register(new AdvancedTooltipsCommand("tooltips", "geyser.commands.advancedtooltips.desc", "geyser.command.tooltips")); registerBuiltInCommand(new AdvancedTooltipsCommand("tooltips", "geyser.commands.advancedtooltips.desc", "geyser.command.tooltips"));
register(new ExtensionsCommand(geyser, "extensions", "geyser.commands.extensions.desc", "geyser.command.extensions"));
if (GeyserImpl.getInstance().getPlatformType() == PlatformType.STANDALONE) { if (GeyserImpl.getInstance().getPlatformType() == PlatformType.STANDALONE) {
register(new StopCommand(geyser, "stop", "geyser.commands.stop.desc", "geyser.command.stop")); registerBuiltInCommand(new StopCommand(geyser, "stop", "geyser.commands.stop.desc", "geyser.command.stop"));
} }
this.geyser.eventBus().fire(new GeyserDefineCommandsEvent(this, this.commands())); register(new HelpCommand(geyser, "help", "geyser.commands.exthelp.desc", "geyser.command.exthelp", "geyserext", extensionCommands));
}
/**
* For internal Geyser commands
*/
public void registerBuiltInCommand(GeyserCommand command) {
register(command, this.commands);
} }
@Override @Override
public void register(@NonNull Command command) { public void register(@NonNull Command command) {
this.commands.put(command.name(), command); register(command, this.extensionCommands);
this.geyser.getLogger().debug(GeyserLocale.getLocaleStringLog("geyser.commands.registered", command.name())); }
private void register(Command command, Map<String, Command> commands) {
commands.put(command.name(), command);
geyser.getLogger().debug(GeyserLocale.getLocaleStringLog("geyser.commands.registered", command.name()));
if (command.aliases().isEmpty()) { if (command.aliases().isEmpty()) {
return; return;
} }
for (String alias : command.aliases()) { for (String alias : command.aliases()) {
this.commands.put(alias, command); commands.put(alias, command);
} }
} }
@Override @Override
public void unregister(@NonNull Command command) { public void unregister(@NonNull Command command) {
this.commands.remove(command.name(), command); this.extensionCommands.remove(command.name(), command);
if (command.aliases().isEmpty()) { if (command.aliases().isEmpty()) {
return; return;
} }
for (String alias : command.aliases()) { for (String alias : command.aliases()) {
this.commands.remove(alias, command); this.extensionCommands.remove(alias, command);
} }
} }
@NotNull @NotNull
@Override @Override
public Map<String, Command> commands() { public Map<String, Command> commands() {
return Collections.unmodifiableMap(this.commands); return Collections.unmodifiableMap(this.extensionCommands);
} }
public void runCommand(GeyserCommandSource sender, String command) { public boolean runCommand(GeyserCommandSource sender, String command) {
if (!command.startsWith("geyser ")) boolean extensionCommand = command.startsWith("geyserext ");
return; if (!command.startsWith("geyser ") && !extensionCommand) {
return false;
}
command = command.trim().replace("geyser ", ""); command = command.trim().replace(extensionCommand ? "geyserext " : "geyser ", "");
String label; String label;
String[] args; String[] args;
if (!command.contains(" ")) { if (!command.contains(" ")) {
label = command.toLowerCase(); label = command.toLowerCase(Locale.ROOT);
args = new String[0]; args = new String[0];
} else { } else {
label = command.substring(0, command.indexOf(" ")).toLowerCase(); label = command.substring(0, command.indexOf(" ")).toLowerCase(Locale.ROOT);
String argLine = command.substring(command.indexOf(" ") + 1); String argLine = command.substring(command.indexOf(" ") + 1);
args = argLine.contains(" ") ? argLine.split(" ") : new String[] { argLine }; args = argLine.contains(" ") ? argLine.split(" ") : new String[] { argLine };
} }
Command cmd = commands.get(label); Command cmd = (extensionCommand ? this.extensionCommands : this.commands).get(label);
if (cmd == null) { if (cmd == null) {
geyser.getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.invalid")); geyser.getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.invalid"));
return; return false;
} }
if (cmd instanceof GeyserCommand) { if (cmd instanceof GeyserCommand) {
@ -140,6 +153,8 @@ public abstract class GeyserCommandManager extends CommandManager {
} }
} }
} }
return true;
} }
/** /**

Datei anzeigen

@ -39,10 +39,15 @@ import java.util.Map;
public class HelpCommand extends GeyserCommand { public class HelpCommand extends GeyserCommand {
private final GeyserImpl geyser; private final GeyserImpl geyser;
private final String baseCommand;
private final Map<String, Command> commands;
public HelpCommand(GeyserImpl geyser, String name, String description, String permission) { public HelpCommand(GeyserImpl geyser, String name, String description, String permission,
String baseCommand, Map<String, Command> commands) {
super(name, description, permission); super(name, description, permission);
this.geyser = geyser; this.geyser = geyser;
this.baseCommand = baseCommand;
this.commands = commands;
this.setAliases(Collections.singletonList("?")); this.setAliases(Collections.singletonList("?"));
} }
@ -61,8 +66,7 @@ public class HelpCommand extends GeyserCommand {
String header = GeyserLocale.getPlayerLocaleString("geyser.commands.help.header", sender.locale(), page, maxPage); String header = GeyserLocale.getPlayerLocaleString("geyser.commands.help.header", sender.locale(), page, maxPage);
sender.sendMessage(header); sender.sendMessage(header);
Map<String, Command> cmds = geyser.commandManager().getCommands(); for (Map.Entry<String, Command> entry : commands.entrySet()) {
for (Map.Entry<String, Command> entry : cmds.entrySet()) {
Command cmd = entry.getValue(); Command cmd = entry.getValue();
// Standalone hack-in since it doesn't have a concept of permissions // Standalone hack-in since it doesn't have a concept of permissions
@ -72,7 +76,7 @@ public class HelpCommand extends GeyserCommand {
continue; continue;
} }
sender.sendMessage(ChatColor.YELLOW + "/geyser " + entry.getKey() + ChatColor.WHITE + ": " + sender.sendMessage(ChatColor.YELLOW + "/" + baseCommand + " " + entry.getKey() + ChatColor.WHITE + ": " +
GeyserLocale.getPlayerLocaleString(cmd.description(), sender.locale())); GeyserLocale.getPlayerLocaleString(cmd.description(), sender.locale()));
} }
} }

Datei anzeigen

@ -28,7 +28,6 @@ package org.geysermc.geyser.translator.protocol.bedrock;
import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket; import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.GeyserCommandManager;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.translator.protocol.Translator;
@ -40,10 +39,8 @@ public class BedrockCommandRequestTranslator extends PacketTranslator<CommandReq
@Override @Override
public void translate(GeyserSession session, CommandRequestPacket packet) { public void translate(GeyserSession session, CommandRequestPacket packet) {
String command = packet.getCommand().replace("/", ""); String command = packet.getCommand().replace("/", "");
GeyserCommandManager commandManager = GeyserImpl.getInstance().commandManager(); if (!(session.getGeyser().getPlatformType() == PlatformType.STANDALONE
if (session.getGeyser().getPlatformType() == PlatformType.STANDALONE && command.trim().startsWith("geyser ") && commandManager.getCommands().containsKey(command.split(" ")[1])) { && GeyserImpl.getInstance().commandManager().runCommand(session, command))) {
commandManager.runCommand(session, command);
} else {
String message = packet.getCommand().trim(); String message = packet.getCommand().trim();
if (MessageTranslator.isTooLong(message, session)) { if (MessageTranslator.isTooLong(message, session)) {