3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-19 22:40:18 +01:00

Merge remote-tracking branch 'upstream/master' into feature/blocky

Dieser Commit ist enthalten in:
Joshua Castle 2023-02-24 21:55:40 -08:00
Commit 7a8796a90f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: F674F38216C35D5D
14 geänderte Dateien mit 154 neuen und 194 gelöschten Zeilen

57
.github/workflows/build.yml vendored Normale Datei
Datei anzeigen

@ -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 }}

Datei anzeigen

@ -48,34 +48,34 @@ jobs:
if: success() if: success()
with: with:
name: Geyser Fabric 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) - name: Archive artifacts (Geyser Standalone)
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
if: success() if: success()
with: with:
name: Geyser Standalone 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) - name: Archive artifacts (Geyser Spigot)
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
if: success() if: success()
with: with:
name: Geyser Spigot 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) - name: Archive artifacts (Geyser BungeeCord)
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
if: success() if: success()
with: with:
name: Geyser BungeeCord 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) - name: Archive artifacts (Geyser Sponge)
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
if: success() if: success()
with: with:
name: Geyser Sponge 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) - name: Archive artifacts (Geyser Velocity)
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
if: success() if: success()
with: with:
name: Geyser Velocity name: Geyser Velocity
path: bootstrap/velocity/build/libs/Geyser-Velocity.jar path: geyser/bootstrap/velocity/build/libs/Geyser-Velocity.jar

71
Jenkinsfile vendored
Datei anzeigen

