1
0
mirror of https://github.com/GeyserMC/Geyser.git synced 2025-12-19 14:59:27 +00:00

Add methods to open quick actions and pause screen additions dialog tags and add command to open quick actions dialog tag

This commit is contained in:
Eclipse
2025-06-06 14:24:26 +00:00
parent 946c1615ea
commit 05f1bf2135
5 changed files with 112 additions and 17 deletions

View File

@@ -75,6 +75,33 @@ public interface GeyserConnection extends Connection, CommandSource {
*/ */
int protocolVersion(); 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:
*
* <ul>
* <li>If there are multiple dialogs in the additions tag, the {@code minecraft:custom_options} dialog is opened to select a dialog.</li>
* <li>If there is one dialog in the additions tag, that dialog is opened.</li>
* <li>If there are no dialogs in the tag, but there are server links sent to the client, the {@code minecraft:server_links} dialog is opened.</li>
* <li>If all of the above fails, no dialog is opened.</li>
* </ul>
*
* <p>This method returns {@code true} if a dialog was opened, and {@code false} otherwise.</p>
*/
boolean openPauseScreenAdditions();
/**
* Tries to open the {@code minecraft:quick_actions} dialog tag. This method opens this tag the same way Java does, that is:
*
* <ul>
* <li>If there are multiple dialogs in the actions tag, the {@code minecraft:quick_actions} dialog is opened to select a dialog.</li>
* <li>If there is one dialog in the actions tag, that dialog is opened.</li>
* <li>If there are no dialogs in the tag, no dialog is opened.</li>
* </ul>
*
* <p>This method returns {@code true} if a dialog was opened, and {@code false} otherwise.</p>
*/
boolean openQuickActions();
/** /**
* @param javaId the Java entity ID to look up. * @param javaId the Java entity ID to look up.
* @return a {@link GeyserEntity} if present in this connection's entity tracker. * @return a {@link GeyserEntity} if present in this connection's entity tracker.

View File

@@ -52,6 +52,7 @@ import org.geysermc.geyser.command.defaults.HelpCommand;
import org.geysermc.geyser.command.defaults.ListCommand; import org.geysermc.geyser.command.defaults.ListCommand;
import org.geysermc.geyser.command.defaults.OffhandCommand; import org.geysermc.geyser.command.defaults.OffhandCommand;
import org.geysermc.geyser.command.defaults.PingCommand; 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.ReloadCommand;
import org.geysermc.geyser.command.defaults.SettingsCommand; import org.geysermc.geyser.command.defaults.SettingsCommand;
import org.geysermc.geyser.command.defaults.StatisticsCommand; 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 ConnectionTestCommand(geyser, "connectiontest", "geyser.commands.connectiontest.desc", "geyser.command.connectiontest"));
registerBuiltInCommand(new PingCommand("ping", "geyser.commands.ping.desc", "geyser.command.ping")); 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 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) { if (this.geyser.getPlatformType() == PlatformType.STANDALONE) {
registerBuiltInCommand(new StopCommand(geyser, "stop", "geyser.commands.stop.desc", "geyser.command.stop")); registerBuiltInCommand(new StopCommand(geyser, "stop", "geyser.commands.stop.desc", "geyser.command.stop"));

View File

@@ -29,13 +29,8 @@ import net.kyori.adventure.text.Component;
import org.geysermc.geyser.api.util.TriState; import org.geysermc.geyser.api.util.TriState;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.command.GeyserCommandSource; 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 org.incendo.cloud.context.CommandContext;
import java.util.List;
import java.util.Objects; import java.util.Objects;
public class CustomOptionsCommand extends GeyserCommand { public class CustomOptionsCommand extends GeyserCommand {
@@ -46,18 +41,8 @@ public class CustomOptionsCommand extends GeyserCommand {
@Override @Override
public void execute(CommandContext<GeyserCommandSource> context) { public void execute(CommandContext<GeyserCommandSource> context) {
GeyserSession session = Objects.requireNonNull(context.sender().connection()); if (!Objects.requireNonNull(context.sender().connection()).openPauseScreenAdditions()) {
List<Dialog> 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")); 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);
} }
} }
} }

View File

@@ -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<GeyserCommandSource> context) {
if (!Objects.requireNonNull(context.sender().connection()).openQuickActions()) {
context.sender().sendMessage(Component.text("The server has not provided any quick actions"));
}
}
}

View File

@@ -176,6 +176,9 @@ import org.geysermc.geyser.session.cache.TeleportCache;
import org.geysermc.geyser.session.cache.WorldBorder; import org.geysermc.geyser.session.cache.WorldBorder;
import org.geysermc.geyser.session.cache.WorldCache; import org.geysermc.geyser.session.cache.WorldCache;
import org.geysermc.geyser.session.cache.registry.JavaRegistries; 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.session.dialog.DialogManager;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.translator.inventory.InventoryTranslator; 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)); sendDownstreamGamePacket(new ServerboundChatCommandSignedPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), 0, new BitSet(), (byte) 0));
} }
@Override
public boolean openPauseScreenAdditions() {
List<Dialog> 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<Dialog> 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) { public void setClientRenderDistance(int clientRenderDistance) {
boolean oldSquareToCircle = this.clientRenderDistance < this.serverRenderDistance; boolean oldSquareToCircle = this.clientRenderDistance < this.serverRenderDistance;
this.clientRenderDistance = clientRenderDistance; this.clientRenderDistance = clientRenderDistance;