diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..f83b9a901 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,57 @@ +name: Build + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository and submodules + uses: actions/checkout@v3 + with: + submodules: recursive + + - uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: temurin + cache: gradle + + - name: Build + uses: gradle/gradle-build-action@v2 + with: + arguments: build + + - name: Publish to Maven Repository + if: ${{ job.status == 'success' && github.repository == 'GeyserMC/Geyser' && github.ref_name == 'master' }} + uses: gradle/gradle-build-action@v2 + env: + ORG_GRADLE_PROJECT_geysermcUsername: ${{ vars.DEPLOY_USER }} + ORG_GRADLE_PROJECT_geysermcPassword: ${{ secrets.DEPLOY_PASS }} + with: + arguments: publish + + - name: Publish to Downloads API + if: ${{ github.ref_name == 'master' && job.status == 'success' && github.repository == 'GeyserMC/Geyser' }} + shell: bash + env: + DOWNLOADS_USERNAME: ${{ vars.DOWNLOADS_USERNAME }} + DOWNLOADS_PRIVATE_KEY: ${{ secrets.DOWNLOADS_PRIVATE_KEY }} + DOWNLOADS_SERVER_IP: ${{ secrets.DOWNLOADS_SERVER_IP }} + run: | + # Save the private key to a file + echo "$DOWNLOADS_PRIVATE_KEY" > id_ecdsa + chmod 600 id_ecdsa + # Get the version from gradle.properties + version=$(cat gradle.properties | grep -o "version=[0-9\\.]*" | cut -d"=" -f2) + # Copy over artifacts + scp -B -o StrictHostKeyChecking=no -i id_ecdsa bootstrap/**/build/libs/Geyser-*.jar $DOWNLOADS_USERNAME@$DOWNLOADS_SERVER_IP:~/files/ + # Run the build script + ssh -o StrictHostKeyChecking=no -i id_ecdsa $DOWNLOADS_USERNAME@$DOWNLOADS_SERVER_IP ./handleBuild.sh geyser $version $GITHUB_RUN_NUMBER $GITHUB_SHA + + - name: Notify Discord + if: ${{ (success() || failure()) && github.repository == 'GeyserMC/Geyser' }} + uses: Tim203/actions-git-discord-webhook@main + with: + webhook_url: ${{ secrets.DISCORD_WEBHOOK }} + status: ${{ job.status }} diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index 6781d7483..8d5f5c03c 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -48,34 +48,34 @@ jobs: if: success() with: name: Geyser Fabric - path: bootstrap/fabric/build/libs/Geyser-Fabric.jar + path: geyser/bootstrap/fabric/build/libs/Geyser-Fabric.jar - name: Archive artifacts (Geyser Standalone) uses: actions/upload-artifact@v2 if: success() with: name: Geyser Standalone - path: bootstrap/standalone/build/libs/Geyser-Standalone.jar + path: geyser/bootstrap/standalone/build/libs/Geyser-Standalone.jar - name: Archive artifacts (Geyser Spigot) uses: actions/upload-artifact@v2 if: success() with: name: Geyser Spigot - path: bootstrap/spigot/build/libs/Geyser-Spigot.jar + path: geyser/bootstrap/spigot/build/libs/Geyser-Spigot.jar - name: Archive artifacts (Geyser BungeeCord) uses: actions/upload-artifact@v2 if: success() with: name: Geyser BungeeCord - path: bootstrap/bungeecord/build/libs/Geyser-BungeeCord.jar + path: geyser/bootstrap/bungeecord/build/libs/Geyser-BungeeCord.jar - name: Archive artifacts (Geyser Sponge) uses: actions/upload-artifact@v2 if: success() with: name: Geyser Sponge - path: bootstrap/sponge/build/libs/Geyser-Sponge.jar + path: geyser/bootstrap/sponge/build/libs/Geyser-Sponge.jar - name: Archive artifacts (Geyser Velocity) uses: actions/upload-artifact@v2 if: success() with: name: Geyser Velocity - path: bootstrap/velocity/build/libs/Geyser-Velocity.jar + path: geyser/bootstrap/velocity/build/libs/Geyser-Velocity.jar diff --git a/Jenkinsfile b/Jenkinsfile index 072f99154..5c2eada3d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,80 +24,9 @@ pipeline { } } } - - stage ('Deploy') { - when { - anyOf { - branch "master" - } - } - - steps { - rtGradleDeployer( - id: "GRADLE_DEPLOYER", - serverId: "opencollab-artifactory", - releaseRepo: "maven-releases", - snapshotRepo: "maven-snapshots" - ) - rtGradleResolver( - id: "GRADLE_RESOLVER", - serverId: "opencollab-artifactory" - ) - rtGradleRun( - usesPlugin: true, - tool: 'Gradle 7', - rootDir: "", - useWrapper: true, - buildFile: 'build.gradle.kts', - tasks: 'artifactoryPublish', - deployerId: "GRADLE_DEPLOYER", - resolverId: "GRADLE_RESOLVER" - ) - rtPublishBuildInfo( - serverId: "opencollab-artifactory" - ) - } - } } post { - always { - script { - def changeLogSets = currentBuild.changeSets - def message = "**Changes:**" - - if (changeLogSets.size() == 0) { - message += "\n*No changes.*" - } else { - def repositoryUrl = scm.userRemoteConfigs[0].url.replace(".git", "") - def count = 0; - def extra = 0; - for (int i = 0; i < changeLogSets.size(); i++) { - def entries = changeLogSets[i].items - for (int j = 0; j < entries.length; j++) { - if (count <= 10) { - def entry = entries[j] - def commitId = entry.commitId.substring(0, 6) - message += "\n - [`${commitId}`](${repositoryUrl}/commit/${entry.commitId}) ${entry.msg}" - count++ - } else { - extra++; - } - } - } - - if (extra != 0) { - message += "\n - ${extra} more commits" - } - } - - env.changes = message - } - deleteDir() - withCredentials([string(credentialsId: 'geyser-discord-webhook', variable: 'DISCORD_WEBHOOK')]) { - discordSend description: "**Build:** [${currentBuild.id}](${env.BUILD_URL})\n**Status:** [${currentBuild.currentResult}](${env.BUILD_URL})\n${changes}\n\n[**Artifacts on Jenkins**](https://ci.opencollab.dev/job/GeyserMC/job/Geyser)", footer: 'Open Collaboration Jenkins', link: env.BUILD_URL, successful: currentBuild.resultIsBetterOrEqualTo('SUCCESS'), title: "${env.JOB_NAME} #${currentBuild.id}", webhookURL: DISCORD_WEBHOOK - } - } success { script { if (env.BRANCH_NAME == 'master') { diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index e21806660..3d1fb47f7 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { `kotlin-dsl` } @@ -10,17 +8,10 @@ repositories { } dependencies { - implementation("net.kyori", "indra-common", "2.0.6") - implementation("org.jfrog.buildinfo", "build-info-extractor-gradle", "4.26.1") + implementation("net.kyori", "indra-common", "3.0.1") implementation("com.github.johnrengelman", "shadow", "7.1.3-SNAPSHOT") // Within the gradle plugin classpath, there is a version conflict between loom and some other // plugin for databind. This fixes it: minimum 2.13.2 is required by loom. implementation("com.fasterxml.jackson.core:jackson-databind:2.14.0") } - -tasks.withType { - kotlinOptions { - jvmTarget = "16" - } -} diff --git a/build-logic/src/main/kotlin/extensions.kt b/build-logic/src/main/kotlin/extensions.kt index 0c01913d2..1e1732852 100644 --- a/build-logic/src/main/kotlin/extensions.kt +++ b/build-logic/src/main/kotlin/extensions.kt @@ -30,9 +30,6 @@ import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.provider.Provider import org.gradle.kotlin.dsl.named -fun Project.isSnapshot(): Boolean = - version.toString().endsWith("-SNAPSHOT") - fun Project.relocate(pattern: String) { tasks.named("shadowJar") { relocate(pattern, "org.geysermc.geyser.shaded.$pattern") diff --git a/build-logic/src/main/kotlin/geyser.base-conventions.gradle.kts b/build-logic/src/main/kotlin/geyser.base-conventions.gradle.kts index 44a74db3d..709867300 100644 --- a/build-logic/src/main/kotlin/geyser.base-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/geyser.base-conventions.gradle.kts @@ -1,12 +1,25 @@ plugins { `java-library` - `maven-publish` + id("net.kyori.indra") } dependencies { compileOnly("org.checkerframework", "checker-qual", "3.19.0") } +indra { + github("GeyserMC", "Geyser") { + ci(true) + issues(true) + scm(true) + } + mitLicense() + + javaVersions { + target(16) + } +} + tasks { processResources { // Spigot, BungeeCord, Velocity, Sponge, Fabric @@ -21,14 +34,4 @@ tasks { ) } } - compileJava { - options.encoding = Charsets.UTF_8.name() - } -} - -java { - sourceCompatibility = JavaVersion.VERSION_16 - targetCompatibility = JavaVersion.VERSION_16 - - withSourcesJar() } diff --git a/build-logic/src/main/kotlin/geyser.publish-conventions.gradle.kts b/build-logic/src/main/kotlin/geyser.publish-conventions.gradle.kts index 7525f97fa..036ee803c 100644 --- a/build-logic/src/main/kotlin/geyser.publish-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/geyser.publish-conventions.gradle.kts @@ -1,33 +1,9 @@ plugins { id("geyser.shadow-conventions") - id("com.jfrog.artifactory") - id("maven-publish") + id("net.kyori.indra.publishing") } -publishing { - publications { - create("mavenJava") { - groupId = project.group as String - artifactId = project.name - version = project.version as String - - from(components["java"]) - } - } -} - -artifactory { - setContextUrl("https://repo.opencollab.dev/artifactory") - publish { - repository { - setRepoKey(if (isSnapshot()) "maven-snapshots" else "maven-releases") - setMavenCompatible(true) - } - defaults { - publications("mavenJava") - setPublishArtifacts(true) - setPublishPom(true) - setPublishIvy(false) - } - } +indra { + publishSnapshotsTo("geysermc", "https://repo.opencollab.dev/maven-snapshots") + publishReleasesTo("geysermc", "https://repo.opencollab.dev/maven-releases") } diff --git a/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java b/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java index 257854726..42e18a416 100644 --- a/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java +++ b/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java @@ -31,6 +31,7 @@ import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.v557.Bedrock_v557; import com.nukkitx.protocol.bedrock.v560.Bedrock_v560; import com.nukkitx.protocol.bedrock.v567.Bedrock_v567; +import com.nukkitx.protocol.bedrock.v567.Bedrock_v567patch; import org.geysermc.geyser.session.GeyserSession; import java.util.ArrayList; @@ -65,8 +66,7 @@ public final class GameProtocol { .minecraftVersion("1.19.50/1.19.51") .build()); SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC); - // So the version checker will work - SUPPORTED_BEDROCK_CODECS.add(Bedrock_v567.V567_CODEC.toBuilder() + SUPPORTED_BEDROCK_CODECS.add(Bedrock_v567patch.BEDROCK_V567PATCH.toBuilder() .protocolVersion(568) .minecraftVersion("1.19.62") .build()); 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 70c16a9db..817e5381d 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -180,7 +180,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { private final AdvancementsCache advancementsCache; private final BookEditCache bookEditCache; - private @org.checkerframework.checker.nullness.qual.NonNull final ChunkCache chunkCache; + private final ChunkCache chunkCache; private final EntityCache entityCache; private final EntityEffectCache effectCache; private final FormCache formCache; @@ -1416,10 +1416,6 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { } public void setServerRenderDistance(int renderDistance) { - // +1 is for Fabric and Spigot - // Without the client misses loading some chunks per https://github.com/GeyserMC/Geyser/issues/3490 - // Fog still appears essentially normally - renderDistance = renderDistance + 1; this.serverRenderDistance = renderDistance; ChunkRadiusUpdatedPacket chunkRadiusUpdatedPacket = new ChunkRadiusUpdatedPacket(); @@ -1431,11 +1427,13 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { return this.upstream.getAddress(); } + @Override public boolean sendForm(@NonNull Form form) { formCache.showForm(form); return true; } + @Override public boolean sendForm(@NonNull FormBuilder formBuilder) { formCache.showForm(formBuilder.build()); return true; diff --git a/core/src/main/java/org/geysermc/geyser/util/ChunkUtils.java b/core/src/main/java/org/geysermc/geyser/util/ChunkUtils.java index b1ebd877b..717e40451 100644 --- a/core/src/main/java/org/geysermc/geyser/util/ChunkUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/ChunkUtils.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.util; +import com.nukkitx.math.GenericMath; import com.nukkitx.math.vector.Vector2i; import com.nukkitx.math.vector.Vector3i; import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; @@ -92,7 +93,9 @@ public class ChunkUtils { if (chunkPos == null || !chunkPos.equals(newChunkPos)) { NetworkChunkPublisherUpdatePacket chunkPublisherUpdatePacket = new NetworkChunkPublisherUpdatePacket(); chunkPublisherUpdatePacket.setPosition(position); - chunkPublisherUpdatePacket.setRadius(session.getServerRenderDistance() << 4); + // Mitigates chunks not loading on 1.17.1 Paper and 1.19.3 Fabric. As of Bedrock 1.19.60. + // https://github.com/GeyserMC/Geyser/issues/3490 + chunkPublisherUpdatePacket.setRadius(GenericMath.ceil((session.getServerRenderDistance() + 1) * MathUtils.SQRT_OF_TWO) << 4); session.sendUpstreamPacket(chunkPublisherUpdatePacket); session.setLastChunkPosition(newChunkPos); diff --git a/core/src/test/java/org/geysermc/geyser/network/translators/chat/MessageTranslatorTest.java b/core/src/test/java/org/geysermc/geyser/network/translators/chat/MessageTranslatorTest.java index e83c6f73d..a804916fa 100644 --- a/core/src/test/java/org/geysermc/geyser/network/translators/chat/MessageTranslatorTest.java +++ b/core/src/test/java/org/geysermc/geyser/network/translators/chat/MessageTranslatorTest.java @@ -27,18 +27,20 @@ package org.geysermc.geyser.network.translators.chat; import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer; import org.geysermc.geyser.translator.text.MessageTranslator; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.util.HashMap; import java.util.Map; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class MessageTranslatorTest { private Map messages = new HashMap<>(); - @Before + @BeforeAll public void setUp() throws Exception { messages.put("{\"text\":\"\",\"extra\":[{\"text\":\"DoctorMad9952 joined the game\",\"color\":\"yellow\"}]}", "§r§eDoctorMad9952 joined the game"); @@ -70,27 +72,27 @@ public class MessageTranslatorTest { public void convertMessage() { for (Map.Entry entry : messages.entrySet()) { String bedrockMessage = MessageTranslator.convertMessage(entry.getKey(), "en_US"); - Assert.assertEquals("Translation of messages is incorrect", entry.getValue(), bedrockMessage); + Assertions.assertEquals(entry.getValue(), bedrockMessage, "Translation of messages is incorrect"); } } @Test public void convertMessageLenient() { - Assert.assertEquals("All newline message is not handled properly", "\n\n\n\n", MessageTranslator.convertMessageLenient("\n\n\n\n")); - Assert.assertEquals("Empty message is not handled properly", "", MessageTranslator.convertMessageLenient("")); - Assert.assertEquals("Reset before message is not handled properly", "§r§eGame Selector", MessageTranslator.convertMessageLenient("§r§eGame Selector")); - Assert.assertEquals("Unimplemented formatting chars not stripped", "Bold Underline", MessageTranslator.convertMessageLenient("§m§nBold Underline")); + Assertions.assertEquals("\n\n\n\n", MessageTranslator.convertMessageLenient("\n\n\n\n"), "All newline message is not handled properly"); + Assertions.assertEquals("", MessageTranslator.convertMessageLenient(""), "Empty message is not handled properly"); + Assertions.assertEquals("§r§eGame Selector", MessageTranslator.convertMessageLenient("§r§eGame Selector"), "Reset before message is not handled properly"); + Assertions.assertEquals("Bold Underline", MessageTranslator.convertMessageLenient("§m§nBold Underline"), "Unimplemented formatting chars not stripped"); } @Test public void convertToPlainText() { - Assert.assertEquals("JSON message is not handled properly", "Many colors here", MessageTranslator.convertToPlainText("{\"extra\":[{\"color\":\"red\",\"text\":\"M\"},{\"color\":\"gold\",\"text\":\"a\"},{\"color\":\"yellow\",\"text\":\"n\"},{\"color\":\"green\",\"text\":\"y \"},{\"color\":\"aqua\",\"text\":\"c\"},{\"color\":\"dark_purple\",\"text\":\"o\"},{\"color\":\"red\",\"text\":\"l\"},{\"color\":\"gold\",\"text\":\"o\"},{\"color\":\"yellow\",\"text\":\"r\"},{\"color\":\"green\",\"text\":\"s \"},{\"color\":\"aqua\",\"text\":\"h\"},{\"color\":\"dark_purple\",\"text\":\"e\"},{\"color\":\"red\",\"text\":\"r\"},{\"color\":\"gold\",\"text\":\"e\"}],\"text\":\"\"}", "en_US")); - Assert.assertEquals("Legacy formatted message is not handled properly (Colors)", "Many colors here", MessageTranslator.convertToPlainText("§cM§6a§en§ay §bc§5o§cl§6o§er§as §bh§5e§cr§6e")); - Assert.assertEquals("Legacy formatted message is not handled properly (Colors)", "Many colors here", MessageTranslator.convertToPlainText("§cM§6a§en§ay §bc§5o§cl§6o§er§as §bh§5e§cr§6e", "en_US")); - Assert.assertEquals("Legacy formatted message is not handled properly (Style)", "Obf Bold Strikethrough Underline Italic Reset", MessageTranslator.convertToPlainText("§kObf §lBold §mStrikethrough §nUnderline §oItalic §rReset", "en_US")); - Assert.assertEquals("Valid lenient JSON is not handled properly", "Strange", MessageTranslator.convertToPlainText("§rStrange", "en_US")); - Assert.assertEquals("Empty message is not handled properly", "", MessageTranslator.convertToPlainText("", "en_US")); - Assert.assertEquals("Whitespace is not preserved", " ", MessageTranslator.convertToPlainText(" ", "en_US")); + Assertions.assertEquals("Many colors here", MessageTranslator.convertToPlainText("{\"extra\":[{\"color\":\"red\",\"text\":\"M\"},{\"color\":\"gold\",\"text\":\"a\"},{\"color\":\"yellow\",\"text\":\"n\"},{\"color\":\"green\",\"text\":\"y \"},{\"color\":\"aqua\",\"text\":\"c\"},{\"color\":\"dark_purple\",\"text\":\"o\"},{\"color\":\"red\",\"text\":\"l\"},{\"color\":\"gold\",\"text\":\"o\"},{\"color\":\"yellow\",\"text\":\"r\"},{\"color\":\"green\",\"text\":\"s \"},{\"color\":\"aqua\",\"text\":\"h\"},{\"color\":\"dark_purple\",\"text\":\"e\"},{\"color\":\"red\",\"text\":\"r\"},{\"color\":\"gold\",\"text\":\"e\"}],\"text\":\"\"}", "en_US"), "JSON message is not handled properly"); + Assertions.assertEquals("Many colors here", MessageTranslator.convertToPlainText("§cM§6a§en§ay §bc§5o§cl§6o§er§as §bh§5e§cr§6e"), "Legacy formatted message is not handled properly (Colors)"); + Assertions.assertEquals("Many colors here", MessageTranslator.convertToPlainText("§cM§6a§en§ay §bc§5o§cl§6o§er§as §bh§5e§cr§6e", "en_US"), "Legacy formatted message is not handled properly (Colors)"); + Assertions.assertEquals("Obf Bold Strikethrough Underline Italic Reset", MessageTranslator.convertToPlainText("§kObf §lBold §mStrikethrough §nUnderline §oItalic §rReset", "en_US"), "Legacy formatted message is not handled properly (Style)"); + Assertions.assertEquals("Strange", MessageTranslator.convertToPlainText("§rStrange", "en_US"), "Valid lenient JSON is not handled properly"); + Assertions.assertEquals("", MessageTranslator.convertToPlainText("", "en_US"), "Empty message is not handled properly"); + Assertions.assertEquals(" ", MessageTranslator.convertToPlainText(" ", "en_US"), "Whitespace is not preserved"); } @Test diff --git a/core/src/test/java/org/geysermc/geyser/translator/inventory/item/CustomItemsTest.java b/core/src/test/java/org/geysermc/geyser/translator/inventory/item/CustomItemsTest.java index 145f46369..806ec4542 100644 --- a/core/src/test/java/org/geysermc/geyser/translator/inventory/item/CustomItemsTest.java +++ b/core/src/test/java/org/geysermc/geyser/translator/inventory/item/CustomItemsTest.java @@ -36,20 +36,22 @@ import org.geysermc.geyser.api.item.custom.CustomItemOptions; import org.geysermc.geyser.api.util.TriState; import org.geysermc.geyser.item.GeyserCustomItemOptions; import org.geysermc.geyser.registry.type.ItemMapping; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.util.List; import java.util.OptionalInt; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class CustomItemsTest { private ItemMapping testMappingWithDamage; private Object2IntMap tagToCustomItemWithDamage; private ItemMapping testMappingWithNoDamage; private Object2IntMap tagToCustomItemWithNoDamage; - @Before + @BeforeAll public void setup() { CustomItemOptions a = new GeyserCustomItemOptions(TriState.TRUE, OptionalInt.of(2), OptionalInt.empty()); CustomItemOptions b = new GeyserCustomItemOptions(TriState.FALSE, OptionalInt.of(5), OptionalInt.empty()); @@ -147,12 +149,12 @@ public class CustomItemsTest { public void testCustomItems() { for (Object2IntMap.Entry entry : this.tagToCustomItemWithDamage.object2IntEntrySet()) { int id = CustomItemTranslator.getCustomItem(entry.getKey(), this.testMappingWithDamage); - Assert.assertEquals(entry.getKey() + " did not produce the correct custom item", entry.getIntValue(), id); + Assertions.assertEquals(entry.getIntValue(), id, entry.getKey() + " did not produce the correct custom item"); } for (Object2IntMap.Entry entry : this.tagToCustomItemWithNoDamage.object2IntEntrySet()) { int id = CustomItemTranslator.getCustomItem(entry.getKey(), this.testMappingWithNoDamage); - Assert.assertEquals(entry.getKey() + " did not produce the correct custom item", entry.getIntValue(), id); + Assertions.assertEquals(entry.getIntValue(), id, entry.getKey() + " did not produce the correct custom item"); } } } diff --git a/core/src/test/java/org/geysermc/geyser/util/collection/GeyserCollectionsTest.java b/core/src/test/java/org/geysermc/geyser/util/collection/GeyserCollectionsTest.java index a2a9f98f6..639c79331 100644 --- a/core/src/test/java/org/geysermc/geyser/util/collection/GeyserCollectionsTest.java +++ b/core/src/test/java/org/geysermc/geyser/util/collection/GeyserCollectionsTest.java @@ -25,9 +25,11 @@ package org.geysermc.geyser.util.collection; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class GeyserCollectionsTest { private final byte[] bytes = new byte[] {(byte) 5, (byte) 4, (byte) 3, (byte) 2, (byte) 2, (byte) 1}; private final boolean[] booleans = new boolean[] {true, false, false, true}; @@ -51,35 +53,35 @@ public class GeyserCollectionsTest { int lastKey = index; // Easy, understandable out-of-bounds checks - Assert.assertFalse("Map contains key bigger by one!", map.containsKey(lastKey)); - Assert.assertTrue("Map doesn't contain final key!", map.containsKey(lastKey - 1)); + Assertions.assertFalse(map.containsKey(lastKey), "Map contains key bigger by one!"); + Assertions.assertTrue(map.containsKey(lastKey - 1), "Map doesn't contain final key!"); // Ensure the first and last values do not throw an exception on get, and test getOrDefault map.get(start - 1); map.get(lastKey); - Assert.assertEquals(map.getOrDefault(start - 1, Byte.MAX_VALUE), Byte.MAX_VALUE); - Assert.assertEquals(map.getOrDefault(lastKey, Byte.MAX_VALUE), Byte.MAX_VALUE); - Assert.assertEquals(map.getOrDefault(lastKey, Byte.MIN_VALUE), Byte.MIN_VALUE); + Assertions.assertEquals(map.getOrDefault(start - 1, Byte.MAX_VALUE), Byte.MAX_VALUE); + Assertions.assertEquals(map.getOrDefault(lastKey, Byte.MAX_VALUE), Byte.MAX_VALUE); + Assertions.assertEquals(map.getOrDefault(lastKey, Byte.MIN_VALUE), Byte.MIN_VALUE); - Assert.assertEquals(map.size(), bytes.length); + Assertions.assertEquals(map.size(), bytes.length); for (int i = start; i < bytes.length; i++) { - Assert.assertTrue(map.containsKey(i)); - Assert.assertEquals(map.get(i), bytes[i - start]); + Assertions.assertTrue(map.containsKey(i)); + Assertions.assertEquals(map.get(i), bytes[i - start]); } for (int i = start - 1; i >= (start - 6); i--) { // Lower than expected check - Assert.assertFalse(i + " is in a map that starts with " + start, map.containsKey(i)); + Assertions.assertFalse(map.containsKey(i), i + " is in a map that starts with " + start); } for (int i = bytes.length + start; i < bytes.length + 5 + start; i++) { // Higher than expected check - Assert.assertFalse(i + " is in a map that ends with " + (start + bytes.length), map.containsKey(i)); + Assertions.assertFalse(map.containsKey(i), i + " is in a map that ends with " + (start + bytes.length)); } for (byte b : bytes) { - Assert.assertTrue(map.containsValue(b)); + Assertions.assertTrue(map.containsValue(b)); } } @@ -99,33 +101,33 @@ public class GeyserCollectionsTest { int lastKey = index; // Easy, understandable out-of-bounds checks - Assert.assertFalse("Map contains key bigger by one!", map.containsKey(lastKey)); - Assert.assertTrue("Map doesn't contain final key!", map.containsKey(lastKey - 1)); + Assertions.assertFalse(map.containsKey(lastKey), "Map contains key bigger by one!"); + Assertions.assertTrue(map.containsKey(lastKey - 1), "Map doesn't contain final key!"); // Ensure the first and last values do not throw an exception on get map.get(start - 1); map.get(lastKey); - Assert.assertTrue(map.getOrDefault(lastKey, true)); + Assertions.assertTrue(map.getOrDefault(lastKey, true)); - Assert.assertEquals(map.size(), booleans.length); + Assertions.assertEquals(map.size(), booleans.length); for (int i = start; i < booleans.length; i++) { - Assert.assertTrue(map.containsKey(i)); - Assert.assertEquals(map.get(i), booleans[i - start]); + Assertions.assertTrue(map.containsKey(i)); + Assertions.assertEquals(map.get(i), booleans[i - start]); } for (int i = start - 1; i >= (start - 6); i--) { // Lower than expected check - Assert.assertFalse(i + " is in a map that starts with " + start, map.containsKey(i)); + Assertions.assertFalse(map.containsKey(i), i + " is in a map that starts with " + start); } for (int i = booleans.length + start; i < booleans.length + start + 5; i++) { // Higher than expected check - Assert.assertFalse(i + " is in a map that ends with " + (start + booleans.length), map.containsKey(i)); + Assertions.assertFalse(map.containsKey(i), i + " is in a map that ends with " + (start + booleans.length)); } for (boolean b : booleans) { - Assert.assertTrue(map.containsValue(b)); + Assertions.assertTrue(map.containsValue(b)); } } @@ -145,35 +147,35 @@ public class GeyserCollectionsTest { int lastKey = index; // Easy, understandable out-of-bounds checks - Assert.assertFalse("Map contains key bigger by one!", map.containsKey(lastKey)); - Assert.assertTrue("Map doesn't contain final key!", map.containsKey(lastKey - 1)); + Assertions.assertFalse(map.containsKey(lastKey), "Map contains key bigger by one!"); + Assertions.assertTrue(map.containsKey(lastKey - 1), "Map doesn't contain final key!"); // Ensure the first and last values do not throw an exception on get, and test getOrDefault map.get(start - 1); map.get(lastKey); - Assert.assertEquals(map.getOrDefault(start - 1, Integer.MAX_VALUE), Integer.MAX_VALUE); - Assert.assertEquals(map.getOrDefault(lastKey, Integer.MAX_VALUE), Integer.MAX_VALUE); - Assert.assertEquals(map.getOrDefault(lastKey, Integer.MIN_VALUE), Integer.MIN_VALUE); + Assertions.assertEquals(map.getOrDefault(start - 1, Integer.MAX_VALUE), Integer.MAX_VALUE); + Assertions.assertEquals(map.getOrDefault(lastKey, Integer.MAX_VALUE), Integer.MAX_VALUE); + Assertions.assertEquals(map.getOrDefault(lastKey, Integer.MIN_VALUE), Integer.MIN_VALUE); - Assert.assertEquals(map.size(), ints.length); + Assertions.assertEquals(map.size(), ints.length); for (int i = start; i < ints.length; i++) { - Assert.assertTrue(map.containsKey(i)); - Assert.assertEquals(map.get(i), ints[i - start]); + Assertions.assertTrue(map.containsKey(i)); + Assertions.assertEquals(map.get(i), ints[i - start]); } for (int i = start - 1; i >= (start - 6); i--) { // Lower than expected check - Assert.assertFalse(i + " is in a map that starts with " + start, map.containsKey(i)); + Assertions.assertFalse(map.containsKey(i), i + " is in a map that starts with " + start); } for (int i = ints.length + start; i < ints.length + 5 + start; i++) { // Higher than expected check - Assert.assertFalse(i + " is in a map that ends with " + (start + ints.length), map.containsKey(i)); + Assertions.assertFalse(map.containsKey(i), i + " is in a map that ends with " + (start + ints.length)); } for (int i : ints) { - Assert.assertTrue(map.containsValue(i)); + Assertions.assertTrue(map.containsValue(i)); } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f62faa54f..8858edc68 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,7 +15,7 @@ mcprotocollib = "1.19.3-20230107.194116-10" packetlib = "3.0.1" adventure = "4.12.0-20220629.025215-9" adventure-platform = "4.1.2" -junit = "4.13.1" +junit = "5.9.2" checkerframework = "3.19.0" log4j = "2.17.1" jline = "3.21.0" @@ -81,7 +81,7 @@ checker-qual = { group = "org.checkerframework", name = "checker-qual", version. commodore = { group = "me.lucko", name = "commodore", version.ref = "commodore" } guava = { group = "com.google.guava", name = "guava", version.ref = "guava" } gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" } -junit = { group = "junit", name = "junit", version.ref = "junit" } +junit = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junit" } mcauthlib = { group = "com.github.GeyserMC", name = "MCAuthLib", version.ref = "mcauthlib" } mcprotocollib = { group = "com.github.steveice10", name = "mcprotocollib", version.ref = "mcprotocollib" } packetlib = { group = "com.github.steveice10", name = "packetlib", version.ref = "packetlib" }