mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Implement support for adding Geyser subcommands
This commit is contained in:
parent
57345fa102
commit
30303d5f16
90 changed files with 1207 additions and 402 deletions
|
@ -38,6 +38,7 @@ import lombok.Getter;
|
|||
import org.geysermc.common.PlatformType;
|
||||
import org.geysermc.geyser.GeyserBootstrap;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.command.GeyserCommandManager;
|
||||
import org.geysermc.geyser.configuration.GeyserConfiguration;
|
||||
import org.geysermc.geyser.dump.BootstrapDumpInfo;
|
||||
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
|
||||
|
@ -145,6 +146,8 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
|
|||
// Will be initialized after the proxy has been bound
|
||||
|
||||
this.geyserCommandManager = new GeyserVelocityCommandManager(geyser);
|
||||
this.geyserCommandManager.init();
|
||||
|
||||
this.commandManager.register("geyser", new GeyserVelocityCommandExecutor(geyser));
|
||||
if (geyserConfig.isLegacyPingPassthrough()) {
|
||||
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(geyser);
|
||||
|
@ -174,7 +177,7 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
|
|||
}
|
||||
|
||||
@Override
|
||||
public org.geysermc.geyser.command.CommandManager getGeyserCommandManager() {
|
||||
public GeyserCommandManager getGeyserCommandManager() {
|
||||
return this.geyserCommandManager;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ package org.geysermc.geyser.platform.velocity.command;
|
|||
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.command.CommandExecutor;
|
||||
import org.geysermc.geyser.command.CommandSender;
|
||||
import org.geysermc.geyser.command.GeyserCommandExecutor;
|
||||
import org.geysermc.geyser.command.GeyserCommandSource;
|
||||
import org.geysermc.geyser.command.GeyserCommand;
|
||||
import org.geysermc.geyser.text.ChatColor;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
|
@ -38,7 +38,7 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GeyserVelocityCommandExecutor extends CommandExecutor implements SimpleCommand {
|
||||
public class GeyserVelocityCommandExecutor extends GeyserCommandExecutor implements SimpleCommand {
|
||||
|
||||
public GeyserVelocityCommandExecutor(GeyserImpl geyser) {
|
||||
super(geyser);
|
||||
|
@ -46,18 +46,18 @@ public class GeyserVelocityCommandExecutor extends CommandExecutor implements Si
|
|||
|
||||
@Override
|
||||
public void execute(Invocation invocation) {
|
||||
CommandSender sender = new VelocityCommandSender(invocation.source());
|
||||
GeyserCommandSource sender = new VelocityCommandSource(invocation.source());
|
||||
GeyserSession session = getGeyserSession(sender);
|
||||
|
||||
if (invocation.arguments().length > 0) {
|
||||
GeyserCommand command = getCommand(invocation.arguments()[0]);
|
||||
if (command != null) {
|
||||
if (!invocation.source().hasPermission(getCommand(invocation.arguments()[0]).getPermission())) {
|
||||
sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.getLocale()));
|
||||
if (!invocation.source().hasPermission(getCommand(invocation.arguments()[0]).permission())) {
|
||||
sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.locale()));
|
||||
return;
|
||||
}
|
||||
if (command.isBedrockOnly() && session == null) {
|
||||
sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", sender.getLocale()));
|
||||
sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", sender.locale()));
|
||||
return;
|
||||
}
|
||||
command.execute(session, sender, invocation.arguments().length > 1 ? Arrays.copyOfRange(invocation.arguments(), 1, invocation.arguments().length) : new String[0]);
|
||||
|
@ -71,7 +71,7 @@ public class GeyserVelocityCommandExecutor extends CommandExecutor implements Si
|
|||
public List<String> suggest(Invocation invocation) {
|
||||
// Velocity seems to do the splitting a bit differently. This results in the same behaviour in bungeecord/spigot.
|
||||
if (invocation.arguments().length == 0 || invocation.arguments().length == 1) {
|
||||
return tabComplete(new VelocityCommandSender(invocation.source()));
|
||||
return tabComplete(new VelocityCommandSource(invocation.source()));
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
|
|
@ -26,16 +26,16 @@
|
|||
package org.geysermc.geyser.platform.velocity.command;
|
||||
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.command.CommandManager;
|
||||
import org.geysermc.geyser.command.GeyserCommandManager;
|
||||
|
||||
public class GeyserVelocityCommandManager extends CommandManager {
|
||||
public class GeyserVelocityCommandManager extends GeyserCommandManager {
|
||||
|
||||
public GeyserVelocityCommandManager(GeyserImpl geyser) {
|
||||
super(geyser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription(String command) {
|
||||
public String description(String command) {
|
||||
return ""; // no support for command descriptions in velocity
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,19 +29,19 @@ import com.velocitypowered.api.command.CommandSource;
|
|||
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.geysermc.geyser.command.CommandSender;
|
||||
import org.geysermc.geyser.command.GeyserCommandSource;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class VelocityCommandSender implements CommandSender {
|
||||
public class VelocityCommandSource implements GeyserCommandSource {
|
||||
|
||||
private final CommandSource handle;
|
||||
|
||||
public VelocityCommandSender(CommandSource handle) {
|
||||
public VelocityCommandSource(CommandSource handle) {
|
||||
this.handle = handle;
|
||||
// Ensure even Java players' languages are loaded
|
||||
GeyserLocale.loadGeyserLocale(getLocale());
|
||||
GeyserLocale.loadGeyserLocale(this.locale());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,7 +65,7 @@ public class VelocityCommandSender implements CommandSender {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getLocale() {
|
||||
public String locale() {
|
||||
if (handle instanceof Player) {
|
||||
Locale locale = ((Player) handle).getPlayerSettings().getLocale();
|
||||
return GeyserLocale.formatLocale(locale.getLanguage() + "_" + locale.getCountry());
|
Loading…
Add table
Add a link
Reference in a new issue