From fe63665d8818af2836e9db3447f8625d49beaeb6 Mon Sep 17 00:00:00 2001 From: Kas-tle <26531652+Kas-tle@users.noreply.github.com> Date: Tue, 28 May 2024 00:11:05 -0700 Subject: [PATCH 1/3] Composite gradle setup and artifact archival (#4696) * Composite gradle setup and artifact archival * Remove 'geyser' path for PRs * Move upload-preview workflow --- .github/workflows/build-remote.yml | 85 +++++-------------------- .github/workflows/build.yml | 86 +++++--------------------- .github/workflows/dispatch-preview.yml | 33 ++++++++++ .github/workflows/preview.yml | 83 ------------------------- .github/workflows/pull-request.yml | 16 ++++- 5 files changed, 77 insertions(+), 226 deletions(-) create mode 100644 .github/workflows/dispatch-preview.yml delete mode 100644 .github/workflows/preview.yml diff --git a/.github/workflows/build-remote.yml b/.github/workflows/build-remote.yml index c815b4740..7cb89cc61 100644 --- a/.github/workflows/build-remote.yml +++ b/.github/workflows/build-remote.yml @@ -22,81 +22,26 @@ jobs: run: | echo "BUILD_NUMBER=${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV - - name: Setup Java - # See https://github.com/actions/setup-java/commits - uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 - with: - java-version: 21 - distribution: temurin - - - name: Checkout repository and submodules - # See https://github.com/actions/checkout/commits - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 - with: - repository: ${{ inputs.repository }} - ref: ${{ inputs.ref }} - submodules: recursive - - - name: Validate Gradle Wrapper - # See https://github.com/gradle/wrapper-validation-action/commits - uses: gradle/actions/wrapper-validation@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 - - name: Setup Gradle - # See https://github.com/gradle/actions/commits - uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 + uses: GeyserMC/actions/setup-gradle-composite@master with: - cache-read-only: true + checkout_repository: ${{ inputs.repository }} + checkout_ref: ${{ inputs.ref }} + setup-java_java-version: 21 + setup-gradle_cache-read-only: true - name: Build Geyser run: ./gradlew build - - name: Archive artifacts (Geyser Fabric) - # See https://github.com/actions/upload-artifact/commits - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 + - name: Archive Artifacts + uses: GeyserMC/actions/upload-multi-artifact@master if: success() with: - name: Geyser Fabric - path: geyser/bootstrap/mod/fabric/build/libs/Geyser-Fabric.jar - if-no-files-found: error - - name: Archive artifacts (Geyser NeoForge) - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 - if: success() - with: - name: Geyser NeoForge - path: geyser/bootstrap/mod/neoforge/build/libs/Geyser-NeoForge.jar - if-no-files-found: error - - name: Archive artifacts (Geyser Standalone) - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 - if: success() - with: - name: Geyser Standalone - path: geyser/bootstrap/standalone/build/libs/Geyser-Standalone.jar - if-no-files-found: error - - name: Archive artifacts (Geyser Spigot) - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 - if: success() - with: - name: Geyser Spigot - path: geyser/bootstrap/spigot/build/libs/Geyser-Spigot.jar - if-no-files-found: error - - name: Archive artifacts (Geyser BungeeCord) - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 - if: success() - with: - name: Geyser BungeeCord - path: geyser/bootstrap/bungeecord/build/libs/Geyser-BungeeCord.jar - if-no-files-found: error - - name: Archive artifacts (Geyser Velocity) - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 - if: success() - with: - name: Geyser Velocity - path: geyser/bootstrap/velocity/build/libs/Geyser-Velocity.jar - if-no-files-found: error - - name: Archive artifacts (Geyser ViaProxy) - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 - if: success() - with: - name: Geyser ViaProxy - path: geyser/bootstrap/viaproxy/build/libs/Geyser-ViaProxy.jar - if-no-files-found: error \ No newline at end of file + artifacts: | + bootstrap/mod/fabric/build/libs/Geyser-Fabric.jar + bootstrap/mod/neoforge/build/libs/Geyser-NeoForge.jar + bootstrap/standalone/build/libs/Geyser-Standalone.jar + bootstrap/spigot/build/libs/Geyser-Spigot.jar + bootstrap/bungeecord/build/libs/Geyser-BungeeCord.jar + bootstrap/velocity/build/libs/Geyser-Velocity.jar + bootstrap/viaproxy/build/libs/Geyser-ViaProxy.jar \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f2f2a2c82..b8f855a53 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,84 +28,28 @@ jobs: with: data: ${{ vars.RELEASEACTION_PREVRELEASE }} - - name: Checkout repository and submodules - # See https://github.com/actions/checkout/commits - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 - with: - submodules: recursive - - - name: Validate Gradle Wrapper - # See https://github.com/gradle/actions/commits - uses: gradle/actions/wrapper-validation@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 - - # See https://github.com/actions/setup-java/commits - - name: Setup Java - uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 - with: - java-version: 21 - distribution: temurin - - name: Setup Gradle - # See https://github.com/gradle/actions/commits - uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 + uses: GeyserMC/actions/setup-gradle-composite@master with: - gradle-home-cache-cleanup: true + setup-java_java-version: 21 - name: Build Geyser run: ./gradlew build env: BUILD_NUMBER: ${{ steps.release-info.outputs.curentRelease }} - - name: Archive artifacts (Geyser Fabric) - # See https://github.com/actions/upload-artifact/commits - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 + - name: Archive Artifacts + uses: GeyserMC/actions/upload-multi-artifact@master if: success() with: - name: Geyser Fabric - path: bootstrap/mod/fabric/build/libs/Geyser-Fabric.jar - if-no-files-found: error - - name: Archive artifacts (Geyser NeoForge) - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 - if: success() - with: - name: Geyser NeoForge - path: bootstrap/mod/neoforge/build/libs/Geyser-NeoForge.jar - if-no-files-found: error - - name: Archive artifacts (Geyser Standalone) - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 - if: success() - with: - name: Geyser Standalone - path: bootstrap/standalone/build/libs/Geyser-Standalone.jar - if-no-files-found: error - - name: Archive artifacts (Geyser Spigot) - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 - if: success() - with: - name: Geyser Spigot - path: bootstrap/spigot/build/libs/Geyser-Spigot.jar - if-no-files-found: error - - name: Archive artifacts (Geyser BungeeCord) - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 - if: success() - with: - name: Geyser BungeeCord - path: bootstrap/bungeecord/build/libs/Geyser-BungeeCord.jar - if-no-files-found: error - - name: Archive artifacts (Geyser Velocity) - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 - if: success() - with: - name: Geyser Velocity - path: bootstrap/velocity/build/libs/Geyser-Velocity.jar - if-no-files-found: error - - name: Archive artifacts (Geyser ViaProxy) - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 - if: success() - with: - name: Geyser ViaProxy - path: bootstrap/viaproxy/build/libs/Geyser-ViaProxy.jar - if-no-files-found: error + artifacts: | + bootstrap/mod/fabric/build/libs/Geyser-Fabric.jar + bootstrap/mod/neoforge/build/libs/Geyser-NeoForge.jar + bootstrap/standalone/build/libs/Geyser-Standalone.jar + bootstrap/spigot/build/libs/Geyser-Spigot.jar + bootstrap/bungeecord/build/libs/Geyser-BungeeCord.jar + bootstrap/velocity/build/libs/Geyser-Velocity.jar + bootstrap/viaproxy/build/libs/Geyser-ViaProxy.jar - name: Publish to Maven Repository if: ${{ success() && github.repository == 'GeyserMC/Geyser' && github.ref_name == 'master' }} @@ -116,14 +60,14 @@ jobs: ORG_GRADLE_PROJECT_geysermcPassword: ${{ secrets.DEPLOY_PASS }} - name: Get Version - if: ${{ success() && github.repository == 'GeyserMC/Geyser' && github.ref_name == 'master' }} + if: ${{ (success() || failure()) && github.repository == 'GeyserMC/Geyser' }} id: get-version run: | version=$(cat gradle.properties | grep -o "version=[0-9\\.]*" | cut -d"=" -f2) echo "VERSION=${version}" >> $GITHUB_OUTPUT - name: Get Release Metadata - if: ${{ success() && github.repository == 'GeyserMC/Geyser' && github.ref_name == 'master' }} + if: ${{ (success() || failure()) && github.repository == 'GeyserMC/Geyser' }} uses: GeyserMC/actions/release@master id: metadata with: @@ -141,6 +85,7 @@ jobs: saveMetadata: true releaseProject: 'geyser' releaseVersion: ${{ steps.get-version.outputs.VERSION }} + - name: Publish to Downloads API if: ${{ success() && github.repository == 'GeyserMC/Geyser' && github.ref_name == 'master' }} uses: GeyserMC/actions/upload-release@master @@ -156,6 +101,7 @@ jobs: bootstrap/standalone/build/libs/Geyser-Standalone.jar bootstrap/velocity/build/libs/Geyser-Velocity.jar bootstrap/viaproxy/build/libs/Geyser-ViaProxy.jar + changelog: ${{ steps.metadata.outputs.body }} - name: Publish to Modrinth (Fabric) if: ${{ success() && github.repository == 'GeyserMC/Geyser' && github.ref_name == 'master' }} diff --git a/.github/workflows/dispatch-preview.yml b/.github/workflows/dispatch-preview.yml new file mode 100644 index 000000000..83df08e37 --- /dev/null +++ b/.github/workflows/dispatch-preview.yml @@ -0,0 +1,33 @@ +name: Dispatch Preview + +on: + workflow_dispatch: + inputs: + runId: + required: true + description: 'ID of the action to pull artifacts from' + build: + required: true + description: 'Build number for the release' + version: + required: true + description: 'Version under which to upload to the Downloads API' + +jobs: + dispatch-preview: + # Allow access to secrets if we are uploading a preview + secrets: inherit + uses: GeyserMC/actions/.github/workflows/upload-preview.yml@master + with: + build: ${{ inputs.build }} + version: ${{ inputs.version }} + files: | + bungeecord:Geyser-BungeeCord.jar + fabric:Geyser-Fabric.jar + neoforge:Geyser-NeoForge.jar + spigot:Geyser-Spigot.jar + standalone:Geyser-Standalone.jar + velocity:Geyser-Velocity.jar + viaproxy:Geyser-ViaProxy.jar + project: geyserpreview + runId: ${{ inputs.runId }} \ No newline at end of file diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml deleted file mode 100644 index a90d60ef7..000000000 --- a/.github/workflows/preview.yml +++ /dev/null @@ -1,83 +0,0 @@ -name: Upload Preview - -on: - workflow_dispatch: - inputs: - runId: - required: true - description: 'ID of the action to pull artifacts from' - build: - required: true - description: 'Build number for the release' - version: - required: true - description: 'Version under which to upload to the Downloads API' - workflow_call: - inputs: - build: - required: true - description: 'Build number for the release' - type: string - version: - required: true - description: 'Version under which to upload to the Downloads API' - type: string - -jobs: - upload: - runs-on: ubuntu-latest - steps: - - name: Set Variables - id: setvars - run: | - if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then - echo "BUILD=${{ github.event.inputs.build }}" >> $GITHUB_ENV - echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT - echo "RUN=${{ github.event.inputs.runId }}" >> $GITHUB_OUTPUT - else - echo "BUILD=${{ inputs.build }}" >> $GITHUB_ENV - echo "VERSION=${{ inputs.version }}" >> $GITHUB_OUTPUT - echo "RUN=${{ github.run_id }}" >> $GITHUB_OUTPUT - fi - - name: Download Artifacts - # See https://github.com/actions/download-artifact/commits - uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.6 - with: - run-id: ${{ steps.setvars.outputs.RUN }} - github-token: ${{ secrets.GITHUB_TOKEN }} - merge-multiple: true - - name: Get Preview Metadata - if: success() - uses: GeyserMC/actions/release@master - id: metadata - with: - appID: ${{ secrets.RELEASE_APP_ID }} - appPrivateKey: ${{ secrets.RELEASE_APP_PK }} - files: | - bungeecord:Geyser-BungeeCord.jar - fabric:Geyser-Fabric.jar - neoforge:Geyser-NeoForge.jar - spigot:Geyser-Spigot.jar - standalone:Geyser-Standalone.jar - velocity:Geyser-Velocity.jar - viaproxy:Geyser-ViaProxy.jar - releaseEnabled: false - saveMetadata: true - updateReleaseData: false - releaseProject: 'geyserpreview' - releaseVersion: ${{ steps.setvars.outputs.VERSION }} - - name: Publish to Downloads API - if: success() - uses: GeyserMC/actions/upload-release@master - with: - username: ${{ vars.DOWNLOADS_USERNAME }} - privateKey: ${{ secrets.DOWNLOADS_PRIVATE_KEY }} - host: ${{ secrets.DOWNLOADS_SERVER_IP }} - files: | - Geyser-BungeeCord.jar - Geyser-Fabric.jar - Geyser-NeoForge.jar - Geyser-Spigot.jar - Geyser-Standalone.jar - Geyser-Velocity.jar - Geyser-ViaProxy.jar diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index bc5e57b6b..6167bb18e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -8,7 +8,7 @@ jobs: # Forbid access to secrets nor GH Token perms while building the PR permissions: {} secrets: {} - uses: ./.github/workflows/build-remote.yml + uses: GeyserMC/Geyser/.github/workflows/build-remote.yml@master with: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.event.pull_request.head.sha }} @@ -18,7 +18,17 @@ jobs: contains(github.event.pull_request.labels.*.name, 'PR: Needs Testing') # Allow access to secrets if we are uploading a preview secrets: inherit - uses: ./.github/workflows/preview.yml + uses: GeyserMC/actions/.github/workflows/upload-preview.yml@master with: build: ${{ github.run_number }} - version: pr.${{ github.event.pull_request.number }} \ No newline at end of file + version: pr.${{ github.event.pull_request.number }} + files: | + bungeecord:Geyser-BungeeCord.jar + fabric:Geyser-Fabric.jar + neoforge:Geyser-NeoForge.jar + spigot:Geyser-Spigot.jar + standalone:Geyser-Standalone.jar + velocity:Geyser-Velocity.jar + viaproxy:Geyser-ViaProxy.jar + project: geyserpreview + runId: ${{ github.run_id }} \ No newline at end of file From 0fcf0f9b4f62e4b0deb03678f029f60b2112ae8b Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 28 May 2024 17:23:19 +0200 Subject: [PATCH 2/3] Update Bungee version check, create logger earlier (#4697) * use the logger where possible instead of system.out.print * make loggers final * yeet unused constructors * velocity is more complicated --- .../bungeecord/GeyserBungeeLogger.java | 7 +-- .../bungeecord/GeyserBungeePlugin.java | 23 +++++----- .../platform/mod/GeyserModBootstrap.java | 7 ++- .../geyser/platform/mod/GeyserModLogger.java | 4 -- .../platform/spigot/GeyserPaperLogger.java | 4 +- .../platform/spigot/GeyserSpigotLogger.java | 4 +- .../platform/spigot/GeyserSpigotPlugin.java | 43 +++++++++---------- .../standalone/GeyserStandaloneBootstrap.java | 4 +- .../velocity/GeyserVelocityLogger.java | 4 +- .../velocity/GeyserVelocityPlugin.java | 38 ++++++++-------- .../java/org/geysermc/geyser/GeyserImpl.java | 1 + .../geysermc/geyser/text/GeyserLocale.java | 11 ++--- 12 files changed, 67 insertions(+), 83 deletions(-) diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeLogger.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeLogger.java index daeb20102..e8cf7ee39 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeLogger.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeLogger.java @@ -26,22 +26,19 @@ package org.geysermc.geyser.platform.bungeecord; import lombok.Getter; +import lombok.RequiredArgsConstructor; import lombok.Setter; import org.geysermc.geyser.GeyserLogger; import java.util.logging.Level; import java.util.logging.Logger; +@RequiredArgsConstructor public class GeyserBungeeLogger implements GeyserLogger { private final Logger logger; @Getter @Setter private boolean debug; - public GeyserBungeeLogger(Logger logger, boolean debug) { - this.logger = logger; - this.debug = debug; - } - @Override public void severe(String message) { logger.severe(message); diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java index 4191c8578..062ef6f76 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java @@ -58,14 +58,13 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap { private GeyserCommandManager geyserCommandManager; private GeyserBungeeConfiguration geyserConfig; private GeyserBungeeInjector geyserInjector; - private GeyserBungeeLogger geyserLogger; + private final GeyserBungeeLogger geyserLogger = new GeyserBungeeLogger(getLogger()); private IGeyserPingPassthrough geyserBungeePingPassthrough; private GeyserImpl geyser; @@ -82,21 +81,21 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap { // Copied from ViaVersion. // https://github.com/ViaVersion/ViaVersion/blob/b8072aad86695cc8ec6f5e4103e43baf3abf6cc5/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java#L43 try { - ProtocolConstants.class.getField("MINECRAFT_1_20_3"); + ProtocolConstants.class.getField("MINECRAFT_1_20_5"); } catch (NoSuchFieldException e) { - getLogger().warning(" / \\"); - getLogger().warning(" / \\"); - getLogger().warning(" / | \\"); - getLogger().warning(" / | \\ " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_proxy", getProxy().getName())); - getLogger().warning(" / \\ " + GeyserLocale.getLocaleStringLog("geyser.may_not_work_as_intended_all_caps")); - getLogger().warning(" / o \\"); - getLogger().warning("/_____________\\"); + geyserLogger.error(" / \\"); + geyserLogger.error(" / \\"); + geyserLogger.error(" / | \\"); + geyserLogger.error(" / | \\ " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_proxy", getProxy().getName())); + geyserLogger.error(" / \\ " + GeyserLocale.getLocaleStringLog("geyser.may_not_work_as_intended_all_caps")); + geyserLogger.error(" / o \\"); + geyserLogger.error("/_____________\\"); } if (!this.loadConfig()) { return; } - this.geyserLogger = new GeyserBungeeLogger(getLogger(), geyserConfig.isDebugMode()); + this.geyserLogger.setDebug(geyserConfig.isDebugMode()); GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger); this.geyser = GeyserImpl.load(PlatformType.BUNGEECORD, this); this.geyserInjector = new GeyserBungeeInjector(this); @@ -293,7 +292,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap { "config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()), this); this.geyserConfig = FileUtils.loadConfig(configFile, GeyserBungeeConfiguration.class); } catch (IOException ex) { - getLogger().log(Level.SEVERE, GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex); + geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex); ex.printStackTrace(); return false; } diff --git a/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModBootstrap.java b/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModBootstrap.java index 786faac93..d7373f0a9 100644 --- a/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModBootstrap.java +++ b/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModBootstrap.java @@ -34,7 +34,6 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.server.MinecraftServer; import net.minecraft.world.entity.player.Player; -import org.apache.logging.log4j.LogManager; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserBootstrap; @@ -80,7 +79,7 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap { private GeyserCommandManager geyserCommandManager; private GeyserModConfiguration geyserConfig; private GeyserModInjector geyserInjector; - private GeyserModLogger geyserLogger; + private final GeyserModLogger geyserLogger = new GeyserModLogger(); private IGeyserPingPassthrough geyserPingPassthrough; private WorldManager geyserWorldManager; @@ -92,7 +91,7 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap { if (!loadConfig()) { return; } - this.geyserLogger = new GeyserModLogger(geyserConfig.isDebugMode()); + this.geyserLogger.setDebug(geyserConfig.isDebugMode()); GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger); this.geyser = GeyserImpl.load(this.platform.platformType(), this); @@ -288,7 +287,7 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap { this.geyserConfig = FileUtils.loadConfig(configFile, GeyserModConfiguration.class); return true; } catch (IOException ex) { - LogManager.getLogger("geyser").error(GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex); + geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex); ex.printStackTrace(); return false; } diff --git a/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModLogger.java b/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModLogger.java index 444b725e9..9260288d7 100644 --- a/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModLogger.java +++ b/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModLogger.java @@ -37,10 +37,6 @@ public class GeyserModLogger implements GeyserLogger { private boolean debug; - public GeyserModLogger(boolean isDebug) { - debug = isDebug; - } - @Override public void severe(String message) { logger.fatal(message); diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserPaperLogger.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserPaperLogger.java index 930f84cec..9ebd6519a 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserPaperLogger.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserPaperLogger.java @@ -34,8 +34,8 @@ import java.util.logging.Logger; public final class GeyserPaperLogger extends GeyserSpigotLogger { private final ComponentLogger componentLogger; - public GeyserPaperLogger(Plugin plugin, Logger logger, boolean debug) { - super(logger, debug); + public GeyserPaperLogger(Plugin plugin, Logger logger) { + super(logger); componentLogger = plugin.getComponentLogger(); } diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotLogger.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotLogger.java index fe56cba1c..5c6101eae 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotLogger.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotLogger.java @@ -25,15 +25,15 @@ package org.geysermc.geyser.platform.spigot; -import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.RequiredArgsConstructor; import lombok.Setter; import org.geysermc.geyser.GeyserLogger; import java.util.logging.Level; import java.util.logging.Logger; -@AllArgsConstructor +@RequiredArgsConstructor public class GeyserSpigotLogger implements GeyserLogger { private final Logger logger; @Getter @Setter diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java index e33de5f9b..d138ad074 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java @@ -79,14 +79,14 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.UUID; -import java.util.logging.Level; public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap { private GeyserSpigotCommandManager geyserCommandManager; private GeyserSpigotConfiguration geyserConfig; private GeyserSpigotInjector geyserInjector; - private GeyserSpigotLogger geyserLogger; + private final GeyserSpigotLogger geyserLogger = GeyserPaperLogger.supported() ? + new GeyserPaperLogger(this, getLogger()) : new GeyserSpigotLogger(getLogger()); private IGeyserPingPassthrough geyserSpigotPingPassthrough; private GeyserSpigotWorldManager geyserWorldManager; @@ -114,12 +114,12 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap { // We depend on this as a fallback in certain scenarios BlockData.class.getMethod("getAsString"); } catch (ClassNotFoundException | NoSuchMethodException e) { - getLogger().severe("*********************************************"); - getLogger().severe(""); - getLogger().severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_server.header")); - getLogger().severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_server.message", "1.13.2")); - getLogger().severe(""); - getLogger().severe("*********************************************"); + geyserLogger.error("*********************************************"); + geyserLogger.error(""); + geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_server.header")); + geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_server.message", "1.13.2")); + geyserLogger.error(""); + geyserLogger.error("*********************************************"); Bukkit.getPluginManager().disablePlugin(this); return; } @@ -128,12 +128,12 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap { Class.forName("net.md_5.bungee.chat.ComponentSerializer"); } catch (ClassNotFoundException e) { if (!PaperAdventure.canSendMessageUsingComponent()) { // Prepare for Paper eventually removing Bungee chat - getLogger().severe("*********************************************"); - getLogger().severe(""); - getLogger().severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_server_type.header", getServer().getName())); - getLogger().severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_server_type.message", "Paper")); - getLogger().severe(""); - getLogger().severe("*********************************************"); + geyserLogger.error("*********************************************"); + geyserLogger.error(""); + geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_server_type.header", getServer().getName())); + geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_server_type.message", "Paper")); + geyserLogger.error(""); + geyserLogger.error("*********************************************"); Bukkit.getPluginManager().disablePlugin(this); return; } @@ -142,11 +142,11 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap { try { Class.forName("io.netty.util.internal.ObjectPool$ObjectCreator"); } catch (ClassNotFoundException e) { - getLogger().severe("*********************************************"); - getLogger().severe(""); - getLogger().severe("This version of Spigot is using an outdated version of netty. Please use Paper instead!"); - getLogger().severe(""); - getLogger().severe("*********************************************"); + geyserLogger.error("*********************************************"); + geyserLogger.error(""); + geyserLogger.error("This version of Spigot is using an outdated version of netty. Please use Paper instead!"); + geyserLogger.error(""); + geyserLogger.error("*********************************************"); Bukkit.getPluginManager().disablePlugin(this); return; } @@ -154,8 +154,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap { if (!loadConfig()) { return; } - this.geyserLogger = GeyserPaperLogger.supported() ? new GeyserPaperLogger(this, getLogger(), geyserConfig.isDebugMode()) - : new GeyserSpigotLogger(getLogger(), geyserConfig.isDebugMode()); + this.geyserLogger.setDebug(geyserConfig.isDebugMode()); GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger); // Turn "(MC: 1.16.4)" into 1.16.4. @@ -486,7 +485,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap { (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()), this); this.geyserConfig = FileUtils.loadConfig(configFile, GeyserSpigotConfiguration.class); } catch (IOException ex) { - getLogger().log(Level.SEVERE, GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex); + geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex); ex.printStackTrace(); Bukkit.getPluginManager().disablePlugin(this); return false; diff --git a/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/GeyserStandaloneBootstrap.java b/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/GeyserStandaloneBootstrap.java index 039004867..f289fa2ba 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/GeyserStandaloneBootstrap.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/GeyserStandaloneBootstrap.java @@ -71,7 +71,7 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap { private GeyserCommandManager geyserCommandManager; private GeyserStandaloneConfiguration geyserConfig; - private GeyserStandaloneLogger geyserLogger; + private final GeyserStandaloneLogger geyserLogger = new GeyserStandaloneLogger(); private IGeyserPingPassthrough geyserPingPassthrough; private GeyserStandaloneGUI gui; @Getter @@ -181,8 +181,6 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap { } } - this.geyserLogger = new GeyserStandaloneLogger(); - if (useGui && gui == null) { gui = new GeyserStandaloneGUI(geyserLogger); gui.redirectSystemStreams(); diff --git a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityLogger.java b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityLogger.java index 567870e7f..4d10e4daf 100644 --- a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityLogger.java +++ b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityLogger.java @@ -25,13 +25,13 @@ package org.geysermc.geyser.platform.velocity; -import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.RequiredArgsConstructor; import lombok.Setter; import org.geysermc.geyser.GeyserLogger; import org.slf4j.Logger; -@AllArgsConstructor +@RequiredArgsConstructor public class GeyserVelocityLogger implements GeyserLogger { private final Logger logger; @Getter @Setter diff --git a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java index 347a47d63..539bdadbf 100644 --- a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java +++ b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java @@ -64,44 +64,44 @@ import java.util.UUID; @Plugin(id = "geyser", name = GeyserImpl.NAME + "-Velocity", version = GeyserImpl.VERSION, url = "https://geysermc.org", authors = "GeyserMC") public class GeyserVelocityPlugin implements GeyserBootstrap { - @Inject - private Logger logger; - - @Inject - private ProxyServer proxyServer; - - @Inject - private CommandManager commandManager; + private final ProxyServer proxyServer; + private final CommandManager commandManager; + private final GeyserVelocityLogger geyserLogger; private GeyserCommandManager geyserCommandManager; private GeyserVelocityConfiguration geyserConfig; private GeyserVelocityInjector geyserInjector; - private GeyserVelocityLogger geyserLogger; private IGeyserPingPassthrough geyserPingPassthrough; - private GeyserImpl geyser; @Getter private final Path configFolder = Paths.get("plugins/" + GeyserImpl.NAME + "-Velocity/"); + @Inject + public GeyserVelocityPlugin(ProxyServer server, Logger logger, CommandManager manager) { + this.geyserLogger = new GeyserVelocityLogger(logger); + this.proxyServer = server; + this.commandManager = manager; + } + @Override public void onGeyserInitialize() { GeyserLocale.init(this); if (!ProtocolVersion.isSupported(GameProtocol.getJavaProtocolVersion())) { - logger.error(" / \\"); - logger.error(" / \\"); - logger.error(" / | \\"); - logger.error(" / | \\ " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_proxy", proxyServer.getVersion().getName())); - logger.error(" / \\ " + GeyserLocale.getLocaleStringLog("geyser.may_not_work_as_intended_all_caps")); - logger.error(" / o \\"); - logger.error("/_____________\\"); + geyserLogger.error(" / \\"); + geyserLogger.error(" / \\"); + geyserLogger.error(" / | \\"); + geyserLogger.error(" / | \\ " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_proxy", proxyServer.getVersion().getName())); + geyserLogger.error(" / \\ " + GeyserLocale.getLocaleStringLog("geyser.may_not_work_as_intended_all_caps")); + geyserLogger.error(" / o \\"); + geyserLogger.error("/_____________\\"); } if (!loadConfig()) { return; } - this.geyserLogger = new GeyserVelocityLogger(logger, geyserConfig.isDebugMode()); + this.geyserLogger.setDebug(geyserConfig.isDebugMode()); GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger); this.geyser = GeyserImpl.load(PlatformType.VELOCITY, this); @@ -249,7 +249,7 @@ public class GeyserVelocityPlugin implements GeyserBootstrap { "config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()), this); this.geyserConfig = FileUtils.loadConfig(configFile, GeyserVelocityConfiguration.class); } catch (IOException ex) { - logger.error(GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex); + geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex); ex.printStackTrace(); return false; } diff --git a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java index d5635acf9..6a404ae11 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java @@ -766,6 +766,7 @@ public class GeyserImpl implements GeyserApi { return 0; } + //noinspection DataFlowIssue return Integer.parseInt(BUILD_NUMBER); } diff --git a/core/src/main/java/org/geysermc/geyser/text/GeyserLocale.java b/core/src/main/java/org/geysermc/geyser/text/GeyserLocale.java index c6a58e75e..cfe950409 100644 --- a/core/src/main/java/org/geysermc/geyser/text/GeyserLocale.java +++ b/core/src/main/java/org/geysermc/geyser/text/GeyserLocale.java @@ -148,9 +148,9 @@ public class GeyserLocale { } catch (IOException ignored) {} } } else { - if (GeyserImpl.getInstance() != null && !validLocalLanguage) { + if (!validLocalLanguage) { // Don't warn on missing locales if a local file has been found - GeyserImpl.getInstance().getLogger().warning("Missing locale: " + locale); + bootstrap.getGeyserLogger().warning("Missing locale: " + locale); } } @@ -162,12 +162,7 @@ public class GeyserLocale { localeProp.load(stream); } catch (IOException e) { String message = "Unable to load custom language override!"; - if (GeyserImpl.getInstance() != null) { - GeyserImpl.getInstance().getLogger().error(message, e); - } else { - System.err.println(message); - e.printStackTrace(); - } + bootstrap.getGeyserLogger().error(message, e); } LOCALE_MAPPINGS.putIfAbsent(locale, localeProp); From 66f30a2cb6f477ec8ff9d9aa34ec015a6cd6891d Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 29 May 2024 23:43:39 +0200 Subject: [PATCH 3/3] Ensure we send commands/chat the same way a Java client would (#4703) * Ensure we send commands/chat the same way a Java client would * yeet static import, move blank check --- .../BedrockCommandRequestTranslator.java | 12 ++++--- .../bedrock/BedrockTextTranslator.java | 11 ++++++- .../translator/text/MessageTranslator.java | 33 +++++++++++++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockCommandRequestTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockCommandRequestTranslator.java index 322d64cce..8d4df6f3f 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockCommandRequestTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockCommandRequestTranslator.java @@ -26,8 +26,8 @@ package org.geysermc.geyser.translator.protocol.bedrock; import org.cloudburstmc.protocol.bedrock.packet.CommandRequestPacket; -import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.Translator; @@ -39,15 +39,17 @@ public class BedrockCommandRequestTranslator extends PacketTranslator { @Override public void translate(GeyserSession session, TextPacket packet) { - String message = MessageTranslator.convertToPlainText(packet.getMessage()); + // Java trims all messages, and then checks for the leading slash + String message = MessageTranslator.convertToPlainText( + MessageTranslator.normalizeSpace(packet.getMessage()) + ); if (message.isBlank()) { // Java Edition (as of 1.17.1) just doesn't pass on these messages, so... we won't either! return; } + if (message.startsWith("/")) { + // Yes, Java actually allows whitespaces before commands and will still see those as valid + BedrockCommandRequestTranslator.handleCommand(session, message.substring(1)); + return; + } + if (MessageTranslator.isTooLong(message, session)) { return; } diff --git a/core/src/main/java/org/geysermc/geyser/translator/text/MessageTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/text/MessageTranslator.java index 5a0121039..bf6fdd763 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/text/MessageTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/text/MessageTranslator.java @@ -387,6 +387,39 @@ public class MessageTranslator { return false; } + /** + * Normalizes whitespaces - a thing a vanilla client apparently does with commands and chat messages. + */ + public static String normalizeSpace(String string) { + if (string == null || string.isEmpty()) { + return string; + } + final int size = string.length(); + final char[] newChars = new char[size]; + int count = 0; + int whitespacesCount = 0; + boolean startWhitespaces = true; + for (int i = 0; i < size; i++) { + final char actualChar = string.charAt(i); + final boolean isWhitespace = Character.isWhitespace(actualChar); + if (isWhitespace) { + if (whitespacesCount == 0 && !startWhitespaces) { + newChars[count++] = ' '; + } + whitespacesCount++; + } else { + startWhitespaces = false; + // Replace non-breaking spaces with regular spaces for normalization + newChars[count++] = (actualChar == '\u00A0' ? ' ' : actualChar); + whitespacesCount = 0; + } + } + if (startWhitespaces) { + return ""; + } + return new String(newChars, 0, count - (whitespacesCount > 0 ? 1 : 0)).trim(); + } + public static void init() { // no-op }