Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 00:00:41 +01:00
Fix help command (#2604)
* Always pass session to execute() if the sender is a geyser player * cleanup
Dieser Commit ist enthalten in:
Ursprung
eb211884de
Commit
1929a5be83
@ -35,6 +35,7 @@ import org.geysermc.connector.command.GeyserCommand;
|
|||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.utils.LanguageUtils;
|
import org.geysermc.connector.utils.LanguageUtils;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
@ -52,30 +53,28 @@ public class GeyserBungeeCommandExecutor extends Command implements TabExecutor
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
BungeeCommandSender commandSender = new BungeeCommandSender(sender);
|
||||||
|
GeyserSession session = this.commandExecutor.getGeyserSession(commandSender);
|
||||||
|
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
GeyserCommand command = this.commandExecutor.getCommand(args[0]);
|
GeyserCommand command = this.commandExecutor.getCommand(args[0]);
|
||||||
if (command != null) {
|
if (command != null) {
|
||||||
BungeeCommandSender commandSender = new BungeeCommandSender(sender);
|
|
||||||
if (!sender.hasPermission(command.getPermission())) {
|
if (!sender.hasPermission(command.getPermission())) {
|
||||||
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale());
|
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale());
|
||||||
|
|
||||||
commandSender.sendMessage(ChatColor.RED + message);
|
commandSender.sendMessage(ChatColor.RED + message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GeyserSession session = null;
|
if (command.isBedrockOnly() && session == null) {
|
||||||
if (command.isBedrockOnly()) {
|
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", commandSender.getLocale());
|
||||||
session = this.commandExecutor.getGeyserSession(commandSender);
|
|
||||||
if (session == null) {
|
|
||||||
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", commandSender.getLocale());
|
|
||||||
|
|
||||||
commandSender.sendMessage(ChatColor.RED + message);
|
commandSender.sendMessage(ChatColor.RED + message);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
command.execute(session, commandSender, args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
|
command.execute(session, commandSender, args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.commandExecutor.getCommand("help").execute(null, new BungeeCommandSender(sender), new String[0]);
|
this.commandExecutor.getCommand("help").execute(session, commandSender, new String[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,29 +47,27 @@ public class GeyserSpigotCommandExecutor extends CommandExecutor implements TabE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
SpigotCommandSender commandSender = new SpigotCommandSender(sender);
|
||||||
|
GeyserSession session = getGeyserSession(commandSender);
|
||||||
|
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
GeyserCommand geyserCommand = getCommand(args[0]);
|
GeyserCommand geyserCommand = getCommand(args[0]);
|
||||||
if (geyserCommand != null) {
|
if (geyserCommand != null) {
|
||||||
SpigotCommandSender commandSender = new SpigotCommandSender(sender);
|
|
||||||
if (!sender.hasPermission(geyserCommand.getPermission())) {
|
if (!sender.hasPermission(geyserCommand.getPermission())) {
|
||||||
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale());
|
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale());
|
||||||
|
|
||||||
commandSender.sendMessage(ChatColor.RED + message);
|
commandSender.sendMessage(ChatColor.RED + message);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
GeyserSession session = null;
|
if (geyserCommand.isBedrockOnly() && session == null) {
|
||||||
if (geyserCommand.isBedrockOnly()) {
|
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", commandSender.getLocale()));
|
||||||
session = getGeyserSession(commandSender);
|
return true;
|
||||||
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]);
|
geyserCommand.execute(session, commandSender, args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getCommand("help").execute(null, new SpigotCommandSender(sender), new String[0]);
|
getCommand("help").execute(session, commandSender, new String[0]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -53,28 +53,26 @@ public class GeyserSpongeCommandExecutor extends CommandExecutor implements Comm
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult process(CommandSource source, String arguments) {
|
public CommandResult process(CommandSource source, String arguments) {
|
||||||
|
CommandSender commandSender = new SpongeCommandSender(source);
|
||||||
|
GeyserSession session = getGeyserSession(commandSender);
|
||||||
|
|
||||||
String[] args = arguments.split(" ");
|
String[] args = arguments.split(" ");
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
GeyserCommand command = getCommand(args[0]);
|
GeyserCommand command = getCommand(args[0]);
|
||||||
if (command != null) {
|
if (command != null) {
|
||||||
CommandSender commandSender = new SpongeCommandSender(source);
|
|
||||||
if (!source.hasPermission(command.getPermission())) {
|
if (!source.hasPermission(command.getPermission())) {
|
||||||
// Not ideal to use log here but we dont get a session
|
// 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")));
|
source.sendMessage(Text.of(ChatColor.RED + LanguageUtils.getLocaleStringLog("geyser.bootstrap.command.permission_fail")));
|
||||||
return CommandResult.success();
|
return CommandResult.success();
|
||||||
}
|
}
|
||||||
GeyserSession session = null;
|
if (command.isBedrockOnly() && session == null) {
|
||||||
if (command.isBedrockOnly()) {
|
source.sendMessage(Text.of(ChatColor.RED + LanguageUtils.getLocaleStringLog("geyser.bootstrap.command.bedrock_only")));
|
||||||
session = getGeyserSession(commandSender);
|
return CommandResult.success();
|
||||||
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]);
|
getCommand(args[0]).execute(session, commandSender, args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getCommand("help").execute(null, new SpongeCommandSender(source), new String[0]);
|
getCommand("help").execute(session, commandSender, new String[0]);
|
||||||
}
|
}
|
||||||
return CommandResult.success();
|
return CommandResult.success();
|
||||||
}
|
}
|
||||||
|
@ -46,26 +46,24 @@ public class GeyserVelocityCommandExecutor extends CommandExecutor implements Si
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Invocation invocation) {
|
public void execute(Invocation invocation) {
|
||||||
|
CommandSender sender = new VelocityCommandSender(invocation.source());
|
||||||
|
GeyserSession session = getGeyserSession(sender);
|
||||||
|
|
||||||
if (invocation.arguments().length > 0) {
|
if (invocation.arguments().length > 0) {
|
||||||
GeyserCommand command = getCommand(invocation.arguments()[0]);
|
GeyserCommand command = getCommand(invocation.arguments()[0]);
|
||||||
if (command != null) {
|
if (command != null) {
|
||||||
CommandSender sender = new VelocityCommandSender(invocation.source());
|
|
||||||
if (!invocation.source().hasPermission(getCommand(invocation.arguments()[0]).getPermission())) {
|
if (!invocation.source().hasPermission(getCommand(invocation.arguments()[0]).getPermission())) {
|
||||||
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.getLocale()));
|
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.getLocale()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GeyserSession session = null;
|
if (command.isBedrockOnly() && session == null) {
|
||||||
if (command.isBedrockOnly()) {
|
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", sender.getLocale()));
|
||||||
session = getGeyserSession(sender);
|
return;
|
||||||
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]);
|
command.execute(session, sender, invocation.arguments().length > 1 ? Arrays.copyOfRange(invocation.arguments(), 1, invocation.arguments().length) : new String[0]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getCommand("help").execute(null, new VelocityCommandSender(invocation.source()), new String[0]);
|
getCommand("help").execute(session, sender, new String[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -46,6 +47,7 @@ public class CommandExecutor {
|
|||||||
return connector.getCommandManager().getCommands().get(label);
|
return connector.getCommandManager().getCommands().get(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public GeyserSession getGeyserSession(CommandSender sender) {
|
public GeyserSession getGeyserSession(CommandSender sender) {
|
||||||
if (sender.isConsole()) {
|
if (sender.isConsole()) {
|
||||||
return null;
|
return null;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren