mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Update command handling
This commit is contained in:
parent
24da65dcb5
commit
c3569093b6
3 changed files with 27 additions and 24 deletions
|
@ -149,11 +149,12 @@ public class GeyserFabricMod implements ModInitializer, GeyserBootstrap {
|
||||||
// Start command building
|
// Start command building
|
||||||
// Set just "geyser" as the help command
|
// Set just "geyser" as the help command
|
||||||
LiteralArgumentBuilder<ServerCommandSource> builder = net.minecraft.server.command.CommandManager.literal("geyser")
|
LiteralArgumentBuilder<ServerCommandSource> builder = net.minecraft.server.command.CommandManager.literal("geyser")
|
||||||
.executes(new GeyserFabricCommandExecutor(connector, "help", !playerCommands.contains("help")));
|
.executes(new GeyserFabricCommandExecutor(connector, connector.getCommandManager().getCommands().get("help"),
|
||||||
|
!playerCommands.contains("help")));
|
||||||
for (Map.Entry<String, GeyserCommand> command : connector.getCommandManager().getCommands().entrySet()) {
|
for (Map.Entry<String, GeyserCommand> command : connector.getCommandManager().getCommands().entrySet()) {
|
||||||
// Register all subcommands as valid
|
// Register all subcommands as valid
|
||||||
builder.then(net.minecraft.server.command.CommandManager.literal(
|
builder.then(net.minecraft.server.command.CommandManager.literal(
|
||||||
command.getKey()).executes(new GeyserFabricCommandExecutor(connector, command.getKey(),
|
command.getKey()).executes(new GeyserFabricCommandExecutor(connector, command.getValue(),
|
||||||
!playerCommands.contains(command.getKey()))));
|
!playerCommands.contains(command.getKey()))));
|
||||||
}
|
}
|
||||||
server.getCommandManager().getDispatcher().register(builder);
|
server.getCommandManager().getDispatcher().register(builder);
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
|
|
||||||
package org.geysermc.platform.fabric.command;
|
package org.geysermc.platform.fabric.command;
|
||||||
|
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.command.CommandSender;
|
import org.geysermc.connector.command.CommandSender;
|
||||||
|
@ -47,20 +47,15 @@ public class FabricCommandSender implements CommandSender {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(String message) {
|
public void sendMessage(String message) {
|
||||||
try {
|
if (source.getEntity() instanceof ServerPlayerEntity) {
|
||||||
source.getPlayer().sendMessage(new LiteralText(message), false);
|
((ServerPlayerEntity) source.getEntity()).sendMessage(new LiteralText(message), false);
|
||||||
} catch (CommandSyntaxException e) { // why
|
} else {
|
||||||
GeyserConnector.getInstance().getLogger().info(ChatColor.toANSI(message + ChatColor.RESET));
|
GeyserConnector.getInstance().getLogger().info(ChatColor.toANSI(message + ChatColor.RESET));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConsole() {
|
public boolean isConsole() {
|
||||||
try {
|
return !(source.getEntity() instanceof ServerPlayerEntity);
|
||||||
source.getPlayer();
|
|
||||||
return false;
|
|
||||||
} catch (CommandSyntaxException e) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,22 +29,24 @@ import com.mojang.brigadier.Command;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
|
import org.geysermc.connector.command.CommandExecutor;
|
||||||
import org.geysermc.connector.command.GeyserCommand;
|
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.geysermc.connector.utils.LanguageUtils;
|
||||||
import org.geysermc.platform.fabric.GeyserFabricMod;
|
import org.geysermc.platform.fabric.GeyserFabricMod;
|
||||||
|
|
||||||
public class GeyserFabricCommandExecutor implements Command<ServerCommandSource> {
|
public class GeyserFabricCommandExecutor extends CommandExecutor implements Command<ServerCommandSource> {
|
||||||
|
|
||||||
private final String commandName;
|
private final GeyserCommand command;
|
||||||
private final GeyserConnector connector;
|
|
||||||
/**
|
/**
|
||||||
* Whether the command requires an OP permission level of 2 or greater
|
* Whether the command requires an OP permission level of 2 or greater
|
||||||
*/
|
*/
|
||||||
private final boolean requiresPermission;
|
private final boolean requiresPermission;
|
||||||
|
|
||||||
public GeyserFabricCommandExecutor(GeyserConnector connector, String commandName, boolean requiresPermission) {
|
public GeyserFabricCommandExecutor(GeyserConnector connector, GeyserCommand command, boolean requiresPermission) {
|
||||||
this.commandName = commandName;
|
super(connector);
|
||||||
this.connector = connector;
|
this.command = command;
|
||||||
this.requiresPermission = requiresPermission;
|
this.requiresPermission = requiresPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,14 +58,19 @@ public class GeyserFabricCommandExecutor implements Command<ServerCommandSource>
|
||||||
sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.bootstrap.command.permission_fail"));
|
sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.bootstrap.command.permission_fail"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (this.commandName.equals("reload")) {
|
if (this.command.getName().equals("reload")) {
|
||||||
GeyserFabricMod.getInstance().setReloading(true);
|
GeyserFabricMod.getInstance().setReloading(true);
|
||||||
}
|
}
|
||||||
getCommand(commandName).execute(sender, 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 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private GeyserCommand getCommand(String label) {
|
command.execute(session, sender, new String[0]);
|
||||||
return connector.getCommandManager().getCommands().get(label);
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue