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