Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build and test

on:
push:
branches: ["master", "codex/**"]
pull_request:
branches: ["master"]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Java 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21"
cache: gradle
- name: Make Gradle wrapper executable
run: chmod +x ./gradlew
- name: Test and build all plugin variants
run: ./gradlew --no-daemon clean test shadowJar
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ Requires a JDK 21 toolchain. Artifacts land in each module's `build/libs/` (`Gey

### Java features
- [Geyser Recipe Fix](https://modrinth.com/plugin/geyser-recipe-fix) - Fixes smithing table recipes to work properly on Bedrock


## Server owner customization

GeyserPlus supports configurable menu titles, form content, button visibility, disabled-state labels/icons/messages, icon paths or URLs, ordering, settings-section buttons, and translation-key overrides. See [the server menu customization guide](docs/server-menu-customization.md) for all keys and examples.
4 changes: 4 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
implementation("org.spongepowered:configurate-yaml:4.2.0-GeyserMC-SNAPSHOT")
shadow("org.spongepowered:configurate-yaml:4.2.0-GeyserMC-SNAPSHOT")
implementation("com.fasterxml.jackson.core:jackson-annotations:2.17.0")
Expand Down Expand Up @@ -28,3 +29,6 @@ tasks {
}
}

tasks.test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,34 @@ public void onDisconnect() {
}

public void reconnect() {
session.transfer(session.joinAddress(), session.joinPort());
GeyserSession current = this.session;
if (current == null) {
SERVER.warn("Skipped GeyserPlus reconnect because the Geyser session is unavailable.");
return;
}

final String address;
final int port;
try {
// joinAddress/joinPort rely on the upstream login data; disconnect and shutdown events
// can run before that data exists (including the Education Edition failure path).
address = current.joinAddress();
port = current.joinPort();
} catch (RuntimeException exception) {
SERVER.debugWarn("Skipped GeyserPlus reconnect because the upstream address is not available yet.");
return;
}

if (address == null || address.isBlank() || port < 1 || port > 65535) {
SERVER.warn("Skipped GeyserPlus reconnect because the upstream address or port is invalid.");
return;
}

try {
current.transfer(address.trim(), port);
} catch (RuntimeException exception) {
SERVER.warn("GeyserPlus could not start the reconnect transfer: " + exception.getClass().getSimpleName());
}
}


Expand Down Expand Up @@ -280,14 +307,18 @@ public void swingArm() {
}

public String translate(String lang) {
return MinecraftLocale.getLocaleString(lang, session.locale());
String translated = MinecraftLocale.getLocaleString(lang, session.locale());
return GE.getConfig() == null ? translated : GE.getConfig().textOverride(lang, translated);
}

public String translateGE(String lang) {
return GELocale.translate(lang, session.locale());
String translated = GELocale.translate(lang, session.locale());
return GE.getConfig() == null ? translated : GE.getConfig().textOverride(lang, translated);
}

