From 05f1bf2135afd67026db8defdfeab49c221381a7 Mon Sep 17 00:00:00 2001 From: Eclipse Date: Fri, 6 Jun 2025 14:24:26 +0000 Subject: [PATCH] Add methods to open quick actions and pause screen additions dialog tags and add command to open quick actions dialog tag --- .../api/connection/GeyserConnection.java | 27 +++++++++++ .../geyser/command/CommandRegistry.java | 2 + .../defaults/CustomOptionsCommand.java | 19 +------- .../command/defaults/QuickActionsCommand.java | 48 +++++++++++++++++++ .../geyser/session/GeyserSession.java | 33 +++++++++++++ 5 files changed, 112 insertions(+), 17 deletions(-) create mode 100644 core/src/main/java/org/geysermc/geyser/command/defaults/QuickActionsCommand.java diff --git a/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java b/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java index ede4c1bc4..437b776a9 100644 --- a/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java +++ b/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java @@ -75,6 +75,33 @@ public interface GeyserConnection extends Connection, CommandSource { */ int protocolVersion(); + /** + * Tries to open the {@code minecraft:pause_screen_additions} dialog tag. This method opens this tag the same way Java does, that is: + * + * + * + *

This method returns {@code true} if a dialog was opened, and {@code false} otherwise.

+ */ + boolean openPauseScreenAdditions(); + + /** + * Tries to open the {@code minecraft:quick_actions} dialog tag. This method opens this tag the same way Java does, that is: + * + * + * + *

This method returns {@code true} if a dialog was opened, and {@code false} otherwise.

+ */ + boolean openQuickActions(); + /** * @param javaId the Java entity ID to look up. * @return a {@link GeyserEntity} if present in this connection's entity tracker. diff --git a/core/src/main/java/org/geysermc/geyser/command/CommandRegistry.java b/core/src/main/java/org/geysermc/geyser/command/CommandRegistry.java index dec837f55..057266ede 100644 --- a/core/src/main/java/org/geysermc/geyser/command/CommandRegistry.java +++ b/core/src/main/java/org/geysermc/geyser/command/CommandRegistry.java @@ -52,6 +52,7 @@ import org.geysermc.geyser.command.defaults.HelpCommand; import org.geysermc.geyser.command.defaults.ListCommand; import org.geysermc.geyser.command.defaults.OffhandCommand; import org.geysermc.geyser.command.defaults.PingCommand; +import org.geysermc.geyser.command.defaults.QuickActionsCommand; import org.geysermc.geyser.command.defaults.ReloadCommand; import org.geysermc.geyser.command.defaults.SettingsCommand; import org.geysermc.geyser.command.defaults.StatisticsCommand; @@ -165,6 +166,7 @@ public class CommandRegistry implements EventRegistrar { registerBuiltInCommand(new ConnectionTestCommand(geyser, "connectiontest", "geyser.commands.connectiontest.desc", "geyser.command.connectiontest")); registerBuiltInCommand(new PingCommand("ping", "geyser.commands.ping.desc", "geyser.command.ping")); registerBuiltInCommand(new CustomOptionsCommand("options", "Opens the custom options dialog provided by the server, if any", "geyser.command.options")); + registerBuiltInCommand(new QuickActionsCommand("quickactions", "Opens the quick actions dialog provided by the server, if any", "geyser.command.options")); if (this.geyser.getPlatformType() == PlatformType.STANDALONE) { registerBuiltInCommand(new StopCommand(geyser, "stop", "geyser.commands.stop.desc", "geyser.command.stop")); diff --git a/core/src/main/java/org/geysermc/geyser/command/defaults/CustomOptionsCommand.java b/core/src/main/java/org/geysermc/geyser/command/defaults/CustomOptionsCommand.java index c434ac5c4..49fdd3898 100644 --- a/core/src/main/java/org/geysermc/geyser/command/defaults/CustomOptionsCommand.java +++ b/core/src/main/java/org/geysermc/geyser/command/defaults/CustomOptionsCommand.java @@ -29,13 +29,8 @@ import net.kyori.adventure.text.Component; import org.geysermc.geyser.api.util.TriState; import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommandSource; -import org.geysermc.geyser.session.GeyserSession; -import org.geysermc.geyser.session.cache.tags.DialogTag; -import org.geysermc.geyser.session.dialog.BuiltInDialog; -import org.geysermc.geyser.session.dialog.Dialog; import org.incendo.cloud.context.CommandContext; -import java.util.List; import java.util.Objects; public class CustomOptionsCommand extends GeyserCommand { @@ -46,18 +41,8 @@ public class CustomOptionsCommand extends GeyserCommand { @Override public void execute(CommandContext context) { - GeyserSession session = Objects.requireNonNull(context.sender().connection()); - List additions = session.getTagCache().get(DialogTag.PAUSE_SCREEN_ADDITIONS); - if (additions.isEmpty()) { - if (session.getServerLinks().isEmpty()) { - context.sender().sendMessage(Component.text("The server has not provided any custom options")); - } else { - session.getDialogManager().openDialog(BuiltInDialog.SERVER_LINKS); - } - } else if (additions.size() == 1) { - session.getDialogManager().openDialog(additions.get(0)); - } else { - session.getDialogManager().openDialog(BuiltInDialog.CUSTOM_OPTIONS); + if (!Objects.requireNonNull(context.sender().connection()).openPauseScreenAdditions()) { + context.sender().sendMessage(Component.text("The server has not provided any custom options")); } } } diff --git a/core/src/main/java/org/geysermc/geyser/command/defaults/QuickActionsCommand.java b/core/src/main/java/org/geysermc/geyser/command/defaults/QuickActionsCommand.java new file mode 100644 index 000000000..2fbaf7c0e --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/command/defaults/QuickActionsCommand.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.command.defaults; + +import net.kyori.adventure.text.Component; +import org.geysermc.geyser.api.util.TriState; +import org.geysermc.geyser.command.GeyserCommand; +import org.geysermc.geyser.command.GeyserCommandSource; +import org.incendo.cloud.context.CommandContext; + +import java.util.Objects; + +public class QuickActionsCommand extends GeyserCommand { + + public QuickActionsCommand(String name, String description, String permission) { + super(name, description, permission, TriState.TRUE, true, true); + } + + @Override + public void execute(CommandContext context) { + if (!Objects.requireNonNull(context.sender().connection()).openQuickActions()) { + context.sender().sendMessage(Component.text("The server has not provided any quick actions")); + } + } +} diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index 009d3841d..722be5d9f 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -176,6 +176,9 @@ import org.geysermc.geyser.session.cache.TeleportCache; import org.geysermc.geyser.session.cache.WorldBorder; import org.geysermc.geyser.session.cache.WorldCache; import org.geysermc.geyser.session.cache.registry.JavaRegistries; +import org.geysermc.geyser.session.cache.tags.DialogTag; +import org.geysermc.geyser.session.dialog.BuiltInDialog; +import org.geysermc.geyser.session.dialog.Dialog; import org.geysermc.geyser.session.dialog.DialogManager; import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.translator.inventory.InventoryTranslator; @@ -1503,6 +1506,36 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { sendDownstreamGamePacket(new ServerboundChatCommandSignedPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), 0, new BitSet(), (byte) 0)); } + @Override + public boolean openPauseScreenAdditions() { + List additions = tagCache.get(DialogTag.PAUSE_SCREEN_ADDITIONS); + if (additions.isEmpty()) { + if (serverLinks.isEmpty()) { + return false; + } else { + dialogManager.openDialog(BuiltInDialog.SERVER_LINKS); + } + } else if (additions.size() == 1) { + dialogManager.openDialog(additions.get(0)); + } else { + dialogManager.openDialog(BuiltInDialog.CUSTOM_OPTIONS); + } + return true; + } + + @Override + public boolean openQuickActions() { + List quickActions = tagCache.get(DialogTag.QUICK_ACTIONS); + if (quickActions.isEmpty()) { + return false; + } else if (quickActions.size() == 1) { + dialogManager.openDialog(quickActions.get(0)); + } else { + dialogManager.openDialog(BuiltInDialog.QUICK_ACTIONS); + } + return true; + } + public void setClientRenderDistance(int clientRenderDistance) { boolean oldSquareToCircle = this.clientRenderDistance < this.serverRenderDistance; this.clientRenderDistance = clientRenderDistance;