3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-20 06:50:09 +01:00

Pull command descriptions from Bukkit and Sponge versions when listing commands

This allows the description of the commands to display when listing the commands in bedrock by tab-completing. This is currently only available on Sponge and Bukkit versions as there is no support in BungeeCord and Velocity to get these values. This data is also not sent in any packet, so we cannot retrieve that from standalone either.
Dieser Commit ist enthalten in:
RednedEpic 2020-04-19 18:08:14 -05:00
Ursprung 672024c718
Commit bab2b4a420
22 geänderte Dateien mit 340 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -27,14 +27,18 @@ package org.geysermc.platform.bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.common.command.ICommandManager;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.common.bootstrap.IGeyserBootstrap; import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.connector.command.CommandManager;
import org.geysermc.platform.bukkit.command.GeyserBukkitCommandExecutor; import org.geysermc.platform.bukkit.command.GeyserBukkitCommandExecutor;
import org.geysermc.platform.bukkit.command.GeyserBukkitCommandManager;
import java.util.UUID; import java.util.UUID;
public class GeyserBukkitPlugin extends JavaPlugin implements IGeyserBootstrap { public class GeyserBukkitPlugin extends JavaPlugin implements IGeyserBootstrap {
private GeyserBukkitCommandManager geyserCommandManager;
private GeyserBukkitConfiguration geyserConfig; private GeyserBukkitConfiguration geyserConfig;
private GeyserBukkitLogger geyserLogger; private GeyserBukkitLogger geyserLogger;
@ -53,6 +57,8 @@ public class GeyserBukkitPlugin extends JavaPlugin implements IGeyserBootstrap {
this.geyserLogger = new GeyserBukkitLogger(getLogger(), geyserConfig.isDebugMode()); this.geyserLogger = new GeyserBukkitLogger(getLogger(), geyserConfig.isDebugMode());
this.connector = GeyserConnector.start(PlatformType.BUKKIT, this); this.connector = GeyserConnector.start(PlatformType.BUKKIT, this);
this.geyserCommandManager = new GeyserBukkitCommandManager(this, connector);
this.getCommand("geyser").setExecutor(new GeyserBukkitCommandExecutor(connector)); this.getCommand("geyser").setExecutor(new GeyserBukkitCommandExecutor(connector));
} }
@ -70,4 +76,9 @@ public class GeyserBukkitPlugin extends JavaPlugin implements IGeyserBootstrap {
public GeyserBukkitLogger getGeyserLogger() { public GeyserBukkitLogger getGeyserLogger() {
return geyserLogger; return geyserLogger;
} }
@Override
public CommandManager getGeyserCommandManager() {
return this.geyserCommandManager;
}
} }

Datei anzeigen

@ -70,6 +70,6 @@ public class GeyserBukkitCommandExecutor implements TabExecutor {
} }
private GeyserCommand getCommand(String label) { private GeyserCommand getCommand(String label) {
return connector.getCommandMap().getCommands().get(label); return connector.getCommandManager().getCommands().get(label);
} }
} }

Datei anzeigen