@ -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 { 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 { success {
script { script {
if (env.BRANCH_NAME == 'master') { if (env.BRANCH_NAME == 'master') {

Datei anzeigen

@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
`kotlin-dsl` `kotlin-dsl`
} }
@ -10,17 +8,10 @@ repositories {
} }
dependencies { dependencies {
implementation("net.kyori", "indra-common", "2.0.6") implementation("net.kyori", "indra-common", "3.0.1")
implementation("org.jfrog.buildinfo", "build-info-extractor-gradle", "4.26.1")
implementation("com.github.johnrengelman", "shadow", "7.1.3-SNAPSHOT") implementation("com.github.johnrengelman", "shadow", "7.1.3-SNAPSHOT")
// Within the gradle plugin classpath, there is a version conflict between loom and some other // 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. // plugin for databind. This fixes it: minimum 2.13.2 is required by loom.
implementation("com.fasterxml.jackson.core:jackson-databind:2.14.0") implementation("com.fasterxml.jackson.core:jackson-databind:2.14.0")
} }
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "16"
}
}

Datei anzeigen

@ -30,9 +30,6 @@ import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.provider.Provider import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.named import org.gradle.kotlin.dsl.named
fun Project.isSnapshot(): Boolean =
version.toString().endsWith("-SNAPSHOT")
fun Project.relocate(pattern: String) { fun Project.relocate(pattern: String) {
tasks.named<ShadowJar>("shadowJar") { tasks.named<ShadowJar>("shadowJar") {
relocate(pattern, "org.geysermc.geyser.shaded.$pattern") relocate(pattern, "org.geysermc.geyser.shaded.$pattern")

Datei anzeigen

@ -1,12 +1,25 @@
plugins { plugins {
`java-library` `java-library`
`maven-publish` id("net.kyori.indra")
} }
dependencies { dependencies {
compileOnly("org.checkerframework", "checker-qual", "3.19.0") compileOnly("org.checkerframework", "checker-qual", "3.19.0")
} }
indra {
github("GeyserMC", "Geyser") {
ci(true)
issues(true)
scm(true)
}
mitLicense()
javaVersions {
target(16)
}
}
tasks { tasks {
processResources { processResources {
// Spigot, BungeeCord, Velocity, Sponge, Fabric // 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()
} }

Datei anzeigen

@ -1,33 +1,9 @@
plugins { plugins {
id("geyser.shadow-conventions") id("geyser.shadow-conventions")
id("com.jfrog.artifactory") id("net.kyori.indra.publishing")
id("maven-publish")
} }
publishing { indra {
publications { publishSnapshotsTo("geysermc", "https://repo.opencollab.dev/maven-snapshots")
create<MavenPublication>("mavenJava") { publishReleasesTo("geysermc", "https://repo.opencollab.dev/maven-releases")
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)
}
}
} }

Datei anzeigen

@ -31,6 +31,7 @@ import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
import com.nukkitx.protocol.bedrock.v557.Bedrock_v557; import com.nukkitx.protocol.bedrock.v557.Bedrock_v557;
import com.nukkitx.protocol.bedrock.v560.Bedrock_v560; import com.nukkitx.protocol.bedrock.v560.Bedrock_v560;
import com.nukkitx.protocol.bedrock.v567.Bedrock_v567; import com.nukkitx.protocol.bedrock.v567.Bedrock_v567;
import com.nukkitx.protocol.bedrock.v567.Bedrock_v567patch;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import java.util.ArrayList; import java.util.ArrayList;
@ -65,8 +66,7 @@ public final class GameProtocol {
.minecraftVersion("1.19.50/1.19.51") .minecraftVersion("1.19.50/1.19.51")
.build()); .build());
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC); SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC);
// So the version checker will work SUPPORTED_BEDROCK_CODECS.add(Bedrock_v567patch.BEDROCK_V567PATCH.toBuilder()
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v567.V567_CODEC.toBuilder()
.protocolVersion(568) .protocolVersion(568)
.minecraftVersion("1.19.62") .minecraftVersion("1.19.62")
.build()); .build());

Datei anzeigen

@ -180,7 +180,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
private final AdvancementsCache advancementsCache; private final AdvancementsCache advancementsCache;
private final BookEditCache bookEditCache; private final BookEditCache bookEditCache;
private @org.checkerframework.checker.nullness.qual.NonNull final ChunkCache chunkCache; private final ChunkCache chunkCache;
private final EntityCache entityCache; private final EntityCache entityCache;
private final EntityEffectCache effectCache; private final EntityEffectCache effectCache;
private final FormCache formCache; private final FormCache formCache;
@ -1416,10 +1416,6 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
} }
public void setServerRenderDistance(int renderDistance) { 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; this.serverRenderDistance = renderDistance;
ChunkRadiusUpdatedPacket chunkRadiusUpdatedPacket = new ChunkRadiusUpdatedPacket(); ChunkRadiusUpdatedPacket chunkRadiusUpdatedPacket = new ChunkRadiusUpdatedPacket();
@ -1431,11 +1427,13 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
return this.upstream.getAddress(); return this.upstream.getAddress();
} }
@Override
public boolean sendForm(@NonNull Form form) { public boolean sendForm(@NonNull Form form) {
formCache.showForm(form); formCache.showForm(form);
return true; return true;
} }
@Override
public boolean sendForm(@NonNull FormBuilder<?, ?, ?> formBuilder) { public boolean sendForm(@NonNull FormBuilder<?, ?, ?> formBuilder) {
formCache.showForm(formBuilder.build()); formCache.showForm(formBuilder.build());
return true; return true;

Datei anzeigen

@ -25,6 +25,7 @@
package org.geysermc.geyser.util; package org.geysermc.geyser.util;
import com.nukkitx.math.GenericMath;
import com.nukkitx.math.vector.Vector2i; import com.nukkitx.math.vector.Vector2i;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
@ -92,7 +93,9 @@ public class ChunkUtils {
if (chunkPos == null || !chunkPos.equals(newChunkPos)) { if (chunkPos == null || !chunkPos.equals(newChunkPos)) {
NetworkChunkPublisherUpdatePacket chunkPublisherUpdatePacket = new NetworkChunkPublisherUpdatePacket(); NetworkChunkPublisherUpdatePacket chunkPublisherUpdatePacket = new NetworkChunkPublisherUpdatePacket();
chunkPublisherUpdatePacket.setPosition(position); 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.sendUpstreamPacket(chunkPublisherUpdatePacket);
session.setLastChunkPosition(newChunkPos); session.setLastChunkPosition(newChunkPos);

Datei anzeigen

@ -27,18 +27,20 @@ package org.geysermc.geyser.network.translators.chat;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer; import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import org.geysermc.geyser.translator.text.MessageTranslator; import org.geysermc.geyser.translator.text.MessageTranslator;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class MessageTranslatorTest { public class MessageTranslatorTest {
private Map<String, String> messages = new HashMap<>(); private Map<String, String> messages = new HashMap<>();
@Before @BeforeAll
public void setUp() throws Exception { public void setUp() throws Exception {
messages.put("{\"text\":\"\",\"extra\":[{\"text\":\"DoctorMad9952 joined the game\",\"color\":\"yellow\"}]}", messages.put("{\"text\":\"\",\"extra\":[{\"text\":\"DoctorMad9952 joined the game\",\"color\":\"yellow\"}]}",
"§r§eDoctorMad9952 joined the game"); "§r§eDoctorMad9952 joined the game");
@ -70,27 +72,27 @@ public class MessageTranslatorTest {
public void convertMessage() { public void convertMessage() {
for (Map.Entry<String, String> entry : messages.entrySet()) { for (Map.Entry<String, String> entry : messages.entrySet()) {
String bedrockMessage = MessageTranslator.convertMessage(entry.getKey(), "en_US"); 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 @Test
public void convertMessageLenient() { public void convertMessageLenient() {
Assert.assertEquals("All newline message is not handled properly", "\n\n\n\n", MessageTranslator.convertMessageLenient("\n\n\n\n")); Assertions.assertEquals("\n\n\n\n", MessageTranslator.convertMessageLenient("\n\n\n\n"), "All newline message is not handled properly");
Assert.assertEquals("Empty message is not handled properly", "", MessageTranslator.convertMessageLenient("")); Assertions.assertEquals("", MessageTranslator.convertMessageLenient(""), "Empty message is not handled properly");
Assert.assertEquals("Reset before message is not handled properly", "§r§eGame Selector", MessageTranslator.convertMessageLenient("§r§eGame Selector")); Assertions.assertEquals("§r§eGame Selector", MessageTranslator.convertMessageLenient("§r§eGame Selector"), "Reset before message is not handled properly");
Assert.assertEquals("Unimplemented formatting chars not stripped", "Bold Underline", MessageTranslator.convertMessageLenient("§m§nBold Underline")); Assertions.assertEquals("Bold Underline", MessageTranslator.convertMessageLenient("§m§nBold Underline"), "Unimplemented formatting chars not stripped");
} }
@Test @Test
public void convertToPlainText() { 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")); 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");
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")); 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)");
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")); 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)");
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")); 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)");
Assert.assertEquals("Valid lenient JSON is not handled properly", "Strange", MessageTranslator.convertToPlainText("§rStrange", "en_US")); Assertions.assertEquals("Strange", MessageTranslator.convertToPlainText("§rStrange", "en_US"), "Valid lenient JSON is not handled properly");
Assert.assertEquals("Empty message is not handled properly", "", MessageTranslator.convertToPlainText("", "en_US")); Assertions.assertEquals("", MessageTranslator.convertToPlainText("", "en_US"), "Empty message is not handled properly");
Assert.assertEquals("Whitespace is not preserved", " ", MessageTranslator.convertToPlainText(" ", "en_US")); Assertions.assertEquals(" ", MessageTranslator.convertToPlainText(" ", "en_US"), "Whitespace is not preserved");
} }
@Test @Test

Datei anzeigen

@ -36,20 +36,22 @@ import org.geysermc.geyser.api.item.custom.CustomItemOptions;
import org.geysermc.geyser.api.util.TriState; import org.geysermc.geyser.api.util.TriState;
import org.geysermc.geyser.item.GeyserCustomItemOptions; import org.geysermc.geyser.item.GeyserCustomItemOptions;
import org.geysermc.geyser.registry.type.ItemMapping; import org.geysermc.geyser.registry.type.ItemMapping;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import java.util.List; import java.util.List;
import java.util.OptionalInt; import java.util.OptionalInt;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class CustomItemsTest { public class CustomItemsTest {
private ItemMapping testMappingWithDamage; private ItemMapping testMappingWithDamage;
private Object2IntMap<CompoundTag> tagToCustomItemWithDamage; private Object2IntMap<CompoundTag> tagToCustomItemWithDamage;
private ItemMapping testMappingWithNoDamage; private ItemMapping testMappingWithNoDamage;
private Object2IntMap<CompoundTag> tagToCustomItemWithNoDamage; private Object2IntMap<CompoundTag> tagToCustomItemWithNoDamage;
@Before @BeforeAll
public void setup() { public void setup() {
CustomItemOptions a = new GeyserCustomItemOptions(TriState.TRUE, OptionalInt.of(2), OptionalInt.empty()); CustomItemOptions a = new GeyserCustomItemOptions(TriState.TRUE, OptionalInt.of(2), OptionalInt.empty());
CustomItemOptions b = new GeyserCustomItemOptions(TriState.FALSE, OptionalInt.of(5), OptionalInt.empty()); CustomItemOptions b = new GeyserCustomItemOptions(TriState.FALSE, OptionalInt.of(5), OptionalInt.empty());
@ -147,12 +149,12 @@ public class CustomItemsTest {
public void testCustomItems() { public void testCustomItems() {
for (Object2IntMap.Entry<CompoundTag> entry : this.tagToCustomItemWithDamage.object2IntEntrySet()) { for (Object2IntMap.Entry<CompoundTag> entry : this.tagToCustomItemWithDamage.object2IntEntrySet()) {
int id = CustomItemTranslator.getCustomItem(entry.getKey(), this.testMappingWithDamage); 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<CompoundTag> entry : this.tagToCustomItemWithNoDamage.object2IntEntrySet()) { for (Object2IntMap.Entry<CompoundTag> entry : this.tagToCustomItemWithNoDamage.object2IntEntrySet()) {
int id = CustomItemTranslator.getCustomItem(entry.getKey(), this.testMappingWithNoDamage); 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");
} }
} }
} }

Datei anzeigen

@ -25,9 +25,11 @@
package org.geysermc.geyser.util.collection; package org.geysermc.geyser.util.collection;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class GeyserCollectionsTest { public class GeyserCollectionsTest {
private final byte[] bytes = new byte[] {(byte) 5, (byte) 4, (byte) 3, (byte) 2, (byte) 2, (byte) 1}; 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}; private final boolean[] booleans = new boolean[] {true, false, false, true};
@ -51,35 +53,35 @@ public class GeyserCollectionsTest {
int lastKey = index; int lastKey = index;
// Easy, understandable out-of-bounds checks // Easy, understandable out-of-bounds checks
Assert.assertFalse("Map contains key bigger by one!", map.containsKey(lastKey)); Assertions.assertFalse(map.containsKey(lastKey), "Map contains key bigger by one!");
Assert.assertTrue("Map doesn't contain final key!", map.containsKey(lastKey - 1)); 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 // Ensure the first and last values do not throw an exception on get, and test getOrDefault
map.get(start - 1); map.get(start - 1);
map.get(lastKey); map.get(lastKey);
Assert.assertEquals(map.getOrDefault(start - 1, Byte.MAX_VALUE), Byte.MAX_VALUE); Assertions.assertEquals(map.getOrDefault(start - 1, Byte.MAX_VALUE), Byte.MAX_VALUE);
Assert.assertEquals(map.getOrDefault(lastKey, Byte.MAX_VALUE), Byte.MAX_VALUE); Assertions.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(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++) { for (int i = start; i < bytes.length; i++) {
Assert.assertTrue(map.containsKey(i)); Assertions.assertTrue(map.containsKey(i));
Assert.assertEquals(map.get(i), bytes[i - start]); Assertions.assertEquals(map.get(i), bytes[i - start]);
} }
for (int i = start - 1; i >= (start - 6); i--) { for (int i = start - 1; i >= (start - 6); i--) {
// Lower than expected check // 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++) { for (int i = bytes.length + start; i < bytes.length + 5 + start; i++) {
// Higher than expected check // 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) { for (byte b : bytes) {
Assert.assertTrue(map.containsValue(b)); Assertions.assertTrue(map.containsValue(b));
} }
} }
@ -99,33 +101,33 @@ public class GeyserCollectionsTest {
int lastKey = index; int lastKey = index;
// Easy, understandable out-of-bounds checks // Easy, understandable out-of-bounds checks
Assert.assertFalse("Map contains key bigger by one!", map.containsKey(lastKey)); Assertions.assertFalse(map.containsKey(lastKey), "Map contains key bigger by one!");
Assert.assertTrue("Map doesn't contain final key!", map.containsKey(lastKey - 1)); 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 // Ensure the first and last values do not throw an exception on get
map.get(start - 1); map.get(start - 1);
map.get(lastKey); 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++) { for (int i = start; i < booleans.length; i++) {
Assert.assertTrue(map.containsKey(i)); Assertions.assertTrue(map.containsKey(i));
Assert.assertEquals(map.get(i), booleans[i - start]); Assertions.assertEquals(map.get(i), booleans[i - start]);
} }
for (int i = start - 1; i >= (start - 6); i--) { for (int i = start - 1; i >= (start - 6); i--) {
// Lower than expected check // 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++) { for (int i = booleans.length + start; i < booleans.length + start + 5; i++) {
// Higher than expected check // 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) { for (boolean b : booleans) {
Assert.assertTrue(map.containsValue(b)); Assertions.assertTrue(map.containsValue(b));
} }
} }
@ -145,35 +147,35 @@ public class GeyserCollectionsTest {
int lastKey = index; int lastKey = index;
// Easy, understandable out-of-bounds checks // Easy, understandable out-of-bounds checks
Assert.assertFalse("Map contains key bigger by one!", map.containsKey(lastKey)); Assertions.assertFalse(map.containsKey(lastKey), "Map contains key bigger by one!");
Assert.assertTrue("Map doesn't contain final key!", map.containsKey(lastKey - 1)); 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 // Ensure the first and last values do not throw an exception on get, and test getOrDefault
map.get(start - 1); map.get(start - 1);
map.get(lastKey); map.get(lastKey);
Assert.assertEquals(map.getOrDefault(start - 1, Integer.MAX_VALUE), Integer.MAX_VALUE); Assertions.assertEquals(map.getOrDefault(start - 1, Integer.MAX_VALUE), Integer.MAX_VALUE);
Assert.assertEquals(map.getOrDefault(lastKey, Integer.MAX_VALUE), Integer.MAX_VALUE); Assertions.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(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++) { for (int i = start; i < ints.length; i++) {
Assert.assertTrue(map.containsKey(i)); Assertions.assertTrue(map.containsKey(i));
Assert.assertEquals(map.get(i), ints[i - start]); Assertions.assertEquals(map.get(i), ints[i - start]);
} }
for (int i = start - 1; i >= (start - 6); i--) { for (int i = start - 1; i >= (start - 6); i--) {
// Lower than expected check // 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++) { for (int i = ints.length + start; i < ints.length + 5 + start; i++) {
// Higher than expected check // 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) { for (int i : ints) {
Assert.assertTrue(map.containsValue(i)); Assertions.assertTrue(map.containsValue(i));
} }
} }
} }

Datei anzeigen

@ -15,7 +15,7 @@ mcprotocollib = "1.19.3-20230107.194116-10"
packetlib = "3.0.1" packetlib = "3.0.1"
adventure = "4.12.0-20220629.025215-9" adventure = "4.12.0-20220629.025215-9"
adventure-platform = "4.1.2" adventure-platform = "4.1.2"
junit = "4.13.1" junit = "5.9.2"
checkerframework = "3.19.0" checkerframework = "3.19.0"
log4j = "2.17.1" log4j = "2.17.1"
jline = "3.21.0" 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" } commodore = { group = "me.lucko", name = "commodore", version.ref = "commodore" }
guava = { group = "com.google.guava", name = "guava", version.ref = "guava" } guava = { group = "com.google.guava", name = "guava", version.ref = "guava" }
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" } 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" } mcauthlib = { group = "com.github.GeyserMC", name = "MCAuthLib", version.ref = "mcauthlib" }
mcprotocollib = { group = "com.github.steveice10", name = "mcprotocollib", version.ref = "mcprotocollib" } mcprotocollib = { group = "com.github.steveice10", name = "mcprotocollib", version.ref = "mcprotocollib" }
packetlib = { group = "com.github.steveice10", name = "packetlib", version.ref = "packetlib" } packetlib = { group = "com.github.steveice10", name = "packetlib", version.ref = "packetlib" }