Send message to Java if command is Bedrock-only (#1834)

* Send message to Java if command is Bedrock-only

If a Java player attempts to use a Bedrock-only command, such as `geyser statistics`, they will get an error message stating that this command is only for Bedrock players.

This commit also cleans up Velocity Adventure dependency usage. Issues were caused because of the way relocation works and because Velocity also uses Adventure.

* Only look for a session if we have to

* Update languages submodule
This commit is contained in:
Camotoy 2021-01-16 22:18:13 -05:00 committed by GitHub
parent da512da511
commit 2d9baf1bfc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 222 additions and 157 deletions

View file

@ -30,7 +30,9 @@ import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.TabExecutor;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandExecutor;
import org.geysermc.connector.command.GeyserCommand;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.LanguageUtils;
import java.util.ArrayList;
@ -38,29 +40,42 @@ import java.util.Arrays;
public class GeyserBungeeCommandExecutor extends Command implements TabExecutor {
private final CommandExecutor commandExecutor;
private final GeyserConnector connector;
public GeyserBungeeCommandExecutor(GeyserConnector connector) {
super("geyser");
this.commandExecutor = new CommandExecutor(connector);
this.connector = connector;
}
@Override
public void execute(CommandSender sender, String[] args) {
if (args.length > 0) {
if (getCommand(args[0]) != null) {
if (!sender.hasPermission(getCommand(args[0]).getPermission())) {
BungeeCommandSender commandSender = new BungeeCommandSender(sender);
GeyserCommand command = this.commandExecutor.getCommand(args[0]);
if (command != null) {
BungeeCommandSender commandSender = new BungeeCommandSender(sender);
if (!sender.hasPermission(command.getPermission())) {
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale());
commandSender.sendMessage(ChatColor.RED + message);
return;
}
getCommand(args[0]).execute(new BungeeCommandSender(sender), args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
GeyserSession session = null;
if (command.isBedrockOnly()) {
session = this.commandExecutor.getGeyserSession(commandSender);
if (session == null) {
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", commandSender.getLocale());
commandSender.sendMessage(ChatColor.RED + message);
return;
}
}
command.execute(session, commandSender, args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
}
} else {
getCommand("help").execute(new BungeeCommandSender(sender), new String[0]);
this.commandExecutor.getCommand("help").execute(null, new BungeeCommandSender(sender), new String[0]);
}
}
@ -71,8 +86,4 @@ public class GeyserBungeeCommandExecutor extends Command implements TabExecutor
}
return new ArrayList<>();
}
private GeyserCommand getCommand(String label) {
return connector.getCommandManager().getCommands().get(label);
}
}

View file

@ -25,40 +25,51 @@
package org.geysermc.platform.spigot.command;
import lombok.AllArgsConstructor;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandExecutor;
import org.geysermc.connector.command.GeyserCommand;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.LanguageUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@AllArgsConstructor
public class GeyserSpigotCommandExecutor implements TabExecutor {
public class GeyserSpigotCommandExecutor extends CommandExecutor implements TabExecutor {
private final GeyserConnector connector;
public GeyserSpigotCommandExecutor(GeyserConnector connector) {
super(connector);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length > 0) {
if (getCommand(args[0]) != null) {
if (!sender.hasPermission(getCommand(args[0]).getPermission())) {
SpigotCommandSender commandSender = new SpigotCommandSender(sender);
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale());;
GeyserCommand geyserCommand = getCommand(args[0]);
if (geyserCommand != null) {
SpigotCommandSender commandSender = new SpigotCommandSender(sender);
if (!sender.hasPermission(geyserCommand.getPermission())) {
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale());
commandSender.sendMessage(ChatColor.RED + message);
return true;
}
getCommand(args[0]).execute(new SpigotCommandSender(sender), args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
GeyserSession session = null;
if (geyserCommand.isBedrockOnly()) {
session = getGeyserSession(commandSender);
if (session == null) {
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", commandSender.getLocale()));
return true;
}
}
geyserCommand.execute(session, commandSender, args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
return true;
}
} else {
getCommand("help").execute(new SpigotCommandSender(sender), new String[0]);
getCommand("help").execute(null, new SpigotCommandSender(sender), new String[0]);
return true;
}
return true;
@ -71,8 +82,4 @@ public class GeyserSpigotCommandExecutor implements TabExecutor {
}
return new ArrayList<>();
}
private GeyserCommand getCommand(String label) {
return connector.getCommandManager().getCommands().get(label);
}
}

View file

@ -25,10 +25,12 @@
package org.geysermc.platform.sponge.command;
import lombok.AllArgsConstructor;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.common.ChatColor;
import org.geysermc.connector.command.CommandExecutor;
import org.geysermc.connector.command.CommandSender;
import org.geysermc.connector.command.GeyserCommand;
import org.geysermc.connector.common.ChatColor;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.LanguageUtils;
import org.spongepowered.api.command.CommandCallable;
import org.spongepowered.api.command.CommandException;
@ -44,25 +46,36 @@ import java.util.Arrays;
import java.util.List;
import java.util.Optional;
@AllArgsConstructor
public class GeyserSpongeCommandExecutor implements CommandCallable {
public class GeyserSpongeCommandExecutor extends CommandExecutor implements CommandCallable {
private GeyserConnector connector;
public GeyserSpongeCommandExecutor(GeyserConnector connector) {
super(connector);
}
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
public CommandResult process(CommandSource source, String arguments) {
String[] args = arguments.split(" ");
if (args.length > 0) {
if (getCommand(args[0]) != null) {
if (!source.hasPermission(getCommand(args[0]).getPermission())) {
GeyserCommand command = getCommand(args[0]);
if (command != null) {
CommandSender commandSender = new SpongeCommandSender(source);
if (!source.hasPermission(command.getPermission())) {
// Not ideal to use log here but we dont get a session
source.sendMessage(Text.of(ChatColor.RED + LanguageUtils.getLocaleStringLog("geyser.bootstrap.command.permission_fail")));
return CommandResult.success();
}
getCommand(args[0]).execute(new SpongeCommandSender(source), args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
GeyserSession session = null;
if (command.isBedrockOnly()) {
session = getGeyserSession(commandSender);
if (session == null) {
source.sendMessage(Text.of(ChatColor.RED + LanguageUtils.getLocaleStringLog("geyser.bootstrap.command.bedrock_only")));
return CommandResult.success();
}
}
getCommand(args[0]).execute(session, commandSender, args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
}
} else {
getCommand("help").execute(new SpongeCommandSender(source), new String[0]);
getCommand("help").execute(null, new SpongeCommandSender(source), new String[0]);
}
return CommandResult.success();
}
@ -94,8 +107,4 @@ public class GeyserSpongeCommandExecutor implements CommandCallable {
public Text getUsage(CommandSource source) {
return Text.of("/geyser help");
}
private GeyserCommand getCommand(String label) {
return connector.getCommandManager().getCommands().get(label);
}
}

View file

@ -271,17 +271,17 @@ public class GeyserStandaloneGUI {
JMenuItem commandButton = hasSubCommands ? new JMenu(command.getValue().getName()) : new JMenuItem(command.getValue().getName());
commandButton.getAccessibleContext().setAccessibleDescription(command.getValue().getDescription());
if (!hasSubCommands) {
commandButton.addActionListener(e -> command.getValue().execute(geyserStandaloneLogger, new String[]{ }));
commandButton.addActionListener(e -> command.getValue().execute(null, geyserStandaloneLogger, new String[]{ }));
} else {
// Add a submenu that's the same name as the menu can't be pressed
JMenuItem otherCommandButton = new JMenuItem(command.getValue().getName());
otherCommandButton.getAccessibleContext().setAccessibleDescription(command.getValue().getDescription());
otherCommandButton.addActionListener(e -> command.getValue().execute(geyserStandaloneLogger, new String[]{ }));
otherCommandButton.addActionListener(e -> command.getValue().execute(null, geyserStandaloneLogger, new String[]{ }));
commandButton.add(otherCommandButton);
// Add a menu option for all possible subcommands
for (String subCommandName : command.getValue().getSubCommands()) {
JMenuItem item = new JMenuItem(subCommandName);
item.addActionListener(e -> command.getValue().execute(geyserStandaloneLogger, new String[]{subCommandName}));
item.addActionListener(e -> command.getValue().execute(null, geyserStandaloneLogger, new String[]{subCommandName}));
commandButton.add(item);
}
}

View file

@ -82,8 +82,8 @@
<shadedPattern>org.geysermc.platform.velocity.shaded.dom4j</shadedPattern>
</relocation>
<relocation>
<pattern>net.kyori</pattern>
<shadedPattern>org.geysermc.platform.velocity.shaded.kyori</shadedPattern>
<pattern>net.kyori.adventure.text.serializer.gson.legacyimpl</pattern>
<shadedPattern>org.geysermc.platform.velocity.shaded.kyori.legacyimpl</shadedPattern>
</relocation>
</relocations>
</configuration>
@ -105,6 +105,13 @@
<exclude>io.netty:netty-codec:*</exclude>
<exclude>org.slf4j:*</exclude>
<exclude>org.ow2.asm:*</exclude>
<!-- Exclude all Kyori dependencies except the legacy NBT serializer -->
<exclude>net.kyori:adventure-api:*</exclude>
<exclude>net.kyori:examination-api:*</exclude>
<exclude>net.kyori:examination-string:*</exclude>
<exclude>net.kyori:adventure-text-serializer-gson:*</exclude>
<exclude>net.kyori:adventure-text-serializer-legacy:*</exclude>
<exclude>net.kyori:adventure-nbt:*</exclude>
</excludes>
</artifactSet>
</configuration>

View file

@ -31,11 +31,10 @@ import com.velocitypowered.api.proxy.InboundConnection;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.server.ServerPing;
import lombok.AllArgsConstructor;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.geysermc.connector.common.ping.GeyserPingInfo;
import org.geysermc.connector.ping.IGeyserPingPassthrough;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
@ -50,13 +49,13 @@ public class GeyserVelocityPingPassthrough implements IGeyserPingPassthrough {
ProxyPingEvent event;
try {
event = server.getEventManager().fire(new ProxyPingEvent(new GeyserInboundConnection(inetSocketAddress), ServerPing.builder()
.description(server.getConfiguration().getMotdComponent()).onlinePlayers(server.getPlayerCount())
.description(server.getConfiguration().getMotd()).onlinePlayers(server.getPlayerCount())
.maximumPlayers(server.getConfiguration().getShowMaxPlayers()).build())).get();
} catch (ExecutionException | InterruptedException e) {
throw new RuntimeException(e);
}
GeyserPingInfo geyserPingInfo = new GeyserPingInfo(
LegacyComponentSerializer.legacy().serialize(event.getPing().getDescription(), '§'),
LegacyComponentSerializer.legacy('§').serialize(event.getPing().getDescriptionComponent()),
new GeyserPingInfo.Players(
event.getPing().getPlayers().orElseThrow(IllegalStateException::new).getMax(),
event.getPing().getPlayers().orElseThrow(IllegalStateException::new).getOnline()

View file

@ -25,37 +25,47 @@
package org.geysermc.platform.velocity.command;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import lombok.AllArgsConstructor;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandExecutor;
import org.geysermc.connector.command.CommandSender;
import org.geysermc.connector.command.GeyserCommand;
import org.geysermc.connector.common.ChatColor;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.LanguageUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@AllArgsConstructor
public class GeyserVelocityCommandExecutor implements SimpleCommand {
public class GeyserVelocityCommandExecutor extends CommandExecutor implements SimpleCommand {
private final GeyserConnector connector;
public GeyserVelocityCommandExecutor(GeyserConnector connector) {
super(connector);
}
@Override
public void execute(Invocation invocation) {
if (invocation.arguments().length > 0) {
if (getCommand(invocation.arguments()[0]) != null) {
GeyserCommand command = getCommand(invocation.arguments()[0]);
if (command != null) {
CommandSender sender = new VelocityCommandSender(invocation.source());
if (!invocation.source().hasPermission(getCommand(invocation.arguments()[0]).getPermission())) {
CommandSender sender = new VelocityCommandSender(invocation.source());
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.getLocale()));
return;
}
getCommand(invocation.arguments()[0]).execute(new VelocityCommandSender(invocation.source()), invocation.arguments().length > 1 ? Arrays.copyOfRange(invocation.arguments(), 1, invocation.arguments().length) : new String[0]);
GeyserSession session = null;
if (command.isBedrockOnly()) {
session = getGeyserSession(sender);
if (session == null) {
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", sender.getLocale()));
return;
}
}
command.execute(session, sender, invocation.arguments().length > 1 ? Arrays.copyOfRange(invocation.arguments(), 1, invocation.arguments().length) : new String[0]);
}
} else {
getCommand("help").execute(new VelocityCommandSender(invocation.source()), new String[0]);
getCommand("help").execute(null, new VelocityCommandSender(invocation.source()), new String[0]);
}
}
@ -66,8 +76,4 @@ public class GeyserVelocityCommandExecutor implements SimpleCommand {
}
return new ArrayList<>();
}
private GeyserCommand getCommand(String label) {
return connector.getCommandManager().getCommands().get(label);
}
}