@ -0,0 +1,64 @@
/*
* Copyright (c) 2019-2020 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.platform.bukkit.command;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandManager;
import org.geysermc.platform.bukkit.GeyserBukkitPlugin;
import java.lang.reflect.Field;
public class GeyserBukkitCommandManager extends CommandManager {
private static CommandMap COMMAND_MAP;
static {
try {
Field cmdMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
cmdMapField.setAccessible(true);
COMMAND_MAP = (CommandMap) cmdMapField.get(Bukkit.getServer());
} catch (NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace();
}
}
private GeyserBukkitPlugin plugin;
public GeyserBukkitCommandManager(GeyserBukkitPlugin plugin, GeyserConnector connector) {
super(connector);
this.plugin = plugin;
}
@Override
public String getDescription(String command) {
Command cmd = COMMAND_MAP.getCommand(command.replace("/", ""));
return cmd != null ? cmd.getDescription() : "";
}
}

Datei anzeigen

@ -33,7 +33,9 @@ import net.md_5.bungee.config.YamlConfiguration;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.common.bootstrap.IGeyserBootstrap; import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.connector.command.CommandManager;
import org.geysermc.platform.bungeecord.command.GeyserBungeeCommandExecutor; import org.geysermc.platform.bungeecord.command.GeyserBungeeCommandExecutor;
import org.geysermc.platform.bungeecord.command.GeyserBungeeCommandManager;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -44,6 +46,7 @@ import java.util.logging.Level;
public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap {
private GeyserBungeeCommandManager geyserCommandManager;
private GeyserBungeeConfiguration geyserConfig; private GeyserBungeeConfiguration geyserConfig;
private GeyserBungeeLogger geyserLogger; private GeyserBungeeLogger geyserLogger;
@ -91,6 +94,8 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap {
this.geyserLogger = new GeyserBungeeLogger(getLogger(), geyserConfig.isDebugMode()); this.geyserLogger = new GeyserBungeeLogger(getLogger(), geyserConfig.isDebugMode());
this.connector = GeyserConnector.start(PlatformType.BUNGEECORD, this); this.connector = GeyserConnector.start(PlatformType.BUNGEECORD, this);
this.geyserCommandManager = new GeyserBungeeCommandManager(connector);
this.getProxy().getPluginManager().registerCommand(this, new GeyserBungeeCommandExecutor(connector)); this.getProxy().getPluginManager().registerCommand(this, new GeyserBungeeCommandExecutor(connector));
} }
@ -108,4 +113,9 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap {
public GeyserBungeeLogger getGeyserLogger() { public GeyserBungeeLogger getGeyserLogger() {
return geyserLogger; return geyserLogger;
} }
@Override
public CommandManager getGeyserCommandManager() {
return this.geyserCommandManager;
}
} }

Datei anzeigen

@ -71,6 +71,6 @@ public class GeyserBungeeCommandExecutor extends Command implements TabExecutor
} }
private GeyserCommand getCommand(String label) { private GeyserCommand getCommand(String label) {
return connector.getCommandMap().getCommands().get(label); return connector.getCommandManager().getCommands().get(label);
} }
} }

Datei anzeigen

@ -0,0 +1,41 @@
/*
* Copyright (c) 2019-2020 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.platform.bungeecord.command;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandManager;
public class GeyserBungeeCommandManager extends CommandManager {
public GeyserBungeeCommandManager(GeyserConnector connector) {
super(connector);
}
@Override
public String getDescription(String command) {
return ""; // no support for command descriptions in bungee
}
}

Datei anzeigen

@ -32,9 +32,12 @@ import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.common.bootstrap.IGeyserBootstrap; import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.common.command.ICommandManager;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandManager;
import org.geysermc.connector.utils.FileUtils; import org.geysermc.connector.utils.FileUtils;
import org.geysermc.platform.sponge.command.GeyserSpongeCommandExecutor; import org.geysermc.platform.sponge.command.GeyserSpongeCommandExecutor;
import org.geysermc.platform.sponge.command.GeyserSpongeCommandManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.spongepowered.api.Sponge; import org.spongepowered.api.Sponge;
import org.spongepowered.api.config.ConfigDir; import org.spongepowered.api.config.ConfigDir;
@ -57,6 +60,7 @@ public class GeyserSpongePlugin implements IGeyserBootstrap {
@ConfigDir(sharedRoot = false) @ConfigDir(sharedRoot = false)
private File configDir; private File configDir;
private GeyserSpongeCommandManager geyserCommandManager;
private GeyserSpongeConfiguration geyserConfig; private GeyserSpongeConfiguration geyserConfig;
private GeyserSpongeLogger geyserLogger; private GeyserSpongeLogger geyserLogger;
@ -86,6 +90,7 @@ public class GeyserSpongePlugin implements IGeyserBootstrap {
this.geyserLogger = new GeyserSpongeLogger(logger, geyserConfig.isDebugMode()); this.geyserLogger = new GeyserSpongeLogger(logger, geyserConfig.isDebugMode());
this.connector = GeyserConnector.start(PlatformType.SPONGE, this); this.connector = GeyserConnector.start(PlatformType.SPONGE, this);
this.geyserCommandManager = new GeyserSpongeCommandManager(Sponge.getCommandManager(), connector);
Sponge.getCommandManager().register(this, new GeyserSpongeCommandExecutor(connector), "geyser"); Sponge.getCommandManager().register(this, new GeyserSpongeCommandExecutor(connector), "geyser");
} }
@ -105,6 +110,11 @@ public class GeyserSpongePlugin implements IGeyserBootstrap {
return geyserLogger; return geyserLogger;
} }
@Override
public CommandManager getGeyserCommandManager() {
return this.geyserCommandManager;
}
@Listener @Listener
public void onServerStart(GameStartedServerEvent event) { public void onServerStart(GameStartedServerEvent event) {
onEnable(); onEnable();

Datei anzeigen

@ -95,6 +95,6 @@ public class GeyserSpongeCommandExecutor implements CommandCallable {
} }
private GeyserCommand getCommand(String label) { private GeyserCommand getCommand(String label) {
return connector.getCommandMap().getCommands().get(label); return connector.getCommandManager().getCommands().get(label);
} }
} }

Datei anzeigen

@ -0,0 +1,48 @@
/*
* Copyright (c) 2019-2020 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.platform.sponge.command;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandManager;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandMapping;
import org.spongepowered.api.text.Text;
public class GeyserSpongeCommandManager extends CommandManager {
private org.spongepowered.api.command.CommandManager handle;
public GeyserSpongeCommandManager(org.spongepowered.api.command.CommandManager handle, GeyserConnector connector) {
super(connector);
this.handle = handle;
}
@Override
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();
}
}

Datei anzeigen

@ -32,11 +32,14 @@ import java.util.UUID;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.common.bootstrap.IGeyserBootstrap; import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandManager;
import org.geysermc.connector.utils.FileUtils; import org.geysermc.connector.utils.FileUtils;
import org.geysermc.platform.standalone.command.GeyserCommandManager;
import org.geysermc.platform.standalone.console.GeyserLogger; import org.geysermc.platform.standalone.console.GeyserLogger;
public class GeyserBootstrap implements IGeyserBootstrap { public class GeyserBootstrap implements IGeyserBootstrap {
private GeyserCommandManager geyserCommandManager;
private GeyserConfiguration geyserConfig; private GeyserConfiguration geyserConfig;
private GeyserLogger geyserLogger; private GeyserLogger geyserLogger;
@ -62,6 +65,7 @@ public class GeyserBootstrap implements IGeyserBootstrap {
connector = GeyserConnector.start(PlatformType.STANDALONE, this); connector = GeyserConnector.start(PlatformType.STANDALONE, this);
geyserLogger.start(); geyserLogger.start();
geyserCommandManager = new GeyserCommandManager(connector);
} }
@Override @Override
@ -79,4 +83,9 @@ public class GeyserBootstrap implements IGeyserBootstrap {
public GeyserLogger getGeyserLogger() { public GeyserLogger getGeyserLogger() {
return geyserLogger; return geyserLogger;
} }
@Override
public CommandManager getGeyserCommandManager() {
return geyserCommandManager;
}
} }

Datei anzeigen

@ -0,0 +1,41 @@
/*
* Copyright (c) 2019-2020 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.platform.standalone.command;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandManager;
public class GeyserCommandManager extends CommandManager {
public GeyserCommandManager(GeyserConnector connector) {
super(connector);
}
@Override
public String getDescription(String command) {
return ""; // this is not sent over the protocol, so we return none
}
}

Datei anzeigen

@ -47,7 +47,7 @@ public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger
@Override @Override
protected void runCommand(String line) { protected void runCommand(String line) {
GeyserConnector.getInstance().getCommandMap().runCommand(this, line); GeyserConnector.getInstance().getCommandManager().runCommand(this, line);
} }
@Override @Override

Datei anzeigen

@ -38,6 +38,7 @@ import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.utils.FileUtils; import org.geysermc.connector.utils.FileUtils;
import org.geysermc.platform.velocity.command.GeyserVelocityCommandExecutor; import org.geysermc.platform.velocity.command.GeyserVelocityCommandExecutor;
import org.geysermc.platform.velocity.command.GeyserVelocityCommandManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.io.File; import java.io.File;
@ -53,6 +54,7 @@ public class GeyserVelocityPlugin implements IGeyserBootstrap {
@Inject @Inject
private CommandManager commandManager; private CommandManager commandManager;
private GeyserVelocityCommandManager geyserCommandManager;
private GeyserVelocityConfiguration geyserConfig; private GeyserVelocityConfiguration geyserConfig;
private GeyserVelocityLogger geyserLogger; private GeyserVelocityLogger geyserLogger;
@ -74,6 +76,7 @@ public class GeyserVelocityPlugin implements IGeyserBootstrap {
this.geyserLogger = new GeyserVelocityLogger(logger, geyserConfig.isDebugMode()); this.geyserLogger = new GeyserVelocityLogger(logger, geyserConfig.isDebugMode());
this.connector = GeyserConnector.start(PlatformType.VELOCITY, this); this.connector = GeyserConnector.start(PlatformType.VELOCITY, this);
this.geyserCommandManager = new GeyserVelocityCommandManager(connector);
this.commandManager.register(new GeyserVelocityCommandExecutor(connector), "geyser"); this.commandManager.register(new GeyserVelocityCommandExecutor(connector), "geyser");
} }
@ -92,6 +95,11 @@ public class GeyserVelocityPlugin implements IGeyserBootstrap {
return geyserLogger; return geyserLogger;
} }
@Override
public org.geysermc.connector.command.CommandManager getGeyserCommandManager() {
return this.geyserCommandManager;
}
@Subscribe @Subscribe
public void onInit(ProxyInitializeEvent event) { public void onInit(ProxyInitializeEvent event) {
onEnable(); onEnable();

Datei anzeigen

@ -57,6 +57,6 @@ public class GeyserVelocityCommandExecutor implements Command {
} }
private GeyserCommand getCommand(String label) { private GeyserCommand getCommand(String label) {
return connector.getCommandMap().getCommands().get(label); return connector.getCommandManager().getCommands().get(label);
} }
} }

Datei anzeigen

@ -0,0 +1,41 @@
/*
* Copyright (c) 2019-2020 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.platform.velocity.command;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandManager;
public class GeyserVelocityCommandManager extends CommandManager {
public GeyserVelocityCommandManager(GeyserConnector connector) {
super(connector);
}
@Override
public String getDescription(String command) {
return ""; // no support for command descriptions in velocity
}
}

Datei anzeigen

@ -26,6 +26,7 @@
package org.geysermc.common.bootstrap; package org.geysermc.common.bootstrap;
import org.geysermc.common.IGeyserConfiguration; import org.geysermc.common.IGeyserConfiguration;
import org.geysermc.common.command.ICommandManager;
import org.geysermc.common.logger.IGeyserLogger; import org.geysermc.common.logger.IGeyserLogger;
public interface IGeyserBootstrap { public interface IGeyserBootstrap {
@ -37,4 +38,6 @@ public interface IGeyserBootstrap {
IGeyserConfiguration getGeyserConfig(); IGeyserConfiguration getGeyserConfig();
IGeyserLogger getGeyserLogger(); IGeyserLogger getGeyserLogger();
ICommandManager getGeyserCommandManager();
} }

Datei anzeigen

@ -0,0 +1,31 @@
/*
* Copyright (c) 2019-2020 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.common.command;
public interface ICommandManager {
String getDescription(String command);
}

Datei anzeigen

@ -35,7 +35,7 @@ import org.geysermc.common.AuthType;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.common.bootstrap.IGeyserBootstrap; import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.common.logger.IGeyserLogger; import org.geysermc.common.logger.IGeyserLogger;
import org.geysermc.connector.command.GeyserCommandMap; import org.geysermc.connector.command.CommandManager;
import org.geysermc.connector.metrics.Metrics; import org.geysermc.connector.metrics.Metrics;
import org.geysermc.connector.network.ConnectorServerEventHandler; import org.geysermc.connector.network.ConnectorServerEventHandler;
import org.geysermc.connector.network.remote.RemoteServer; import org.geysermc.connector.network.remote.RemoteServer;
@ -50,7 +50,6 @@ import java.text.DecimalFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.UUID;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -70,8 +69,6 @@ public class GeyserConnector {
private RemoteServer remoteServer; private RemoteServer remoteServer;
private AuthType authType; private AuthType authType;
private GeyserCommandMap commandMap;
private boolean shuttingDown = false; private boolean shuttingDown = false;
private final ScheduledExecutorService generalThreadPool; private final ScheduledExecutorService generalThreadPool;
@ -108,7 +105,6 @@ public class GeyserConnector {
Toolbox.init(); Toolbox.init();
Translators.start(); Translators.start();
commandMap = new GeyserCommandMap(this);
remoteServer = new RemoteServer(config.getRemote().getAddress(), config.getRemote().getPort()); remoteServer = new RemoteServer(config.getRemote().getAddress(), config.getRemote().getPort());
authType = AuthType.getByName(config.getRemote().getAuthType()); authType = AuthType.getByName(config.getRemote().getAuthType());
@ -182,8 +178,7 @@ public class GeyserConnector {
players.clear(); players.clear();
remoteServer = null; remoteServer = null;
authType = null; authType = null;
commandMap.getCommands().clear(); this.getCommandManager().getCommands().clear();
commandMap = null;
bootstrap.getGeyserLogger().info("Geyser shutdown successfully."); bootstrap.getGeyserLogger().info("Geyser shutdown successfully.");
} }
@ -213,6 +208,10 @@ public class GeyserConnector {
return bootstrap.getGeyserConfig(); return bootstrap.getGeyserConfig();
} }
public CommandManager getCommandManager() {
return (CommandManager) bootstrap.getGeyserCommandManager();
}
public static GeyserConnector getInstance() { public static GeyserConnector getInstance() {
return instance; return instance;
} }

Datei anzeigen

@ -26,6 +26,7 @@
package org.geysermc.connector.command; package org.geysermc.connector.command;
import lombok.Getter; import lombok.Getter;
import org.geysermc.common.command.ICommandManager;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.defaults.HelpCommand; import org.geysermc.connector.command.defaults.HelpCommand;
import org.geysermc.connector.command.defaults.ReloadCommand; import org.geysermc.connector.command.defaults.ReloadCommand;
@ -35,14 +36,14 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class GeyserCommandMap { public abstract class CommandManager implements ICommandManager {
@Getter @Getter
private final Map<String, GeyserCommand> commands = Collections.synchronizedMap(new HashMap<>()); private final Map<String, GeyserCommand> commands = Collections.synchronizedMap(new HashMap<>());
private GeyserConnector connector; private GeyserConnector connector;
public GeyserCommandMap(GeyserConnector connector) { public CommandManager(GeyserConnector connector) {
this.connector = connector; this.connector = connector;
registerCommand(new HelpCommand(connector, "help", "Shows help for all registered commands.", "geyser.command.help")); registerCommand(new HelpCommand(connector, "help", "Shows help for all registered commands.", "geyser.command.help"));

Datei anzeigen

@ -49,8 +49,8 @@ public class HelpCommand extends GeyserCommand {
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
sender.sendMessage("---- Showing Help For: Geyser (Page 1/1) ----"); sender.sendMessage("---- Showing Help For: Geyser (Page 1/1) ----");
Map<String, GeyserCommand> cmds = connector.getCommandMap().getCommands(); Map<String, GeyserCommand> cmds = connector.getCommandManager().getCommands();
List<String> commands = connector.getCommandMap().getCommands().keySet().stream().sorted().collect(Collectors.toList()); List<String> commands = connector.getCommandManager().getCommands().keySet().stream().sorted().collect(Collectors.toList());
commands.forEach(cmd -> sender.sendMessage(ChatColor.YELLOW + "/geyser " + cmd + ChatColor.WHITE + ": " + cmds.get(cmd).getDescription())); commands.forEach(cmd -> sender.sendMessage(ChatColor.YELLOW + "/geyser " + cmd + ChatColor.WHITE + ": " + cmds.get(cmd).getDescription()));
} }
} }

Datei anzeigen

@ -27,7 +27,7 @@ package org.geysermc.connector.network.translators.bedrock;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.GeyserCommandMap; import org.geysermc.connector.command.CommandManager;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.Translator;
@ -42,9 +42,9 @@ public class BedrockCommandRequestTranslator extends PacketTranslator<CommandReq
@Override @Override
public void translate(CommandRequestPacket packet, GeyserSession session) { public void translate(CommandRequestPacket packet, GeyserSession session) {
String command = packet.getCommand().replace("/", ""); String command = packet.getCommand().replace("/", "");
GeyserCommandMap commandMap = GeyserConnector.getInstance().getCommandMap(); CommandManager commandManager = GeyserConnector.getInstance().getCommandManager();
if (session.getConnector().getPlatformType() == PlatformType.STANDALONE && command.startsWith("geyser ") && commandMap.getCommands().containsKey(command.split(" ")[1])) { if (session.getConnector().getPlatformType() == PlatformType.STANDALONE && command.startsWith("geyser ") && commandManager.getCommands().containsKey(command.split(" ")[1])) {
commandMap.runCommand(session, command); commandManager.runCommand(session, command);
} else { } else {
String message = packet.getCommand().trim(); String message = packet.getCommand().trim();

Datei anzeigen

@ -84,7 +84,7 @@ public class JavaServerDeclareCommandsTranslator extends PacketTranslator<Server
CommandParamData[][] params = getParams(commandID, packet.getNodes()[commandID], packet.getNodes()); CommandParamData[][] params = getParams(commandID, packet.getNodes()[commandID], packet.getNodes());
// Build the completed command and add it to the final list // Build the completed command and add it to the final list
CommandData data = new CommandData(commandName, "A Java server command", flags, (byte) 0, aliases, params); CommandData data = new CommandData(commandName, session.getConnector().getCommandManager().getDescription(commandName), flags, (byte) 0, aliases, params);
commandData.add(data); commandData.add(data);
} }