public String translateOtherwiseGE(String lang, String otherwise) {
return GELocale.translateOtherwise(lang, otherwise, session.locale());
String translated = GELocale.translateOtherwise(lang, otherwise, session.locale());
return GE.getConfig() == null ? translated : GE.getConfig().textOverride(lang, translated);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class ConfigLoader {

public static final int LATEST_VERSION = 4;
public static final int LATEST_VERSION = 6;
private static final String HEADER = """
GeyserExtras
If Geyser is detected, all required config changes will be automatically applied.
Expand All @@ -30,6 +30,7 @@ public class ConfigLoader {
.addVersion(3, twoToThree())
.addVersion(4, threeToFour())
.addVersion(5, fourToFive())
.addVersion(6, fiveToSix())

.build();

Expand Down Expand Up @@ -132,4 +133,9 @@ private static ConfigurationTransformation fourToFive() {
.addAction(NodePath.path("enable-custom-cooldown"), TransformAction.remove())
.build();
}

// Menu customization adds only optional values; default values keep existing installations unchanged.
private static ConfigurationTransformation fiveToSix() {
return ConfigurationTransformation.builder().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@SuppressWarnings("FieldMayBeFinal")
@ConfigSerializable
Expand Down Expand Up @@ -130,6 +132,126 @@ The language that Java Edition players read when using a GeyserExtras command (e
@Comment("Only enable if you know what you are doing.")
private boolean debugMode = false;

@Comment("""
Owner-facing menu customization. Titles left blank keep GeyserExtras' translated default.
Menu button keys: swap-offhand, reconnect, settings, advancements, statistics, player-list,
server-links, resource-packs. Set enabled=false to hide an entry. Set disabled=true to show
the configured disabled label/icon without running its action. sort-order controls button order.
Image types are PATH, URL, or NONE. URL icons must be reachable by the Bedrock client.
""")
private MenuSettings menus = new MenuSettings();

public MenuSettings menuSettings() {
if (menus == null) menus = new MenuSettings();
return menus;
}

public String menuTitle(String key, String fallback) {
return menuSettings().title(key, fallback);
}

public String menuContent(String key, String fallback) {
return menuSettings().content(key, fallback);
}

public String textOverride(String key, String fallback) {
return menuSettings().text(key, fallback);
}

@ConfigSerializable
@Getter
public static final class MenuSettings {
@Comment("Override menu titles by key. Supported keys include main, settings, settings.ingame, packs, server-links, player-list.")
private Map<String, String> titleOverrides = new LinkedHashMap<>();

@Comment("Main menu description/content. Leave blank to keep it empty.")
private String mainContent = "";

@Comment("Content/header overrides by menu key. Missing or blank entries preserve the built-in text.")
private Map<String, String> contentOverrides = new LinkedHashMap<>();

@Comment("Overrides any string passed through ExtrasPlayer.translate/translateGE, keyed by its translation key.")
private Map<String, String> textOverrides = new LinkedHashMap<>();

@Comment("Main menu button overrides. Missing entries use built-in defaults.")
private Map<String, MenuButtonConfig> buttons = defaultButtons();

public String title(String key, String fallback) {
if (titleOverrides == null) return fallback;
String value = titleOverrides.get(key);
return value == null || value.isBlank() ? fallback : value;
}

public String content(String key, String fallback) {
if (contentOverrides != null) {
String value = contentOverrides.get(key);
if (value != null && !value.isBlank()) return value;
}
return fallback == null ? "" : fallback;
}

public String text(String key, String fallback) {
if (textOverrides != null) {
String value = textOverrides.get(key);
if (value != null && !value.isBlank()) return value;
}
return fallback == null ? "" : fallback;
}

public MenuButtonConfig button(String key, int fallbackOrder, String fallbackImageType, String fallbackImage) {
MenuButtonConfig value = buttons == null ? null : buttons.get(key);
return value == null ? MenuButtonConfig.defaults(fallbackOrder, fallbackImageType, fallbackImage) : value;
}

private static Map<String, MenuButtonConfig> defaultButtons() {
Map<String, MenuButtonConfig> values = new LinkedHashMap<>();
values.put("swap-offhand", MenuButtonConfig.defaults(10, "PATH", "textures/ui/move.png"));
values.put("reconnect", MenuButtonConfig.defaults(20, "PATH", "textures/ui/refresh_hover.png"));
values.put("settings", MenuButtonConfig.defaults(30, "PATH", "textures/ui/settings_glyph_color_2x.png"));
values.put("advancements", MenuButtonConfig.defaults(40, "PATH", "textures/ui/achievements.png"));
values.put("statistics", MenuButtonConfig.defaults(50, "PATH", "textures/ui/world_glyph_color_2x_black_outline.png"));
values.put("player-list", MenuButtonConfig.defaults(60, "PATH", "textures/ui/Local.png"));
values.put("server-links", MenuButtonConfig.defaults(70, "PATH", "textures/ui/external_link.png"));
values.put("resource-packs", MenuButtonConfig.defaults(80, "PATH", "textures/ui/glyph_resource_pack.png"));
return values;
}
}

@ConfigSerializable
@Getter
public static final class MenuButtonConfig {
@Comment("Set false to hide this button completely.")
private boolean enabled = true;
@Comment("Show the button as disabled. Its normal action will not run.")
private boolean disabled = false;
@Comment("Show a disabled placeholder when the feature is unavailable (for example, no server links exist).")
private boolean showWhenUnavailable = false;
@Comment("Sort order; lower numbers appear first.")
private int sortOrder = Integer.MIN_VALUE;
@Comment("Label override. Blank keeps the translated built-in label.")
private String title = "";
@Comment("Icon type: PATH, URL, or NONE. Blank keeps the built-in icon type.")
private String imageType = "";
@Comment("Icon value/path/URL. Blank keeps the built-in icon.")
private String image = "";
@Comment("Label shown while disabled. Blank generates a disabled label from the normal title.")
private String disabledTitle = "";
@Comment("Disabled icon type: PATH, URL, or NONE. Blank keeps the normal icon type.")
private String disabledImageType = "";
@Comment("Disabled icon value/path/URL. Blank keeps the normal icon.")
private String disabledImage = "";
@Comment("Message sent when a disabled button is clicked. Blank makes the disabled button silent.")
private String disabledMessage = "This option is currently unavailable.";

private static MenuButtonConfig defaults(int order, String imageType, String image) {
MenuButtonConfig value = new MenuButtonConfig();
value.sortOrder = order;
value.imageType = imageType;
value.image = image;
return value;
}
}

@Comment("The version of the config. DO NOT CHANGE!")
private int version = ConfigLoader.LATEST_VERSION;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.geysermc.cumulus.form.SimpleForm;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class BedrockMenu {
Expand All @@ -31,21 +32,35 @@ public void onButtonClick(ExtrasPlayer player) {
}

public BedrockMenu add(Button button) {
buttons.add(button);
if (button != null) {
if (button.getSortOrder() == Integer.MIN_VALUE) {
button.setSortOrder(buttons.size() * 10);
}
buttons.add(button);
}
return this;
}

public SimpleForm create(ExtrasPlayer player) {
simpleForm = SimpleForm.builder();
simpleForm.title(this.title)
.content(this.header);
for (Button button : buttons) {
List<Button> orderedButtons = new ArrayList<>(buttons);
orderedButtons.sort(Comparator.comparingInt(Button::getSortOrder));
for (Button button : orderedButtons) {
simpleForm.button(button.get());
}
simpleForm.validResultHandler(response -> {
for (Button button : buttons) {
if (response.clickedButtonId() == buttons.indexOf(button)) {
button.onSelect.run();
int clicked = response.clickedButtonId();
if (clicked < 0 || clicked >= orderedButtons.size()) {
// Ignore malformed button IDs without invoking close handlers or menu actions.
return;
}
Button button = orderedButtons.get(clicked);
if (button.onSelect != null) {
button.onSelect.run();
// A visually disabled button must not trigger menu-specific post-click actions.
if (!button.isDisabled()) {
onButtonClick(player);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class Button extends FormElement {
public FormImage.Type type;
public String data;
public Runnable onSelect;
private int sortOrder = Integer.MIN_VALUE;
private boolean disabled;

public Button(String text, FormImage.Type type, String data, Runnable onSelect) {
this.text = text;
Expand All @@ -38,6 +40,24 @@ public void resultRecieved(Object... args) {

}

public int getSortOrder() {
return sortOrder;
}

public Button setSortOrder(int sortOrder) {
this.sortOrder = sortOrder;
return this;
}

public boolean isDisabled() {
return disabled;
}

public Button setDisabled(boolean disabled) {
this.disabled = disabled;
return this;
}

public ButtonComponent get() {
if (this.type != null && this.data != null) {
return ButtonComponent.of(this.text, this.type, this.data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
public class JavaDisconnectInjector extends PacketTranslator<ClientboundDisconnectPacket> {
@Override
public void translate(GeyserSession session, ClientboundDisconnectPacket packet) {
if (GE.getConfig().isAutoReconnect()) {
if (GE.getConfig() != null && GE.getConfig().isAutoReconnect()) {
ExtrasPlayer player = ExtrasPlayer.get(session);
if (player == null) {
return;
}

player.sendToast("", MessageTranslator.convertMessage(packet.getReason(), session.locale()));

player.reconnect();
}
}
Expand Down
Loading
Loading