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

@ -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);
}
}