From 2c4d22b49569a65aa7bd70924b30ce6abae79fb5 Mon Sep 17 00:00:00 2001 From: ApionXD Date: Tue, 7 Feb 2023 23:11:58 -0500 Subject: [PATCH 01/15] Started working on moving to a normal gradle build --- .github/workflows/ci.yml | 43 ----- .github/workflows/dev.yml | 102 ----------- build.gradle | 86 +++++++++ build.gradle.kts | 238 ------------------------- gradle/libs.versions.toml | 64 ------- settings.gradle.kts => settings.gradle | 0 6 files changed, 86 insertions(+), 447 deletions(-) delete mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/dev.yml create mode 100644 build.gradle delete mode 100644 build.gradle.kts delete mode 100644 gradle/libs.versions.toml rename settings.gradle.kts => settings.gradle (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index e0badef93..000000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: CI - -on: - pull_request: - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - java: [ 17 ] - name: CI (Java ${{ matrix.java }}) - - steps: - - uses: actions/checkout@v3 - - uses: gradle/wrapper-validation-action@v1 - - name: Set up JDK - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: ${{ matrix.java }} - - - name: Cache gradle - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ~/.gradle/jdks - ~/.gradle/native - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', 'gradle/libs.versions.toml') }} - restore-keys: | - ${{ runner.os }}-gradle- - - - name: Gradle Build - run: BUILD_EXTRAS=true ./gradlew assemble --no-daemon --stacktrace - - - name: Cleanup Gradle Cache - # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. - # Restoring these files from a GitHub Actions cache might cause problems for future builds. - run: | - rm -f ~/.gradle/caches/modules-2/modules-2.lock - rm -f ~/.gradle/caches/modules-2/gc.properties diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml deleted file mode 100644 index ae61b1dec..000000000 --- a/.github/workflows/dev.yml +++ /dev/null @@ -1,102 +0,0 @@ -name: Dev Build - -on: - push: - branches: [dev, '1.12'] - paths: - - .github/workflows/** - - etc/checkstyle.xml - - src/** - - gradle/** - - gradle.properties - - '**/*.gradle*' - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - java: [ 17 ] - name: Dev Build (Java ${{ matrix.java }}) - - steps: - - uses: actions/checkout@v3 - - uses: gradle/wrapper-validation-action@v1 - - name: Set up JDK - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: ${{ matrix.java }} - - - name: Cache gradle - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ~/.gradle/jdks - ~/.gradle/native - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', 'gradle/libs.versions.toml') }} - restore-keys: | - ${{ runner.os }}-gradle- - - - name: Gradle Build and Deploy - run: BUILD_EXTRAS=true ./gradlew assemble publish --no-daemon --stacktrace - env: - ORG_GRADLE_PROJECT_glowstoneUsername: ${{ secrets.MAVEN_USERNAME }} - ORG_GRADLE_PROJECT_glowstonePassword: ${{ secrets.MAVEN_PASSWORD }} - - - name: Get Minecraft version - id: version - run: | - minecraft_version=$(./gradlew -q printMinecraftVersion) - echo "::set-output name=minecraft_version::$minecraft_version" - - - name: Cleanup Gradle Cache - # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. - # Restoring these files from a GitHub Actions cache might cause problems for future builds. - run: | - rm -f ~/.gradle/caches/modules-2/modules-2.lock - rm -f ~/.gradle/caches/modules-2/gc.properties - - - name: Push Javadocs to Pages - uses: dmnemec/copy_file_to_another_repo_action@v1.1.1 - env: - API_TOKEN_GITHUB: ${{ secrets.GH_TOKEN }} - with: - source_file: 'build/docs/javadoc/.' - destination_repo: 'GlowstoneMC/glowstonemc.github.io' - destination_folder: content/jd/glowstone/${{ steps.version.outputs.minecraft_version }}/ - user_email: 'mastercoms@tuta.io' - user_name: 'mastercoms' - commit_message: Update Javadocs for Glowstone commit ${{ github.sha }} - - - name: GitHub Artifact - uses: actions/upload-artifact@v3 - with: - name: glowstone - path: build/libs/glowstone.jar - - - name: Setup SSH - if: ${{ github.ref == 'refs/heads/1.12' }} - run: | - mkdir -p ~/.ssh - cat << EOF > ~/.ssh/config - Host * - ControlMaster auto - ControlPath ~/.ssh/-%r@%h:%p - ControlPersist 120 - EOF - echo $SSH_KNOWN_HOSTS >> ~/.ssh/known_hosts - sudo apt-get install sshpass - env: - SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }} - - - name: Deploy to Test Server - if: ${{ github.ref == 'refs/heads/1.12' }} - run: | - sshpass -e scp target/glowstone.jar glowstone@$SSH_ADDRESS: - sshpass -e ssh glowstone@$SSH_ADDRESS sudo systemctl restart glowstone - env: - SSH_ADDRESS: ${{ secrets.SSH_ADDRESS }} - SSHPASS: ${{ secrets.SSH_PASSWORD }} diff --git a/build.gradle b/build.gradle new file mode 100644 index 000000000..d1d3c3887 --- /dev/null +++ b/build.gradle @@ -0,0 +1,86 @@ +plugins { + id('java') + id('application') + id('maven-publish') + id('checkstyle') + id('jacoco') + + id("io.freefair.lombok") version "6.5.0-rc1" + id("com.github.johnrengelman.shadow") version "7.1.2" +} +application { + mainClass = "net.glowstone.GlowServer" +} + +repositories { + mavenCentral() + maven { + url "https://libraries.minecraft.net" + } + maven{ + url ("https://repo.papermc.io/repository/maven-public/") + } +} + +dependencies { + implementation("io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT") + + implementation("org.fusesource.jansi:jansi:1.18") + implementation("jline:jline:2.14.6") + implementation("com.eatthepath:fast-uuid:0.1") + implementation("com.mojang:brigadier:1.0.17") + implementation("org.jogamp.gluegen:gluegen-rt-main:2.3.2") + implementation("org.jogamp.jocl:jocl-main:2.3.2") + implementation("com.tobedevoured.naether:core:0.15.8") { + exclude group: "org.slf4j", module: "slf4j-simple" + } + implementation('org.apache.commons:commons-lang3:3.12.0') + + + runtimeOnly("org.apache.logging.log4j:log4j-slf4j18-impl:2.17.1") + runtimeOnly("com.lmax:disruptor:3.4.4") + + testImplementation("junit:junit:4.13.1") + testImplementation("org.junit.vintage:junit-vintage-engine:5.7.2") + testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.2") + testImplementation("org.junit.jupiter:junit-jupiter-params:5.7.2") + testImplementation("org.junit.jupiter:junit-jupiter-engine:5.7.2") + + testImplementation("org.hamcrest:hamcrest:2.2") + testImplementation("org.powermock:powermock-core:2.0.9") + testImplementation("org.powermock:powermock-module-junit4:2.0.9") + testImplementation("org.powermock:powermock-api-mockito2:2.0.9") + + compileOnly("org.jetbrains:annotations:21.0.1") + compileOnly('com.flowpowered:flow-network:1.0.0') +} + +group = "net.glowstone" +version = "2022.6.1-SNAPSHOT" +description = "A fast, customizable and compatible open source Minecraft server." +var javaVersion = 17 +var buildExtras = java.util.Optional.ofNullable(System.getenv("BUILD_EXTRAS")) + +checkstyle { + configFile = new File(project.projectDir, "/etc/checkstyle.xml") + configProperties["checkstyle.header.file"] = new File(project.projectDir, "LICENSE") + ignoreFailures = false +} + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(javaVersion) + } + + if (buildExtras.isPresent() && Boolean.parseBoolean(buildExtras.get())){ + withSourcesJar() + tasks.named("sourcesJar") { + archiveVersion.set("") + } + + withJavadocJar() + tasks.named("javadocJar") { + archiveVersion.set("") + } + } +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts deleted file mode 100644 index 4c6290218..000000000 --- a/build.gradle.kts +++ /dev/null @@ -1,238 +0,0 @@ -import org.gradle.api.tasks.testing.logging.TestExceptionFormat -import org.gradle.api.tasks.testing.logging.TestLogEvent -import java.io.ByteArrayOutputStream - -plugins { - java - `maven-publish` - checkstyle - jacoco - kotlin("jvm") version "1.7.0" - - id("io.freefair.lombok") version "6.5.0-rc1" - id("com.github.johnrengelman.shadow") version "7.1.2" -} - -val buildExtras = System.getenv("BUILD_EXTRAS")?.toBoolean() ?: false - -repositories { - mavenLocal() - - maven("https://repo.glowstone.net/repository/maven-public/") - maven("https://repo.glowstone.net/repository/snapshots/") - maven("https://libraries.minecraft.net") -} - -dependencies { - implementation(libs.bundles.linkstone) - implementation(libs.bundles.glowstone) - - implementation(libs.jansi) - implementation(libs.jline) - implementation(libs.fastutil) - implementation(libs.flow) - implementation(libs.fastuuid) - implementation(libs.brigadier) - implementation(libs.gluegen) - implementation(libs.jocl) - implementation(libs.naether) { - exclude(group = "org.slf4j", module = "slf4j-simple") - } - implementation(libs.maven.artifact) - - runtimeOnly(libs.log4j) - runtimeOnly("com.lmax:disruptor:3.4.4") - - testImplementation(libs.bundles.junit) - testImplementation(kotlin("test")) - testRuntimeOnly(libs.bundles.junitRuntime) - - testImplementation(libs.hamcrest) - testImplementation(libs.bundles.powermock) - - compileOnly(libs.jetbrains.annotations) -} - -group = "net.glowstone" -version = "2022.6.1-SNAPSHOT" -description = "A fast, customizable and compatible open source Minecraft server." - -publishing { - repositories { - val mavenPublishUrl = "https://repo.glowstone.net/content/repositories/" - val isSnapshot = version.toString().endsWith("-SNAPSHOT") - maven { - name = "glowstone" - url = uri(mavenPublishUrl + if (isSnapshot) "snapshots/" else "releases/") - credentials(PasswordCredentials::class) - } - } - publications { - register("maven") { - withoutBuildIdentifier() - from(components["java"]) - pom { - name.set(project.name) - description.set(project.description) - url.set("https://www.glowstone.net") - inceptionYear.set("2011") - - licenses { - license { - name.set("MIT") - url.set("https://github.com/GlowstoneMC/Glowstone/blob/dev/LICENSE") - distribution.set("repo") - } - } - } - } - } -} - -checkstyle { - configFile = File(project.projectDir, "/etc/checkstyle.xml") - configProperties["checkstyle.header.file"] = File(project.projectDir, "LICENSE") - toolVersion = libs.versions.checkstyle.get() - isIgnoreFailures = true -} - -val javaVersion = 17 - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(javaVersion)) - } - - if (buildExtras) { - withSourcesJar() - tasks.named("sourcesJar") { - archiveVersion.set("") - } - - withJavadocJar() - tasks.named("javadocJar") { - archiveVersion.set("") - } - } -} - -kotlin { - jvmToolchain { - (this as JavaToolchainSpec).apply { - languageVersion.set(JavaLanguageVersion.of(javaVersion)) - } - } -} - -tasks.withType { - options.encoding = Charsets.UTF_8.name() - options.release.set(javaVersion) -} - -tasks.withType { - options.encoding = Charsets.UTF_8.name() - - if (JavaVersion.current().isJava9Compatible) { - (options as StandardJavadocDocletOptions).addBooleanOption("html5", true) - } - - exclude("**/*.xml") -} - -tasks.withType { - filteringCharset = Charsets.UTF_8.name() -} - -tasks.withType { - testLogging { - showStackTraces = true - exceptionFormat = TestExceptionFormat.FULL - events(TestLogEvent.STANDARD_OUT) - } -} - -fun getGitHash(): String { - val stdout = ByteArrayOutputStream() - exec { - commandLine = listOf("git", "rev-parse", "--short=7", "HEAD") - standardOutput = stdout - } - return stdout.toString().trim() -} - -fun getGitBranch(): String { - val stdout = ByteArrayOutputStream() - exec { - commandLine = listOf("git", "rev-parse", "--abbrev-ref", "HEAD") - standardOutput = stdout - } - return stdout.toString().trim() -} - -fun getGitDate(gitHash: String): String { - val stdout = ByteArrayOutputStream() - exec { - commandLine = listOf("git", "show", "-s", "--format=%ci", gitHash) - standardOutput = stdout - } - return stdout.toString().trim() -} - -tasks.jar { - enabled = false - manifest { - val gitHash = getGitHash() - val gitBranch = getGitBranch() - val date = getGitDate(gitHash) - attributes( - "Launcher-Agent-Class" to "net.glowstone.util.ClassPathAgent", - "Main-Class" to "net.glowstone.GlowServer", - - "Implementation-Title" to "Glowstone", - "Implementation-Version" to "git-${project.name}-${gitHash}-${project.version}", - "Implementation-Vendor" to date, - - "Specification-Title" to "Bukkit", - "Specification-Version" to libs.versions.api.get(), - "Specification-Vendor" to "Bukkit Team", - - "Git-Branch" to gitBranch, - "Git-Commit" to gitHash, - ) - for (tld in setOf("net", "com", "org")) { - attributes("$tld/bukkit", "Sealed" to true) - } - } -} - -tasks.shadowJar { - val prefix = "org.bukkit.craftbukkit.libs" - listOf( - "jline", - "it.unimi", - ).forEach { pattern -> - relocate(pattern, "$prefix.$pattern") - } - - exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "OSGI-INF/**", "*.profile", "module-info.class", "ant_tasks/**", "mojang-translations/*") - - archiveVersion.set("") - archiveClassifier.set("") -} - -tasks.assemble { dependsOn(tasks.shadowJar) } - -tasks.getByName("test") { - useJUnitPlatform() - finalizedBy(tasks.jacocoTestReport) -} - -tasks.register("printMinecraftVersion") { - doLast { - println(providers.gradleProperty("mcVersion").get().trim()) - } -} - -tasks.jacocoTestReport { - dependsOn(tasks.test) -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml deleted file mode 100644 index 279705bbd..000000000 --- a/gradle/libs.versions.toml +++ /dev/null @@ -1,64 +0,0 @@ -[versions] -api = "1.19-R0.1-SNAPSHOT" -redstone-transformer = "1.1.0-SNAPSHOT" -linkstone = "1.0.0-SNAPSHOT" - -checkstyle = "8.44" -jansi = "1.18" -jline = "2.14.6" -fastutil = "1.0" -flow = "1.2.10-SNAPSHOT" -fastuuid = "0.1" -brigadier = "1.0.17" -gluegen = "2.3.2" -jocl = "2.3.2" -naether = "0.15.8" -maven-artifact = "3.8.1" -log4j = "2.17.1" -junit-core = "4.13.1" -junit-ext = "5.7.2" -hamcrest = "2.2" -powermock = "2.0.9" -jetbrains-annotations = "21.0.1" - -[libraries] -linkstone-annotations = { module = "net.glowstone:linkstone-annotations", version.ref = "linkstone" } -linkstone-runtime = { module = "net.glowstone:linkstone-runtime", version.ref = "linkstone" } - -glowstone-glowkit = { module = "net.glowstone:glowkit", version.ref = "api" } -glowstone-blockdata = { module = "net.glowstone:block-data-generated", version.ref = "redstone-transformer" } -glowstone-datapack = { module = "net.glowstone:data-pack-generated", version.ref = "redstone-transformer" } - -gluegen = { module = "org.jogamp.gluegen:gluegen-rt-main", version.ref = "gluegen" } -jocl = { module = "org.jogamp.jocl:jocl-main", version.ref = "jocl" } - -naether = { module = "com.tobedevoured.naether:core", version.ref = "naether" } -maven-artifact = { module = "org.apache.maven:maven-artifact", version.ref = "maven-artifact" } -log4j = { module = "org.apache.logging.log4j:log4j-slf4j18-impl", version.ref = "log4j" } -jansi = { module = "org.fusesource.jansi:jansi", version.ref = "jansi" } -jline = { module = "jline:jline", version.ref = "jline" } -fastutil = { module = "co.aikar:fastutil-lite", version.ref = "fastutil" } -flow = { module = "com.flowpowered:flow-network", version.ref = "flow" } -fastuuid = { module = "com.eatthepath:fast-uuid", version.ref = "fastuuid" } -brigadier = { module = "com.mojang:brigadier", version.ref = "brigadier" } - -junit-core = { module = "junit:junit", version.ref = "junit-core" } -junit-vintage-engine = { module = "org.junit.vintage:junit-vintage-engine", version.ref = "junit-ext" } -junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-ext" } -junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit-ext" } -junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-ext" } - -hamcrest = { module = "org.hamcrest:hamcrest", version.ref = "hamcrest" } -powermock-core = { module = "org.powermock:powermock-core", version.ref = "powermock" } -powermock-module-junit4 = { module = "org.powermock:powermock-module-junit4", version.ref = "powermock" } -powermock-api-mockito2 = { module = "org.powermock:powermock-api-mockito2", version.ref = "powermock" } - -jetbrains-annotations = { module = "org.jetbrains:annotations", version.ref = "jetbrains-annotations" } - -[bundles] -glowstone = ["glowstone-glowkit", "glowstone-blockdata", "glowstone-datapack"] - -linkstone = ["linkstone-annotations", "linkstone-runtime"] -junit = ["junit-core", "junit-jupiter-api", "junit-jupiter-params"] -junitRuntime = ["junit-jupiter-engine", "junit-vintage-engine"] -powermock = ["powermock-core", "powermock-module-junit4", "powermock-api-mockito2"] diff --git a/settings.gradle.kts b/settings.gradle similarity index 100% rename from settings.gradle.kts rename to settings.gradle From 3fa9a339f2ccbcf398a37b3512dc378984ca8a43 Mon Sep 17 00:00:00 2001 From: ApionXD Date: Wed, 8 Feb 2023 22:46:33 -0500 Subject: [PATCH 02/15] Added method stubs for all new API methods, fixed compile issues, removed all Linkstone stuff --- build.gradle | 13 +- gradle.properties | 3 +- settings.gradle | 1 - .../java/net/glowstone/GlowOfflinePlayer.java | 2 +- src/main/java/net/glowstone/GlowServer.java | 62 +++++-- src/main/java/net/glowstone/GlowWorld.java | 27 ++++ .../java/net/glowstone/GlowWorldBorder.java | 18 +++ .../advancement/GlowAdvancement.java | 6 + .../advancement/GlowAdvancementDisplay.java | 5 + .../java/net/glowstone/block/GlowBlock.java | 20 +++ .../net/glowstone/block/GlowBlockState.java | 20 +++ .../block/entity/state/GlowDispenser.java | 8 + .../block/entity/state/GlowSkull.java | 11 ++ .../block/itemtype/ItemItemFrame.java | 2 +- .../java/net/glowstone/chunk/GlowChunk.java | 6 + .../glowstone/chunk/GlowChunkSnapshot.java | 5 + .../net/glowstone/entity/GlowCreature.java | 19 +++ .../java/net/glowstone/entity/GlowEntity.java | 46 ++++++ .../net/glowstone/entity/GlowHumanEntity.java | 76 +++++++++ .../glowstone/entity/GlowLivingEntity.java | 75 ++++++++- .../java/net/glowstone/entity/GlowPlayer.java | 151 ++++++++++++++++++ .../meta/profile/GlowPlayerProfile.java | 2 +- .../glowstone/entity/monster/GlowBlaze.java | 6 +- .../entity/monster/GlowCaveSpider.java | 6 +- .../glowstone/entity/monster/GlowCreeper.java | 4 +- .../entity/monster/GlowElderGuardian.java | 6 +- .../entity/monster/GlowEnderman.java | 6 +- .../entity/monster/GlowEndermite.java | 16 +- .../glowstone/entity/monster/GlowEvoker.java | 6 +- .../glowstone/entity/monster/GlowGhast.java | 6 +- .../glowstone/entity/monster/GlowGiant.java | 2 +- .../entity/monster/GlowGuardian.java | 6 +- .../entity/monster/GlowIronGolem.java | 4 +- .../entity/monster/GlowMagmaCube.java | 4 +- .../glowstone/entity/monster/GlowMonster.java | 1 + .../entity/monster/GlowPigZombie.java | 6 +- .../glowstone/entity/monster/GlowRaider.java | 7 + .../glowstone/entity/monster/GlowShulker.java | 6 +- .../entity/monster/GlowSilverfish.java | 6 +- .../entity/monster/GlowSkeleton.java | 6 +- .../glowstone/entity/monster/GlowSlime.java | 4 +- .../glowstone/entity/monster/GlowSnowman.java | 6 +- .../glowstone/entity/monster/GlowSpider.java | 6 +- .../glowstone/entity/monster/GlowStray.java | 6 +- .../net/glowstone/entity/monster/GlowVex.java | 6 +- .../entity/monster/GlowVindicator.java | 6 +- .../glowstone/entity/monster/GlowWitch.java | 6 +- .../glowstone/entity/monster/GlowWither.java | 6 +- .../entity/monster/GlowWitherSkeleton.java | 6 +- .../glowstone/entity/monster/GlowZombie.java | 6 +- .../entity/monster/GlowZombieVillager.java | 11 +- .../monster/complex/GlowEnderDragon.java | 4 +- .../entity/objects/GlowArmorStand.java | 80 ++++++++++ .../glowstone/entity/objects/GlowBoat.java | 15 ++ .../glowstone/entity/objects/GlowItem.java | 11 ++ .../entity/objects/GlowMinecart.java | 20 +++ .../net/glowstone/entity/passive/GlowBat.java | 37 ++++- .../glowstone/entity/passive/GlowChicken.java | 11 +- .../net/glowstone/entity/passive/GlowCow.java | 6 +- .../glowstone/entity/passive/GlowDonkey.java | 6 +- .../entity/passive/GlowFirework.java | 55 +++++++ .../entity/passive/GlowFishingHook.java | 20 +++ .../glowstone/entity/passive/GlowHorse.java | 6 +- .../glowstone/entity/passive/GlowLlama.java | 38 ++++- .../entity/passive/GlowMooshroom.java | 28 +++- .../glowstone/entity/passive/GlowMule.java | 6 +- .../glowstone/entity/passive/GlowOcelot.java | 6 +- .../glowstone/entity/passive/GlowParrot.java | 11 +- .../net/glowstone/entity/passive/GlowPig.java | 6 +- .../entity/passive/GlowPolarBear.java | 6 +- .../glowstone/entity/passive/GlowRabbit.java | 16 +- .../glowstone/entity/passive/GlowSheep.java | 6 +- .../entity/passive/GlowSkeletonHorse.java | 6 +- .../glowstone/entity/passive/GlowSquid.java | 6 +- .../entity/passive/GlowVillager.java | 16 +- .../glowstone/entity/passive/GlowWolf.java | 16 +- .../entity/passive/GlowZombieHorse.java | 6 +- .../entity/projectile/GlowArrow.java | 21 +++ .../projectile/GlowLingeringPotion.java | 5 + .../entity/projectile/GlowProjectile.java | 19 +++ .../entity/projectile/GlowSplashPotion.java | 5 + .../glowstone/inventory/GlowMetaSkull.java | 12 ++ .../handler/legacyping/LegacyPingHandler.java | 3 +- .../glowstone/net/protocol/GlowProtocol.java | 2 +- .../glowstone/scoreboard/GlowObjective.java | 6 + .../glowstone/scoreboard/GlowScoreboard.java | 26 +++ .../net/glowstone/util/GlowUnsafeValues.java | 19 +++ .../linkstone/LinkstoneClassInitObserver.java | 116 -------------- .../util/linkstone/LinkstonePluginLoader.java | 63 -------- .../linkstone/LinkstonePluginScanner.java | 59 ------- 90 files changed, 1153 insertions(+), 398 deletions(-) delete mode 100644 src/main/java/net/glowstone/util/linkstone/LinkstoneClassInitObserver.java delete mode 100644 src/main/java/net/glowstone/util/linkstone/LinkstonePluginLoader.java delete mode 100644 src/main/java/net/glowstone/util/linkstone/LinkstonePluginScanner.java diff --git a/build.gradle b/build.gradle index d1d3c3887..990e2bed7 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,7 @@ application { repositories { mavenCentral() + mavenLocal() maven { url "https://libraries.minecraft.net" } @@ -24,7 +25,13 @@ repositories { dependencies { implementation("io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT") + implementation("net.glowstone:glowkit:1.19.3-R0.1-SNAPSHOT") + implementation("net.glowstone:block-data-generated:1.1.0-SNAPSHOT") + implementation("net.glowstone:data-pack-generated:1.1.0-SNAPSHOT") + implementation("io.netty:netty-all:4.1.87.Final") + implementation("org.ow2.asm:asm:9.2") + implementation("org.ow2.asm:asm-commons:9.2") implementation("org.fusesource.jansi:jansi:1.18") implementation("jline:jline:2.14.6") implementation("com.eatthepath:fast-uuid:0.1") @@ -35,6 +42,7 @@ dependencies { exclude group: "org.slf4j", module: "slf4j-simple" } implementation('org.apache.commons:commons-lang3:3.12.0') + implementation("org.apache.maven:maven-artifact:3.8.1") runtimeOnly("org.apache.logging.log4j:log4j-slf4j18-impl:2.17.1") @@ -52,7 +60,7 @@ dependencies { testImplementation("org.powermock:powermock-api-mockito2:2.0.9") compileOnly("org.jetbrains:annotations:21.0.1") - compileOnly('com.flowpowered:flow-network:1.0.0') + implementation('com.flowpowered:flow-network:1.0.0') } group = "net.glowstone" @@ -83,4 +91,7 @@ java { archiveVersion.set("") } } +} +tasks.withType(JavaCompile) { + options.warnings = false } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index d688a63e6..ca394264e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,6 @@ group = net.glowstone -mcVersion = 1.19 +mcVersion = 1.19.3 +org.gradle.warning.mode=fail org.gradle.caching=true org.gradle.parallel=true diff --git a/settings.gradle b/settings.gradle index e67cbfc1e..31a709459 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,5 +3,4 @@ */ rootProject.name = "glowstone" -enableFeaturePreview("VERSION_CATALOGS") enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") diff --git a/src/main/java/net/glowstone/GlowOfflinePlayer.java b/src/main/java/net/glowstone/GlowOfflinePlayer.java index 4d158bc3e..c9d809b8d 100644 --- a/src/main/java/net/glowstone/GlowOfflinePlayer.java +++ b/src/main/java/net/glowstone/GlowOfflinePlayer.java @@ -1,5 +1,6 @@ package net.glowstone; +import com.destroystokyo.paper.profile.PlayerProfile; import lombok.Getter; import net.glowstone.entity.meta.profile.GlowPlayerProfile; import net.glowstone.entity.meta.profile.ProfileCache; @@ -15,7 +16,6 @@ import org.bukkit.configuration.serialization.SerializableAs; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; -import org.bukkit.profile.PlayerProfile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/glowstone/GlowServer.java b/src/main/java/net/glowstone/GlowServer.java index 079c70afa..39db9caf6 100644 --- a/src/main/java/net/glowstone/GlowServer.java +++ b/src/main/java/net/glowstone/GlowServer.java @@ -102,10 +102,10 @@ import net.glowstone.io.ScoreboardIoService; import net.glowstone.io.WorldStorageProviderFactory; import net.glowstone.io.anvil.AnvilWorldStorageProvider; -import net.glowstone.linkstone.runtime.Boxes; -import net.glowstone.linkstone.runtime.FieldSet; -import net.glowstone.linkstone.runtime.LinkstoneRuntimeData; -import net.glowstone.linkstone.runtime.inithook.ClassInitHook; +//import net.glowstone.linkstone.runtime.Boxes; +//import net.glowstone.linkstone.runtime.FieldSet; +//import net.glowstone.linkstone.runtime.LinkstoneRuntimeData; +//import net.glowstone.linkstone.runtime.inithook.ClassInitHook; import net.glowstone.map.GlowMapView; import net.glowstone.net.GameServer; import net.glowstone.net.GlowSession; @@ -137,9 +137,9 @@ import net.glowstone.util.library.Library; import net.glowstone.util.library.LibraryKey; import net.glowstone.util.library.LibraryManager; -import net.glowstone.util.linkstone.LinkstoneClassInitObserver; -import net.glowstone.util.linkstone.LinkstonePluginLoader; -import net.glowstone.util.linkstone.LinkstonePluginScanner; +//import net.glowstone.util.linkstone.LinkstoneClassInitObserver; +//import net.glowstone.util.linkstone.LinkstonePluginLoader; +//import net.glowstone.util.linkstone.LinkstonePluginScanner; import net.glowstone.util.loot.LootingManager; import net.glowstone.util.mojangson.Mojangson; import net.glowstone.util.mojangson.ex.MojangsonParseException; @@ -161,6 +161,7 @@ import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.OfflinePlayer; +import org.bukkit.Registry; import org.bukkit.Server; import org.bukkit.StructureType; import org.bukkit.Tag; @@ -216,6 +217,7 @@ import org.bukkit.plugin.messaging.StandardMessenger; import org.bukkit.potion.PotionBrewer; import org.bukkit.profile.PlayerProfile; +import org.bukkit.scoreboard.Criteria; import org.bukkit.structure.StructureManager; import org.bukkit.util.CachedServerIcon; import org.bukkit.util.permissions.DefaultPermissions; @@ -541,7 +543,7 @@ public GlowServer(ServerConfig config) { nameBans = new GlowBanList(this, Type.NAME); ipBans = new GlowBanList(this, Type.IP); - ClassInitHook.register(new LinkstoneClassInitObserver()); + //ClassInitHook.register(new LinkstoneClassInitObserver()); loadConfig(); bossBars = new ConcurrentHashMap<>(); @@ -1333,16 +1335,16 @@ private void loadPlugins() { pluginTypeDetector.scan(); // scan plugins for @Field and @Box annotated fields - FieldSet annotatedFields = new FieldSet(); - Boxes boxes = new Boxes(); - LinkstoneRuntimeData.setFields(annotatedFields); - LinkstoneRuntimeData.setBoxes(boxes); - new LinkstonePluginScanner(annotatedFields, boxes) - .scanPlugins(pluginTypeDetector.bukkitPlugins); + //FieldSet annotatedFields = new FieldSet(); + //Boxes boxes = new Boxes(); + //LinkstoneRuntimeData.setFields(annotatedFields); + //LinkstoneRuntimeData.setBoxes(boxes); + //new LinkstonePluginScanner(annotatedFields, boxes) + // .scanPlugins(pluginTypeDetector.bukkitPlugins); // clear plugins and prepare to load (Bukkit) pluginManager.clearPlugins(); - pluginManager.registerInterface(LinkstonePluginLoader.class); + //pluginManager.registerInterface(LinkstonePluginLoader.class); Plugin[] plugins = pluginManager .loadPlugins(folder, pluginTypeDetector.bukkitPlugins); @@ -1611,6 +1613,11 @@ public LootTable getLootTable(@NotNull NamespacedKey tableKey) { return null; } + @Override + public @org.jetbrains.annotations.Nullable Registry getRegistry(@NotNull Class tClass) { + return null; + } + /** * Registers an advancement to the advancement registry. * @@ -1972,6 +1979,11 @@ public GlowScoreboardManager getScoreboardManager() { return scoreboardManager; } + @Override + public @NotNull Criteria getScoreboardCriteria(@NotNull String name) { + return null; + } + @Override @Deprecated public UnsafeValues getUnsafe() { @@ -2517,6 +2529,11 @@ public List getWorlds() { return (List) worlds.getWorlds(); } + @Override + public boolean isTickingWorlds() { + return false; + } + /** * Gets the default ChunkGenerator for the given environment and type. * @@ -2685,6 +2702,11 @@ public Merchant createMerchant(String title) { return null; } + @Override + public int getMaxChainedNeighborUpdates() { + return 0; + } + @Override public GlowServerIcon getServerIcon() { return defaultIcon; @@ -2748,6 +2770,16 @@ public void setSpawnRadius(int value) { spawnRadius = value; } + @Override + public boolean shouldSendChatPreviews() { + return false; + } + + @Override + public boolean isEnforcingSecureProfiles() { + return false; + } + @Override public boolean getHideOnlinePlayers() { return false; diff --git a/src/main/java/net/glowstone/GlowWorld.java b/src/main/java/net/glowstone/GlowWorld.java index 0dae48922..704535cf4 100644 --- a/src/main/java/net/glowstone/GlowWorld.java +++ b/src/main/java/net/glowstone/GlowWorld.java @@ -100,6 +100,7 @@ import org.bukkit.generator.BiomeProvider; import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; +import org.bukkit.generator.structure.Structure; import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; import org.bukkit.metadata.MetadataStore; @@ -110,6 +111,7 @@ import org.bukkit.plugin.messaging.StandardMessenger; import org.bukkit.util.Consumer; import org.bukkit.util.RayTraceResult; +import org.bukkit.util.StructureSearchResult; import org.bukkit.util.Vector; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -1555,6 +1557,11 @@ public boolean lineOfSightExists(@NotNull Location from, @NotNull Location to) { return false; } + @Override + public boolean hasCollisionsIn(org.bukkit.util.@NotNull BoundingBox boundingBox) { + return false; + } + //////////////////////////////////////////////////////////////////////////// // Chunk loading and unloading @@ -2398,11 +2405,21 @@ public void playSound(@NotNull Entity entity, @NotNull Sound sound, float volume } + @Override + public void playSound(@NotNull Entity entity, @NotNull String sound, float volume, float pitch) { + + } + @Override public void playSound(@NotNull Entity entity, @NotNull Sound sound, @NotNull SoundCategory category, float volume, float pitch) { } + @Override + public void playSound(@NotNull Entity entity, @NotNull String sound, @NotNull SoundCategory category, float volume, float pitch) { + + } + @Override public Spigot spigot() { return spigot; @@ -2740,6 +2757,16 @@ public void spawnParticle(@NotNull Particle particle, double v, double v1, d return null; } + @Override + public @Nullable StructureSearchResult locateNearestStructure(@NotNull Location origin, org.bukkit.generator.structure.@NotNull StructureType structureType, int radius, boolean findUnexplored) { + return null; + } + + @Override + public @Nullable StructureSearchResult locateNearestStructure(@NotNull Location origin, @NotNull Structure structure, int radius, boolean findUnexplored) { + return null; + } + @Override public @Nullable Location locateNearestBiome(@NotNull Location location, @NotNull Biome biome, int i) { // TODO: 1.16 diff --git a/src/main/java/net/glowstone/GlowWorldBorder.java b/src/main/java/net/glowstone/GlowWorldBorder.java index 0145d9259..12fc07ad7 100644 --- a/src/main/java/net/glowstone/GlowWorldBorder.java +++ b/src/main/java/net/glowstone/GlowWorldBorder.java @@ -8,6 +8,9 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.WorldBorder; +import org.jetbrains.annotations.NotNull; + +import java.util.concurrent.TimeUnit; public class GlowWorldBorder implements WorldBorder { @@ -131,6 +134,11 @@ public void setSize(double size, long seconds) { broadcast(createMessage()); // TODO 1.19 packet } + @Override + public void setSize(double newSize, @NotNull TimeUnit unit, long time) { + + } + @Override public void setCenter(Location location) { center = location.clone(); @@ -162,6 +170,16 @@ public boolean isInside(Location location) { && location.getX() >= min.getX() && location.getZ() >= min.getZ(); } + @Override + public double getMaxSize() { + return 0; + } + + @Override + public double getMaxCenterCoordinate() { + return 0; + } + private void broadcast(WorldBorderMessage message) { world.getPlayers().forEach(player -> ((GlowPlayer) player).getSession().send(message)); } diff --git a/src/main/java/net/glowstone/advancement/GlowAdvancement.java b/src/main/java/net/glowstone/advancement/GlowAdvancement.java index e29d24410..e29d07a9e 100644 --- a/src/main/java/net/glowstone/advancement/GlowAdvancement.java +++ b/src/main/java/net/glowstone/advancement/GlowAdvancement.java @@ -5,6 +5,7 @@ import io.netty.buffer.ByteBuf; import io.papermc.paper.advancement.AdvancementDisplay; import lombok.Data; +import net.kyori.adventure.text.Component; import org.bukkit.NamespacedKey; import org.bukkit.advancement.Advancement; import org.jetbrains.annotations.NotNull; @@ -114,4 +115,9 @@ public ByteBuf encode(ByteBuf buf) throws IOException { public @Nullable AdvancementDisplay getDisplay() { return display; } + + @Override + public @NotNull Component displayName() { + return null; + } } diff --git a/src/main/java/net/glowstone/advancement/GlowAdvancementDisplay.java b/src/main/java/net/glowstone/advancement/GlowAdvancementDisplay.java index 75f89b1ab..0c0f980d5 100644 --- a/src/main/java/net/glowstone/advancement/GlowAdvancementDisplay.java +++ b/src/main/java/net/glowstone/advancement/GlowAdvancementDisplay.java @@ -116,4 +116,9 @@ public boolean isHidden() { public @Nullable NamespacedKey backgroundPath() { return background; } + + @Override + public @NotNull Component displayName() { + return null; + } } diff --git a/src/main/java/net/glowstone/block/GlowBlock.java b/src/main/java/net/glowstone/block/GlowBlock.java index f2c5a721a..42f5ba31f 100644 --- a/src/main/java/net/glowstone/block/GlowBlock.java +++ b/src/main/java/net/glowstone/block/GlowBlock.java @@ -579,12 +579,32 @@ public boolean breakNaturally(boolean triggerEffect) { return false; } + @Override + public boolean breakNaturally(boolean triggerEffect, boolean dropExperience) { + return true; + } + @Override public boolean breakNaturally(@NotNull ItemStack tool, boolean triggerEffect) { // TODO: triggerEffect return breakNaturally(tool); } + @Override + public boolean breakNaturally(@NotNull ItemStack tool, boolean triggerEffect, boolean dropExperience) { + return false; + } + + @Override + public void tick() { + + } + + @Override + public void randomTick() { + + } + @Override public boolean applyBoneMeal(@NotNull BlockFace blockFace) { return false; diff --git a/src/main/java/net/glowstone/block/GlowBlockState.java b/src/main/java/net/glowstone/block/GlowBlockState.java index 304257209..e1c6e6bd8 100644 --- a/src/main/java/net/glowstone/block/GlowBlockState.java +++ b/src/main/java/net/glowstone/block/GlowBlockState.java @@ -12,12 +12,17 @@ import org.bukkit.block.BlockState; import org.bukkit.block.TileState; import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Entity; +import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; import org.bukkit.metadata.MetadataValue; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; +import java.util.Collection; import java.util.List; /** @@ -110,6 +115,21 @@ public boolean isCollidable() { return false; } + @Override + public @Unmodifiable @NotNull Collection getDrops() { + return null; + } + + @Override + public @Unmodifiable @NotNull Collection getDrops(@Nullable ItemStack tool) { + return null; + } + + @Override + public @Unmodifiable @NotNull Collection getDrops(@NotNull ItemStack tool, @Nullable Entity entity) { + return null; + } + //////////////////////////////////////////////////////////////////////////// // Update diff --git a/src/main/java/net/glowstone/block/entity/state/GlowDispenser.java b/src/main/java/net/glowstone/block/entity/state/GlowDispenser.java index 7cb60619e..c704f4a09 100644 --- a/src/main/java/net/glowstone/block/entity/state/GlowDispenser.java +++ b/src/main/java/net/glowstone/block/entity/state/GlowDispenser.java @@ -33,7 +33,10 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.projectiles.BlockProjectileSource; +import org.bukkit.util.Consumer; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Map; import java.util.concurrent.ThreadLocalRandom; @@ -204,4 +207,9 @@ public T launchProjectile(Class projectile, return null; } + @Override + public @NotNull T launchProjectile(@NotNull Class projectile, @Nullable Vector velocity, @Nullable Consumer function) { + return null; + } + } diff --git a/src/main/java/net/glowstone/block/entity/state/GlowSkull.java b/src/main/java/net/glowstone/block/entity/state/GlowSkull.java index 3e707727a..d5d1605d4 100644 --- a/src/main/java/net/glowstone/block/entity/state/GlowSkull.java +++ b/src/main/java/net/glowstone/block/entity/state/GlowSkull.java @@ -10,6 +10,7 @@ import net.glowstone.entity.meta.profile.GlowPlayerProfile; import net.glowstone.util.Position; import org.bukkit.Bukkit; +import org.bukkit.NamespacedKey; import org.bukkit.OfflinePlayer; import org.bukkit.SkullType; import org.bukkit.block.BlockFace; @@ -106,6 +107,16 @@ public void setOwnerProfile(org.bukkit.profile.@Nullable PlayerProfile profile) owner = (GlowPlayerProfile) profile; } + @Override + public @Nullable NamespacedKey getNoteBlockSound() { + return null; + } + + @Override + public void setNoteBlockSound(@Nullable NamespacedKey noteBlockSound) { + + } + public void setOwner(org.bukkit.profile.@Nullable PlayerProfile profile) { this.owner = (GlowPlayerProfile) profile; } diff --git a/src/main/java/net/glowstone/block/itemtype/ItemItemFrame.java b/src/main/java/net/glowstone/block/itemtype/ItemItemFrame.java index 15689f306..d869163d3 100644 --- a/src/main/java/net/glowstone/block/itemtype/ItemItemFrame.java +++ b/src/main/java/net/glowstone/block/itemtype/ItemItemFrame.java @@ -22,7 +22,7 @@ public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, face); if (EventFactory.getInstance() - .callEvent(new HangingPlaceEvent(entity, player, target, face)) + .callEvent(new HangingPlaceEvent(entity, player, target, face, hand)) .isCancelled()) { return; } diff --git a/src/main/java/net/glowstone/chunk/GlowChunk.java b/src/main/java/net/glowstone/chunk/GlowChunk.java index ce5d49c9f..ef72a6290 100644 --- a/src/main/java/net/glowstone/chunk/GlowChunk.java +++ b/src/main/java/net/glowstone/chunk/GlowChunk.java @@ -27,6 +27,7 @@ import org.bukkit.Difficulty; import org.bukkit.Material; import org.bukkit.World.Environment; +import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; @@ -264,6 +265,11 @@ public boolean contains(@NotNull BlockData block) { return false; } + @Override + public boolean contains(@NotNull Biome biome) { + return false; + } + @Override public @NotNull GlowChunkSnapshot getChunkSnapshot() { return getChunkSnapshot(true, false, false); diff --git a/src/main/java/net/glowstone/chunk/GlowChunkSnapshot.java b/src/main/java/net/glowstone/chunk/GlowChunkSnapshot.java index 3dc44915c..4bc47a8fc 100644 --- a/src/main/java/net/glowstone/chunk/GlowChunkSnapshot.java +++ b/src/main/java/net/glowstone/chunk/GlowChunkSnapshot.java @@ -118,6 +118,11 @@ public boolean contains(@NotNull BlockData blockData) { throw new UnsupportedOperationException("Not supported yet."); } + @Override + public boolean contains(@NotNull Biome biome) { + return false; + } + public int getBlockTypeId(int x, int y, int z) { ChunkSection section = getSection(y); return section == null ? 0 : section.getType(x, y, z) >> 4; diff --git a/src/main/java/net/glowstone/entity/GlowCreature.java b/src/main/java/net/glowstone/entity/GlowCreature.java index 076ae9e77..c6ccaf3de 100644 --- a/src/main/java/net/glowstone/entity/GlowCreature.java +++ b/src/main/java/net/glowstone/entity/GlowCreature.java @@ -8,11 +8,15 @@ import net.glowstone.net.message.play.entity.EntityMetadataMessage; import net.glowstone.net.message.play.entity.SpawnEntityMessage; import net.glowstone.util.Position; +import net.kyori.adventure.util.TriState; import org.bukkit.Location; import org.bukkit.entity.Creature; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Projectile; import org.bukkit.loot.LootTable; +import org.bukkit.util.Consumer; +import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -97,4 +101,19 @@ public long getSeed() { public void setSeed(long seed) { } + + @Override + public @NotNull TriState getFrictionState() { + return TriState.NOT_SET; + } + + @Override + public void setFrictionState(@NotNull TriState state) { + + } + + @Override + public @NotNull T launchProjectile(@NotNull Class projectile, @Nullable Vector velocity, @Nullable Consumer function) { + return null; + } } diff --git a/src/main/java/net/glowstone/entity/GlowEntity.java b/src/main/java/net/glowstone/entity/GlowEntity.java index fc40bbeda..514095b56 100644 --- a/src/main/java/net/glowstone/entity/GlowEntity.java +++ b/src/main/java/net/glowstone/entity/GlowEntity.java @@ -39,6 +39,7 @@ import org.bukkit.EntityEffect; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Sound; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.block.Block; @@ -1812,6 +1813,51 @@ public PersistentDataContainer getPersistentDataContainer() { throw new UnsupportedOperationException("Not implemented yet."); } + @Override + public boolean teleport(@NotNull Location location, @NotNull TeleportCause cause, boolean ignorePassengers, boolean dismount) { + return teleport(location, cause, ignorePassengers); + } + + @Override + public @NotNull Sound getSwimSound() { + return Sound.ENTITY_GENERIC_SWIM; + } + + @Override + public @NotNull Sound getSwimSplashSound() { + return Sound.ENTITY_GENERIC_SPLASH; + } + + @Override + public @NotNull Sound getSwimHighSpeedSplashSound() { + return Sound.ENTITY_GENERIC_SPLASH; + } + + @Override + public boolean isSneaking() { + return false; + } + + @Override + public void setSneaking(boolean sneak) { + + } + + @Override + public boolean isUnderWater() { + return false; + } + + @Override + public boolean collidesAt(@NotNull Location location) { + return false; + } + + @Override + public boolean wouldCollideUsing(org.bukkit.util.@NotNull BoundingBox boundingBox) { + return false; + } + /** * The metadata store class for entities. */ diff --git a/src/main/java/net/glowstone/entity/GlowHumanEntity.java b/src/main/java/net/glowstone/entity/GlowHumanEntity.java index 48cf99343..e2fdb6ba9 100644 --- a/src/main/java/net/glowstone/entity/GlowHumanEntity.java +++ b/src/main/java/net/glowstone/entity/GlowHumanEntity.java @@ -23,19 +23,24 @@ import net.glowstone.util.Position; import net.glowstone.util.UuidUtils; import net.glowstone.util.nbt.CompoundTag; +import org.bukkit.FluidCollisionMode; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.NamespacedKey; +import org.bukkit.Sound; +import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; import org.bukkit.entity.Entity; import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; import org.bukkit.entity.Villager; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType.SlotType; import org.bukkit.inventory.EntityEquipment; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView.Property; @@ -47,6 +52,7 @@ import org.bukkit.permissions.PermissionAttachment; import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.Plugin; +import org.bukkit.util.RayTraceResult; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -823,4 +829,74 @@ public void setStarvationRate(int ticks) { public void setLastDeathLocation(@Nullable Location location) { } + + @Override + public @Nullable BlockFace getTargetBlockFace(int maxDistance, @NotNull FluidCollisionMode fluidMode) { + return null; + } + + @Override + public @Nullable RayTraceResult rayTraceEntities(int maxDistance, boolean ignoreBlocks) { + return null; + } + + @Override + public void setArrowsInBody(int count, boolean fireEvent) { + + } + + @Override + public @NotNull Sound getFallDamageSound(int fallHeight) { + return null; + } + + @Override + public @NotNull Sound getFallDamageSoundSmall() { + return null; + } + + @Override + public @NotNull Sound getFallDamageSoundBig() { + return null; + } + + @Override + public @NotNull Sound getDrinkingSound(@NotNull ItemStack itemStack) { + return Sound.ENTITY_GENERIC_DRINK; + } + + @Override + public @NotNull Sound getEatingSound(@NotNull ItemStack itemStack) { + return Sound.ENTITY_GENERIC_EAT; + } + + @Override + public boolean canBreatheUnderwater() { + return false; + } + + @Override + public void knockback(double strength, double directionX, double directionZ) { + + } + + @Override + public void broadcastSlotBreak(@NotNull EquipmentSlot slot) { + + } + + @Override + public void broadcastSlotBreak(@NotNull EquipmentSlot slot, @NotNull Collection players) { + + } + + @Override + public @NotNull ItemStack damageItemStack(@NotNull ItemStack stack, int amount) { + return null; + } + + @Override + public void damageItemStack(@NotNull EquipmentSlot slot, int amount) { + + } } diff --git a/src/main/java/net/glowstone/entity/GlowLivingEntity.java b/src/main/java/net/glowstone/entity/GlowLivingEntity.java index f054b9105..79e3ebb48 100644 --- a/src/main/java/net/glowstone/entity/GlowLivingEntity.java +++ b/src/main/java/net/glowstone/entity/GlowLivingEntity.java @@ -111,6 +111,75 @@ * @author Graham Edgecombe. */ public abstract class GlowLivingEntity extends GlowEntity implements LivingEntity { + @Override + public @Nullable BlockFace getTargetBlockFace(int maxDistance, @NotNull FluidCollisionMode fluidMode) { + return null; + } + + @Override + public @Nullable RayTraceResult rayTraceEntities(int maxDistance, boolean ignoreBlocks) { + return null; + } + + @Override + public void setArrowsInBody(int count, boolean fireEvent) { + + } + + @Override + public @NotNull Sound getFallDamageSound(int fallHeight) { + return Sound.ENTITY_GENERIC_BIG_FALL; + } + + @Override + public @NotNull Sound getFallDamageSoundSmall() { + return Sound.ENTITY_GENERIC_SMALL_FALL; + } + + @Override + public @NotNull Sound getFallDamageSoundBig() { + return Sound.ENTITY_GENERIC_BIG_FALL; + } + + @Override + public @NotNull Sound getDrinkingSound(@NotNull ItemStack itemStack) { + return Sound.ENTITY_GENERIC_DRINK; + } + + @Override + public @NotNull Sound getEatingSound(@NotNull ItemStack itemStack) { + return Sound.ENTITY_GENERIC_EAT; + } + + @Override + public boolean canBreatheUnderwater() { + return false; + } + + @Override + public void knockback(double strength, double directionX, double directionZ) { + + } + + @Override + public void broadcastSlotBreak(@NotNull EquipmentSlot slot) { + + } + + @Override + public void broadcastSlotBreak(@NotNull EquipmentSlot slot, @NotNull Collection players) { + + } + + @Override + public @NotNull ItemStack damageItemStack(@NotNull ItemStack stack, int amount) { + return null; + } + + @Override + public void damageItemStack(@NotNull EquipmentSlot slot, int amount) { + + } /** * The entity's AI task manager. @@ -654,7 +723,7 @@ public boolean getCanPickupItems() { * * @return the hurt sound if available */ - protected Sound getHurtSound() { + public Sound getHurtSound() { return null; } @@ -663,7 +732,7 @@ protected Sound getHurtSound() { * * @return the death sound if available */ - protected Sound getDeathSound() { + public Sound getDeathSound() { return null; } @@ -672,7 +741,7 @@ protected Sound getDeathSound() { * * @return the ambient sound if available */ - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return null; } diff --git a/src/main/java/net/glowstone/entity/GlowPlayer.java b/src/main/java/net/glowstone/entity/GlowPlayer.java index 27f9d4561..9449aca6e 100644 --- a/src/main/java/net/glowstone/entity/GlowPlayer.java +++ b/src/main/java/net/glowstone/entity/GlowPlayer.java @@ -10,6 +10,8 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.Unpooled; +import io.papermc.paper.entity.LookAnchor; +import io.papermc.paper.entity.RelativeTeleportFlag; import lombok.Getter; import lombok.Setter; import net.glowstone.EventFactory; @@ -103,6 +105,7 @@ import net.glowstone.util.nbt.ListTag; import net.glowstone.util.nbt.TagType; import net.kyori.adventure.text.Component; +import net.kyori.adventure.util.TriState; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.chat.ComponentSerializer; @@ -133,6 +136,7 @@ import org.bukkit.advancement.AdvancementProgress; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; import org.bukkit.boss.BossBar; import org.bukkit.configuration.serialization.DelegateDeserialization; @@ -142,6 +146,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Firework; +import org.bukkit.entity.FishHook; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; @@ -189,6 +194,7 @@ import org.bukkit.scoreboard.Scoreboard; import org.bukkit.util.BlockVector; import org.bukkit.util.BoundingBox; +import org.bukkit.util.Consumer; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.json.simple.JSONObject; @@ -1604,6 +1610,61 @@ public void setRotation(float yaw, float pitch) { } + @Override + public boolean teleport(@NotNull Location location, @NotNull TeleportCause cause, boolean ignorePassengers, boolean dismount, @NotNull RelativeTeleportFlag @NotNull ... teleportFlags) { + return false; + } + + @Override + public void lookAt(double x, double y, double z, @NotNull LookAnchor playerAnchor) { + + } + + @Override + public void lookAt(@NotNull Entity entity, @NotNull LookAnchor playerAnchor, @NotNull LookAnchor entityAnchor) { + + } + + @Override + public void showElderGuardian(boolean silent) { + + } + + @Override + public int getWardenWarningCooldown() { + return 0; + } + + @Override + public void setWardenWarningCooldown(int cooldown) { + + } + + @Override + public int getWardenTimeSinceLastWarning() { + return 0; + } + + @Override + public void setWardenTimeSinceLastWarning(int time) { + + } + + @Override + public int getWardenWarningLevel() { + return 0; + } + + @Override + public void setWardenWarningLevel(int warningLevel) { + + } + + @Override + public void increaseWardenWarningLevel() { + + } + /** * Set this player's client settings. * @@ -1982,6 +2043,16 @@ public void setAllowFlight(boolean flight) { getServer().sendPlayerAbilities(this); } + @Override + public void setFlyingFallDamage(@NotNull TriState flyingFallDamage) { + + } + + @Override + public @NotNull TriState hasFlyingFallDamage() { + return null; + } + @Override public void setFlying(boolean value) { flying = value && canFly; @@ -2269,6 +2340,11 @@ public void setStarvationRate(int i) { throw new UnsupportedOperationException("Not supported yet."); } + @Override + public @org.jetbrains.annotations.Nullable Firework fireworkBoost(@NotNull ItemStack fireworkItemStack) { + return null; + } + private boolean shouldCalculateExhaustion() { return getGameMode() == GameMode.SURVIVAL | getGameMode() == GameMode.ADVENTURE; } @@ -2993,6 +3069,16 @@ public void sendOpLevel(byte b) { throw new UnsupportedOperationException("Not supported yet."); } + @Override + public void addAdditionalChatCompletions(@NotNull Collection completions) { + + } + + @Override + public void removeAdditionalChatCompletions(@NotNull Collection completions) { + + } + @Override public @NotNull Set getTrackedPlayers() { throw new UnsupportedOperationException("Not supported yet."); @@ -3093,11 +3179,21 @@ public void playSound(@NotNull Entity entity, @NotNull Sound sound, float volume } + @Override + public void playSound(@NotNull Entity entity, @NotNull String sound, float volume, float pitch) { + + } + @Override public void playSound(@NotNull Entity entity, @NotNull Sound sound, @NotNull SoundCategory category, float volume, float pitch) { } + @Override + public void playSound(@NotNull Entity entity, @NotNull String sound, @NotNull SoundCategory category, float volume, float pitch) { + + } + @Override public void playSound(Location location, Sound sound, SoundCategory category, float volume, float pitch) { @@ -3122,6 +3218,11 @@ public void stopSound(String sound, SoundCategory category) { session.send(new StopSoundMessage(category, sound)); } + @Override + public void stopSound(@NotNull SoundCategory category) { + + } + @Override public void stopAllSounds() { @@ -3189,6 +3290,11 @@ public void sendBlockChange(@NotNull Location loc, @NotNull BlockData blockData) sendBlockChange(loc, MaterialUtil.getId(blockData)); } + @Override + public void sendBlockChanges(@NotNull Collection blocks, boolean suppressLightUpdates) { + + } + private void sendBlockChange(@NotNull Location loc, int type) { sendBlockChange(new BlockChangeMessage(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), type)); } @@ -3216,6 +3322,11 @@ public void sendBlockDamage(@NotNull Location location, float v) { throw new UnsupportedOperationException("Not supported yet."); } + @Override + public void sendBlockDamage(@NotNull Location loc, float progress, int destroyerIdentity) { + + } + @Override public void sendMultiBlockChange(@NotNull Map blockChanges, boolean suppressLightUpdates) { @@ -3226,6 +3337,11 @@ public void sendEquipmentChange(@NotNull LivingEntity entity, @NotNull Equipment } + @Override + public void sendEquipmentChange(@NotNull LivingEntity entity, @NotNull Map equipmentChanges) { + + } + @Override public void sendSignChange(@NotNull Location location, @org.jetbrains.annotations.Nullable List list) @@ -3314,6 +3430,11 @@ public void sendMap(MapView map) { mapCanvas.toSection())); } + @Override + public void showWinScreen() { + + } + @Override public void setPlayerListHeaderFooter(@Nullable String header, @Nullable String footer) { @@ -3696,6 +3817,11 @@ public boolean isDeeplySleeping() { throw new UnsupportedOperationException("Not supported yet."); } + @Override + public @org.jetbrains.annotations.Nullable FishHook getFishHook() { + return null; + } + @Override public MainHand getMainHand() { return metadata.getByte(MetadataIndex.PLAYER_MAIN_HAND) == 0 ? MainHand.LEFT @@ -3711,6 +3837,16 @@ public boolean setWindowProperty(Property prop, int value) { return true; } + @Override + public int getEnchantmentSeed() { + return 0; + } + + @Override + public void setEnchantmentSeed(int seed) { + + } + @Override public void openInventory(InventoryView view) { session.send(new CloseWindowMessage(invMonitor.getId())); @@ -4319,4 +4455,19 @@ public int getOpenWindowId() { } return invMonitor.getId(); } + + @Override + public @NotNull TriState getFrictionState() { + return null; + } + + @Override + public void setFrictionState(@NotNull TriState state) { + + } + + @Override + public @NotNull T launchProjectile(@NotNull Class projectile, @org.jetbrains.annotations.Nullable Vector velocity, @org.jetbrains.annotations.Nullable Consumer function) { + return null; + } } diff --git a/src/main/java/net/glowstone/entity/meta/profile/GlowPlayerProfile.java b/src/main/java/net/glowstone/entity/meta/profile/GlowPlayerProfile.java index a207cab2e..adbf28af1 100644 --- a/src/main/java/net/glowstone/entity/meta/profile/GlowPlayerProfile.java +++ b/src/main/java/net/glowstone/entity/meta/profile/GlowPlayerProfile.java @@ -351,7 +351,7 @@ public boolean isComplete() { } @Override - public @NotNull CompletableFuture update() { + public @NotNull CompletableFuture update() { return null; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowBlaze.java b/src/main/java/net/glowstone/entity/monster/GlowBlaze.java index 5334fa2f8..7da84839c 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowBlaze.java +++ b/src/main/java/net/glowstone/entity/monster/GlowBlaze.java @@ -22,17 +22,17 @@ public void setOnFire(boolean onFire) { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_BLAZE_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_BLAZE_HURT; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_BLAZE_AMBIENT; } } diff --git a/src/main/java/net/glowstone/entity/monster/GlowCaveSpider.java b/src/main/java/net/glowstone/entity/monster/GlowCaveSpider.java index 9a21bcc33..222401fcf 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowCaveSpider.java +++ b/src/main/java/net/glowstone/entity/monster/GlowCaveSpider.java @@ -13,17 +13,17 @@ public GlowCaveSpider(Location loc) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_SPIDER_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_SPIDER_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_SPIDER_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowCreeper.java b/src/main/java/net/glowstone/entity/monster/GlowCreeper.java index 58913e936..9e9aa5a4b 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowCreeper.java +++ b/src/main/java/net/glowstone/entity/monster/GlowCreeper.java @@ -66,12 +66,12 @@ public void ignite() { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_CREEPER_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_CREEPER_HURT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowElderGuardian.java b/src/main/java/net/glowstone/entity/monster/GlowElderGuardian.java index 44d20912e..a17a14921 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowElderGuardian.java +++ b/src/main/java/net/glowstone/entity/monster/GlowElderGuardian.java @@ -13,17 +13,17 @@ public GlowElderGuardian(Location loc) { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_ELDER_GUARDIAN_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_ELDER_GUARDIAN_HURT; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_ELDER_GUARDIAN_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowEnderman.java b/src/main/java/net/glowstone/entity/monster/GlowEnderman.java index acea9c559..efa44b8c8 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowEnderman.java +++ b/src/main/java/net/glowstone/entity/monster/GlowEnderman.java @@ -69,17 +69,17 @@ public void setHasBeenStaredAt(boolean hasBeenStaredAt) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_ENDERMAN_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_ENDERMAN_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_ENDERMAN_AMBIENT; } } diff --git a/src/main/java/net/glowstone/entity/monster/GlowEndermite.java b/src/main/java/net/glowstone/entity/monster/GlowEndermite.java index e07e5e286..6ec3c63fe 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowEndermite.java +++ b/src/main/java/net/glowstone/entity/monster/GlowEndermite.java @@ -23,17 +23,27 @@ public void setPlayerSpawned(boolean playerSpawned) { } @Override - protected Sound getDeathSound() { + public void setLifetimeTicks(int ticks) { + + } + + @Override + public int getLifetimeTicks() { + return 0; + } + + @Override + public Sound getDeathSound() { return Sound.ENTITY_ENDERMITE_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_ENDERMITE_HURT; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_ENDERMITE_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowEvoker.java b/src/main/java/net/glowstone/entity/monster/GlowEvoker.java index af661e6e6..6161cb644 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowEvoker.java +++ b/src/main/java/net/glowstone/entity/monster/GlowEvoker.java @@ -80,12 +80,12 @@ public void setCurrentSpell(Evoker.Spell spell) { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_EVOKER_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_EVOKER_HURT; } @@ -96,7 +96,7 @@ public void damage(double amount, Entity source, @NotNull EntityDamageEvent.Dama } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_EVOKER_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowGhast.java b/src/main/java/net/glowstone/entity/monster/GlowGhast.java index 48b805800..debb8eaa0 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowGhast.java +++ b/src/main/java/net/glowstone/entity/monster/GlowGhast.java @@ -20,17 +20,17 @@ public GlowGhast(Location loc) { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_GHAST_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_GHAST_HURT; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_GHAST_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowGiant.java b/src/main/java/net/glowstone/entity/monster/GlowGiant.java index f84b129f0..d4264a9a5 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowGiant.java +++ b/src/main/java/net/glowstone/entity/monster/GlowGiant.java @@ -13,7 +13,7 @@ public GlowGiant(Location loc) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_PLAYER_HURT; } } diff --git a/src/main/java/net/glowstone/entity/monster/GlowGuardian.java b/src/main/java/net/glowstone/entity/monster/GlowGuardian.java index 7ba061c91..7fb936c96 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowGuardian.java +++ b/src/main/java/net/glowstone/entity/monster/GlowGuardian.java @@ -49,17 +49,17 @@ public void setElder(boolean elder) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_GUARDIAN_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_GUARDIAN_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_GUARDIAN_AMBIENT; } } diff --git a/src/main/java/net/glowstone/entity/monster/GlowIronGolem.java b/src/main/java/net/glowstone/entity/monster/GlowIronGolem.java index e08b625ee..e1a8667f8 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowIronGolem.java +++ b/src/main/java/net/glowstone/entity/monster/GlowIronGolem.java @@ -29,12 +29,12 @@ public void setPlayerCreated(boolean playerCreated) { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_IRON_GOLEM_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_IRON_GOLEM_HURT; } } diff --git a/src/main/java/net/glowstone/entity/monster/GlowMagmaCube.java b/src/main/java/net/glowstone/entity/monster/GlowMagmaCube.java index f667d2ae4..f44d95fc5 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowMagmaCube.java +++ b/src/main/java/net/glowstone/entity/monster/GlowMagmaCube.java @@ -12,12 +12,12 @@ public GlowMagmaCube(Location loc) { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_MAGMA_CUBE_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_MAGMA_CUBE_HURT; } } diff --git a/src/main/java/net/glowstone/entity/monster/GlowMonster.java b/src/main/java/net/glowstone/entity/monster/GlowMonster.java index 77225c77e..d593981e1 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowMonster.java +++ b/src/main/java/net/glowstone/entity/monster/GlowMonster.java @@ -2,6 +2,7 @@ import net.glowstone.entity.GlowCreature; import org.bukkit.Location; +import org.bukkit.Sound; import org.bukkit.entity.EntityType; import org.bukkit.entity.Monster; diff --git a/src/main/java/net/glowstone/entity/monster/GlowPigZombie.java b/src/main/java/net/glowstone/entity/monster/GlowPigZombie.java index 898376639..8bfa9d298 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowPigZombie.java +++ b/src/main/java/net/glowstone/entity/monster/GlowPigZombie.java @@ -39,17 +39,17 @@ public void setAngry(boolean angry) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_ZOMBIFIED_PIGLIN_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_ZOMBIFIED_PIGLIN_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_ZOMBIFIED_PIGLIN_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowRaider.java b/src/main/java/net/glowstone/entity/monster/GlowRaider.java index 1b668c2be..cf3342124 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowRaider.java +++ b/src/main/java/net/glowstone/entity/monster/GlowRaider.java @@ -3,9 +3,11 @@ import lombok.Getter; import lombok.Setter; import org.bukkit.Location; +import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.entity.EntityType; import org.bukkit.entity.Raider; +import org.jetbrains.annotations.NotNull; /** * A mob that can raid villages. @@ -34,4 +36,9 @@ public boolean isCelebrating() { public void setCelebrating(boolean celebrating) { } + + @Override + public @NotNull Sound getCelebrationSound() { + return Sound.ENTITY_PILLAGER_CELEBRATE; + } } diff --git a/src/main/java/net/glowstone/entity/monster/GlowShulker.java b/src/main/java/net/glowstone/entity/monster/GlowShulker.java index 189403595..db538e646 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowShulker.java +++ b/src/main/java/net/glowstone/entity/monster/GlowShulker.java @@ -78,12 +78,12 @@ public void setAttachment(Location attachment) { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_SHULKER_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { if (getShieldHeight() == 0) { return Sound.ENTITY_SHULKER_HURT_CLOSED; } @@ -91,7 +91,7 @@ protected Sound getHurtSound() { } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_SHULKER_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowSilverfish.java b/src/main/java/net/glowstone/entity/monster/GlowSilverfish.java index f67054b84..1f49e6e85 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowSilverfish.java +++ b/src/main/java/net/glowstone/entity/monster/GlowSilverfish.java @@ -13,17 +13,17 @@ public GlowSilverfish(Location loc) { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_SILVERFISH_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_SILVERFISH_HURT; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_SILVERFISH_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowSkeleton.java b/src/main/java/net/glowstone/entity/monster/GlowSkeleton.java index a9a7c2dc0..4afa1f66e 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowSkeleton.java +++ b/src/main/java/net/glowstone/entity/monster/GlowSkeleton.java @@ -33,17 +33,17 @@ public void setSkeletonType(SkeletonType type) { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_SKELETON_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_SKELETON_HURT; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_SKELETON_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowSlime.java b/src/main/java/net/glowstone/entity/monster/GlowSlime.java index 879dc13d1..9e265a806 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowSlime.java +++ b/src/main/java/net/glowstone/entity/monster/GlowSlime.java @@ -51,12 +51,12 @@ public void setWander(boolean canWander) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_SLIME_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_SLIME_DEATH; } } diff --git a/src/main/java/net/glowstone/entity/monster/GlowSnowman.java b/src/main/java/net/glowstone/entity/monster/GlowSnowman.java index b5fc911a8..ea5a096c6 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowSnowman.java +++ b/src/main/java/net/glowstone/entity/monster/GlowSnowman.java @@ -25,17 +25,17 @@ public void setDerp(boolean derp) { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_SNOW_GOLEM_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_SNOW_GOLEM_HURT; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_SNOW_GOLEM_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowSpider.java b/src/main/java/net/glowstone/entity/monster/GlowSpider.java index 55f5bcba4..8cf226430 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowSpider.java +++ b/src/main/java/net/glowstone/entity/monster/GlowSpider.java @@ -22,17 +22,17 @@ public void setClimbing(boolean climbing) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_SPIDER_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_SPIDER_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_SPIDER_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowStray.java b/src/main/java/net/glowstone/entity/monster/GlowStray.java index b93ca719e..60a9a8853 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowStray.java +++ b/src/main/java/net/glowstone/entity/monster/GlowStray.java @@ -12,17 +12,17 @@ public GlowStray(Location loc) { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_STRAY_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_STRAY_HURT; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_STRAY_AMBIENT; } } diff --git a/src/main/java/net/glowstone/entity/monster/GlowVex.java b/src/main/java/net/glowstone/entity/monster/GlowVex.java index d004afcb4..47fb53964 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowVex.java +++ b/src/main/java/net/glowstone/entity/monster/GlowVex.java @@ -45,17 +45,17 @@ public void pulse() { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_VEX_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_VEX_HURT; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_VEX_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowVindicator.java b/src/main/java/net/glowstone/entity/monster/GlowVindicator.java index dc45b36f3..87f689c6b 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowVindicator.java +++ b/src/main/java/net/glowstone/entity/monster/GlowVindicator.java @@ -23,17 +23,17 @@ public void setJohnny(boolean johnny) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_VINDICATOR_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_VINDICATOR_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_VINDICATOR_AMBIENT; } } diff --git a/src/main/java/net/glowstone/entity/monster/GlowWitch.java b/src/main/java/net/glowstone/entity/monster/GlowWitch.java index 26f981a52..1f604697b 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowWitch.java +++ b/src/main/java/net/glowstone/entity/monster/GlowWitch.java @@ -34,17 +34,17 @@ public void setAggressive(boolean aggressive) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_WITCH_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_WITCH_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_WITCH_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowWither.java b/src/main/java/net/glowstone/entity/monster/GlowWither.java index 9b298d913..680570699 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowWither.java +++ b/src/main/java/net/glowstone/entity/monster/GlowWither.java @@ -124,17 +124,17 @@ public void pulse() { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_WITHER_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_WITHER_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_WITHER_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowWitherSkeleton.java b/src/main/java/net/glowstone/entity/monster/GlowWitherSkeleton.java index 50f9175cd..64f4ff4cd 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowWitherSkeleton.java +++ b/src/main/java/net/glowstone/entity/monster/GlowWitherSkeleton.java @@ -13,17 +13,17 @@ public GlowWitherSkeleton(Location loc) { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_WITHER_SKELETON_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_WITHER_SKELETON_HURT; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_WITHER_SKELETON_AMBIENT; } } diff --git a/src/main/java/net/glowstone/entity/monster/GlowZombie.java b/src/main/java/net/glowstone/entity/monster/GlowZombie.java index cae85e65a..3a37972d9 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowZombie.java +++ b/src/main/java/net/glowstone/entity/monster/GlowZombie.java @@ -166,17 +166,17 @@ protected float getSoundPitch() { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_ZOMBIE_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_ZOMBIE_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_ZOMBIE_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/monster/GlowZombieVillager.java b/src/main/java/net/glowstone/entity/monster/GlowZombieVillager.java index 44093c0e2..e4eac17fa 100644 --- a/src/main/java/net/glowstone/entity/monster/GlowZombieVillager.java +++ b/src/main/java/net/glowstone/entity/monster/GlowZombieVillager.java @@ -71,17 +71,17 @@ public void setVillagerType(@NotNull Villager.Type type) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_ZOMBIE_VILLAGER_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_ZOMBIE_VILLAGER_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_ZOMBIE_VILLAGER_AMBIENT; } @@ -111,4 +111,9 @@ public void setConversionPlayer(@Nullable OfflinePlayer offlinePlayer) { conversionPlayerId = offlinePlayer.getUniqueId(); } } + + @Override + public void setConversionTime(int time, boolean broadcastEntityEvent) { + + } } diff --git a/src/main/java/net/glowstone/entity/monster/complex/GlowEnderDragon.java b/src/main/java/net/glowstone/entity/monster/complex/GlowEnderDragon.java index 70147bda2..a47a1cbb4 100644 --- a/src/main/java/net/glowstone/entity/monster/complex/GlowEnderDragon.java +++ b/src/main/java/net/glowstone/entity/monster/complex/GlowEnderDragon.java @@ -85,12 +85,12 @@ public Set getParts() { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_ENDER_DRAGON_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_ENDER_DRAGON_AMBIENT; } } diff --git a/src/main/java/net/glowstone/entity/objects/GlowArmorStand.java b/src/main/java/net/glowstone/entity/objects/GlowArmorStand.java index 9641db34d..1b429dbc0 100644 --- a/src/main/java/net/glowstone/entity/objects/GlowArmorStand.java +++ b/src/main/java/net/glowstone/entity/objects/GlowArmorStand.java @@ -1,6 +1,7 @@ package net.glowstone.entity.objects; import com.flowpowered.network.Message; +import io.papermc.paper.math.Rotations; import net.glowstone.EventFactory; import net.glowstone.entity.GlowLivingEntity; import net.glowstone.entity.GlowPlayer; @@ -17,6 +18,7 @@ import net.glowstone.net.message.play.player.InteractEntityMessage; import net.glowstone.net.message.play.player.InteractEntityMessage.Action; import net.glowstone.util.InventoryUtil; +import net.kyori.adventure.util.TriState; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -37,8 +39,11 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.scoreboard.Criterias; import org.bukkit.scoreboard.Objective; +import org.bukkit.util.Consumer; import org.bukkit.util.EulerAngle; +import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.Collections; @@ -610,6 +615,66 @@ public boolean isSlotDisabled(EquipmentSlot equipmentSlot) { throw new UnsupportedOperationException("Not implemented yet."); } + @Override + public @NotNull Rotations getBodyRotations() { + return null; + } + + @Override + public void setBodyRotations(@NotNull Rotations rotations) { + + } + + @Override + public @NotNull Rotations getLeftArmRotations() { + return null; + } + + @Override + public void setLeftArmRotations(@NotNull Rotations rotations) { + + } + + @Override + public @NotNull Rotations getRightArmRotations() { + return null; + } + + @Override + public void setRightArmRotations(@NotNull Rotations rotations) { + + } + + @Override + public @NotNull Rotations getLeftLegRotations() { + return null; + } + + @Override + public void setLeftLegRotations(@NotNull Rotations rotations) { + + } + + @Override + public @NotNull Rotations getRightLegRotations() { + return null; + } + + @Override + public void setRightLegRotations(@NotNull Rotations rotations) { + + } + + @Override + public @NotNull Rotations getHeadRotations() { + return null; + } + + @Override + public void setHeadRotations(@NotNull Rotations rotations) { + + } + @Override public void addEquipmentLock(@NotNull EquipmentSlot equipmentSlot, @NotNull LockType lockType) { // TODO: 1.16 @@ -634,4 +699,19 @@ public boolean hasEquipmentLock(@NotNull EquipmentSlot equipmentSlot, public EntityEquipment getEquipment() { return this.equipment; } + + @Override + public @NotNull TriState getFrictionState() { + return null; + } + + @Override + public void setFrictionState(@NotNull TriState state) { + + } + + @Override + public @NotNull T launchProjectile(@NotNull Class projectile, @Nullable Vector velocity, @Nullable Consumer function) { + return null; + } } diff --git a/src/main/java/net/glowstone/entity/objects/GlowBoat.java b/src/main/java/net/glowstone/entity/objects/GlowBoat.java index 63356413f..d5df9f6af 100644 --- a/src/main/java/net/glowstone/entity/objects/GlowBoat.java +++ b/src/main/java/net/glowstone/entity/objects/GlowBoat.java @@ -163,6 +163,16 @@ public void setWoodType(TreeSpecies treeSpecies) { metadata.set(MetadataIndex.BOAT_TYPE, this.woodType.ordinal()); } + @Override + public @NotNull Type getBoatType() { + return null; + } + + @Override + public void setBoatType(@NotNull Type type) { + + } + @Override public double getMaxSpeed() { return 0.4; @@ -203,6 +213,11 @@ public void setWorkOnLand(boolean workOnLand) { this.workOnLand = workOnLand; } + @Override + public @NotNull Status getStatus() { + return null; + } + @Override public @NotNull Material getBoatMaterial() { switch (this.woodType) { diff --git a/src/main/java/net/glowstone/entity/objects/GlowItem.java b/src/main/java/net/glowstone/entity/objects/GlowItem.java index 2cdb1eaf8..62179f1d1 100644 --- a/src/main/java/net/glowstone/entity/objects/GlowItem.java +++ b/src/main/java/net/glowstone/entity/objects/GlowItem.java @@ -14,6 +14,7 @@ import net.glowstone.net.message.play.entity.SpawnEntityMessage; import net.glowstone.util.InventoryUtil; import net.glowstone.util.TickUtil; +import net.kyori.adventure.util.TriState; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -256,4 +257,14 @@ public boolean canPlayerPickup() { public boolean willAge() { return willAge; } + + @Override + public @NotNull TriState getFrictionState() { + return TriState.NOT_SET; + } + + @Override + public void setFrictionState(@NotNull TriState state) { + + } } diff --git a/src/main/java/net/glowstone/entity/objects/GlowMinecart.java b/src/main/java/net/glowstone/entity/objects/GlowMinecart.java index b44944264..8abc49bbf 100644 --- a/src/main/java/net/glowstone/entity/objects/GlowMinecart.java +++ b/src/main/java/net/glowstone/entity/objects/GlowMinecart.java @@ -320,6 +320,16 @@ public static class Explosive extends GlowMinecart implements ExplosiveMinecart public Explosive(Location location) { super(location, MinecartType.TNT); } + + @Override + public void setFuseTicks(int fuseTicks) { + + } + + @Override + public int getFuseTicks() { + return 0; + } } public static class Hopper extends GlowMinecart implements HopperMinecart { @@ -424,6 +434,16 @@ public long getSeed() { public void setSeed(long seed) { } + + @Override + public int getPickupCooldown() { + return 0; + } + + @Override + public void setPickupCooldown(int cooldown) { + + } } public static class Spawner extends GlowMinecart implements SpawnerMinecart { diff --git a/src/main/java/net/glowstone/entity/passive/GlowBat.java b/src/main/java/net/glowstone/entity/passive/GlowBat.java index 1b6256587..ceace6315 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowBat.java +++ b/src/main/java/net/glowstone/entity/passive/GlowBat.java @@ -8,11 +8,17 @@ import net.glowstone.net.message.play.entity.EntityMetadataMessage; import net.glowstone.net.message.play.entity.SpawnEntityMessage; import net.glowstone.util.Position; +import net.kyori.adventure.util.TriState; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.Bat; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Projectile; +import org.bukkit.util.Consumer; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.LinkedList; import java.util.List; @@ -48,23 +54,33 @@ public void setAwake(boolean isAwake) { metadata.setBit(MetadataIndex.BAT_FLAGS, MetadataIndex.BatFlags.IS_HANGING, !isAwake); } + @Override + public @Nullable Location getTargetLocation() { + return null; + } + + @Override + public void setTargetLocation(@Nullable Location location) { + + } + @Override public EntityType getType() { return EntityType.BAT; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_BAT_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_BAT_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_BAT_AMBIENT; } @@ -77,4 +93,19 @@ public LivingEntity getTarget() { public void setTarget(LivingEntity target) { throw new UnsupportedOperationException("Not implemented yet."); } + + @Override + public @NotNull TriState getFrictionState() { + return null; + } + + @Override + public void setFrictionState(@NotNull TriState state) { + + } + + @Override + public @NotNull T launchProjectile(@NotNull Class projectile, @Nullable Vector velocity, @Nullable Consumer function) { + return null; + } } diff --git a/src/main/java/net/glowstone/entity/passive/GlowChicken.java b/src/main/java/net/glowstone/entity/passive/GlowChicken.java index aa8bf71ed..e5cbfcb74 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowChicken.java +++ b/src/main/java/net/glowstone/entity/passive/GlowChicken.java @@ -57,17 +57,17 @@ public void pulse() { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_CHICKEN_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_CHICKEN_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_CHICKEN_AMBIENT; } @@ -75,4 +75,9 @@ protected Sound getAmbientSound() { public Set getBreedingFoods() { return BREEDING_FOODS; } + + @Override + public void setIsChickenJockey(boolean isChickenJockey) { + + } } diff --git a/src/main/java/net/glowstone/entity/passive/GlowCow.java b/src/main/java/net/glowstone/entity/passive/GlowCow.java index 52ba74bd1..af761d631 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowCow.java +++ b/src/main/java/net/glowstone/entity/passive/GlowCow.java @@ -60,17 +60,17 @@ public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_COW_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_COW_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_COW_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/passive/GlowDonkey.java b/src/main/java/net/glowstone/entity/passive/GlowDonkey.java index f76297594..f988828f2 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowDonkey.java +++ b/src/main/java/net/glowstone/entity/passive/GlowDonkey.java @@ -13,17 +13,17 @@ public GlowDonkey(Location location) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_DONKEY_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_DONKEY_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_DONKEY_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/passive/GlowFirework.java b/src/main/java/net/glowstone/entity/passive/GlowFirework.java index d63ee637d..bfb0f4a83 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowFirework.java +++ b/src/main/java/net/glowstone/entity/passive/GlowFirework.java @@ -119,6 +119,36 @@ public void setFireworkMeta(FireworkMeta fireworkMeta) { this.lifeTime = calculateLifeTime(fireworkMeta.getPower()); } + @Override + public boolean setAttachedTo(@Nullable LivingEntity entity) { + return false; + } + + @Override + public @Nullable LivingEntity getAttachedTo() { + return null; + } + + @Override + public boolean setLife(int ticks) { + return false; + } + + @Override + public int getLife() { + return 0; + } + + @Override + public boolean setMaxLife(int ticks) { + return false; + } + + @Override + public int getMaxLife() { + return 0; + } + /** * Get the underlying firework item. * @@ -158,6 +188,11 @@ public void detonate() { setTicksLived(lifeTime); } + @Override + public boolean isDetonated() { + return false; + } + @Override public @NotNull ItemStack getItem() { return null; @@ -301,4 +336,24 @@ public boolean doesBounce() { public void setBounce(boolean doesBounce) { // deprecated, does not do anything } + + @Override + public boolean hasLeftShooter() { + return false; + } + + @Override + public void setHasLeftShooter(boolean leftShooter) { + + } + + @Override + public boolean hasBeenShot() { + return false; + } + + @Override + public void setHasBeenShot(boolean beenShot) { + + } } diff --git a/src/main/java/net/glowstone/entity/passive/GlowFishingHook.java b/src/main/java/net/glowstone/entity/passive/GlowFishingHook.java index 599016ee7..efe3ad1fb 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowFishingHook.java +++ b/src/main/java/net/glowstone/entity/passive/GlowFishingHook.java @@ -140,6 +140,26 @@ public void setShooter(ProjectileSource shooter) { } } + @Override + public boolean hasLeftShooter() { + return false; + } + + @Override + public void setHasLeftShooter(boolean leftShooter) { + + } + + @Override + public boolean hasBeenShot() { + return false; + } + + @Override + public void setHasBeenShot(boolean beenShot) { + + } + private int calculateLifeTime() { // Waiting time is 5-45 seconds int lifeTime = ThreadLocalRandom.current().nextInt(MINIMUM_BASE_WAIT, MAXIMUM_WAIT + 1); diff --git a/src/main/java/net/glowstone/entity/passive/GlowHorse.java b/src/main/java/net/glowstone/entity/passive/GlowHorse.java index 2a4d1ce86..8a97465cd 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowHorse.java +++ b/src/main/java/net/glowstone/entity/passive/GlowHorse.java @@ -128,17 +128,17 @@ private int getHorseArmorData() { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_HORSE_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_HORSE_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_HORSE_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/passive/GlowLlama.java b/src/main/java/net/glowstone/entity/passive/GlowLlama.java index 3155a02ee..164f10ba2 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowLlama.java +++ b/src/main/java/net/glowstone/entity/passive/GlowLlama.java @@ -11,6 +11,8 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Llama; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Map; import java.util.Set; @@ -65,17 +67,47 @@ public void setStrength(int strength) { } @Override - protected Sound getDeathSound() { + public boolean inCaravan() { + return false; + } + + @Override + public void joinCaravan(@NotNull Llama llama) { + + } + + @Override + public void leaveCaravan() { + + } + + @Override + public @Nullable Llama getCaravanHead() { + return null; + } + + @Override + public boolean hasCaravanTail() { + return false; + } + + @Override + public @Nullable Llama getCaravanTail() { + return null; + } + + @Override + public Sound getDeathSound() { return Sound.ENTITY_LLAMA_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_LLAMA_HURT; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_LLAMA_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/passive/GlowMooshroom.java b/src/main/java/net/glowstone/entity/passive/GlowMooshroom.java index 907ae1649..7fb804851 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowMooshroom.java +++ b/src/main/java/net/glowstone/entity/passive/GlowMooshroom.java @@ -9,6 +9,8 @@ import org.bukkit.Sound; import org.bukkit.entity.EntityType; import org.bukkit.entity.MushroomCow; +import org.bukkit.potion.PotionEffectType; +import org.jetbrains.annotations.Nullable; import java.util.Set; @@ -25,17 +27,17 @@ public GlowMooshroom(Location location) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_COW_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_COW_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_COW_AMBIENT; } @@ -43,4 +45,24 @@ protected Sound getAmbientSound() { public Set getBreedingFoods() { return BREEDING_FOODS; } + + @Override + public int getStewEffectDuration() { + return 0; + } + + @Override + public void setStewEffectDuration(int duration) { + + } + + @Override + public @Nullable PotionEffectType getStewEffectType() { + return null; + } + + @Override + public void setStewEffect(@Nullable PotionEffectType type) { + + } } diff --git a/src/main/java/net/glowstone/entity/passive/GlowMule.java b/src/main/java/net/glowstone/entity/passive/GlowMule.java index 717d476c4..17eaff904 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowMule.java +++ b/src/main/java/net/glowstone/entity/passive/GlowMule.java @@ -18,17 +18,17 @@ public boolean canBreed() { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_MULE_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_MULE_HURT; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_MULE_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/passive/GlowOcelot.java b/src/main/java/net/glowstone/entity/passive/GlowOcelot.java index 3b6779265..eb550c83c 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowOcelot.java +++ b/src/main/java/net/glowstone/entity/passive/GlowOcelot.java @@ -56,17 +56,17 @@ public void setOwner(AnimalTamer animalTamer) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_CAT_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_CAT_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_CAT_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/passive/GlowParrot.java b/src/main/java/net/glowstone/entity/passive/GlowParrot.java index bf7067a73..330179b97 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowParrot.java +++ b/src/main/java/net/glowstone/entity/passive/GlowParrot.java @@ -58,6 +58,11 @@ public void setVariant(Variant variant) { metadata.set(MetadataIndex.PARROT_VARIANT, variant.ordinal()); } + @Override + public boolean isDancing() { + return false; + } + public LivingEntity getImitatedEntity() { return null; } @@ -142,17 +147,17 @@ && fireEntityTameEvent(player)) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_PARROT_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_PARROT_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_PARROT_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/passive/GlowPig.java b/src/main/java/net/glowstone/entity/passive/GlowPig.java index 942982624..32bf982b0 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowPig.java +++ b/src/main/java/net/glowstone/entity/passive/GlowPig.java @@ -80,17 +80,17 @@ public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_PIG_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_PIG_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_PIG_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/passive/GlowPolarBear.java b/src/main/java/net/glowstone/entity/passive/GlowPolarBear.java index 968229253..83f4d2938 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowPolarBear.java +++ b/src/main/java/net/glowstone/entity/passive/GlowPolarBear.java @@ -23,17 +23,17 @@ public void setStanding(boolean standing) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_POLAR_BEAR_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_POLAR_BEAR_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_POLAR_BEAR_AMBIENT; } } diff --git a/src/main/java/net/glowstone/entity/passive/GlowRabbit.java b/src/main/java/net/glowstone/entity/passive/GlowRabbit.java index d5c589b3e..8268304bb 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowRabbit.java +++ b/src/main/java/net/glowstone/entity/passive/GlowRabbit.java @@ -57,17 +57,27 @@ public void setRabbitType(Type type) { } @Override - protected Sound getHurtSound() { + public void setMoreCarrotTicks(int ticks) { + + } + + @Override + public int getMoreCarrotTicks() { + return 0; + } + + @Override + public Sound getHurtSound() { return Sound.ENTITY_RABBIT_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_RABBIT_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_RABBIT_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/passive/GlowSheep.java b/src/main/java/net/glowstone/entity/passive/GlowSheep.java index 1c160453b..06be12965 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowSheep.java +++ b/src/main/java/net/glowstone/entity/passive/GlowSheep.java @@ -211,17 +211,17 @@ public void pulse() { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_SHEEP_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_SHEEP_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_SHEEP_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/passive/GlowSkeletonHorse.java b/src/main/java/net/glowstone/entity/passive/GlowSkeletonHorse.java index d552b9c62..e20e5e0e6 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowSkeletonHorse.java +++ b/src/main/java/net/glowstone/entity/passive/GlowSkeletonHorse.java @@ -12,17 +12,17 @@ public GlowSkeletonHorse(Location location) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_SKELETON_HORSE_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_SKELETON_HORSE_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_SKELETON_HORSE_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/passive/GlowSquid.java b/src/main/java/net/glowstone/entity/passive/GlowSquid.java index 41393892a..421bcf185 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowSquid.java +++ b/src/main/java/net/glowstone/entity/passive/GlowSquid.java @@ -14,17 +14,17 @@ public GlowSquid(Location location) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_SQUID_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_SQUID_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_SQUID_AMBIENT; } } diff --git a/src/main/java/net/glowstone/entity/passive/GlowVillager.java b/src/main/java/net/glowstone/entity/passive/GlowVillager.java index a9a5fd344..41a2aa044 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowVillager.java +++ b/src/main/java/net/glowstone/entity/passive/GlowVillager.java @@ -172,6 +172,16 @@ public void setVillagerExperience(int i) { throw new UnsupportedOperationException(); } + @Override + public boolean increaseLevel(int amount) { + return false; + } + + @Override + public boolean addTrades(int amount) { + return false; + } + @Override public int getRestocksToday() { throw new UnsupportedOperationException(); @@ -339,17 +349,17 @@ private void sendRecipes(GlowMerchantInventory inventory, GlowPlayer player) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_VILLAGER_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_VILLAGER_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_VILLAGER_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/passive/GlowWolf.java b/src/main/java/net/glowstone/entity/passive/GlowWolf.java index 641244237..7dc68b154 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowWolf.java +++ b/src/main/java/net/glowstone/entity/passive/GlowWolf.java @@ -73,6 +73,16 @@ public void setCollarColor(DyeColor color) { metadata.set(MetadataIndex.WOLF_COLOR, color.getDyeData()); } + @Override + public boolean isWet() { + return false; + } + + @Override + public float getTailAngle() { + return 0; + } + @Override public void setInterested(boolean interested) { @@ -166,17 +176,17 @@ public void setHealth(double health) { } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_WOLF_HURT; } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_WOLF_DEATH; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_WOLF_AMBIENT; } diff --git a/src/main/java/net/glowstone/entity/passive/GlowZombieHorse.java b/src/main/java/net/glowstone/entity/passive/GlowZombieHorse.java index 3624f8b4e..0838f0173 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowZombieHorse.java +++ b/src/main/java/net/glowstone/entity/passive/GlowZombieHorse.java @@ -12,17 +12,17 @@ public GlowZombieHorse(Location location) { } @Override - protected Sound getDeathSound() { + public Sound getDeathSound() { return Sound.ENTITY_ZOMBIE_HORSE_DEATH; } @Override - protected Sound getHurtSound() { + public Sound getHurtSound() { return Sound.ENTITY_ZOMBIE_HORSE_HURT; } @Override - protected Sound getAmbientSound() { + public Sound getAmbientSound() { return Sound.ENTITY_ZOMBIE_HORSE_AMBIENT; } } diff --git a/src/main/java/net/glowstone/entity/projectile/GlowArrow.java b/src/main/java/net/glowstone/entity/projectile/GlowArrow.java index 8173b1e8d..5bd25f29a 100644 --- a/src/main/java/net/glowstone/entity/projectile/GlowArrow.java +++ b/src/main/java/net/glowstone/entity/projectile/GlowArrow.java @@ -9,6 +9,7 @@ import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; @@ -195,6 +196,26 @@ public void setShotFromCrossbow(boolean b) { return new ItemStack(Material.ARROW); } + @Override + public void setLifetimeTicks(int ticks) { + + } + + @Override + public int getLifetimeTicks() { + return 0; + } + + @Override + public @NotNull Sound getHitSound() { + return Sound.ENTITY_ARROW_HIT; + } + + @Override + public void setHitSound(@NotNull Sound sound) { + + } + @Override public void setNoPhysics(boolean noPhysics) { diff --git a/src/main/java/net/glowstone/entity/projectile/GlowLingeringPotion.java b/src/main/java/net/glowstone/entity/projectile/GlowLingeringPotion.java index 6f5616582..723729618 100644 --- a/src/main/java/net/glowstone/entity/projectile/GlowLingeringPotion.java +++ b/src/main/java/net/glowstone/entity/projectile/GlowLingeringPotion.java @@ -43,4 +43,9 @@ private void createEffectCloud() { } remove(); } + + @Override + public void splash() { + + } } diff --git a/src/main/java/net/glowstone/entity/projectile/GlowProjectile.java b/src/main/java/net/glowstone/entity/projectile/GlowProjectile.java index 4509a879f..73361ce67 100644 --- a/src/main/java/net/glowstone/entity/projectile/GlowProjectile.java +++ b/src/main/java/net/glowstone/entity/projectile/GlowProjectile.java @@ -28,6 +28,25 @@ * with other entities. */ public abstract class GlowProjectile extends GlowEntity implements Projectile { + @Override + public boolean hasLeftShooter() { + return false; + } + + @Override + public void setHasLeftShooter(boolean leftShooter) { + + } + + @Override + public boolean hasBeenShot() { + return true; + } + + @Override + public void setHasBeenShot(boolean beenShot) { + + } @Getter @Setter diff --git a/src/main/java/net/glowstone/entity/projectile/GlowSplashPotion.java b/src/main/java/net/glowstone/entity/projectile/GlowSplashPotion.java index c75cb32ee..24f9e0b8d 100644 --- a/src/main/java/net/glowstone/entity/projectile/GlowSplashPotion.java +++ b/src/main/java/net/glowstone/entity/projectile/GlowSplashPotion.java @@ -102,4 +102,9 @@ public Collection getEffects() { public void setPotionMeta(@NotNull PotionMeta meta) { } + + @Override + public void splash() { + + } } diff --git a/src/main/java/net/glowstone/inventory/GlowMetaSkull.java b/src/main/java/net/glowstone/inventory/GlowMetaSkull.java index 6a517f996..397d9f05f 100644 --- a/src/main/java/net/glowstone/inventory/GlowMetaSkull.java +++ b/src/main/java/net/glowstone/inventory/GlowMetaSkull.java @@ -4,10 +4,12 @@ import net.glowstone.GlowOfflinePlayer; import net.glowstone.GlowServer; import net.glowstone.ServerProvider; +import net.glowstone.block.data.BlockDataManager; import net.glowstone.entity.GlowPlayer; import net.glowstone.entity.meta.profile.GlowPlayerProfile; import net.glowstone.util.nbt.CompoundTag; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.OfflinePlayer; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; @@ -176,6 +178,16 @@ public void setOwnerProfile(org.bukkit.profile.@Nullable PlayerProfile profile) owner.set((GlowPlayerProfile) profile); } + @Override + public void setNoteBlockSound(@Nullable NamespacedKey noteBlockSound) { + + } + + @Override + public @Nullable NamespacedKey getNoteBlockSound() { + return NamespacedKey.fromString("minecraft:guitar"); + } + private boolean setOwningPlayerInternal(OfflinePlayer owningPlayer) { if (owningPlayer instanceof GlowOfflinePlayer) { GlowOfflinePlayer impl = (GlowOfflinePlayer) owningPlayer; diff --git a/src/main/java/net/glowstone/net/handler/legacyping/LegacyPingHandler.java b/src/main/java/net/glowstone/net/handler/legacyping/LegacyPingHandler.java index 0bd4dc6b0..1c8d4b523 100644 --- a/src/main/java/net/glowstone/net/handler/legacyping/LegacyPingHandler.java +++ b/src/main/java/net/glowstone/net/handler/legacyping/LegacyPingHandler.java @@ -8,6 +8,7 @@ import net.glowstone.EventFactory; import net.glowstone.GlowServer; import net.glowstone.net.GameServer; +import net.kyori.adventure.text.Component; import org.bukkit.event.server.ServerListPingEvent; import java.io.UnsupportedEncodingException; @@ -37,7 +38,7 @@ public void channelRead(ChannelHandlerContext channelHandlerContext, Object obje .channel().remoteAddress(); ServerListPingEvent legacyPingEvent = new ServerListPingEvent( - inetsocketaddress.getAddress(), server.getMotd(), + inetsocketaddress.getAddress(), Component.text(server.getMotd()), server.getOnlinePlayers().size(), server.getMaxPlayers()); EventFactory.getInstance().callEvent(legacyPingEvent); diff --git a/src/main/java/net/glowstone/net/protocol/GlowProtocol.java b/src/main/java/net/glowstone/net/protocol/GlowProtocol.java index 1bfeb01e7..8f3c8c0e3 100644 --- a/src/main/java/net/glowstone/net/protocol/GlowProtocol.java +++ b/src/main/java/net/glowstone/net/protocol/GlowProtocol.java @@ -63,7 +63,7 @@ public GlowProtocol(String name, int highestOpcode) { int opcode, Class message, Class codec, H handler) { try { inboundCodecs.bind(message, codec, opcode); - handlers.bind(message, handler); + handlers.bind(message, handler.getClass()); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { getLogger().error("Error registering inbound " + opcode + " in " + getName(), e); } diff --git a/src/main/java/net/glowstone/scoreboard/GlowObjective.java b/src/main/java/net/glowstone/scoreboard/GlowObjective.java index d8d46547f..f30ceb24b 100644 --- a/src/main/java/net/glowstone/scoreboard/GlowObjective.java +++ b/src/main/java/net/glowstone/scoreboard/GlowObjective.java @@ -6,6 +6,7 @@ import net.kyori.adventure.text.Component; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Entity; +import org.bukkit.scoreboard.Criteria; import org.bukkit.scoreboard.Criterias; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; @@ -98,6 +99,11 @@ public String getCriteria() throws IllegalStateException { return criteria; } + @Override + public @NotNull Criteria getTrackedCriteria() throws IllegalStateException { + return null; + } + @Override public String getDisplayName() throws IllegalStateException { checkValid(); diff --git a/src/main/java/net/glowstone/scoreboard/GlowScoreboard.java b/src/main/java/net/glowstone/scoreboard/GlowScoreboard.java index aaeeb0457..48f6ad665 100644 --- a/src/main/java/net/glowstone/scoreboard/GlowScoreboard.java +++ b/src/main/java/net/glowstone/scoreboard/GlowScoreboard.java @@ -13,6 +13,7 @@ import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Entity; +import org.bukkit.scoreboard.Criteria; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.RenderType; @@ -253,6 +254,16 @@ public Objective registerNewObjective(String name, String criteria) throw new UnsupportedOperationException("Adventure API is not yet supported."); } + @Override + public @NotNull Objective registerNewObjective(@NotNull String name, @NotNull Criteria criteria, @Nullable Component displayName) throws IllegalArgumentException { + return null; + } + + @Override + public @NotNull Objective registerNewObjective(@NotNull String name, @NotNull Criteria criteria, @Nullable Component displayName, @NotNull RenderType renderType) throws IllegalArgumentException { + return null; + } + @Override public Objective registerNewObjective(String name, String criteria, String displayName) throws IllegalArgumentException { @@ -269,6 +280,16 @@ public Objective registerNewObjective(String name, String criteria, return objective; } + @Override + public @NotNull Objective registerNewObjective(@NotNull String name, @NotNull Criteria criteria, @NotNull String displayName) throws IllegalArgumentException { + return null; + } + + @Override + public @NotNull Objective registerNewObjective(@NotNull String name, @NotNull Criteria criteria, @NotNull String displayName, @NotNull RenderType renderType) throws IllegalArgumentException { + return null; + } + @Override public Objective getObjective(String name) throws IllegalArgumentException { return objectives.get(name); @@ -285,6 +306,11 @@ public Set getObjectivesByCriteria(String criteria) throws IllegalArg return ImmutableSet.copyOf(getForCriteria(criteria)); } + @Override + public @NotNull Set getObjectivesByCriteria(@NotNull Criteria criteria) throws IllegalArgumentException { + return null; + } + @Override public Set getObjectives() { return ImmutableSet.copyOf(objectives.values()); diff --git a/src/main/java/net/glowstone/util/GlowUnsafeValues.java b/src/main/java/net/glowstone/util/GlowUnsafeValues.java index 3663cc986..757f31737 100644 --- a/src/main/java/net/glowstone/util/GlowUnsafeValues.java +++ b/src/main/java/net/glowstone/util/GlowUnsafeValues.java @@ -3,6 +3,7 @@ import com.google.common.collect.Multimap; import io.papermc.paper.inventory.ItemRarity; import net.glowstone.GlowServer; +import net.kyori.adventure.text.Component; import net.kyori.adventure.text.flattener.ComponentFlattener; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -11,6 +12,7 @@ import org.bukkit.Keyed; import org.bukkit.Material; import org.bukkit.NamespacedKey; +import org.bukkit.RegionAccessor; import org.bukkit.Registry; import org.bukkit.Statistic; import org.bukkit.UnsafeValues; @@ -21,6 +23,7 @@ import org.bukkit.attribute.AttributeModifier; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.inventory.CreativeCategory; @@ -31,6 +34,7 @@ import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; @@ -94,6 +98,11 @@ public LegacyComponentSerializer legacyComponentSerializer() { return LegacyComponentSerializer.builder().build(); } + @Override + public Component resolveWithContext(Component component, CommandSender context, Entity scoreboardSubject, boolean bypassPermissions) throws IOException { + return null; + } + @Override public void reportTimings() { throw new UnsupportedOperationException(); @@ -341,4 +350,14 @@ public boolean hasDefaultEntityAttributes(@NotNull NamespacedKey entityKey) { public boolean isCollidable(@NotNull Material material) { return false; } + + @Override + public @NotNull NamespacedKey getBiomeKey(RegionAccessor accessor, int x, int y, int z) { + return null; + } + + @Override + public void setBiomeKey(RegionAccessor accessor, int x, int y, int z, NamespacedKey biomeKey) { + + } } diff --git a/src/main/java/net/glowstone/util/linkstone/LinkstoneClassInitObserver.java b/src/main/java/net/glowstone/util/linkstone/LinkstoneClassInitObserver.java deleted file mode 100644 index 680da65d6..000000000 --- a/src/main/java/net/glowstone/util/linkstone/LinkstoneClassInitObserver.java +++ /dev/null @@ -1,116 +0,0 @@ -package net.glowstone.util.linkstone; - -import net.glowstone.linkstone.annotations.LBox; -import net.glowstone.linkstone.annotations.LField; -import net.glowstone.linkstone.runtime.inithook.ClassInitHook; -import net.glowstone.linkstone.runtime.reflectionredirect.DynamicClassLoader; -import net.glowstone.linkstone.runtime.reflectionredirect.ReflectionUtil; -import net.glowstone.linkstone.runtime.reflectionredirect.field.BoxingFieldAccessor; -import net.glowstone.linkstone.runtime.reflectionredirect.field.FieldAccessorUtility; -import net.glowstone.linkstone.runtime.reflectionredirect.field.LFieldAccessor; -import net.glowstone.linkstone.runtime.reflectionredirect.field.RedirectFieldAccessorGenerator; -import net.glowstone.linkstone.runtime.reflectionredirect.method.BoxingMethodAccessor; -import net.glowstone.linkstone.runtime.reflectionredirect.method.LMethodAccessor; -import net.glowstone.linkstone.runtime.reflectionredirect.method.MethodAccessorUtility; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.Map; -import java.util.WeakHashMap; - -/** - * Utility that redirects reflective uses of annotated fields to their getters and setters. - */ -public class LinkstoneClassInitObserver implements ClassInitHook.Observer { - private final FieldAccessorUtility fieldAccessorUtil; - private final MethodAccessorUtility methodAccessorUtil; - - private final Map classLoaders = new WeakHashMap<>(); - - /** - * Create a new observer instance. - */ - public LinkstoneClassInitObserver() { - try { - fieldAccessorUtil = FieldAccessorUtility.isSupported() - ? new FieldAccessorUtility() : null; - } catch (Exception t) { - throw new IllegalStateException("Could not initialize FieldAccessorUtility"); - } - - try { - methodAccessorUtil = MethodAccessorUtility.isSupported() - ? new MethodAccessorUtility() : null; - } catch (Exception e) { - throw new IllegalStateException("Could not initialize MethodAccessorUtility"); - } - } - - @Override - public void onInit(Class clazz) { - try { - hijackFields(clazz); - hijackMethods(clazz); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private void hijackFields(Class clazz) throws ReflectiveOperationException { - if (fieldAccessorUtil == null) { - return; - } - - boolean isBox = clazz.getAnnotation(LBox.class) != null; - - for (Field field : ReflectionUtil.getInternalFields(clazz)) { - LField[] fieldAnnotations = field.getAnnotationsByType(LField.class); - if (fieldAnnotations.length > 0) { - LFieldAccessor accessor = newRedirectFieldAccessor(field); - fieldAccessorUtil.setAccessor(field, accessor); - fieldAccessorUtil.setOverrideAccessor(field, accessor); - } - - if (isBox) { - LFieldAccessor accessor = fieldAccessorUtil.getAccessor(field); - accessor = new BoxingFieldAccessor(accessor, field); - fieldAccessorUtil.setAccessor(field, accessor); - - LFieldAccessor overrideAccessor = fieldAccessorUtil.getOverrideAccessor(field); - overrideAccessor = new BoxingFieldAccessor(overrideAccessor, field); - fieldAccessorUtil.setOverrideAccessor(field, overrideAccessor); - } - } - } - - private LFieldAccessor newRedirectFieldAccessor(Field field) - throws ReflectiveOperationException { - DynamicClassLoader classloader = classLoaders.computeIfAbsent( - field.getDeclaringClass().getClassLoader(), DynamicClassLoader::new); - - RedirectFieldAccessorGenerator generator = new RedirectFieldAccessorGenerator(field); - String className = generator.getClassName().replace('/', '.'); - - Class accessorClass; - try { - accessorClass = Class.forName(className, false, classloader); - } catch (ClassNotFoundException e) { - byte[] bytecode = generator.generateAccessor(); - accessorClass = classloader.loadBytecode(className, bytecode); - } - - return (LFieldAccessor) accessorClass.getDeclaredConstructor().newInstance(); - } - - private void hijackMethods(Class clazz) throws ReflectiveOperationException { - if (methodAccessorUtil == null || clazz.getAnnotation(LBox.class) == null) { - return; - } - - for (Method method : ReflectionUtil.getInternalMethods(clazz)) { - LMethodAccessor accessor = methodAccessorUtil.getAccessor(method); - accessor = new BoxingMethodAccessor(method, accessor); - methodAccessorUtil.setAccessor(method, accessor); - } - } -} diff --git a/src/main/java/net/glowstone/util/linkstone/LinkstonePluginLoader.java b/src/main/java/net/glowstone/util/linkstone/LinkstonePluginLoader.java deleted file mode 100644 index c4c459c16..000000000 --- a/src/main/java/net/glowstone/util/linkstone/LinkstonePluginLoader.java +++ /dev/null @@ -1,63 +0,0 @@ -package net.glowstone.util.linkstone; - -import net.glowstone.linkstone.runtime.LinkstoneRuntimeData; -import net.glowstone.linkstone.runtime.boxing.BoxPatchVisitor; -import net.glowstone.linkstone.runtime.direct.DirectFieldAccessReplaceVisitor; -import net.glowstone.linkstone.runtime.inithook.ClassInitInvokeVisitor; -import net.glowstone.linkstone.runtime.reflectionredirect.field.FieldAccessorUtility; -import net.glowstone.linkstone.runtime.reflectionredirect.method.MethodAccessorUtility; -import net.glowstone.linkstone.runtime.reflectionreplace.ReflectionReplaceVisitor; -import org.bukkit.Server; -import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.plugin.java.JavaPluginLoader; -import org.bukkit.plugin.java.PluginClassLoader; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; - -import java.io.File; - -public class LinkstonePluginLoader extends JavaPluginLoader { - /** - * Bukkit will invoke this constructor via reflection. - * Its signature should therefore not be changed! - * - * @param instance the server instance - */ - public LinkstonePluginLoader(Server instance) { - super(instance); - LinkstoneRuntimeData.setPluginClassLoader(new ClassLoader() { - @Override - protected Class findClass(String name) throws ClassNotFoundException { - return loadClass(name); - } - }); - } - - @Override - protected PluginClassLoader newPluginLoader(JavaPluginLoader loader, ClassLoader parent, PluginDescriptionFile description, File dataFolder, File file, ClassLoader libraryLoader) throws Exception { - return new PluginClassLoader(loader, parent, description, dataFolder, file, libraryLoader) { - @Override - protected byte[] transformBytecode(byte[] bytecode) { - if (LinkstoneRuntimeData.getFields().isEmpty() - && LinkstoneRuntimeData.getBoxes().isEmpty()) { - // There are no plugins installed that use a @LField or @LBox annotation - // so there's no need for runtime support - return bytecode; - } - ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); - - ClassVisitor cv = cw; - cv = new DirectFieldAccessReplaceVisitor(LinkstoneRuntimeData.getFields(), cv); - if (!FieldAccessorUtility.isSupported() || !MethodAccessorUtility.isSupported()) { - cv = new ReflectionReplaceVisitor(cv); - } - cv = new ClassInitInvokeVisitor(cv); - cv = new BoxPatchVisitor(LinkstoneRuntimeData.getBoxes(), cv); - - new ClassReader(bytecode).accept(cv, 0); - return cw.toByteArray(); - } - }; - } -} diff --git a/src/main/java/net/glowstone/util/linkstone/LinkstonePluginScanner.java b/src/main/java/net/glowstone/util/linkstone/LinkstonePluginScanner.java deleted file mode 100644 index 8f3ecdb16..000000000 --- a/src/main/java/net/glowstone/util/linkstone/LinkstonePluginScanner.java +++ /dev/null @@ -1,59 +0,0 @@ -package net.glowstone.util.linkstone; - -import net.glowstone.linkstone.annotations.LField; -import net.glowstone.linkstone.runtime.Boxes; -import net.glowstone.linkstone.runtime.FieldSet; -import net.glowstone.linkstone.runtime.collect.AnnotatedFieldCollectVisitor; -import net.glowstone.linkstone.runtime.collect.BoxCollectVisitor; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.List; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -public class LinkstonePluginScanner { - private final FieldSet fields; - private final Boxes boxes; - - public LinkstonePluginScanner(final FieldSet fields, final Boxes boxes) { - this.fields = fields; - this.boxes = boxes; - } - - /** - * Look through a list of plugins jar files and store all - * fields annotated with a {@link LField} annotation. - * - * @param pluginJars list of plugins jars to be scanned - */ - public void scanPlugins(List pluginJars) { - for (File pluginJar : pluginJars) { - try { - scanPlugin(pluginJar); - } catch (Throwable t) { - t.printStackTrace(); - } - } - } - - private void scanPlugin(File pluginJar) throws IOException { - ZipInputStream zin = new ZipInputStream(new FileInputStream(pluginJar)); - ZipEntry entry; - while ((entry = zin.getNextEntry()) != null) { - if (entry.isDirectory() || !entry.getName().endsWith(".class")) { - continue; - } - - ClassVisitor cv = new AnnotatedFieldCollectVisitor(this.fields); - cv = new BoxCollectVisitor(this.boxes, cv); - - new ClassReader(zin).accept(cv, ClassReader.SKIP_CODE); - zin.closeEntry(); - } - zin.close(); - } -} From 6bee65445de7ac39cc1849cd22eb5536ac8277ad Mon Sep 17 00:00:00 2001 From: ApionXD Date: Thu, 9 Feb 2023 10:42:14 -0500 Subject: [PATCH 03/15] Upgraded flow-network and rolled back a change to reflect newer flow API, updated game ver strings --- build.gradle | 2 +- src/main/java/net/glowstone/GlowServer.java | 4 ++-- src/main/java/net/glowstone/net/protocol/GlowProtocol.java | 2 +- src/test/java/net/glowstone/testutils/ServerShim.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 990e2bed7..6bf55a62a 100644 --- a/build.gradle +++ b/build.gradle @@ -60,7 +60,7 @@ dependencies { testImplementation("org.powermock:powermock-api-mockito2:2.0.9") compileOnly("org.jetbrains:annotations:21.0.1") - implementation('com.flowpowered:flow-network:1.0.0') + implementation('com.flowpowered:flow-network:1.2.11-SNAPSHOT') } group = "net.glowstone" diff --git a/src/main/java/net/glowstone/GlowServer.java b/src/main/java/net/glowstone/GlowServer.java index 39db9caf6..c544149f3 100644 --- a/src/main/java/net/glowstone/GlowServer.java +++ b/src/main/java/net/glowstone/GlowServer.java @@ -284,11 +284,11 @@ public class GlowServer implements Server { /** * The game version supported by the server. */ - public static final String GAME_VERSION = NoInline.of("1.19"); + public static final String GAME_VERSION = NoInline.of("1.19.3"); /** * The protocol version supported by the server. */ - public static final int PROTOCOL_VERSION = NoInline.of(759); + public static final int PROTOCOL_VERSION = NoInline.of(761); /** * The data version supported by the server. */ diff --git a/src/main/java/net/glowstone/net/protocol/GlowProtocol.java b/src/main/java/net/glowstone/net/protocol/GlowProtocol.java index 8f3c8c0e3..1bfeb01e7 100644 --- a/src/main/java/net/glowstone/net/protocol/GlowProtocol.java +++ b/src/main/java/net/glowstone/net/protocol/GlowProtocol.java @@ -63,7 +63,7 @@ public GlowProtocol(String name, int highestOpcode) { int opcode, Class message, Class codec, H handler) { try { inboundCodecs.bind(message, codec, opcode); - handlers.bind(message, handler.getClass()); + handlers.bind(message, handler); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { getLogger().error("Error registering inbound " + opcode + " in " + getName(), e); } diff --git a/src/test/java/net/glowstone/testutils/ServerShim.java b/src/test/java/net/glowstone/testutils/ServerShim.java index 6eec7afa5..5a1ccfe85 100644 --- a/src/test/java/net/glowstone/testutils/ServerShim.java +++ b/src/test/java/net/glowstone/testutils/ServerShim.java @@ -130,7 +130,7 @@ public String getBukkitVersion() { @Override public @NotNull String getMinecraftVersion() { - return "1.19"; + return "1.19.3"; } @Override From 7d884f2b8154824f408a290c21e09bb841db4f3d Mon Sep 17 00:00:00 2001 From: ApionXD Date: Thu, 9 Feb 2023 19:17:11 -0500 Subject: [PATCH 04/15] Added all new 1.19.3 events to PlayProtocol --- .../glowstone/net/protocol/PlayProtocol.java | 237 ++++++++++-------- 1 file changed, 126 insertions(+), 111 deletions(-) diff --git a/src/main/java/net/glowstone/net/protocol/PlayProtocol.java b/src/main/java/net/glowstone/net/protocol/PlayProtocol.java index ac6d6b690..506309148 100644 --- a/src/main/java/net/glowstone/net/protocol/PlayProtocol.java +++ b/src/main/java/net/glowstone/net/protocol/PlayProtocol.java @@ -170,10 +170,11 @@ public PlayProtocol() { TeleportConfirmHandler.class); // TODO 0x01 : Query Block NBT // Note: 0x02 (Set Difficulty) is unused in multiplayer - // TODO 0x03 Chat Command - inbound(0x04, IncomingChatMessage.class, IncomingChatCodec.class, + // TODO 0x03 Message Acknowledge + // TODO 0x04 Chat Command + // TODO 0x05 Update Chat Message Handling to relfect Protocol changes + inbound(0x05, IncomingChatMessage.class, IncomingChatCodec.class, IncomingChatHandler.class); - // TODO 0x05 Chat Preview inbound(0x06, ClientStatusMessage.class, ClientStatusCodec.class, ClientStatusHandler.class); inbound(0x07, ClientSettingsMessage.class, ClientSettingsCodec.class, @@ -181,11 +182,14 @@ public PlayProtocol() { inbound(0x08, TabCompleteMessage.class, TabCompleteCodec.class, TabCompleteHandler.class); inbound(0x09, ClickWindowButtonMessage.class, ClickWindowButtonCodec.class, ClickWindowButtonHandler.class); + //TODO 0x0A : Update WindowClickMessage inbound(0x0A, WindowClickMessage.class, WindowClickCodec.class, WindowClickHandler.class); inbound(0x0B, CloseWindowMessage.class, CloseWindowCodec.class, CloseWindowHandler.class); inbound(0x0C, PluginMessage.class, PluginMessageCodec.class, PluginMessageHandler.class); + //TODO 0x0D : Update EditBookMessage inbound(0x0D, EditBookMessage.class, EditBookCodec.class, EditBookHandler.class); // TODO 0x0E : Query Entity NBT + // TODO 0x0F : Add shifting flag to InteractEntityMessage inbound(0x0F, InteractEntityMessage.class, InteractEntityCodec.class, InteractEntityHandler.class); // TODO 0x10 : Generate Structure (Jigsaw Block stuff: https://wiki.vg/Protocol#Generate_Structure) @@ -193,6 +197,7 @@ public PlayProtocol() { // Note: 0x12 (Lock Difficulty) is unused in multiplayer inbound(0x13, PlayerPositionMessage.class, PlayerPositionCodec.class, PlayerUpdateHandler.class); + inbound(0x14, PlayerPositionLookMessage.class, PlayerPositionLookCodec.class, PlayerUpdateHandler.class); inbound(0x15, PlayerLookMessage.class, PlayerLookCodec.class, PlayerUpdateHandler.class); @@ -203,39 +208,44 @@ public PlayProtocol() { // TODO 0x19 : Pick Item (see https://wiki.vg/Protocol#Pick_Item) inbound(0x1A, CraftRecipeRequestMessage.class, CraftRecipeRequestCodec.class, CraftRecipeRequestHandler.class); + // TODO 0x1B Update PlayerAbilitiesMessage inbound(0x1B, PlayerAbilitiesMessage.class, PlayerAbilitiesCodec.class, PlayerAbilitiesHandler.class); + // TODO 0x1C Update DiggingMessage inbound(0x1C, DiggingMessage.class, DiggingCodec.class, DiggingHandler.class); inbound(0x1D, PlayerActionMessage.class, PlayerActionCodec.class, PlayerActionHandler.class); inbound(0x1E, SteerVehicleMessage.class, SteerVehicleCodec.class, SteerVehicleHandler.class); // TODO 0x1F : Pong - inbound(0x20, RecipeBookStateMessage.class, RecipeBookStateCodec.class, + // TODO 0x20 : PlayerSession + inbound(0x21, RecipeBookStateMessage.class, RecipeBookStateCodec.class, RecipeBookStateHandler.class); - inbound(0x21, DisplayedRecipeMessage.class, DisplayedRecipeCodec.class, DisplayedRecipeHandler.class); - inbound(0x22, NameItemMessage.class, NameItemCodec.class, NameItemHandler.class); - inbound(0x23, ResourcePackStatusMessage.class, ResourcePackStatusCodec.class, + inbound(0x22, DisplayedRecipeMessage.class, DisplayedRecipeCodec.class, DisplayedRecipeHandler.class); + inbound(0x23, NameItemMessage.class, NameItemCodec.class, NameItemHandler.class); + inbound(0x24, ResourcePackStatusMessage.class, ResourcePackStatusCodec.class, ResourcePackStatusHandler.class); - inbound(0x24, AdvancementTabMessage.class, AdvancementTabCodec.class, + inbound(0x25, AdvancementTabMessage.class, AdvancementTabCodec.class, AdvancementTabHandler.class); - // TODO 0x25 : Select Trade (when a player selects a specific trade in a villager GUI) - inbound(0x26, BeaconEffectMessage.class, BeaconEffectCodec.class, + // TODO 0x26 : Select Trade (when a player selects a specific trade in a villager GUI) + // TODO 0x27 : Update BeaconEffectMessage + inbound(0x27, BeaconEffectMessage.class, BeaconEffectCodec.class, BeaconEffectHandler.class); - inbound(0x27, HeldItemMessage.class, HeldItemCodec.class, HeldItemHandler.class); - // TODO 0x28 : Update Command Block - // TODO 0x29 : Update Command Block Minecart - inbound(0x2A, CreativeItemMessage.class, CreativeItemCodec.class, + inbound(0x28, HeldItemMessage.class, HeldItemCodec.class, HeldItemHandler.class); + // TODO 0x29 : Update Command Block + // TODO 0x2A : Update Command Block Minecart + inbound(0x2B, CreativeItemMessage.class, CreativeItemCodec.class, CreativeItemHandler.class); - // TODO 0x2B : Update Jigsaw Block - // TODO 0x2C : Update Structure Block (difference with 0x29) - inbound(0x2D, UpdateSignMessage.class, UpdateSignCodec.class, UpdateSignHandler.class); - inbound(0x2E, PlayerSwingArmMessage.class, PlayerSwingArmCodec.class, + // TODO 0x2C : Update Jigsaw Block + // TODO 0x2D : Update Structure Block (difference with 0x29) + inbound(0x2E, UpdateSignMessage.class, UpdateSignCodec.class, UpdateSignHandler.class); + inbound(0x2F, PlayerSwingArmMessage.class, PlayerSwingArmCodec.class, PlayerSwingArmHandler.class); - inbound(0x2F, SpectateMessage.class, SpectateCodec.class, SpectateHandler.class); - inbound(0x30, BlockPlacementMessage.class, BlockPlacementCodec.class, + inbound(0x30, SpectateMessage.class, SpectateCodec.class, SpectateHandler.class); + inbound(0x31, BlockPlacementMessage.class, BlockPlacementCodec.class, BlockPlacementHandler.class); - inbound(0x31, UseItemMessage.class, UseItemCodec.class, UseItemHandler.class); + // TODO 0x32 : Add sequence field to UseItemMessage + inbound(0x32, UseItemMessage.class, UseItemCodec.class, UseItemHandler.class); outbound(0x00, SpawnEntityMessage.class, SpawnEntityCodec.class); outbound(0x01, SpawnXpOrbMessage.class, SpawnXpOrbCodec.class); @@ -249,99 +259,104 @@ public PlayProtocol() { outbound(0x09, BlockChangeMessage.class, BlockChangeCodec.class); outbound(0x0A, BossBarMessage.class, BossBarCodec.class); outbound(0x0B, ServerDifficultyMessage.class, ServerDifficultyCodec.class); - // TODO 0x0C : Chat preview - // TODO 0x0D : Clear Titles - outbound(0x0E, TabCompleteResponseMessage.class, TabCompleteResponseCodec.class); - outbound(0x0F, DeclareCommandsMessage.class, DeclareCommandsCodec.class); - outbound(0x10, CloseWindowMessage.class, CloseWindowCodec.class); - outbound(0x11, SetWindowContentsMessage.class, SetWindowContentsCodec.class); - outbound(0x12, WindowPropertyMessage.class, WindowPropertyCodec.class); - outbound(0x13, SetWindowSlotMessage.class, SetWindowSlotCodec.class); - outbound(0x14, SetCooldownMessage.class, SetCooldownCodec.class); + // TODO 0x0C : Clear Titles + outbound(0x0D, TabCompleteResponseMessage.class, TabCompleteResponseCodec.class); + outbound(0x0E, DeclareCommandsMessage.class, DeclareCommandsCodec.class); + outbound(0x0F, CloseWindowMessage.class, CloseWindowCodec.class); + outbound(0x10, SetWindowContentsMessage.class, SetWindowContentsCodec.class); + outbound(0x11, WindowPropertyMessage.class, WindowPropertyCodec.class); + outbound(0x12, SetWindowSlotMessage.class, SetWindowSlotCodec.class); + outbound(0x13, SetCooldownMessage.class, SetCooldownCodec.class); + //TODO 0x14 : Add ChatSuggestionsMessage outbound(0x15, PluginMessage.class, PluginMessageCodec.class); - outbound(0x16, NamedSoundEffectMessage.class, NamedSoundEffectCodec.class); + //TODO 0x16 : Add DeleteMessageMessage + //outbound(0x16, NamedSoundEffectMessage.class, NamedSoundEffectCodec.class); outbound(0x17, KickMessage.class, KickCodec.class); - outbound(0x18, EntityStatusMessage.class, EntityStatusCodec.class); - outbound(0x19, ExplosionMessage.class, ExplosionCodec.class); - outbound(0x1A, UnloadChunkMessage.class, UnloadChunkCodec.class); - outbound(0x1B, StateChangeMessage.class, StateChangeCodec.class); - // TODO 0x1C : Open Horse Window (opens the horse window, all other inventories use 0x2D) - outbound(0x1D, WorldBorderMessage.class, WorldBorderCodec.class); - outbound(0x1E, PingMessage.class, PingCodec.class); - outbound(0x1F, ChunkDataMessage.class, ChunkDataCodec.class); - outbound(0x20, PlayEffectMessage.class, PlayEffectCodec.class); - outbound(0x21, PlayParticleMessage.class, PlayParticleCodec.class); - outbound(0x22, ChunkLightDataMessage.class, ChunkLightDataCodec.class); - outbound(0x23, JoinGameMessage.class, JoinGameCodec.class); - outbound(0x24, MapDataMessage.class, MapDataCodec.class); - // TODO 0x25 : Trade List (the list of trades a villager is offering) - outbound(0x26, RelativeEntityPositionMessage.class, RelativeEntityPositionCodec.class); - outbound(0x27, RelativeEntityPositionRotationMessage.class, + //TODO 0x18 Add DisguisedChatMessageMessage + outbound(0x19, EntityStatusMessage.class, EntityStatusCodec.class); + outbound(0x1A, ExplosionMessage.class, ExplosionCodec.class); + outbound(0x1B, UnloadChunkMessage.class, UnloadChunkCodec.class); + outbound(0x1C, StateChangeMessage.class, StateChangeCodec.class); + // TODO 0x1D : Open Horse Window (opens the horse window, all other inventories use 0x2D) + outbound(0x1E, WorldBorderMessage.class, WorldBorderCodec.class); + outbound(0x1F, PingMessage.class, PingCodec.class); + outbound(0x20, ChunkDataMessage.class, ChunkDataCodec.class); + outbound(0x21, PlayEffectMessage.class, PlayEffectCodec.class); + outbound(0x22, PlayParticleMessage.class, PlayParticleCodec.class); + outbound(0x23, ChunkLightDataMessage.class, ChunkLightDataCodec.class); + outbound(0x24, JoinGameMessage.class, JoinGameCodec.class); + outbound(0x25, MapDataMessage.class, MapDataCodec.class); + // TODO 0x26 : Trade List (the list of trades a villager is offering) + outbound(0x27, RelativeEntityPositionMessage.class, RelativeEntityPositionCodec.class); + outbound(0x28, RelativeEntityPositionRotationMessage.class, RelativeEntityPositionRotationCodec.class); - outbound(0x28, EntityRotationMessage.class, EntityRotationCodec.class); - outbound(0x29, VehicleMoveMessage.class, VehicleMoveCodec.class); - // TODO 0x2A : Open Book (this replaces the old plugin channel. tells the client to open the book they have in hand) - outbound(0x2B, OpenWindowMessage.class, OpenWindowCodec.class); - outbound(0x2C, SignEditorMessage.class, SignEditorCodec.class); - // TODO 0x2D Ping (it's different to 0x1E PingMessage) - outbound(0x2E, CraftRecipeResponseMessage.class, CraftRecipeResponseCodec.class); - outbound(0x2F, PlayerAbilitiesMessage.class, PlayerAbilitiesCodec.class); - // TODO 0x30 Player Chat Message - // TODO 0x31 End Combat Event - // TODO 0x32 Enter Combat Event - // TODO 0x33 Death Combat Event - outbound(0x34, UserListItemMessage.class, UserListItemCodec.class); - // TODO 0x35 : Face Player (rotates the client to face a location or entity) - outbound(0x36, PositionRotationMessage.class, PositionRotationCodec.class); - outbound(0x37, UnlockRecipesMessage.class, UnlockRecipesCodec.class); - outbound(0x38, DestroyEntitiesMessage.class, DestroyEntitiesCodec.class); - outbound(0x39, EntityRemoveEffectMessage.class, EntityRemoveEffectCodec.class); - outbound(0x3A, ResourcePackSendMessage.class, ResourcePackSendCodec.class); - outbound(0x3B, RespawnMessage.class, RespawnCodec.class); - outbound(0x3C, EntityHeadRotationMessage.class, EntityHeadRotationCodec.class); - outbound(0x3D, MultiBlockChangeMessage.class, MultiBlockChangeCodec.class); - // TODO 0x3E : Select Advancement Tab (tells the client to switch tabs) - // TODO 0x3F : Server Data - // TODO 0x40 : Action Bar - // TODO 0x41 : World Border Center - // TODO 0x42 : World Border Lerp Size - // TODO 0x43 : World Border Size - // TODO 0x44 : World Border Warning Delay - // TODO 0x45 : World Border Warning Reach - outbound(0x46, CameraMessage.class, CameraCodec.class); - outbound(0x47, HeldItemMessage.class, HeldItemCodec.class); - // TODO 0x48 : "Update View Position" (use unclear, see https://wiki.vg/Protocol#Update_View_Position) - // TODO 0x49 : Update View Distance (unused in Vanilla, but could be used when changing view distance via plugins) - outbound(0x4A, SpawnPositionMessage.class, SpawnPositionCodec.class); + outbound(0x29, EntityRotationMessage.class, EntityRotationCodec.class); + outbound(0x2A, VehicleMoveMessage.class, VehicleMoveCodec.class); + // TODO 0x2B : Open Book (this replaces the old plugin channel. tells the client to open the book they have in hand) + outbound(0x2C, OpenWindowMessage.class, OpenWindowCodec.class); + outbound(0x2D, SignEditorMessage.class, SignEditorCodec.class); + // TODO 0x2E Ping (it's different to 0x1E PingMessage) + outbound(0x2F, CraftRecipeResponseMessage.class, CraftRecipeResponseCodec.class); + outbound(0x30, PlayerAbilitiesMessage.class, PlayerAbilitiesCodec.class); + // TODO 0x31 Player Chat Message + // TODO 0x32 End Combat Event + // TODO 0x33 Enter Combat Event + // TODO 0x34 Death Combat Event + // TODO 0x35 Player Info Remove + // TODO 0x36 Double check spec + outbound(0x36, UserListItemMessage.class, UserListItemCodec.class); + // TODO 0x37 : Face Player (rotates the client to face a location or entity) + outbound(0x38, PositionRotationMessage.class, PositionRotationCodec.class); + outbound(0x39, UnlockRecipesMessage.class, UnlockRecipesCodec.class); + outbound(0x3A, DestroyEntitiesMessage.class, DestroyEntitiesCodec.class); + outbound(0x3B, EntityRemoveEffectMessage.class, EntityRemoveEffectCodec.class); + outbound(0x3C, ResourcePackSendMessage.class, ResourcePackSendCodec.class); + outbound(0x3D, RespawnMessage.class, RespawnCodec.class); + outbound(0x3E, EntityHeadRotationMessage.class, EntityHeadRotationCodec.class); + outbound(0x3F, MultiBlockChangeMessage.class, MultiBlockChangeCodec.class); + // TODO 0x40 : Select Advancement Tab (tells the client to switch tabs) + // TODO 0x41 : Server Data + // TODO 0x42 : Action Bar + // TODO 0x43 : World Border Center + // TODO 0x44 : World Border Lerp Size + // TODO 0x45 : World Border Size + // TODO 0x46 : World Border Warning Delay + // TODO 0x47 : World Border Warning Reach + outbound(0x48, CameraMessage.class, CameraCodec.class); + outbound(0x49, HeldItemMessage.class, HeldItemCodec.class); + // TODO 0x4A Set Center Chunk + // TODO 0x4B Set Render Distance + outbound(0x4C, SpawnPositionMessage.class, SpawnPositionCodec.class); // TODO 0x4B : Set Display Chat Preview - outbound(0x4C, ScoreboardDisplayMessage.class, ScoreboardDisplayCodec.class); - outbound(0x4D, EntityMetadataMessage.class, EntityMetadataCodec.class); - outbound(0x4E, AttachEntityMessage.class, AttachEntityCodec.class); - outbound(0x4F, EntityVelocityMessage.class, EntityVelocityCodec.class); - outbound(0x50, EntityEquipmentMessage.class, EntityEquipmentCodec.class); - outbound(0x51, ExperienceMessage.class, ExperienceCodec.class); - outbound(0x52, HealthMessage.class, HealthCodec.class); - outbound(0x53, ScoreboardObjectiveMessage.class, ScoreboardObjectiveCodec.class); - outbound(0x54, SetPassengerMessage.class, SetPassengerCodec.class); - outbound(0x55, ScoreboardTeamMessage.class, ScoreboardTeamCodec.class); - outbound(0x56, ScoreboardScoreMessage.class, ScoreboardScoreCodec.class); - // TODO 0x57 : Update Simulation Distance - // TODO 0x58 : Set Title SubTitle - outbound(0x59, TimeMessage.class, TimeCodec.class); - // TODO 0x5A : Set Title Text outbound(0x5A, TitleMessage.class, TitleCodec.class); - // TODO 0x5B : Set Title Times - // TODO 0x5C : Entity Sound Effect - outbound(0x5D, SoundEffectMessage.class, SoundEffectCodec.class); - outbound(0x5E, StopSoundMessage.class, StopSoundCodec.class); - outbound(0x5F, ChatMessage.class, ChatCodec.class); - outbound(0x60, UserListHeaderFooterMessage.class, UserListHeaderFooterCodec.class); - // TODO 0x61 : NBT Query Response (response to Query Block/Entity NBT packets) - outbound(0x62, CollectItemMessage.class, CollectItemCodec.class); - outbound(0x63, EntityTeleportMessage.class, EntityTeleportCodec.class); - outbound(0x64, AdvancementsMessage.class, AdvancementsCodec.class); - outbound(0x65, EntityPropertyMessage.class, EntityPropertyCodec.class); - outbound(0x66, EntityEffectMessage.class, EntityEffectCodec.class); - // TODO 0x67 : Declare Recipes - // TODO 0x68 : Tags + outbound(0x4D, ScoreboardDisplayMessage.class, ScoreboardDisplayCodec.class); + outbound(0x4E, EntityMetadataMessage.class, EntityMetadataCodec.class); + outbound(0x4F, AttachEntityMessage.class, AttachEntityCodec.class); + outbound(0x50, EntityVelocityMessage.class, EntityVelocityCodec.class); + outbound(0x51, EntityEquipmentMessage.class, EntityEquipmentCodec.class); + outbound(0x52, ExperienceMessage.class, ExperienceCodec.class); + outbound(0x53, HealthMessage.class, HealthCodec.class); + outbound(0x54, ScoreboardObjectiveMessage.class, ScoreboardObjectiveCodec.class); + outbound(0x55, SetPassengerMessage.class, SetPassengerCodec.class); + outbound(0x56, ScoreboardTeamMessage.class, ScoreboardTeamCodec.class); + outbound(0x57, ScoreboardScoreMessage.class, ScoreboardScoreCodec.class); + // TODO 0x58 : Update Simulation Distance + // TODO 0x59 : Set Title SubTitle + outbound(0x5A, TimeMessage.class, TimeCodec.class); + // TODO 0x5B : Set Title Text outbound(0x5A, TitleMessage.class, TitleCodec.class); + // TODO 0x5C : Set Title Times + // TODO 0x5D : Entity Sound Effect + outbound(0x5E, SoundEffectMessage.class, SoundEffectCodec.class); + outbound(0x5F, StopSoundMessage.class, StopSoundCodec.class); + outbound(0x60, ChatMessage.class, ChatCodec.class); + outbound(0x61, UserListHeaderFooterMessage.class, UserListHeaderFooterCodec.class); + // TODO 0x62 : NBT Query Response (response to Query Block/Entity NBT packets) + outbound(0x63, CollectItemMessage.class, CollectItemCodec.class); + outbound(0x64, EntityTeleportMessage.class, EntityTeleportCodec.class); + outbound(0x65, AdvancementsMessage.class, AdvancementsCodec.class); + outbound(0x66, EntityPropertyMessage.class, EntityPropertyCodec.class); + // TODO 0x67 : Feature flags + outbound(0x68, EntityEffectMessage.class, EntityEffectCodec.class); + // TODO 0x69 : Update recipes + // TODO 0x6A : Update Tags } } From 91db372423b660ad81de7d487edabd4a1ced065f Mon Sep 17 00:00:00 2001 From: ApionXD Date: Thu, 9 Feb 2023 21:24:10 -0500 Subject: [PATCH 05/15] Updated some packets to newer protocol version specs --- src/main/java/net/glowstone/GlowWorld.java | 2 +- .../codec/play/game/ClientSettingsCodec.java | 6 +++- .../codec/play/game/PluginMessageCodec.java | 6 ++-- .../net/codec/play/game/StateChangeCodec.java | 2 +- .../net/codec/play/inv/HeldItemCodec.java | 2 +- .../play/player/BlockPlacementCodec.java | 17 +++++++---- .../play/player/ServerDifficultyCodec.java | 3 +- .../play/player/BlockPlacementHandler.java | 2 +- .../login/EncryptionKeyResponseCodec.java | 17 ++--------- .../net/message/login/LoginStartCodec.java | 30 +++++++++++-------- .../net/message/login/LoginStartMessage.java | 7 +++-- .../play/game/ClientSettingsMessage.java | 2 ++ .../play/player/BlockPlacementMessage.java | 6 ++-- .../play/player/ServerDifficultyMessage.java | 1 + 14 files changed, 58 insertions(+), 45 deletions(-) diff --git a/src/main/java/net/glowstone/GlowWorld.java b/src/main/java/net/glowstone/GlowWorld.java index 704535cf4..a4bb8c379 100644 --- a/src/main/java/net/glowstone/GlowWorld.java +++ b/src/main/java/net/glowstone/GlowWorld.java @@ -1137,7 +1137,7 @@ private void prepareSpawn() { @Override public void setDifficulty(Difficulty difficulty) { this.difficulty = difficulty; - ServerDifficultyMessage message = new ServerDifficultyMessage(difficulty); + ServerDifficultyMessage message = new ServerDifficultyMessage(difficulty, false); for (GlowPlayer player : getRawPlayers()) { player.getSession().send(message); } diff --git a/src/main/java/net/glowstone/net/codec/play/game/ClientSettingsCodec.java b/src/main/java/net/glowstone/net/codec/play/game/ClientSettingsCodec.java index ed4ea3206..1e5b309e0 100644 --- a/src/main/java/net/glowstone/net/codec/play/game/ClientSettingsCodec.java +++ b/src/main/java/net/glowstone/net/codec/play/game/ClientSettingsCodec.java @@ -17,7 +17,9 @@ public ClientSettingsMessage decode(ByteBuf buf) throws IOException { boolean colors = buf.readBoolean(); int skinFlags = buf.readUnsignedByte(); int hand = ByteBufUtils.readVarInt(buf); - return new ClientSettingsMessage(locale, viewDistance, chatFlags, colors, skinFlags, hand); + boolean textFiltering = buf.readBoolean(); + boolean serverListing = buf.readBoolean(); + return new ClientSettingsMessage(locale, viewDistance, chatFlags, colors, skinFlags, hand, textFiltering, serverListing); } @Override @@ -28,6 +30,8 @@ public ByteBuf encode(ByteBuf buf, ClientSettingsMessage message) throws IOExcep buf.writeBoolean(message.isChatColors()); buf.writeByte(message.getSkinFlags()); ByteBufUtils.writeVarInt(buf, message.getHand()); + buf.writeBoolean(message.isTextFilteringEnabled()); + buf.writeBoolean(message.isServerListingEnables()); return buf; } } diff --git a/src/main/java/net/glowstone/net/codec/play/game/PluginMessageCodec.java b/src/main/java/net/glowstone/net/codec/play/game/PluginMessageCodec.java index a684e0c4e..11e61e74e 100644 --- a/src/main/java/net/glowstone/net/codec/play/game/PluginMessageCodec.java +++ b/src/main/java/net/glowstone/net/codec/play/game/PluginMessageCodec.java @@ -3,7 +3,9 @@ import com.flowpowered.network.Codec; import com.flowpowered.network.util.ByteBufUtils; import io.netty.buffer.ByteBuf; +import net.glowstone.net.GlowBufUtils; import net.glowstone.net.message.play.game.PluginMessage; +import org.bukkit.NamespacedKey; import java.io.IOException; @@ -11,12 +13,12 @@ public final class PluginMessageCodec implements Codec { @Override public PluginMessage decode(ByteBuf buf) throws IOException { - String channel = ByteBufUtils.readUTF8(buf); + NamespacedKey channel = GlowBufUtils.readNamespacedKey(buf); // todo: maybe store a ByteBuf in the message instead? byte[] data = new byte[buf.readableBytes()]; buf.readBytes(data); - return new PluginMessage(channel, data); + return new PluginMessage(channel.toString(), data); } @Override diff --git a/src/main/java/net/glowstone/net/codec/play/game/StateChangeCodec.java b/src/main/java/net/glowstone/net/codec/play/game/StateChangeCodec.java index e11b6ccb6..f808842a5 100644 --- a/src/main/java/net/glowstone/net/codec/play/game/StateChangeCodec.java +++ b/src/main/java/net/glowstone/net/codec/play/game/StateChangeCodec.java @@ -10,7 +10,7 @@ public final class StateChangeCodec implements Codec { @Override public StateChangeMessage decode(ByteBuf buffer) throws IOException { - int reason = buffer.readByte(); + int reason = buffer.readUnsignedByte(); float value = buffer.readFloat(); return new StateChangeMessage(reason, value); diff --git a/src/main/java/net/glowstone/net/codec/play/inv/HeldItemCodec.java b/src/main/java/net/glowstone/net/codec/play/inv/HeldItemCodec.java index fb07b7b40..235d9f1bc 100644 --- a/src/main/java/net/glowstone/net/codec/play/inv/HeldItemCodec.java +++ b/src/main/java/net/glowstone/net/codec/play/inv/HeldItemCodec.java @@ -10,7 +10,7 @@ public final class HeldItemCodec implements Codec { @Override public HeldItemMessage decode(ByteBuf buf) throws IOException { - int slot = buf.readShort(); + int slot = buf.readByte(); return new HeldItemMessage(slot); } diff --git a/src/main/java/net/glowstone/net/codec/play/player/BlockPlacementCodec.java b/src/main/java/net/glowstone/net/codec/play/player/BlockPlacementCodec.java index ae2eade36..6e40438bf 100644 --- a/src/main/java/net/glowstone/net/codec/play/player/BlockPlacementCodec.java +++ b/src/main/java/net/glowstone/net/codec/play/player/BlockPlacementCodec.java @@ -13,24 +13,29 @@ public final class BlockPlacementCodec implements Codec { @Override public BlockPlacementMessage decode(ByteBuf buf) throws IOException { - BlockVector pos = GlowBufUtils.readBlockPosition(buf); - int direction = buf.readByte(); int hand = ByteBufUtils.readVarInt(buf); + BlockVector pos = GlowBufUtils.readBlockPosition(buf); + int face = ByteBufUtils.readVarInt(buf); + float cursorX = buf.readFloat(); float cursorY = buf.readFloat(); float cursorZ = buf.readFloat(); - return new BlockPlacementMessage(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), - direction, hand, cursorX, cursorY, cursorZ); + boolean isInsideBlock = buf.readBoolean(); + int sequence = ByteBufUtils.readVarInt(buf); + return new BlockPlacementMessage(hand, pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), face, cursorX, cursorY, cursorZ, isInsideBlock, sequence); } @Override public ByteBuf encode(ByteBuf buf, BlockPlacementMessage message) throws IOException { - GlowBufUtils.writeBlockPosition(buf, message.getX(), message.getY(), message.getZ()); - buf.writeByte(message.getDirection()); ByteBufUtils.writeVarInt(buf, message.getHand()); + GlowBufUtils.writeBlockPosition(buf, message.getX(), message.getY(), message.getZ()); + ByteBufUtils.writeVarInt(buf, message.getFace()); + buf.writeFloat(message.getCursorX()); buf.writeFloat(message.getCursorY()); buf.writeFloat(message.getCursorZ()); + buf.writeBoolean(message.isInsideBlock()); + ByteBufUtils.writeVarInt(buf, message.getSequence()); return buf; } } diff --git a/src/main/java/net/glowstone/net/codec/play/player/ServerDifficultyCodec.java b/src/main/java/net/glowstone/net/codec/play/player/ServerDifficultyCodec.java index 4fe850487..e52c6cb0c 100644 --- a/src/main/java/net/glowstone/net/codec/play/player/ServerDifficultyCodec.java +++ b/src/main/java/net/glowstone/net/codec/play/player/ServerDifficultyCodec.java @@ -12,7 +12,8 @@ public final class ServerDifficultyCodec implements Codec { @Override public LoginStartMessage decode(ByteBuf buffer) throws IOException { String input = ByteBufUtils.readUTF8(buffer); - boolean hasSigData = buffer.readBoolean(); - long timestamp = 0; - byte[] publicKey = null; - byte[] signature = null; - if (hasSigData) { - timestamp = buffer.readLong(); - publicKey = new byte[ByteBufUtils.readVarInt(buffer)]; - buffer.readBytes(publicKey); - signature = new byte[ByteBufUtils.readVarInt(buffer)]; - buffer.readBytes(signature); + boolean hasUuid = buffer.readBoolean(); + UUID uuid = null; + if (hasUuid) { + ByteBuf uuidBuf = buffer.readBytes(16); + uuid = new UUID(uuidBuf.readLong(), uuidBuf.readLong()); } - return new LoginStartMessage(URLEncoder.encode(input, StandardCharsets.UTF_8.toString()), - timestamp, publicKey, signature); + return new LoginStartMessage(input, hasUuid, uuid); } @Override public ByteBuf encode(ByteBuf buf, LoginStartMessage message) throws IOException { ByteBufUtils.writeUTF8(buf, message.getUsername()); + buf.writeBoolean(message.isHasUuid()); + if (message.isHasUuid()) { + UUID uuid = message.getUuid(); + ByteBuffer bb = ByteBuffer.wrap(new byte[16]); + bb.putLong(uuid.getMostSignificantBits()); + bb.putLong(uuid.getLeastSignificantBits()); + buf.writeBytes(bb); + } return buf; } } diff --git a/src/main/java/net/glowstone/net/message/login/LoginStartMessage.java b/src/main/java/net/glowstone/net/message/login/LoginStartMessage.java index 8c81c9739..8521f4048 100644 --- a/src/main/java/net/glowstone/net/message/login/LoginStartMessage.java +++ b/src/main/java/net/glowstone/net/message/login/LoginStartMessage.java @@ -3,13 +3,14 @@ import com.flowpowered.network.AsyncableMessage; import lombok.Data; +import java.util.UUID; + @Data public final class LoginStartMessage implements AsyncableMessage { private final String username; - private final long timestamp; - private final byte[] publicKey; - private final byte[] signature; + private final boolean hasUuid; + private final UUID uuid; @Override public boolean isAsync() { diff --git a/src/main/java/net/glowstone/net/message/play/game/ClientSettingsMessage.java b/src/main/java/net/glowstone/net/message/play/game/ClientSettingsMessage.java index e9f93d4cb..5f380ac9b 100644 --- a/src/main/java/net/glowstone/net/message/play/game/ClientSettingsMessage.java +++ b/src/main/java/net/glowstone/net/message/play/game/ClientSettingsMessage.java @@ -12,5 +12,7 @@ public final class ClientSettingsMessage implements Message { private final boolean chatColors; private final int skinFlags; private final int hand; + private final boolean textFilteringEnabled; + private final boolean serverListingEnables; } diff --git a/src/main/java/net/glowstone/net/message/play/player/BlockPlacementMessage.java b/src/main/java/net/glowstone/net/message/play/player/BlockPlacementMessage.java index c3d84d3e3..af0451246 100644 --- a/src/main/java/net/glowstone/net/message/play/player/BlockPlacementMessage.java +++ b/src/main/java/net/glowstone/net/message/play/player/BlockPlacementMessage.java @@ -7,14 +7,16 @@ @Data public final class BlockPlacementMessage implements Message { + private final int hand; private final int x; private final int y; private final int z; - private final int direction; - private final int hand; + private final int face; private final float cursorX; private final float cursorY; private final float cursorZ; + private final boolean isInsideBlock; + private final int sequence; public EquipmentSlot getHandSlot() { return hand == 1 ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND; diff --git a/src/main/java/net/glowstone/net/message/play/player/ServerDifficultyMessage.java b/src/main/java/net/glowstone/net/message/play/player/ServerDifficultyMessage.java index 4b2f73df0..6af3c014c 100644 --- a/src/main/java/net/glowstone/net/message/play/player/ServerDifficultyMessage.java +++ b/src/main/java/net/glowstone/net/message/play/player/ServerDifficultyMessage.java @@ -8,5 +8,6 @@ public final class ServerDifficultyMessage implements Message { private final Difficulty difficulty; + private final boolean locked; } From b07989c6849ad27bb72e6bec4fac90f78b4de794 Mon Sep 17 00:00:00 2001 From: ApionXD Date: Fri, 10 Feb 2023 06:26:43 -0500 Subject: [PATCH 06/15] Got up to the JoinGameMessage packet of the world join process working --- src/main/java/net/glowstone/GlowServer.java | 2 +- .../java/net/glowstone/chunk/GlowChunk.java | 4 ++- .../java/net/glowstone/constants/ItemIds.java | 4 +-- .../java/net/glowstone/entity/GlowPlayer.java | 26 ++++++++++++++----- .../glowstone/io/nbt/NbtSerialization.java | 3 +++ .../java/net/glowstone/net/GlowBufUtils.java | 2 +- .../java/net/glowstone/net/GlowSession.java | 8 +++--- .../codec/play/game/PluginMessageCodec.java | 7 +++-- .../net/message/login/LoginSuccessCodec.java | 8 +++++- .../message/login/LoginSuccessMessage.java | 10 +++++++ 10 files changed, 53 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/glowstone/GlowServer.java b/src/main/java/net/glowstone/GlowServer.java index c544149f3..58d856167 100644 --- a/src/main/java/net/glowstone/GlowServer.java +++ b/src/main/java/net/glowstone/GlowServer.java @@ -870,7 +870,7 @@ public void start() { String seedString = config.getString(Key.LEVEL_SEED); WorldType type = WorldType.getByName(getWorldType()); if (type == null) { - type = WorldType.NORMAL; + type = WorldType.FLAT; } long seed = new Random().nextLong(); diff --git a/src/main/java/net/glowstone/chunk/GlowChunk.java b/src/main/java/net/glowstone/chunk/GlowChunk.java index ef72a6290..29c2fc5f0 100644 --- a/src/main/java/net/glowstone/chunk/GlowChunk.java +++ b/src/main/java/net/glowstone/chunk/GlowChunk.java @@ -963,7 +963,9 @@ public ChunkDataMessage toMessage(boolean skylight, boolean entireChunk, if (sections != null) { // get the list of sections for (int i = 0; i < sections.length; ++i) { - sections[i].writeToBuf(buf, skylight); + if (sections[i] != null) { + sections[i].writeToBuf(buf, skylight); + } } } diff --git a/src/main/java/net/glowstone/constants/ItemIds.java b/src/main/java/net/glowstone/constants/ItemIds.java index 4c8e60f15..14ee5b300 100644 --- a/src/main/java/net/glowstone/constants/ItemIds.java +++ b/src/main/java/net/glowstone/constants/ItemIds.java @@ -32,6 +32,7 @@ public final class ItemIds { static { // blocks + both(-1, "cave_air"); both(0, "air"); both(1, "stone"); both(2, "grass"); @@ -551,9 +552,8 @@ public static Material getBlock(String name) { if (!blocks.containsKey(name)) { return null; } - return Material.getMaterial(name); + return Material.matchMaterial(name); } - /** * Verify that a given material is a valid item. All non-blocks are valid items, but some blocks * cannot be represented as items. diff --git a/src/main/java/net/glowstone/entity/GlowPlayer.java b/src/main/java/net/glowstone/entity/GlowPlayer.java index 9449aca6e..ad1877afa 100644 --- a/src/main/java/net/glowstone/entity/GlowPlayer.java +++ b/src/main/java/net/glowstone/entity/GlowPlayer.java @@ -7,6 +7,7 @@ import com.flowpowered.network.Message; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.Unpooled; @@ -103,6 +104,7 @@ import net.glowstone.util.mojangson.Mojangson; import net.glowstone.util.nbt.CompoundTag; import net.glowstone.util.nbt.ListTag; +import net.glowstone.util.nbt.StringTag; import net.glowstone.util.nbt.TagType; import net.kyori.adventure.text.Component; import net.kyori.adventure.util.TriState; @@ -805,21 +807,29 @@ public void join(GlowSession session, PlayerReader reader) { List chatList = new ArrayList<>(); { - CompoundTag system = new CompoundTag(); - system.putCompound("chat", new CompoundTag()); + CompoundTag chat = new CompoundTag(); + chat.putString("translation_key", ""); + chat.putCompound("style", new CompoundTag()); + chat.putList("parameters", TagType.STRING, Lists.newArrayList("sender", "target", "content"), (StringTag::new)); CompoundTag narration = new CompoundTag(); - narration.putString("priority", "system"); - system.putCompound("narration", narration); + narration.putString("translation_key", ""); + narration.putList("parameters", TagType.STRING, Lists.newArrayList("sender", "target", "content"), (StringTag::new)); + + CompoundTag element = new CompoundTag(); + element.putCompound("chat", chat); + element.putCompound("narration", narration); + + CompoundTag parent = new CompoundTag(); parent.putString("name", "minecraft:system"); parent.putInt("id", 0); - parent.putCompound("element", system); + parent.putCompound("element", element); chatList.add(parent); } - + /* { CompoundTag gameInfo = new CompoundTag(); gameInfo.putCompound("overlay", new CompoundTag()); @@ -832,11 +842,13 @@ public void join(GlowSession session, PlayerReader reader) { chatList.add(parent); } + */ + CompoundTag chatRegistry = new CompoundTag(); chatRegistry.putString("type", "minecraft:chat_type"); chatRegistry.putCompoundList("value", chatList); - registryCodecs.putCompound("minecraft:chat_typee", chatRegistry); + registryCodecs.putCompound("minecraft:chat_type", chatRegistry); } session.send(new JoinGameMessage( diff --git a/src/main/java/net/glowstone/io/nbt/NbtSerialization.java b/src/main/java/net/glowstone/io/nbt/NbtSerialization.java index 62a0b26cb..b2832e75f 100644 --- a/src/main/java/net/glowstone/io/nbt/NbtSerialization.java +++ b/src/main/java/net/glowstone/io/nbt/NbtSerialization.java @@ -112,6 +112,9 @@ public static CompoundTag writeBlockData(BlockData blockData) { */ public static ItemStack[] readInventory(List tagList, int start, int size) { ItemStack[] items = new ItemStack[size]; + Arrays.setAll(items, (index) -> { + return new ItemStack(Material.AIR); + }); for (CompoundTag tag : tagList) { tag.readByte("Slot", slot -> { if (slot >= start && slot < start + size) { diff --git a/src/main/java/net/glowstone/net/GlowBufUtils.java b/src/main/java/net/glowstone/net/GlowBufUtils.java index 1bd8e5307..420467744 100644 --- a/src/main/java/net/glowstone/net/GlowBufUtils.java +++ b/src/main/java/net/glowstone/net/GlowBufUtils.java @@ -446,7 +446,7 @@ public static void writeBitSet(ByteBuf buf, BitSet bitSet) { @SneakyThrows public static NamespacedKey readNamespacedKey(ByteBuf buf) { String raw = ByteBufUtils.readUTF8(buf); - return NamespacedKey.fromString(ByteBufUtils.readUTF8(buf)); + return NamespacedKey.fromString(raw); } @SneakyThrows diff --git a/src/main/java/net/glowstone/net/GlowSession.java b/src/main/java/net/glowstone/net/GlowSession.java index 0e414c26a..dc56c882b 100644 --- a/src/main/java/net/glowstone/net/GlowSession.java +++ b/src/main/java/net/glowstone/net/GlowSession.java @@ -320,9 +320,9 @@ public ChannelFuture sendWithFuture(Message message) { } // Useful for debugging packet sends // TODO: config option? - // Throwable trace = new Throwable(); - // return super.sendWithFuture(message).addListener(f -> GlowServer.logger.log(Level.INFO, "Message sent: " + message.toString() + " to " + this, trace)); - return super.sendWithFuture(message); + Throwable trace = new Throwable(); + return super.sendWithFuture(message).addListener(f -> GlowServer.logger.log(Level.INFO, "Message sent: " + message.toString() + " to " + this, trace)); + //return super.sendWithFuture(message); } /** @@ -491,7 +491,7 @@ private void finalizeLogin(GlowPlayerProfile profile) { } // send login response - send(new LoginSuccessMessage(profile.getId(), profile.getName())); + send(new LoginSuccessMessage(profile.getId(), profile.getName(), new ArrayList())); setProtocol(protocolProvider.play); } diff --git a/src/main/java/net/glowstone/net/codec/play/game/PluginMessageCodec.java b/src/main/java/net/glowstone/net/codec/play/game/PluginMessageCodec.java index 11e61e74e..3fa6455b1 100644 --- a/src/main/java/net/glowstone/net/codec/play/game/PluginMessageCodec.java +++ b/src/main/java/net/glowstone/net/codec/play/game/PluginMessageCodec.java @@ -3,9 +3,8 @@ import com.flowpowered.network.Codec; import com.flowpowered.network.util.ByteBufUtils; import io.netty.buffer.ByteBuf; -import net.glowstone.net.GlowBufUtils; import net.glowstone.net.message.play.game.PluginMessage; -import org.bukkit.NamespacedKey; +import net.glowstone.net.message.play.game.PluginMessage; import java.io.IOException; @@ -13,12 +12,12 @@ public final class PluginMessageCodec implements Codec { @Override public PluginMessage decode(ByteBuf buf) throws IOException { - NamespacedKey channel = GlowBufUtils.readNamespacedKey(buf); + String channel = ByteBufUtils.readUTF8(buf); // todo: maybe store a ByteBuf in the message instead? byte[] data = new byte[buf.readableBytes()]; buf.readBytes(data); - return new PluginMessage(channel.toString(), data); + return new PluginMessage(channel, data); } @Override diff --git a/src/main/java/net/glowstone/net/message/login/LoginSuccessCodec.java b/src/main/java/net/glowstone/net/message/login/LoginSuccessCodec.java index 19de52aed..d5454f2de 100644 --- a/src/main/java/net/glowstone/net/message/login/LoginSuccessCodec.java +++ b/src/main/java/net/glowstone/net/message/login/LoginSuccessCodec.java @@ -3,10 +3,12 @@ import com.flowpowered.network.Codec; import com.flowpowered.network.util.ByteBufUtils; import io.netty.buffer.ByteBuf; +import io.netty.handler.codec.DecoderException; import net.glowstone.net.GlowBufUtils; import net.glowstone.net.message.login.LoginSuccessMessage; import java.io.IOException; +import java.util.ArrayList; import java.util.UUID; public final class LoginSuccessCodec implements Codec { @@ -15,8 +17,12 @@ public final class LoginSuccessCodec implements Codec { public LoginSuccessMessage decode(ByteBuf buffer) throws IOException { UUID uuid = GlowBufUtils.readUuid(buffer); String username = ByteBufUtils.readUTF8(buffer); + int numProps = ByteBufUtils.readVarInt(buffer); + if (numProps > 0) { + throw new DecoderException("Can't decode LoginSuccessMessage with props"); + } - return new LoginSuccessMessage(uuid, username); + return new LoginSuccessMessage(uuid, username, new ArrayList<>()); } @Override diff --git a/src/main/java/net/glowstone/net/message/login/LoginSuccessMessage.java b/src/main/java/net/glowstone/net/message/login/LoginSuccessMessage.java index 5507be4a9..070d12b4a 100644 --- a/src/main/java/net/glowstone/net/message/login/LoginSuccessMessage.java +++ b/src/main/java/net/glowstone/net/message/login/LoginSuccessMessage.java @@ -3,6 +3,7 @@ import com.flowpowered.network.Message; import lombok.Data; +import java.util.ArrayList; import java.util.UUID; @Data @@ -10,5 +11,14 @@ public final class LoginSuccessMessage implements Message { private final UUID uuid; private final String username; + private final ArrayList properties; + + @Data + public class LoginSuccessProperties { + private final String name; + private final String value; + private final boolean isSigned; + private final String signature; + } } From cfc492058def9c65ba663460a9c14da7b898a7ae Mon Sep 17 00:00:00 2001 From: ApionXD Date: Fri, 10 Feb 2023 21:10:49 -0500 Subject: [PATCH 07/15] Login process through chunk streaming is (kind of) working, need to fix pallettes, currently we hardcode the sent data so it only uses one pallette index. --- .../net/glowstone/chunk/ChunkSection.java | 7 +++-- .../java/net/glowstone/chunk/GlowChunk.java | 14 ++++++++- .../glowstone/entity/GlowLivingEntity.java | 10 ++++++ .../java/net/glowstone/entity/GlowPlayer.java | 31 ++++++++++--------- .../glowstone/io/nbt/NbtSerialization.java | 2 +- .../java/net/glowstone/net/GlowSession.java | 6 ++-- 6 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/glowstone/chunk/ChunkSection.java b/src/main/java/net/glowstone/chunk/ChunkSection.java index bd57f8e46..5f3f0bd5c 100644 --- a/src/main/java/net/glowstone/chunk/ChunkSection.java +++ b/src/main/java/net/glowstone/chunk/ChunkSection.java @@ -437,7 +437,8 @@ public void writeToBuf(ByteBuf buf, boolean skylight) throws IllegalStateExcepti if (this.isEmpty()) { throw new IllegalStateException("Can't write empty sections"); } - + // This should write the number of non air blocks in this section, but we currently dont track that + buf.writeShort(1024); buf.writeByte(data.getBitsPerValue()); // Bit per value -> varies if (palette != null) { ByteBufUtils.writeVarInt(buf, palette.size()); // Palette size @@ -452,11 +453,11 @@ public void writeToBuf(ByteBuf buf, boolean skylight) throws IllegalStateExcepti buf.ensureWritable((backing.length << 3) + blockLight.byteSize() + (skylight ? skyLight .byteSize() : 0)); for (long value : backing) { - buf.writeLong(value); + buf.writeLong(0); } // Palette - ByteBufUtils.writeVarInt(buf, 1); // Palette length + ByteBufUtils.writeVarInt(buf, 0); // Palette length ByteBufUtils.writeVarInt(buf, 0); // Palette data (AIR) // Section data (4096 indices of 4-bit, 64 bit longs -> 256 empty longs) diff --git a/src/main/java/net/glowstone/chunk/GlowChunk.java b/src/main/java/net/glowstone/chunk/GlowChunk.java index 29c2fc5f0..b8ff51ae1 100644 --- a/src/main/java/net/glowstone/chunk/GlowChunk.java +++ b/src/main/java/net/glowstone/chunk/GlowChunk.java @@ -986,7 +986,19 @@ public ChunkDataMessage toMessage(boolean skylight, boolean entireChunk, } CompoundTag heightMap = new CompoundTag(); - heightMap.putByteArray("MOTION_BLOCKING", this.heightMap); + long actualHeightMap[] = new long[37]; + for (int i = 0; i < 37; i++) { + long mappedLong = 0; + for (int j = 0; j < 7; j++) { + if ((i * 7) + j < 256){ + mappedLong = mappedLong << 9; + mappedLong += this.heightMap[(i * 7) + j]; + } + } + actualHeightMap[i] = mappedLong << 1; + } + + heightMap.putLongArray("MOTION_BLOCKING", actualHeightMap); BitSet skyLightMask = new BitSet(); diff --git a/src/main/java/net/glowstone/entity/GlowLivingEntity.java b/src/main/java/net/glowstone/entity/GlowLivingEntity.java index 79e3ebb48..ebdc54be9 100644 --- a/src/main/java/net/glowstone/entity/GlowLivingEntity.java +++ b/src/main/java/net/glowstone/entity/GlowLivingEntity.java @@ -111,6 +111,16 @@ * @author Graham Edgecombe. */ public abstract class GlowLivingEntity extends GlowEntity implements LivingEntity { + @Override + public float getBodyYaw() { + return 0; + } + + @Override + public void setBodyYaw(float bodyYaw) { + + } + @Override public @Nullable BlockFace getTargetBlockFace(int maxDistance, @NotNull FluidCollisionMode fluidMode) { return null; diff --git a/src/main/java/net/glowstone/entity/GlowPlayer.java b/src/main/java/net/glowstone/entity/GlowPlayer.java index ad1877afa..b83814845 100644 --- a/src/main/java/net/glowstone/entity/GlowPlayer.java +++ b/src/main/java/net/glowstone/entity/GlowPlayer.java @@ -890,38 +890,39 @@ public void join(GlowSession session, PlayerReader reader) { sendRainDensity(); sendSkyDarkness(); getServer().sendPlayerAbilities(this); + int count = 0; // send initial location session.send(new PositionRotationMessage(location)); // send initial velocity - session.send(new EntityVelocityMessage(getEntityId(), velocity)); +// session.send(new EntityVelocityMessage(getEntityId(), velocity)); // send initial health - sendHealth(); +// sendHealth(); // send gamemode defaults - setGameModeDefaults(); +// setGameModeDefaults(); // send held item - getSession().send(new HeldItemMessage(getInventory().getHeldItemSlot())); +// getSession().send(new HeldItemMessage(getInventory().getHeldItemSlot())); // send xp bar - sendExperience(); +// sendExperience(); - session.send(world.getWorldBorder().createMessage()); - sendTime(); - setCompassTarget(world.getSpawnLocation()); // set our compass target +// session.send(world.getWorldBorder().createMessage()); +// sendTime(); +// setCompassTarget(world.getSpawnLocation()); // set our compass target - scoreboard = server.getScoreboardManager().getMainScoreboard(); - scoreboard.subscribe(this); + //scoreboard = server.getScoreboardManager().getMainScoreboard(); + //scoreboard.subscribe(this); - invMonitor = new InventoryMonitor(getOpenInventory()); - updateInventory(); // send inventory contents - session.send(recipeMonitor.createInitMessage()); +// invMonitor = new InventoryMonitor(getOpenInventory()); +// updateInventory(); // send inventory contents +// session.send(recipeMonitor.createInitMessage()); if (!server.getResourcePackUrl().isEmpty()) { - setResourcePack(server.getResourcePackUrl(), server.getResourcePackHash()); +// setResourcePack(server.getResourcePackUrl(), server.getResourcePackHash()); } } @@ -4482,4 +4483,6 @@ public void setFrictionState(@NotNull TriState state) { public @NotNull T launchProjectile(@NotNull Class projectile, @org.jetbrains.annotations.Nullable Vector velocity, @org.jetbrains.annotations.Nullable Consumer function) { return null; } + + } diff --git a/src/main/java/net/glowstone/io/nbt/NbtSerialization.java b/src/main/java/net/glowstone/io/nbt/NbtSerialization.java index b2832e75f..cf2787851 100644 --- a/src/main/java/net/glowstone/io/nbt/NbtSerialization.java +++ b/src/main/java/net/glowstone/io/nbt/NbtSerialization.java @@ -90,7 +90,7 @@ public static CompoundTag writeItem(ItemStack stack, int slot) { public static BlockData readBlockData(CompoundTag tag) { NamespacedKey key = namespacedKeyFromString(tag.getString("Name")); - Material type = Material.getMaterial(key.toString()); + Material type = Material.matchMaterial(key.toString()); Optional properties = tag.tryGetCompound("Properties"); return Bukkit.getServer().createBlockData(type); } diff --git a/src/main/java/net/glowstone/net/GlowSession.java b/src/main/java/net/glowstone/net/GlowSession.java index dc56c882b..53210cdc7 100644 --- a/src/main/java/net/glowstone/net/GlowSession.java +++ b/src/main/java/net/glowstone/net/GlowSession.java @@ -320,9 +320,9 @@ public ChannelFuture sendWithFuture(Message message) { } // Useful for debugging packet sends // TODO: config option? - Throwable trace = new Throwable(); - return super.sendWithFuture(message).addListener(f -> GlowServer.logger.log(Level.INFO, "Message sent: " + message.toString() + " to " + this, trace)); - //return super.sendWithFuture(message); + //Throwable trace = new Throwable(); + //return super.sendWithFuture(message).addListener(f -> GlowServer.logger.log(Level.INFO, "Message sent: " + message.toString() + " to " + this, trace)); + return super.sendWithFuture(message); } /** From 553dd3869fc1fcba8e50bd502208e0d4fcce2d2b Mon Sep 17 00:00:00 2001 From: apion Date: Sat, 11 Feb 2023 10:14:03 -0500 Subject: [PATCH 08/15] Login and map loading completely working on 1.19.3 --- .../net/glowstone/chunk/ChunkSection.java | 18 ++-- .../java/net/glowstone/chunk/GlowChunk.java | 2 +- .../java/net/glowstone/entity/GlowPlayer.java | 18 ++-- .../java/net/glowstone/net/GlowSession.java | 13 +-- .../codec/play/game/UserListItemCodec.java | 100 ++++++++---------- .../play/game/UserListItemMessage.java | 66 +++++++----- 6 files changed, 113 insertions(+), 104 deletions(-) diff --git a/src/main/java/net/glowstone/chunk/ChunkSection.java b/src/main/java/net/glowstone/chunk/ChunkSection.java index 5f3f0bd5c..33f595269 100644 --- a/src/main/java/net/glowstone/chunk/ChunkSection.java +++ b/src/main/java/net/glowstone/chunk/ChunkSection.java @@ -1,6 +1,7 @@ package net.glowstone.chunk; import com.flowpowered.network.util.ByteBufUtils; +import com.google.common.primitives.Longs; import io.netty.buffer.ByteBuf; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; @@ -290,6 +291,7 @@ public BlockData getBlockData(int x, int y, int z) { */ public int getType(int x, int y, int z) { int value = data.get(index(x, y, z)); + if (palette != null) { value = palette.getInt(value); } @@ -437,8 +439,7 @@ public void writeToBuf(ByteBuf buf, boolean skylight) throws IllegalStateExcepti if (this.isEmpty()) { throw new IllegalStateException("Can't write empty sections"); } - // This should write the number of non air blocks in this section, but we currently dont track that - buf.writeShort(1024); + buf.writeShort(count); buf.writeByte(data.getBitsPerValue()); // Bit per value -> varies if (palette != null) { ByteBufUtils.writeVarInt(buf, palette.size()); // Palette size @@ -453,16 +454,19 @@ public void writeToBuf(ByteBuf buf, boolean skylight) throws IllegalStateExcepti buf.ensureWritable((backing.length << 3) + blockLight.byteSize() + (skylight ? skyLight .byteSize() : 0)); for (long value : backing) { - buf.writeLong(0); + buf.writeLong(value); } + buf.writeByte(0); + ByteBufUtils.writeVarInt(buf, 0); + ByteBufUtils.writeVarInt(buf, 0); // Palette - ByteBufUtils.writeVarInt(buf, 0); // Palette length - ByteBufUtils.writeVarInt(buf, 0); // Palette data (AIR) + //ByteBufUtils.writeVarInt(buf, 0); // Palette length + //ByteBufUtils.writeVarInt(buf, 0); // Palette data (AIR) // Section data (4096 indices of 4-bit, 64 bit longs -> 256 empty longs) - ByteBufUtils.writeVarInt(buf, 256); // Data size - buf.writeBytes(new byte[2048]); // 256 longs is 2048 bytes + //ByteBufUtils.writeVarInt(buf, 256); // Data size + //buf.writeBytes(new byte[2048]); // 256 longs is 2048 bytes // buf.writeByte(data.getBitsPerValue()); // Bit per value -> varies diff --git a/src/main/java/net/glowstone/chunk/GlowChunk.java b/src/main/java/net/glowstone/chunk/GlowChunk.java index b8ff51ae1..dcc355bed 100644 --- a/src/main/java/net/glowstone/chunk/GlowChunk.java +++ b/src/main/java/net/glowstone/chunk/GlowChunk.java @@ -569,7 +569,7 @@ public BlockData getBlockData(int x, int z, int y) { @Deprecated public int getType(int x, int z, int y) { ChunkSection section = getSection(y); - return section == null ? 0 : section.getType(x, y, z) >> 4; + return section == null ? 0 : section.getType(x, y, z); } /** diff --git a/src/main/java/net/glowstone/entity/GlowPlayer.java b/src/main/java/net/glowstone/entity/GlowPlayer.java index b83814845..feee71e5f 100644 --- a/src/main/java/net/glowstone/entity/GlowPlayer.java +++ b/src/main/java/net/glowstone/entity/GlowPlayer.java @@ -896,23 +896,23 @@ public void join(GlowSession session, PlayerReader reader) { session.send(new PositionRotationMessage(location)); // send initial velocity -// session.send(new EntityVelocityMessage(getEntityId(), velocity)); + session.send(new EntityVelocityMessage(getEntityId(), velocity)); // send initial health -// sendHealth(); + sendHealth(); // send gamemode defaults -// setGameModeDefaults(); + setGameModeDefaults(); // send held item -// getSession().send(new HeldItemMessage(getInventory().getHeldItemSlot())); + getSession().send(new HeldItemMessage(getInventory().getHeldItemSlot())); // send xp bar -// sendExperience(); + sendExperience(); -// session.send(world.getWorldBorder().createMessage()); -// sendTime(); -// setCompassTarget(world.getSpawnLocation()); // set our compass target + session.send(world.getWorldBorder().createMessage()); + sendTime(); + setCompassTarget(world.getSpawnLocation()); // set our compass target //scoreboard = server.getScoreboardManager().getMainScoreboard(); //scoreboard.subscribe(this); @@ -4073,7 +4073,7 @@ public void showPlayer(Player player) { } hiddenEntities.remove(player.getUniqueId()); - session.send(new UserListItemMessage(UserListItemMessage.Action.ADD_PLAYER, ((GlowPlayer) + session.send(new UserListItemMessage(Lists.newArrayList(UserListItemMessage.Action.ADD_PLAYER), ((GlowPlayer) player) .getUserListEntry())); } diff --git a/src/main/java/net/glowstone/net/GlowSession.java b/src/main/java/net/glowstone/net/GlowSession.java index 53210cdc7..b994ae532 100644 --- a/src/main/java/net/glowstone/net/GlowSession.java +++ b/src/main/java/net/glowstone/net/GlowSession.java @@ -6,6 +6,7 @@ import com.flowpowered.network.MessageHandler; import com.flowpowered.network.protocol.AbstractProtocol; import com.flowpowered.network.session.BasicSession; +import com.google.common.collect.Lists; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; @@ -293,12 +294,12 @@ public void setPlayer(GlowPlayerProfile profile) { + UuidUtils.toString(player.getUniqueId())); // message and user list - String message = EventFactory.getInstance().onPlayerJoin(player).getJoinMessage(); + String message = EventFactory.getInstance().onPlayerJoin(player).joinMessage().examinableName(); if (message != null && !message.isEmpty()) { server.broadcastMessage(message); } - Message addMessage = new UserListItemMessage(Action.ADD_PLAYER, player.getUserListEntry()); + Message addMessage = new UserListItemMessage(Lists.newArrayList(Action.ADD_PLAYER), player.getUserListEntry()); List entries = new ArrayList<>(); for (GlowPlayer other : server.getRawOnlinePlayers()) { if (other != player && other.canSee(player)) { @@ -308,7 +309,7 @@ public void setPlayer(GlowPlayerProfile profile) { entries.add(other.getUserListEntry()); } } - send(new UserListItemMessage(Action.ADD_PLAYER, entries)); + send(new UserListItemMessage(Lists.newArrayList(Action.ADD_PLAYER), entries)); send(server.createAdvancementsMessage(false, Collections.emptyList(), player)); } @@ -320,9 +321,9 @@ public ChannelFuture sendWithFuture(Message message) { } // Useful for debugging packet sends // TODO: config option? - //Throwable trace = new Throwable(); - //return super.sendWithFuture(message).addListener(f -> GlowServer.logger.log(Level.INFO, "Message sent: " + message.toString() + " to " + this, trace)); - return super.sendWithFuture(message); + Throwable trace = new Throwable(); + return super.sendWithFuture(message).addListener(f -> GlowServer.logger.log(Level.INFO, "Message sent: " + message.toString() + " to " + this, trace)); + //return super.sendWithFuture(message); } /** diff --git a/src/main/java/net/glowstone/net/codec/play/game/UserListItemCodec.java b/src/main/java/net/glowstone/net/codec/play/game/UserListItemCodec.java index 8c239e978..35b2959e2 100644 --- a/src/main/java/net/glowstone/net/codec/play/game/UserListItemCodec.java +++ b/src/main/java/net/glowstone/net/codec/play/game/UserListItemCodec.java @@ -11,6 +11,8 @@ import net.glowstone.net.message.play.game.UserListItemMessage.Entry; import java.io.IOException; +import java.util.BitSet; +import java.util.Collections; import java.util.List; public final class UserListItemCodec implements Codec { @@ -22,72 +24,64 @@ public UserListItemMessage decode(ByteBuf buf) throws IOException { @Override public ByteBuf encode(ByteBuf buf, UserListItemMessage message) throws IOException { - Action action = message.getAction(); + List actions = message.getActions(); + //Sort list so actions are added to the buf in the correct order + Collections.sort(actions); List entries = message.getEntries(); - ByteBufUtils.writeVarInt(buf, message.getAction().ordinal()); + BitSet actionBitSet = new BitSet(6); + for (Action a : actions) { + actionBitSet.set(a.getBitFieldIndex(), true); + } + byte arr[] = actionBitSet.toByteArray(); + buf.writeByte(arr[0]); ByteBufUtils.writeVarInt(buf, entries.size()); for (Entry entry : entries) { GlowBufUtils.writeUuid(buf, entry.uuid); - // todo: implement the rest of the actions - switch (action) { - case ADD_PLAYER: - // this code is somewhat saddening - ByteBufUtils.writeUTF8(buf, entry.profile.getName()); - ByteBufUtils.writeVarInt(buf, entry.profile.getProperties().size()); - for (ProfileProperty property : entry.profile.getProperties()) { - ByteBufUtils.writeUTF8(buf, property.getName()); - ByteBufUtils.writeUTF8(buf, property.getValue()); - buf.writeBoolean(property.isSigned()); - if (property.isSigned()) { - ByteBufUtils.writeUTF8(buf, property.getSignature()); + for (Action a : actions) { + switch (a) { + case ADD_PLAYER: + // this code is somewhat saddening + ByteBufUtils.writeUTF8(buf, entry.profile.getName()); + ByteBufUtils.writeVarInt(buf, entry.profile.getProperties().size()); + for (ProfileProperty property : entry.profile.getProperties()) { + ByteBufUtils.writeUTF8(buf, property.getName()); + ByteBufUtils.writeUTF8(buf, property.getValue()); + buf.writeBoolean(property.isSigned()); + if (property.isSigned()) { + ByteBufUtils.writeUTF8(buf, property.getSignature()); + } } - } - ByteBufUtils.writeVarInt(buf, entry.gameMode); - ByteBufUtils.writeVarInt(buf, entry.ping); - if (entry.displayName != null) { - buf.writeBoolean(true); - GlowBufUtils.writeChat(buf, entry.displayName); - } else { - buf.writeBoolean(false); - } - if (entry.publicKey != null && entry.signature != null) { - buf.writeBoolean(true); - buf.writeLong(entry.timestamp); - ByteBufUtils.writeVarInt(buf, entry.publicKey.length); - buf.writeBytes(entry.publicKey); - ByteBufUtils.writeVarInt(buf, entry.signature.length); - buf.writeBytes(entry.signature); - } else { - buf.writeBoolean(false); - } - break; + break; - case UPDATE_GAMEMODE: - ByteBufUtils.writeVarInt(buf, entry.gameMode); - break; + case UPDATE_GAMEMODE: + ByteBufUtils.writeVarInt(buf, entry.gameMode); + break; - case UPDATE_LATENCY: - ByteBufUtils.writeVarInt(buf, entry.ping); - break; + case UPDATE_LATENCY: + ByteBufUtils.writeVarInt(buf, entry.ping); + break; - case UPDATE_DISPLAY_NAME: - if (entry.displayName != null) { - buf.writeBoolean(true); - GlowBufUtils.writeChat(buf, entry.displayName); - } else { - buf.writeBoolean(false); - } - break; + case UPDATE_DISPLAY_NAME: + if (entry.displayName != null) { + buf.writeBoolean(true); + GlowBufUtils.writeChat(buf, entry.displayName); + } else { + buf.writeBoolean(false); + } + break; - case REMOVE_PLAYER: - // nothing - break; + case REMOVE_PLAYER: + // nothing + break; - default: - throw new UnsupportedOperationException("not yet implemented: " + action); + default: + throw new UnsupportedOperationException("not yet implemented: " + a); + } } + // todo: implement the rest of the actions + } return buf; } diff --git a/src/main/java/net/glowstone/net/message/play/game/UserListItemMessage.java b/src/main/java/net/glowstone/net/message/play/game/UserListItemMessage.java index 9d9631fe2..6cf323252 100644 --- a/src/main/java/net/glowstone/net/message/play/game/UserListItemMessage.java +++ b/src/main/java/net/glowstone/net/message/play/game/UserListItemMessage.java @@ -1,6 +1,7 @@ package net.glowstone.net.message.play.game; import com.flowpowered.network.Message; +import com.google.common.collect.Lists; import lombok.AllArgsConstructor; import lombok.Data; import lombok.RequiredArgsConstructor; @@ -17,30 +18,28 @@ @Data public final class UserListItemMessage implements Message { - private final Action action; + private final List actions; private final List entries; /** * Creates an instance. * - * @param action the action code: 0 = add player; 1 = update gamemode; 2 = update latency; - * 3 = update display name; 4 = remove player + * @param actions List of actions in this message * @param entries the players to add, update or remove */ - public UserListItemMessage(Action action, List entries) { - this.action = action; + public UserListItemMessage(List actions, List entries) { + this.actions = actions; this.entries = entries; for (Entry entry : entries) { - if (entry.action != action) { - throw new IllegalArgumentException( - "Entries must be " + action + ", not " + entry.action); + if (!entry.actions.equals(actions)) { + throw new IllegalArgumentException("Entries do not match"); } } } - public UserListItemMessage(Action action, Entry entry) { - this(action, Arrays.asList(entry)); + public UserListItemMessage(List actions, Entry entry) { + this(actions, Arrays.asList(entry)); } // add @@ -62,61 +61,72 @@ public static Entry add(GlowPlayerProfile profile, int gameMode, int ping, TextMessage displayName) { // TODO: measure ping return new Entry(profile.getId(), profile, gameMode, ping, displayName, - Action.ADD_PLAYER); + Lists.newArrayList(Action.ADD_PLAYER)); } public static UserListItemMessage addOne(GlowPlayerProfile profile) { - return new UserListItemMessage(Action.ADD_PLAYER, add(profile)); + return new UserListItemMessage(Lists.newArrayList(Action.ADD_PLAYER), add(profile)); } // gamemode public static Entry gameMode(UUID uuid, int gameMode) { - return new Entry(uuid, null, gameMode, 0, null, Action.UPDATE_GAMEMODE); + return new Entry(uuid, null, gameMode, 0, null, Lists.newArrayList(Action.UPDATE_GAMEMODE)); } public static UserListItemMessage gameModeOne(UUID uuid, int gameMode) { - return new UserListItemMessage(Action.UPDATE_GAMEMODE, gameMode(uuid, gameMode)); + return new UserListItemMessage(Lists.newArrayList(Action.UPDATE_GAMEMODE), gameMode(uuid, gameMode)); } // latency public static Entry latency(UUID uuid, int ping) { - return new Entry(uuid, null, 0, ping, null, Action.UPDATE_LATENCY); + return new Entry(uuid, null, 0, ping, null, Lists.newArrayList(Action.UPDATE_LATENCY)); } public static UserListItemMessage latencyOne(UUID uuid, int ping) { - return new UserListItemMessage(Action.UPDATE_LATENCY, latency(uuid, ping)); + return new UserListItemMessage(Lists.newArrayList(Action.UPDATE_LATENCY), latency(uuid, ping)); } // display name public static Entry displayName(UUID uuid, TextMessage displayName) { - return new Entry(uuid, null, 0, 0, displayName, Action.UPDATE_DISPLAY_NAME); + return new Entry(uuid, null, 0, 0, displayName, Lists.newArrayList(Action.UPDATE_DISPLAY_NAME)); } public static UserListItemMessage displayNameOne(UUID uuid, TextMessage displayName) { - return new UserListItemMessage(Action.UPDATE_DISPLAY_NAME, displayName(uuid, displayName)); + return new UserListItemMessage(Lists.newArrayList(Action.UPDATE_DISPLAY_NAME), displayName(uuid, displayName)); } // remove public static Entry remove(UUID uuid) { - return new Entry(uuid, null, 0, 0, null, Action.REMOVE_PLAYER); + return new Entry(uuid, null, 0, 0, null, Lists.newArrayList(Action.REMOVE_PLAYER)); } public static UserListItemMessage removeOne(UUID uuid) { - return new UserListItemMessage(Action.REMOVE_PLAYER, remove(uuid)); + return new UserListItemMessage(Lists.newArrayList(Action.REMOVE_PLAYER), remove(uuid)); } // inner classes + /** + * The actions that can be performed in a user list update + * The bitFieldIndex field is the index of the action fla + */ public enum Action { - ADD_PLAYER, - UPDATE_GAMEMODE, - UPDATE_LATENCY, - UPDATE_DISPLAY_NAME, - REMOVE_PLAYER + ADD_PLAYER(0), + UPDATE_GAMEMODE(2), + REMOVE_PLAYER(3), + UPDATE_LATENCY(4), + UPDATE_DISPLAY_NAME(5); + private int bitFieldIndex; + private Action(int bitIndex) { + this.bitFieldIndex = bitIndex; + } + public int getBitFieldIndex() { + return bitFieldIndex; + } } @Data @@ -128,13 +138,13 @@ public static final class Entry { public final int gameMode; public final int ping; public final TextMessage displayName; - private final Action action; + private final List actions; public final long timestamp; public final byte[] publicKey; public final byte[] signature; - public Entry(UUID uuid, GlowPlayerProfile profile, int gameMode, int ping, TextMessage displayName, Action action) { - this(uuid, profile, gameMode, ping, displayName, action, 0, null, null); + public Entry(UUID uuid, GlowPlayerProfile profile, int gameMode, int ping, TextMessage displayName, List actions) { + this(uuid, profile, gameMode, ping, displayName, actions, 0, null, null); } } } From 1124f629de650fd9d43d27614e4a92083838b939 Mon Sep 17 00:00:00 2001 From: apion Date: Sat, 11 Feb 2023 12:06:06 -0500 Subject: [PATCH 09/15] Fixed issue with respawning --- .../java/net/glowstone/entity/GlowPlayer.java | 7 ++++-- .../java/net/glowstone/net/GlowBufUtils.java | 2 +- .../java/net/glowstone/net/GlowSession.java | 6 ++--- .../net/codec/play/game/RespawnCodec.java | 23 ++++++++++++++----- .../net/message/play/game/RespawnMessage.java | 13 ++++++++--- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/glowstone/entity/GlowPlayer.java b/src/main/java/net/glowstone/entity/GlowPlayer.java index feee71e5f..37181d6fc 100644 --- a/src/main/java/net/glowstone/entity/GlowPlayer.java +++ b/src/main/java/net/glowstone/entity/GlowPlayer.java @@ -1405,13 +1405,16 @@ private void spawnPlayerAt(Location location) { // spawn into world session.send(new RespawnMessage( - world.getName(), + NamespacedKey.fromString("minecraft:overworld"), + world.getKey(), world.getSeedHash(), getGameMode().getValue(), -1, false, world.getWorldType() == WorldType.FLAT, - oldWorld.getEnvironment() != world.getEnvironment() + oldWorld.getEnvironment() != world.getEnvironment(), + oldWorld.getKey(), + location )); setRawLocation(location, false); // take us to spawn position diff --git a/src/main/java/net/glowstone/net/GlowBufUtils.java b/src/main/java/net/glowstone/net/GlowBufUtils.java index 420467744..068633ffb 100644 --- a/src/main/java/net/glowstone/net/GlowBufUtils.java +++ b/src/main/java/net/glowstone/net/GlowBufUtils.java @@ -125,7 +125,7 @@ public static void writeMetadata(ByteBuf buf, List entries) throws IOExce int type = index.getType().getId(); int id = index.getIndex(); - System.out.println("Metadata: " + id + " " + type); + //System.out.println("Metadata: " + id + " " + type); buf.writeByte(id); ByteBufUtils.writeVarInt(buf, type); diff --git a/src/main/java/net/glowstone/net/GlowSession.java b/src/main/java/net/glowstone/net/GlowSession.java index b994ae532..977fe07f6 100644 --- a/src/main/java/net/glowstone/net/GlowSession.java +++ b/src/main/java/net/glowstone/net/GlowSession.java @@ -321,9 +321,9 @@ public ChannelFuture sendWithFuture(Message message) { } // Useful for debugging packet sends // TODO: config option? - Throwable trace = new Throwable(); - return super.sendWithFuture(message).addListener(f -> GlowServer.logger.log(Level.INFO, "Message sent: " + message.toString() + " to " + this, trace)); - //return super.sendWithFuture(message); + //Throwable trace = new Throwable(); + //return super.sendWithFuture(message).addListener(f -> GlowServer.logger.log(Level.INFO, "Message sent: " + message.toString() + " to " + this, trace)); + return super.sendWithFuture(message); } /** diff --git a/src/main/java/net/glowstone/net/codec/play/game/RespawnCodec.java b/src/main/java/net/glowstone/net/codec/play/game/RespawnCodec.java index 83b6bd394..386e212fa 100644 --- a/src/main/java/net/glowstone/net/codec/play/game/RespawnCodec.java +++ b/src/main/java/net/glowstone/net/codec/play/game/RespawnCodec.java @@ -2,9 +2,13 @@ import com.flowpowered.network.Codec; import io.netty.buffer.ByteBuf; +import net.glowstone.net.GlowBufUtils; import net.glowstone.net.message.play.game.RespawnMessage; +import net.glowstone.util.Position; import net.glowstone.util.nbt.CompoundTag; +import org.bukkit.Location; +import javax.naming.OperationNotSupportedException; import java.io.IOException; import static com.flowpowered.network.util.ByteBufUtils.readUTF8; @@ -16,6 +20,8 @@ public final class RespawnCodec implements Codec { @Override public RespawnMessage decode(ByteBuf buf) throws IOException { + throw new RuntimeException("Decoding RespawnMessages Unsupported"); + /** CompoundTag dimension = readCompound(buf); String world = readUTF8(buf); byte[] seedHash = new byte[8]; @@ -26,20 +32,25 @@ public RespawnMessage decode(ByteBuf buf) throws IOException { boolean flat = buf.readBoolean(); boolean copyMetadata = buf.readBoolean(); return new RespawnMessage(world, seedHash, mode, previousMode, debug, flat, copyMetadata); + **/ } @Override public ByteBuf encode(ByteBuf buf, RespawnMessage message) throws IOException { - // TODO: Encode dimension data (1.15+) - CompoundTag dimension = new CompoundTag(); - writeCompound(buf, dimension); - writeUTF8(buf, message.getWorld()); + GlowBufUtils.writeNamespacedKey(buf, message.getDimName()); + GlowBufUtils.writeNamespacedKey(buf, message.getDimType()); buf.writeBytes(message.getSeedHash(), 0, 8); - buf.writeByte(message.getMode()); - buf.writeByte(message.getPreviousMode()); + buf.writeByte(message.getGamemode()); + buf.writeByte(message.getPreviousGamemode()); buf.writeBoolean(message.isDebug()); buf.writeBoolean(message.isFlat()); buf.writeBoolean(message.isCopyMetadata()); + boolean writeDeathInfo = message.getDeathDimName() != null; + buf.writeBoolean(writeDeathInfo); + if (writeDeathInfo) { + GlowBufUtils.writeNamespacedKey(buf, message.getDimType()); + GlowBufUtils.writeBlockPosition(buf, message.getDeathPosition().toVector()); + } return buf; } } diff --git a/src/main/java/net/glowstone/net/message/play/game/RespawnMessage.java b/src/main/java/net/glowstone/net/message/play/game/RespawnMessage.java index 8e631310f..d81aaaaba 100644 --- a/src/main/java/net/glowstone/net/message/play/game/RespawnMessage.java +++ b/src/main/java/net/glowstone/net/message/play/game/RespawnMessage.java @@ -1,18 +1,25 @@ package net.glowstone.net.message.play.game; import com.flowpowered.network.Message; +import io.papermc.paper.math.Position; import lombok.Data; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.util.Vector; @Data public final class RespawnMessage implements Message { // TODO: Dimension (NBT compound) - private final String world; + private final NamespacedKey dimType; + private final NamespacedKey dimName; private final byte[] seedHash; - private final int mode; - private final int previousMode; + private final int gamemode; + private final int previousGamemode; private final boolean debug; private final boolean flat; private final boolean copyMetadata; + private final NamespacedKey deathDimName; + private final Location deathPosition; } From d3050c22cfcd56f221fde59916696fd14046da02 Mon Sep 17 00:00:00 2001 From: apion Date: Sat, 11 Feb 2023 23:30:44 -0500 Subject: [PATCH 10/15] Implemented upstream API changes and implemented PlayerSessionMessage --- .../java/net/glowstone/entity/GlowPlayer.java | 8 +++++ .../entity/passive/GlowFirework.java | 15 ++++++++++ .../entity/projectile/GlowProjectile.java | 16 ++++++++++ .../codec/play/player/PlayerSessionCodec.java | 29 +++++++++++++++++++ .../play/player/PlayerSessionHandler.java | 12 ++++++++ .../play/player/PlayerSessionMessage.java | 15 ++++++++++ .../glowstone/net/protocol/PlayProtocol.java | 5 +++- 7 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/glowstone/net/codec/play/player/PlayerSessionCodec.java create mode 100644 src/main/java/net/glowstone/net/handler/play/player/PlayerSessionHandler.java create mode 100644 src/main/java/net/glowstone/net/message/play/player/PlayerSessionMessage.java diff --git a/src/main/java/net/glowstone/entity/GlowPlayer.java b/src/main/java/net/glowstone/entity/GlowPlayer.java index 37181d6fc..61a543890 100644 --- a/src/main/java/net/glowstone/entity/GlowPlayer.java +++ b/src/main/java/net/glowstone/entity/GlowPlayer.java @@ -4487,5 +4487,13 @@ public void setFrictionState(@NotNull TriState state) { return null; } + @Override + public boolean hasSeenWinScreen() { + return false; + } + @Override + public void setHasSeenWinScreen(boolean hasSeenWinScreen) { + + } } diff --git a/src/main/java/net/glowstone/entity/passive/GlowFirework.java b/src/main/java/net/glowstone/entity/passive/GlowFirework.java index bfb0f4a83..28cf7fa4c 100644 --- a/src/main/java/net/glowstone/entity/passive/GlowFirework.java +++ b/src/main/java/net/glowstone/entity/passive/GlowFirework.java @@ -356,4 +356,19 @@ public boolean hasBeenShot() { public void setHasBeenShot(boolean beenShot) { } + + @Override + public boolean canHitEntity(@NotNull Entity entity) { + return false; + } + + @Override + public void hitEntity(@NotNull Entity entity) { + + } + + @Override + public void hitEntity(@NotNull Entity entity, @NotNull Vector vector) { + + } } diff --git a/src/main/java/net/glowstone/entity/projectile/GlowProjectile.java b/src/main/java/net/glowstone/entity/projectile/GlowProjectile.java index 73361ce67..36fa7559d 100644 --- a/src/main/java/net/glowstone/entity/projectile/GlowProjectile.java +++ b/src/main/java/net/glowstone/entity/projectile/GlowProjectile.java @@ -18,6 +18,7 @@ import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.List; @@ -140,4 +141,19 @@ public boolean doesBounce() { public void setBounce(boolean doesBounce) { // deprecated, does not do anything } + + @Override + public void hitEntity(@NotNull Entity entity, @NotNull Vector vector) { + //TODO: implement + } + + @Override + public boolean canHitEntity(@NotNull Entity entity) { + return false; + } + + @Override + public void hitEntity(@NotNull Entity entity) { + + } } diff --git a/src/main/java/net/glowstone/net/codec/play/player/PlayerSessionCodec.java b/src/main/java/net/glowstone/net/codec/play/player/PlayerSessionCodec.java new file mode 100644 index 000000000..fd0337b2a --- /dev/null +++ b/src/main/java/net/glowstone/net/codec/play/player/PlayerSessionCodec.java @@ -0,0 +1,29 @@ +package net.glowstone.net.codec.play.player; + +import com.flowpowered.network.Codec; +import com.flowpowered.network.util.ByteBufUtils; +import io.netty.buffer.ByteBuf; +import net.glowstone.net.GlowBufUtils; +import net.glowstone.net.message.play.player.PlayerSessionMessage; + +import java.io.IOException; +import java.util.UUID; + +public final class PlayerSessionCodec implements Codec { + @Override + public PlayerSessionMessage decode(ByteBuf byteBuf) throws IOException { + UUID uuid = GlowBufUtils.readUuid(byteBuf); + long expires = byteBuf.readLong(); + int pubKeyLen = ByteBufUtils.readVarInt(byteBuf); + ByteBuf pubKey = byteBuf.readBytes(pubKeyLen); + + int pubKeySigLen = ByteBufUtils.readVarInt(byteBuf); + ByteBuf pubKeySig = byteBuf.readBytes(pubKeySigLen); + return new PlayerSessionMessage(uuid, expires, pubKey, pubKeySig); + } + + @Override + public ByteBuf encode(ByteBuf byteBuf, PlayerSessionMessage playerSessionMessage) throws IOException { + throw new RuntimeException("Can't encode PlayerSessionMessage"); + } +} diff --git a/src/main/java/net/glowstone/net/handler/play/player/PlayerSessionHandler.java b/src/main/java/net/glowstone/net/handler/play/player/PlayerSessionHandler.java new file mode 100644 index 000000000..ca7eab58a --- /dev/null +++ b/src/main/java/net/glowstone/net/handler/play/player/PlayerSessionHandler.java @@ -0,0 +1,12 @@ +package net.glowstone.net.handler.play.player; + +import com.flowpowered.network.MessageHandler; +import net.glowstone.net.GlowSession; +import net.glowstone.net.message.play.player.PlayerSessionMessage; + +public final class PlayerSessionHandler implements MessageHandler { + @Override + public void handle(GlowSession glowSession, PlayerSessionMessage playerSessionMessage) { + //TODO: Handle + } +} diff --git a/src/main/java/net/glowstone/net/message/play/player/PlayerSessionMessage.java b/src/main/java/net/glowstone/net/message/play/player/PlayerSessionMessage.java new file mode 100644 index 000000000..3e9572f79 --- /dev/null +++ b/src/main/java/net/glowstone/net/message/play/player/PlayerSessionMessage.java @@ -0,0 +1,15 @@ +package net.glowstone.net.message.play.player; + +import com.flowpowered.network.Message; +import io.netty.buffer.ByteBuf; +import lombok.Data; + +import java.util.UUID; + +@Data +public final class PlayerSessionMessage implements Message { + private final UUID sessionId; + private final long expiresAt; + private final ByteBuf pubKey; + private final ByteBuf keySig; +} diff --git a/src/main/java/net/glowstone/net/protocol/PlayProtocol.java b/src/main/java/net/glowstone/net/protocol/PlayProtocol.java index 506309148..b0adeb599 100644 --- a/src/main/java/net/glowstone/net/protocol/PlayProtocol.java +++ b/src/main/java/net/glowstone/net/protocol/PlayProtocol.java @@ -46,6 +46,7 @@ import net.glowstone.net.codec.play.player.PlayerLookCodec; import net.glowstone.net.codec.play.player.PlayerPositionCodec; import net.glowstone.net.codec.play.player.PlayerPositionLookCodec; +import net.glowstone.net.codec.play.player.PlayerSessionCodec; import net.glowstone.net.codec.play.player.PlayerSwingArmCodec; import net.glowstone.net.codec.play.player.PlayerUpdateCodec; import net.glowstone.net.codec.play.player.ResourcePackSendCodec; @@ -86,6 +87,7 @@ import net.glowstone.net.handler.play.player.InteractEntityHandler; import net.glowstone.net.handler.play.player.PlayerAbilitiesHandler; import net.glowstone.net.handler.play.player.PlayerActionHandler; +import net.glowstone.net.handler.play.player.PlayerSessionHandler; import net.glowstone.net.handler.play.player.PlayerSwingArmHandler; import net.glowstone.net.handler.play.player.PlayerUpdateHandler; import net.glowstone.net.handler.play.player.ResourcePackStatusHandler; @@ -141,6 +143,7 @@ import net.glowstone.net.message.play.player.PlayerLookMessage; import net.glowstone.net.message.play.player.PlayerPositionLookMessage; import net.glowstone.net.message.play.player.PlayerPositionMessage; +import net.glowstone.net.message.play.player.PlayerSessionMessage; import net.glowstone.net.message.play.player.PlayerSwingArmMessage; import net.glowstone.net.message.play.player.PlayerUpdateMessage; import net.glowstone.net.message.play.player.ResourcePackSendMessage; @@ -218,7 +221,7 @@ public PlayProtocol() { inbound(0x1E, SteerVehicleMessage.class, SteerVehicleCodec.class, SteerVehicleHandler.class); // TODO 0x1F : Pong - // TODO 0x20 : PlayerSession + inbound(0x20, PlayerSessionMessage.class, PlayerSessionCodec.class, PlayerSessionHandler.class); inbound(0x21, RecipeBookStateMessage.class, RecipeBookStateCodec.class, RecipeBookStateHandler.class); inbound(0x22, DisplayedRecipeMessage.class, DisplayedRecipeCodec.class, DisplayedRecipeHandler.class); From b22ad09b9f39b6193eeb89cb98f3fb93a6464d85 Mon Sep 17 00:00:00 2001 From: apion Date: Sun, 12 Feb 2023 03:04:00 -0500 Subject: [PATCH 11/15] Changed order that messages are sent to client on join to reflect wiki.vg's order. This included sending the player's initial position twice --- src/main/java/net/glowstone/EventFactory.java | 2 +- .../java/net/glowstone/entity/GlowPlayer.java | 67 ++++++++++--------- .../java/net/glowstone/net/GlowBufUtils.java | 1 - .../glowstone/net/protocol/PlayProtocol.java | 2 +- 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/main/java/net/glowstone/EventFactory.java b/src/main/java/net/glowstone/EventFactory.java index f695d5ea6..cd842f272 100644 --- a/src/main/java/net/glowstone/EventFactory.java +++ b/src/main/java/net/glowstone/EventFactory.java @@ -196,7 +196,7 @@ public PlayerJoinEvent onPlayerJoin(Player player) { } public PlayerKickEvent onPlayerKick(Player player, String reason) { - return callEvent(new PlayerKickEvent(player, reason, null)); + return callEvent(new PlayerKickEvent(player, reason, "")); } public PlayerQuitEvent onPlayerQuit(Player player) { diff --git a/src/main/java/net/glowstone/entity/GlowPlayer.java b/src/main/java/net/glowstone/entity/GlowPlayer.java index 61a543890..c2b132454 100644 --- a/src/main/java/net/glowstone/entity/GlowPlayer.java +++ b/src/main/java/net/glowstone/entity/GlowPlayer.java @@ -606,7 +606,6 @@ public GlowPlayer(GlowSession session, GlowPlayerProfile profile, PlayerReader r invMonitor = new InventoryMonitor(getOpenInventory()); server.getPlayerStatisticIoService().readStatistics(this); recipeMonitor = new PlayerRecipeMonitor(this); - updateBossBars(); } @@ -870,6 +869,9 @@ public void join(GlowSession session, PlayerReader reader) { world.getWorldType() == WorldType.FLAT, null )); + joinTime = System.currentTimeMillis(); + // Add player to list of online players + getServer().setPlayerOnline(this, true); // send server brand and supported plugin channels Message pluginMessage = PluginMessage.fromString("minecraft:brand", server.getName()); @@ -877,53 +879,46 @@ public void join(GlowSession session, PlayerReader reader) { session.send(pluginMessage); } sendSupportedChannels(); - joinTime = System.currentTimeMillis(); - // Add player to list of online players - getServer().setPlayerOnline(this, true); + getServer().sendPlayerAbilities(this); + // send held item + getSession().send(new HeldItemMessage(getInventory().getHeldItemSlot())); + //TODO: Update recipes and tags + //TODO: Send OP perm level + //TODO: Send commands + session.send(recipeMonitor.createInitMessage()); + // send initial location + session.send(new PositionRotationMessage(location)); + //TODO: Set center chunk + //TODO: Update light + streamBlocks(); // stream the initial set of blocks + session.send(world.getWorldBorder().createMessage()); + setCompassTarget(world.getSpawnLocation()); + //Tell client they can now load in + session.send(new PositionRotationMessage(location)); // save data back out saveData(); - streamBlocks(); // stream the initial set of blocks + //Send client all current world info + session.send(new EntityVelocityMessage(getEntityId(), velocity)); sendWeather(); sendRainDensity(); sendSkyDarkness(); - getServer().sendPlayerAbilities(this); - int count = 0; - - // send initial location - session.send(new PositionRotationMessage(location)); - - // send initial velocity - session.send(new EntityVelocityMessage(getEntityId(), velocity)); - - // send initial health sendHealth(); - - // send gamemode defaults setGameModeDefaults(); - - // send held item - getSession().send(new HeldItemMessage(getInventory().getHeldItemSlot())); - - // send xp bar sendExperience(); - - session.send(world.getWorldBorder().createMessage()); sendTime(); - setCompassTarget(world.getSpawnLocation()); // set our compass target + // set our compass target + invMonitor = new InventoryMonitor(getOpenInventory()); + updateInventory(); // send inventory contents //scoreboard = server.getScoreboardManager().getMainScoreboard(); //scoreboard.subscribe(this); -// invMonitor = new InventoryMonitor(getOpenInventory()); -// updateInventory(); // send inventory contents -// session.send(recipeMonitor.createInitMessage()); - - if (!server.getResourcePackUrl().isEmpty()) { +// if (!server.getResourcePackUrl().isEmpty()) { // setResourcePack(server.getResourcePackUrl(), server.getResourcePackHash()); - } +// } } @Override @@ -1417,7 +1412,8 @@ private void spawnPlayerAt(Location location) { location )); - setRawLocation(location, false); // take us to spawn position + // take us to spawn position + setRawLocation(location, false); session.send(new PositionRotationMessage(location)); teleportedTo = location.clone(); setCompassTarget(world.getSpawnLocation()); // set our compass target @@ -2948,6 +2944,9 @@ public void saveData() { * @param async if true, save asynchronously; if false, block until saved */ public void saveData(boolean async) { + if (this.location.getBlockX() != -94){ + return; + } if (async) { Bukkit.getScheduler().runTaskAsynchronously(null, () -> { server.getPlayerDataService().writeData(GlowPlayer.this); @@ -4496,4 +4495,8 @@ public boolean hasSeenWinScreen() { public void setHasSeenWinScreen(boolean hasSeenWinScreen) { } + + public void savePlayerData() { + world.getStorage().getPlayerDataService().writeData(this); + } } diff --git a/src/main/java/net/glowstone/net/GlowBufUtils.java b/src/main/java/net/glowstone/net/GlowBufUtils.java index 068633ffb..3eff50007 100644 --- a/src/main/java/net/glowstone/net/GlowBufUtils.java +++ b/src/main/java/net/glowstone/net/GlowBufUtils.java @@ -139,7 +139,6 @@ public static void writeMetadata(ByteBuf buf, List entries) throws IOExce continue; } } - writeValue(buf, value, index.getType()); } diff --git a/src/main/java/net/glowstone/net/protocol/PlayProtocol.java b/src/main/java/net/glowstone/net/protocol/PlayProtocol.java index b0adeb599..67225b28a 100644 --- a/src/main/java/net/glowstone/net/protocol/PlayProtocol.java +++ b/src/main/java/net/glowstone/net/protocol/PlayProtocol.java @@ -329,8 +329,8 @@ public PlayProtocol() { outbound(0x49, HeldItemMessage.class, HeldItemCodec.class); // TODO 0x4A Set Center Chunk // TODO 0x4B Set Render Distance - outbound(0x4C, SpawnPositionMessage.class, SpawnPositionCodec.class); // TODO 0x4B : Set Display Chat Preview + outbound(0x4C, SpawnPositionMessage.class, SpawnPositionCodec.class); outbound(0x4D, ScoreboardDisplayMessage.class, ScoreboardDisplayCodec.class); outbound(0x4E, EntityMetadataMessage.class, EntityMetadataCodec.class); outbound(0x4F, AttachEntityMessage.class, AttachEntityCodec.class); From f664971123e5d1d55c8192519d371fcaa21232b1 Mon Sep 17 00:00:00 2001 From: apion Date: Sun, 12 Feb 2023 04:22:42 -0500 Subject: [PATCH 12/15] Send empty sections --- .../net/glowstone/chunk/ChunkManager.java | 3 ++ .../net/glowstone/chunk/ChunkSection.java | 44 ++++++++++++------- .../java/net/glowstone/entity/GlowPlayer.java | 3 -- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/glowstone/chunk/ChunkManager.java b/src/main/java/net/glowstone/chunk/ChunkManager.java index 09caf5ebe..15beae2c3 100644 --- a/src/main/java/net/glowstone/chunk/ChunkManager.java +++ b/src/main/java/net/glowstone/chunk/ChunkManager.java @@ -321,6 +321,9 @@ private void generateChunk(GlowChunk chunk, int x, int z) { if (extSections[i] != null) { sections[i] = ChunkSection.fromStateArray(extSections[i]); } + else { + sections[i] = ChunkSection.initNewEmptySection(); + } } chunk.initializeSections(sections); chunk.setBiomes(biomes.biomes); diff --git a/src/main/java/net/glowstone/chunk/ChunkSection.java b/src/main/java/net/glowstone/chunk/ChunkSection.java index 33f595269..dfe32c2f0 100644 --- a/src/main/java/net/glowstone/chunk/ChunkSection.java +++ b/src/main/java/net/glowstone/chunk/ChunkSection.java @@ -52,6 +52,7 @@ public final class ChunkSection { */ @Nullable private IntList palette; + private VariableValueArray data; /** * The sky light array. This array is always set, even in dimensions without skylight. @@ -177,6 +178,12 @@ public static ChunkSection fromStateArray(int[] types) { return new ChunkSection(types); } + public static ChunkSection initNewEmptySection() { + ChunkSection result = new ChunkSection(); + result.count = 0; + return result; + } + /** * Loads the contents of this chunk section from the given type array, initializing the * palette. @@ -437,26 +444,31 @@ public boolean isEmpty() { */ public void writeToBuf(ByteBuf buf, boolean skylight) throws IllegalStateException { if (this.isEmpty()) { - throw new IllegalStateException("Can't write empty sections"); + buf.writeShort(0); + buf.writeByte(0); + ByteBufUtils.writeVarInt(buf, 0); } - buf.writeShort(count); - buf.writeByte(data.getBitsPerValue()); // Bit per value -> varies - if (palette != null) { - ByteBufUtils.writeVarInt(buf, palette.size()); // Palette size - // Foreach loops can't be used due to autoboxing - IntListIterator itr = palette.iterator(); - while (itr.hasNext()) { - ByteBufUtils.writeVarInt(buf, itr.nextInt()); // The palette entry + else { + buf.writeShort(count); + buf.writeByte(data.getBitsPerValue()); // Bit per value -> varies + if (palette != null) { + ByteBufUtils.writeVarInt(buf, palette.size()); // Palette size + // Foreach loops can't be used due to autoboxing + IntListIterator itr = palette.iterator(); + while (itr.hasNext()) { + ByteBufUtils.writeVarInt(buf, itr.nextInt()); // The palette entry + } + } + long[] backing = data.getBacking(); + ByteBufUtils.writeVarInt(buf, backing.length); + buf.ensureWritable((backing.length << 3) + blockLight.byteSize() + (skylight ? skyLight + .byteSize() : 0)); + for (long value : backing) { + buf.writeLong(value); } - } - long[] backing = data.getBacking(); - ByteBufUtils.writeVarInt(buf, backing.length); - buf.ensureWritable((backing.length << 3) + blockLight.byteSize() + (skylight ? skyLight - .byteSize() : 0)); - for (long value : backing) { - buf.writeLong(value); } + // Biome palette, hardcoded for now buf.writeByte(0); ByteBufUtils.writeVarInt(buf, 0); ByteBufUtils.writeVarInt(buf, 0); diff --git a/src/main/java/net/glowstone/entity/GlowPlayer.java b/src/main/java/net/glowstone/entity/GlowPlayer.java index c2b132454..af4494901 100644 --- a/src/main/java/net/glowstone/entity/GlowPlayer.java +++ b/src/main/java/net/glowstone/entity/GlowPlayer.java @@ -2944,9 +2944,6 @@ public void saveData() { * @param async if true, save asynchronously; if false, block until saved */ public void saveData(boolean async) { - if (this.location.getBlockX() != -94){ - return; - } if (async) { Bukkit.getScheduler().runTaskAsynchronously(null, () -> { server.getPlayerDataService().writeData(GlowPlayer.this); From 2de18a3c896032675ca4f324d393ef84a66ee2dc Mon Sep 17 00:00:00 2001 From: ApionXD Date: Sun, 12 Feb 2023 10:56:38 -0500 Subject: [PATCH 13/15] Fixed bug where player would constantly suffocate when spawning in --- .../net/glowstone/chunk/ChunkManager.java | 27 +++++++--- .../net/glowstone/chunk/ChunkSection.java | 1 + .../net/glowstone/chunk/DimensionTypes.java | 54 +++++++++++++++++++ .../java/net/glowstone/chunk/GlowChunk.java | 11 ++-- .../glowstone/util/config/WorldConfig.java | 2 +- 5 files changed, 85 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/glowstone/chunk/ChunkManager.java b/src/main/java/net/glowstone/chunk/ChunkManager.java index 15beae2c3..6b06b1f20 100644 --- a/src/main/java/net/glowstone/chunk/ChunkManager.java +++ b/src/main/java/net/glowstone/chunk/ChunkManager.java @@ -315,16 +315,31 @@ private void generateChunk(GlowChunk chunk, int x, int z) { if (glowChunkData != null) { int[][] extSections = glowChunkData.getSections(); + DimensionType dimensionType = DimensionTypes.getByEnvironmentId(world.getEnvironment().getId()); + int numSections = dimensionType.getLogicalHeight() / GlowChunk.SEC_DEPTH; + ChunkSection[] sections = new ChunkSection[numSections]; if (extSections != null) { - ChunkSection[] sections = new ChunkSection[extSections.length]; - for (int i = 0; i < extSections.length; ++i) { - if (extSections[i] != null) { - sections[i] = ChunkSection.fromStateArray(extSections[i]); - } - else { + if (DimensionTypes.OVERWORLD.equals(dimensionType)) { + for (int i = 0; i < 4; i++) { sections[i] = ChunkSection.initNewEmptySection(); } + for (int i = 0; i < extSections.length; i++) { + if (extSections[i] != null) { + sections[i+4] = ChunkSection.fromStateArray(extSections[i]); + } + } + } + else { + for (int i = 0; i < extSections.length; ++i) { + if (extSections[i] != null) { + sections[i] = ChunkSection.fromStateArray(extSections[i]); + } + else { + sections[i] = ChunkSection.initNewEmptySection(); + } + } } + chunk.initializeSections(sections); chunk.setBiomes(biomes.biomes); chunk.automaticHeightMap(); diff --git a/src/main/java/net/glowstone/chunk/ChunkSection.java b/src/main/java/net/glowstone/chunk/ChunkSection.java index dfe32c2f0..eaeb53845 100644 --- a/src/main/java/net/glowstone/chunk/ChunkSection.java +++ b/src/main/java/net/glowstone/chunk/ChunkSection.java @@ -447,6 +447,7 @@ public void writeToBuf(ByteBuf buf, boolean skylight) throws IllegalStateExcepti buf.writeShort(0); buf.writeByte(0); ByteBufUtils.writeVarInt(buf, 0); + ByteBufUtils.writeVarInt(buf, 0); } else { buf.writeShort(count); diff --git a/src/main/java/net/glowstone/chunk/DimensionTypes.java b/src/main/java/net/glowstone/chunk/DimensionTypes.java index 2ed2ddd2f..3e05933c5 100644 --- a/src/main/java/net/glowstone/chunk/DimensionTypes.java +++ b/src/main/java/net/glowstone/chunk/DimensionTypes.java @@ -28,4 +28,58 @@ public class DimensionTypes { false ); + public static final DimensionType NETHER = new DimensionType( + true, + false, + 15, + 0, + false, + 0.1f, + OptionalLong.of(18000L), + Optional.of(NamespacedKey.minecraft("infiniburn_nether")), + true, + false, + false, + NamespacedKey.minecraft("the_nether"), + 0, + 256, + 256, + 8.0D, + true, + true + ); + + public static final DimensionType THE_END = new DimensionType( + false, + true, + 15, + 0, + false, + 0.0f, + OptionalLong.of(600L), + Optional.of(NamespacedKey.minecraft("infiniburn_end")), + false, + false, + false, + NamespacedKey.minecraft("the_end"), + 0, + 256, + 256, + 1.0D, + false, + false + ); + + public static DimensionType getByEnvironmentId(int id) { + switch (id) { + case 0: + return OVERWORLD; + case -1: + return NETHER; + case 1: + return THE_END; + default: + throw new IllegalStateException("Dimension id " + id + " does not match a dimension type"); + } + } } diff --git a/src/main/java/net/glowstone/chunk/GlowChunk.java b/src/main/java/net/glowstone/chunk/GlowChunk.java index dcc355bed..f89cfec69 100644 --- a/src/main/java/net/glowstone/chunk/GlowChunk.java +++ b/src/main/java/net/glowstone/chunk/GlowChunk.java @@ -361,7 +361,7 @@ public void initializeSections(ChunkSection[] initSections) { new Throwable()); return; } - if (initSections.length != SEC_COUNT) { + if (initSections.length != 16 && initSections.length != 24) { GlowServer.logger.log(Level.WARNING, "Got an unexpected section length - wanted " + SEC_COUNT + ", but length was " + initSections.length, @@ -369,11 +369,11 @@ public void initializeSections(ChunkSection[] initSections) { } //GlowServer.logger.log(Level.INFO, "Initializing chunk ({0},{1})", new Object[]{x, z}); - sections = new ChunkSection[SEC_COUNT]; + sections = new ChunkSection[initSections.length]; biomes = new byte[WIDTH * HEIGHT]; heightMap = new byte[WIDTH * HEIGHT]; - for (int y = 0; y < SEC_COUNT && y < initSections.length; y++) { + for (int y = 0; y < initSections.length; y++) { if (initSections[y] != null) { initializeSection(y, initSections[y]); } @@ -527,6 +527,11 @@ public BlockEntity createEntity(int cx, int cy, int cz, Material type) { * @return The ChunkSection, or null if it is empty. */ private ChunkSection getSection(int y) { + DimensionType dimensionType = DimensionTypes.getByEnvironmentId(this.getWorld().getEnvironment().getId()); + if (dimensionType.equals(DimensionTypes.OVERWORLD)) { + //Offset y by 64 since our 0th section is at y = -64 + y+=64; + } int idx = y >> 4; if (y < 0 || y >= DEPTH || !load() || idx >= sections.length) { return null; diff --git a/src/main/java/net/glowstone/util/config/WorldConfig.java b/src/main/java/net/glowstone/util/config/WorldConfig.java index 451c835aa..c86cd0f4f 100644 --- a/src/main/java/net/glowstone/util/config/WorldConfig.java +++ b/src/main/java/net/glowstone/util/config/WorldConfig.java @@ -197,7 +197,7 @@ private void report(File file, InvalidConfigurationException e) { */ public enum Key { // World - SEA_LEVEL("general.sea_level", 64), + SEA_LEVEL("general.sea_level", 52), // Overworld generator OVERWORLD_COORDINATE_SCALE("overworld.coordinate-scale", 684.412), OVERWORLD_HEIGHT_SCALE("overworld.height.scale", 684.412), From b5b512c64914450dde6404d13ad7eee46bed5274 Mon Sep 17 00:00:00 2001 From: ApionXD Date: Mon, 13 Feb 2023 15:14:53 -0500 Subject: [PATCH 14/15] Rolled back dumb gradle changes, re-added github workflows --- .github/workflows/ci.yml | 43 +++++ .github/workflows/dev.yml | 102 ++++++++++ build.gradle | 97 ---------- build.gradle.kts | 247 +++++++++++++++++++++++++ gradle.properties | 2 +- gradle/libs.versions.toml | 64 +++++++ settings.gradle => settings.gradle.kts | 0 7 files changed, 457 insertions(+), 98 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/dev.yml delete mode 100644 build.gradle create mode 100644 build.gradle.kts create mode 100644 gradle/libs.versions.toml rename settings.gradle => settings.gradle.kts (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..e0badef93 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,43 @@ +name: CI + +on: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + java: [ 17 ] + name: CI (Java ${{ matrix.java }}) + + steps: + - uses: actions/checkout@v3 + - uses: gradle/wrapper-validation-action@v1 + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: ${{ matrix.java }} + + - name: Cache gradle + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/jdks + ~/.gradle/native + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', 'gradle/libs.versions.toml') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Gradle Build + run: BUILD_EXTRAS=true ./gradlew assemble --no-daemon --stacktrace + + - name: Cleanup Gradle Cache + # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. + # Restoring these files from a GitHub Actions cache might cause problems for future builds. + run: | + rm -f ~/.gradle/caches/modules-2/modules-2.lock + rm -f ~/.gradle/caches/modules-2/gc.properties diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 000000000..56c26ef27 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,102 @@ +name: Dev Build + +on: + push: + branches: [dev, '1.12'] + paths: + - .github/workflows/** + - etc/checkstyle.xml + - src/** + - gradle/** + - gradle.properties + - '**/*.gradle*' + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + java: [ 17 ] + name: Dev Build (Java ${{ matrix.java }}) + + steps: + - uses: actions/checkout@v3 + - uses: gradle/wrapper-validation-action@v1 + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: ${{ matrix.java }} + + - name: Cache gradle + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/jdks + ~/.gradle/native + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', 'gradle/libs.versions.toml') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Gradle Build and Deploy + run: BUILD_EXTRAS=true ./gradlew assemble publish --no-daemon --stacktrace + env: + ORG_GRADLE_PROJECT_glowstoneUsername: ${{ secrets.MAVEN_USERNAME }} + ORG_GRADLE_PROJECT_glowstonePassword: ${{ secrets.MAVEN_PASSWORD }} + + - name: Get Minecraft version + id: version + run: | + minecraft_version=$(./gradlew -q printMinecraftVersion) + echo "::set-output name=minecraft_version::$minecraft_version" + + - name: Cleanup Gradle Cache + # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. + # Restoring these files from a GitHub Actions cache might cause problems for future builds. + run: | + rm -f ~/.gradle/caches/modules-2/modules-2.lock + rm -f ~/.gradle/caches/modules-2/gc.properties + + - name: Push Javadocs to Pages + uses: dmnemec/copy_file_to_another_repo_action@v1.1.1 + env: + API_TOKEN_GITHUB: ${{ secrets.GH_TOKEN }} + with: + source_file: 'build/docs/javadoc/.' + destination_repo: 'GlowstoneMC/glowstonemc.github.io' + destination_folder: content/jd/glowstone/${{ steps.version.outputs.minecraft_version }}/ + user_email: 'mastercoms@tuta.io' + user_name: 'mastercoms' + commit_message: Update Javadocs for Glowstone commit ${{ github.sha }} + + - name: GitHub Artifact + uses: actions/upload-artifact@v3 + with: + name: glowstone + path: build/libs/glowstone.jar + + - name: Setup SSH + if: ${{ github.ref == 'refs/heads/1.12' }} + run: | + mkdir -p ~/.ssh + cat << EOF > ~/.ssh/config + Host * + ControlMaster auto + ControlPath ~/.ssh/-%r@%h:%p + ControlPersist 120 + EOF + echo $SSH_KNOWN_HOSTS >> ~/.ssh/known_hosts + sudo apt-get install sshpass + env: + SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }} + + - name: Deploy to Test Server + if: ${{ github.ref == 'refs/heads/1.12' }} + run: | + sshpass -e scp target/glowstone.jar glowstone@$SSH_ADDRESS: + sshpass -e ssh glowstone@$SSH_ADDRESS sudo systemctl restart glowstone + env: + SSH_ADDRESS: ${{ secrets.SSH_ADDRESS }} + SSHPASS: ${{ secrets.SSH_PASSWORD }} diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 6bf55a62a..000000000 --- a/build.gradle +++ /dev/null @@ -1,97 +0,0 @@ -plugins { - id('java') - id('application') - id('maven-publish') - id('checkstyle') - id('jacoco') - - id("io.freefair.lombok") version "6.5.0-rc1" - id("com.github.johnrengelman.shadow") version "7.1.2" -} -application { - mainClass = "net.glowstone.GlowServer" -} - -repositories { - mavenCentral() - mavenLocal() - maven { - url "https://libraries.minecraft.net" - } - maven{ - url ("https://repo.papermc.io/repository/maven-public/") - } -} - -dependencies { - implementation("io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT") - implementation("net.glowstone:glowkit:1.19.3-R0.1-SNAPSHOT") - implementation("net.glowstone:block-data-generated:1.1.0-SNAPSHOT") - implementation("net.glowstone:data-pack-generated:1.1.0-SNAPSHOT") - - implementation("io.netty:netty-all:4.1.87.Final") - implementation("org.ow2.asm:asm:9.2") - implementation("org.ow2.asm:asm-commons:9.2") - implementation("org.fusesource.jansi:jansi:1.18") - implementation("jline:jline:2.14.6") - implementation("com.eatthepath:fast-uuid:0.1") - implementation("com.mojang:brigadier:1.0.17") - implementation("org.jogamp.gluegen:gluegen-rt-main:2.3.2") - implementation("org.jogamp.jocl:jocl-main:2.3.2") - implementation("com.tobedevoured.naether:core:0.15.8") { - exclude group: "org.slf4j", module: "slf4j-simple" - } - implementation('org.apache.commons:commons-lang3:3.12.0') - implementation("org.apache.maven:maven-artifact:3.8.1") - - - runtimeOnly("org.apache.logging.log4j:log4j-slf4j18-impl:2.17.1") - runtimeOnly("com.lmax:disruptor:3.4.4") - - testImplementation("junit:junit:4.13.1") - testImplementation("org.junit.vintage:junit-vintage-engine:5.7.2") - testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.2") - testImplementation("org.junit.jupiter:junit-jupiter-params:5.7.2") - testImplementation("org.junit.jupiter:junit-jupiter-engine:5.7.2") - - testImplementation("org.hamcrest:hamcrest:2.2") - testImplementation("org.powermock:powermock-core:2.0.9") - testImplementation("org.powermock:powermock-module-junit4:2.0.9") - testImplementation("org.powermock:powermock-api-mockito2:2.0.9") - - compileOnly("org.jetbrains:annotations:21.0.1") - implementation('com.flowpowered:flow-network:1.2.11-SNAPSHOT') -} - -group = "net.glowstone" -version = "2022.6.1-SNAPSHOT" -description = "A fast, customizable and compatible open source Minecraft server." -var javaVersion = 17 -var buildExtras = java.util.Optional.ofNullable(System.getenv("BUILD_EXTRAS")) - -checkstyle { - configFile = new File(project.projectDir, "/etc/checkstyle.xml") - configProperties["checkstyle.header.file"] = new File(project.projectDir, "LICENSE") - ignoreFailures = false -} - -java { - toolchain { - languageVersion = JavaLanguageVersion.of(javaVersion) - } - - if (buildExtras.isPresent() && Boolean.parseBoolean(buildExtras.get())){ - withSourcesJar() - tasks.named("sourcesJar") { - archiveVersion.set("") - } - - withJavadocJar() - tasks.named("javadocJar") { - archiveVersion.set("") - } - } -} -tasks.withType(JavaCompile) { - options.warnings = false -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 000000000..467eff181 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,247 @@ +import org.gradle.api.tasks.testing.logging.TestExceptionFormat +import org.gradle.api.tasks.testing.logging.TestLogEvent +import java.io.ByteArrayOutputStream + +plugins { + java + `maven-publish` + checkstyle + jacoco + kotlin("jvm") version "1.7.0" + application + + id("io.freefair.lombok") version "6.5.0-rc1" + id("com.github.johnrengelman.shadow") version "7.1.2" +} + +val buildExtras = System.getenv("BUILD_EXTRAS")?.toBoolean() ?: false + +repositories { + mavenLocal() + + maven("https://repo.glowstone.net/repository/maven-public/") + maven("https://repo.glowstone.net/repository/snapshots/") + maven("https://libraries.minecraft.net") +} + +dependencies { + implementation(libs.bundles.linkstone) + implementation(libs.bundles.glowstone) + + implementation(libs.jansi) + implementation(libs.jline) + implementation(libs.fastutil) + implementation(libs.flow) + implementation(libs.fastuuid) + implementation(libs.brigadier) + implementation(libs.gluegen) + implementation(libs.jocl) + implementation(libs.naether) { + exclude(group = "org.slf4j", module = "slf4j-simple") + } + implementation(libs.maven.artifact) + + runtimeOnly(libs.log4j) + runtimeOnly("com.lmax:disruptor:3.4.4") + + testImplementation(libs.bundles.junit) + testImplementation(kotlin("test")) + testRuntimeOnly(libs.bundles.junitRuntime) + + testImplementation(libs.hamcrest) + testImplementation(libs.bundles.powermock) + + compileOnly(libs.jetbrains.annotations) +} + + +application { + mainClass.set("net.glowstone.GlowServer") +} + + + +group = "net.glowstone" +version = "2022.6.1-SNAPSHOT" +description = "A fast, customizable and compatible open source Minecraft server." + +publishing { + repositories { + val mavenPublishUrl = "https://repo.glowstone.net/content/repositories/" + val isSnapshot = version.toString().endsWith("-SNAPSHOT") + maven { + name = "glowstone" + url = uri(mavenPublishUrl + if (isSnapshot) "snapshots/" else "releases/") + credentials(PasswordCredentials::class) + } + } + publications { + register("maven") { + withoutBuildIdentifier() + from(components["java"]) + pom { + name.set(project.name) + description.set(project.description) + url.set("https://www.glowstone.net") + inceptionYear.set("2011") + + licenses { + license { + name.set("MIT") + url.set("https://github.com/GlowstoneMC/Glowstone/blob/dev/LICENSE") + distribution.set("repo") + } + } + } + } + } +} + +checkstyle { + configFile = File(project.projectDir, "/etc/checkstyle.xml") + configProperties["checkstyle.header.file"] = File(project.projectDir, "LICENSE") + toolVersion = libs.versions.checkstyle.get() + isIgnoreFailures = true +} + +val javaVersion = 17 + +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(javaVersion)) + } + + if (buildExtras) { + withSourcesJar() + tasks.named("sourcesJar") { + archiveVersion.set("") + } + + withJavadocJar() + tasks.named("javadocJar") { + archiveVersion.set("") + } + } +} + +kotlin { + jvmToolchain { + (this as JavaToolchainSpec).apply { + languageVersion.set(JavaLanguageVersion.of(javaVersion)) + } + } +} + +tasks.withType { + options.encoding = Charsets.UTF_8.name() + options.release.set(javaVersion) + options.isWarnings = false; +} + +tasks.withType { + options.encoding = Charsets.UTF_8.name() + + if (JavaVersion.current().isJava9Compatible) { + (options as StandardJavadocDocletOptions).addBooleanOption("html5", true) + } + + exclude("**/*.xml") +} + +tasks.withType { + filteringCharset = Charsets.UTF_8.name() +} + +tasks.withType { + testLogging { + showStackTraces = true + exceptionFormat = TestExceptionFormat.FULL + events(TestLogEvent.STANDARD_OUT) + } +} + +fun getGitHash(): String { + val stdout = ByteArrayOutputStream() + exec { + commandLine = listOf("git", "rev-parse", "--short=7", "HEAD") + standardOutput = stdout + } + return stdout.toString().trim() +} + +fun getGitBranch(): String { + val stdout = ByteArrayOutputStream() + exec { + commandLine = listOf("git", "rev-parse", "--abbrev-ref", "HEAD") + standardOutput = stdout + } + return stdout.toString().trim() +} + +fun getGitDate(gitHash: String): String { + val stdout = ByteArrayOutputStream() + exec { + commandLine = listOf("git", "show", "-s", "--format=%ci", gitHash) + standardOutput = stdout + } + return stdout.toString().trim() +} + +tasks.jar { + enabled = false + manifest { + val gitHash = getGitHash() + val gitBranch = getGitBranch() + val date = getGitDate(gitHash) + attributes( + "Launcher-Agent-Class" to "net.glowstone.util.ClassPathAgent", + "Main-Class" to "net.glowstone.GlowServer", + + "Implementation-Title" to "Glowstone", + "Implementation-Version" to "git-${project.name}-${gitHash}-${project.version}", + "Implementation-Vendor" to date, + + "Specification-Title" to "Bukkit", + "Specification-Version" to libs.versions.api.get(), + "Specification-Vendor" to "Bukkit Team", + + "Git-Branch" to gitBranch, + "Git-Commit" to gitHash, + ) + for (tld in setOf("net", "com", "org")) { + attributes("$tld/bukkit", "Sealed" to true) + } + } +} + +tasks.shadowJar { + val prefix = "org.bukkit.craftbukkit.libs" + listOf( + "jline", + "it.unimi", + ).forEach { pattern -> + relocate(pattern, "$prefix.$pattern") + } + + exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "OSGI-INF/**", "*.profile", "module-info.class", "ant_tasks/**", "mojang-translations/*") + + archiveVersion.set("") + archiveClassifier.set("") +} + +tasks.assemble { dependsOn(tasks.shadowJar) } + +tasks.getByName("test") { + useJUnitPlatform() + finalizedBy(tasks.jacocoTestReport) +} + +tasks.register("printMinecraftVersion") { + doLast { + println(providers.gradleProperty("mcVersion").get().trim()) + } +} + +tasks.jacocoTestReport { + dependsOn(tasks.test) +} diff --git a/gradle.properties b/gradle.properties index ca394264e..d852712c4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ group = net.glowstone mcVersion = 1.19.3 -org.gradle.warning.mode=fail +org.gradle.warning.mode=none org.gradle.caching=true org.gradle.parallel=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 000000000..6bae085ca --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,64 @@ +[versions] +api = "1.19.3-R0.1-SNAPSHOT" +redstone-transformer = "1.1.0-SNAPSHOT" +linkstone = "1.0.0-SNAPSHOT" + +checkstyle = "8.44" +jansi = "1.18" +jline = "2.14.6" +fastutil = "1.0" +flow = "1.2.11-SNAPSHOT" +fastuuid = "0.1" +brigadier = "1.0.17" +gluegen = "2.3.2" +jocl = "2.3.2" +naether = "0.15.8" +maven-artifact = "3.8.1" +log4j = "2.17.1" +junit-core = "4.13.1" +junit-ext = "5.7.2" +hamcrest = "2.2" +powermock = "2.0.9" +jetbrains-annotations = "21.0.1" + +[libraries] +linkstone-annotations = { module = "net.glowstone:linkstone-annotations", version.ref = "linkstone" } +linkstone-runtime = { module = "net.glowstone:linkstone-runtime", version.ref = "linkstone" } + +glowstone-glowkit = { module = "net.glowstone:glowkit", version.ref = "api" } +glowstone-blockdata = { module = "net.glowstone:block-data-generated", version.ref = "redstone-transformer" } +glowstone-datapack = { module = "net.glowstone:data-pack-generated", version.ref = "redstone-transformer" } + +gluegen = { module = "org.jogamp.gluegen:gluegen-rt-main", version.ref = "gluegen" } +jocl = { module = "org.jogamp.jocl:jocl-main", version.ref = "jocl" } + +naether = { module = "com.tobedevoured.naether:core", version.ref = "naether" } +maven-artifact = { module = "org.apache.maven:maven-artifact", version.ref = "maven-artifact" } +log4j = { module = "org.apache.logging.log4j:log4j-slf4j18-impl", version.ref = "log4j" } +jansi = { module = "org.fusesource.jansi:jansi", version.ref = "jansi" } +jline = { module = "jline:jline", version.ref = "jline" } +fastutil = { module = "co.aikar:fastutil-lite", version.ref = "fastutil" } +flow = { module = "com.flowpowered:flow-network", version.ref = "flow" } +fastuuid = { module = "com.eatthepath:fast-uuid", version.ref = "fastuuid" } +brigadier = { module = "com.mojang:brigadier", version.ref = "brigadier" } + +junit-core = { module = "junit:junit", version.ref = "junit-core" } +junit-vintage-engine = { module = "org.junit.vintage:junit-vintage-engine", version.ref = "junit-ext" } +junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-ext" } +junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit-ext" } +junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-ext" } + +hamcrest = { module = "org.hamcrest:hamcrest", version.ref = "hamcrest" } +powermock-core = { module = "org.powermock:powermock-core", version.ref = "powermock" } +powermock-module-junit4 = { module = "org.powermock:powermock-module-junit4", version.ref = "powermock" } +powermock-api-mockito2 = { module = "org.powermock:powermock-api-mockito2", version.ref = "powermock" } + +jetbrains-annotations = { module = "org.jetbrains:annotations", version.ref = "jetbrains-annotations" } + +[bundles] +glowstone = ["glowstone-glowkit", "glowstone-blockdata", "glowstone-datapack"] + +linkstone = ["linkstone-annotations", "linkstone-runtime"] +junit = ["junit-core", "junit-jupiter-api", "junit-jupiter-params"] +junitRuntime = ["junit-jupiter-engine", "junit-vintage-engine"] +powermock = ["powermock-core", "powermock-module-junit4", "powermock-api-mockito2"] diff --git a/settings.gradle b/settings.gradle.kts similarity index 100% rename from settings.gradle rename to settings.gradle.kts From cd1c0b73a9afb4586d54b2354da0a5116c0ab89c Mon Sep 17 00:00:00 2001 From: ApionXD Date: Mon, 13 Feb 2023 17:01:46 -0500 Subject: [PATCH 15/15] Added all linkstone stuff back --- src/main/java/net/glowstone/GlowServer.java | 34 ++--- .../linkstone/LinkstoneClassInitObserver.java | 116 ++++++++++++++++++ .../util/linkstone/LinkstonePluginLoader.java | 63 ++++++++++ .../linkstone/LinkstonePluginScanner.java | 59 +++++++++ 4 files changed, 257 insertions(+), 15 deletions(-) create mode 100644 src/main/java/net/glowstone/util/linkstone/LinkstoneClassInitObserver.java create mode 100644 src/main/java/net/glowstone/util/linkstone/LinkstonePluginLoader.java create mode 100644 src/main/java/net/glowstone/util/linkstone/LinkstonePluginScanner.java diff --git a/src/main/java/net/glowstone/GlowServer.java b/src/main/java/net/glowstone/GlowServer.java index 58d856167..637ff02ef 100644 --- a/src/main/java/net/glowstone/GlowServer.java +++ b/src/main/java/net/glowstone/GlowServer.java @@ -102,10 +102,12 @@ import net.glowstone.io.ScoreboardIoService; import net.glowstone.io.WorldStorageProviderFactory; import net.glowstone.io.anvil.AnvilWorldStorageProvider; -//import net.glowstone.linkstone.runtime.Boxes; -//import net.glowstone.linkstone.runtime.FieldSet; -//import net.glowstone.linkstone.runtime.LinkstoneRuntimeData; -//import net.glowstone.linkstone.runtime.inithook.ClassInitHook; +import net.glowstone.linkstone.runtime.Boxes; +import net.glowstone.linkstone.runtime.FieldSet; +import net.glowstone.linkstone.runtime.LinkstoneRuntimeData; +import net.glowstone.linkstone.runtime.inithook.ClassInitHook; +import net.glowstone.linkstone.runtime.FieldSet; +import net.glowstone.linkstone.runtime.LinkstoneRuntimeData; import net.glowstone.map.GlowMapView; import net.glowstone.net.GameServer; import net.glowstone.net.GlowSession; @@ -137,9 +139,11 @@ import net.glowstone.util.library.Library; import net.glowstone.util.library.LibraryKey; import net.glowstone.util.library.LibraryManager; -//import net.glowstone.util.linkstone.LinkstoneClassInitObserver; -//import net.glowstone.util.linkstone.LinkstonePluginLoader; -//import net.glowstone.util.linkstone.LinkstonePluginScanner; +import net.glowstone.util.linkstone.LinkstoneClassInitObserver; +import net.glowstone.util.linkstone.LinkstonePluginLoader; +import net.glowstone.util.linkstone.LinkstonePluginScanner; +import net.glowstone.util.linkstone.LinkstoneClassInitObserver; +import net.glowstone.util.linkstone.LinkstonePluginScanner; import net.glowstone.util.loot.LootingManager; import net.glowstone.util.mojangson.Mojangson; import net.glowstone.util.mojangson.ex.MojangsonParseException; @@ -543,7 +547,7 @@ public GlowServer(ServerConfig config) { nameBans = new GlowBanList(this, Type.NAME); ipBans = new GlowBanList(this, Type.IP); - //ClassInitHook.register(new LinkstoneClassInitObserver()); + ClassInitHook.register(new LinkstoneClassInitObserver()); loadConfig(); bossBars = new ConcurrentHashMap<>(); @@ -1335,16 +1339,16 @@ private void loadPlugins() { pluginTypeDetector.scan(); // scan plugins for @Field and @Box annotated fields - //FieldSet annotatedFields = new FieldSet(); - //Boxes boxes = new Boxes(); - //LinkstoneRuntimeData.setFields(annotatedFields); - //LinkstoneRuntimeData.setBoxes(boxes); - //new LinkstonePluginScanner(annotatedFields, boxes) - // .scanPlugins(pluginTypeDetector.bukkitPlugins); + FieldSet annotatedFields = new FieldSet(); + Boxes boxes = new Boxes(); + LinkstoneRuntimeData.setFields(annotatedFields); + LinkstoneRuntimeData.setBoxes(boxes); + new LinkstonePluginScanner(annotatedFields, boxes) + .scanPlugins(pluginTypeDetector.bukkitPlugins); // clear plugins and prepare to load (Bukkit) pluginManager.clearPlugins(); - //pluginManager.registerInterface(LinkstonePluginLoader.class); + pluginManager.registerInterface(LinkstonePluginLoader.class); Plugin[] plugins = pluginManager .loadPlugins(folder, pluginTypeDetector.bukkitPlugins); diff --git a/src/main/java/net/glowstone/util/linkstone/LinkstoneClassInitObserver.java b/src/main/java/net/glowstone/util/linkstone/LinkstoneClassInitObserver.java new file mode 100644 index 000000000..680da65d6 --- /dev/null +++ b/src/main/java/net/glowstone/util/linkstone/LinkstoneClassInitObserver.java @@ -0,0 +1,116 @@ +package net.glowstone.util.linkstone; + +import net.glowstone.linkstone.annotations.LBox; +import net.glowstone.linkstone.annotations.LField; +import net.glowstone.linkstone.runtime.inithook.ClassInitHook; +import net.glowstone.linkstone.runtime.reflectionredirect.DynamicClassLoader; +import net.glowstone.linkstone.runtime.reflectionredirect.ReflectionUtil; +import net.glowstone.linkstone.runtime.reflectionredirect.field.BoxingFieldAccessor; +import net.glowstone.linkstone.runtime.reflectionredirect.field.FieldAccessorUtility; +import net.glowstone.linkstone.runtime.reflectionredirect.field.LFieldAccessor; +import net.glowstone.linkstone.runtime.reflectionredirect.field.RedirectFieldAccessorGenerator; +import net.glowstone.linkstone.runtime.reflectionredirect.method.BoxingMethodAccessor; +import net.glowstone.linkstone.runtime.reflectionredirect.method.LMethodAccessor; +import net.glowstone.linkstone.runtime.reflectionredirect.method.MethodAccessorUtility; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Map; +import java.util.WeakHashMap; + +/** + * Utility that redirects reflective uses of annotated fields to their getters and setters. + */ +public class LinkstoneClassInitObserver implements ClassInitHook.Observer { + private final FieldAccessorUtility fieldAccessorUtil; + private final MethodAccessorUtility methodAccessorUtil; + + private final Map classLoaders = new WeakHashMap<>(); + + /** + * Create a new observer instance. + */ + public LinkstoneClassInitObserver() { + try { + fieldAccessorUtil = FieldAccessorUtility.isSupported() + ? new FieldAccessorUtility() : null; + } catch (Exception t) { + throw new IllegalStateException("Could not initialize FieldAccessorUtility"); + } + + try { + methodAccessorUtil = MethodAccessorUtility.isSupported() + ? new MethodAccessorUtility() : null; + } catch (Exception e) { + throw new IllegalStateException("Could not initialize MethodAccessorUtility"); + } + } + + @Override + public void onInit(Class clazz) { + try { + hijackFields(clazz); + hijackMethods(clazz); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void hijackFields(Class clazz) throws ReflectiveOperationException { + if (fieldAccessorUtil == null) { + return; + } + + boolean isBox = clazz.getAnnotation(LBox.class) != null; + + for (Field field : ReflectionUtil.getInternalFields(clazz)) { + LField[] fieldAnnotations = field.getAnnotationsByType(LField.class); + if (fieldAnnotations.length > 0) { + LFieldAccessor accessor = newRedirectFieldAccessor(field); + fieldAccessorUtil.setAccessor(field, accessor); + fieldAccessorUtil.setOverrideAccessor(field, accessor); + } + + if (isBox) { + LFieldAccessor accessor = fieldAccessorUtil.getAccessor(field); + accessor = new BoxingFieldAccessor(accessor, field); + fieldAccessorUtil.setAccessor(field, accessor); + + LFieldAccessor overrideAccessor = fieldAccessorUtil.getOverrideAccessor(field); + overrideAccessor = new BoxingFieldAccessor(overrideAccessor, field); + fieldAccessorUtil.setOverrideAccessor(field, overrideAccessor); + } + } + } + + private LFieldAccessor newRedirectFieldAccessor(Field field) + throws ReflectiveOperationException { + DynamicClassLoader classloader = classLoaders.computeIfAbsent( + field.getDeclaringClass().getClassLoader(), DynamicClassLoader::new); + + RedirectFieldAccessorGenerator generator = new RedirectFieldAccessorGenerator(field); + String className = generator.getClassName().replace('/', '.'); + + Class accessorClass; + try { + accessorClass = Class.forName(className, false, classloader); + } catch (ClassNotFoundException e) { + byte[] bytecode = generator.generateAccessor(); + accessorClass = classloader.loadBytecode(className, bytecode); + } + + return (LFieldAccessor) accessorClass.getDeclaredConstructor().newInstance(); + } + + private void hijackMethods(Class clazz) throws ReflectiveOperationException { + if (methodAccessorUtil == null || clazz.getAnnotation(LBox.class) == null) { + return; + } + + for (Method method : ReflectionUtil.getInternalMethods(clazz)) { + LMethodAccessor accessor = methodAccessorUtil.getAccessor(method); + accessor = new BoxingMethodAccessor(method, accessor); + methodAccessorUtil.setAccessor(method, accessor); + } + } +} diff --git a/src/main/java/net/glowstone/util/linkstone/LinkstonePluginLoader.java b/src/main/java/net/glowstone/util/linkstone/LinkstonePluginLoader.java new file mode 100644 index 000000000..c4c459c16 --- /dev/null +++ b/src/main/java/net/glowstone/util/linkstone/LinkstonePluginLoader.java @@ -0,0 +1,63 @@ +package net.glowstone.util.linkstone; + +import net.glowstone.linkstone.runtime.LinkstoneRuntimeData; +import net.glowstone.linkstone.runtime.boxing.BoxPatchVisitor; +import net.glowstone.linkstone.runtime.direct.DirectFieldAccessReplaceVisitor; +import net.glowstone.linkstone.runtime.inithook.ClassInitInvokeVisitor; +import net.glowstone.linkstone.runtime.reflectionredirect.field.FieldAccessorUtility; +import net.glowstone.linkstone.runtime.reflectionredirect.method.MethodAccessorUtility; +import net.glowstone.linkstone.runtime.reflectionreplace.ReflectionReplaceVisitor; +import org.bukkit.Server; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.java.JavaPluginLoader; +import org.bukkit.plugin.java.PluginClassLoader; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.ClassWriter; + +import java.io.File; + +public class LinkstonePluginLoader extends JavaPluginLoader { + /** + * Bukkit will invoke this constructor via reflection. + * Its signature should therefore not be changed! + * + * @param instance the server instance + */ + public LinkstonePluginLoader(Server instance) { + super(instance); + LinkstoneRuntimeData.setPluginClassLoader(new ClassLoader() { + @Override + protected Class findClass(String name) throws ClassNotFoundException { + return loadClass(name); + } + }); + } + + @Override + protected PluginClassLoader newPluginLoader(JavaPluginLoader loader, ClassLoader parent, PluginDescriptionFile description, File dataFolder, File file, ClassLoader libraryLoader) throws Exception { + return new PluginClassLoader(loader, parent, description, dataFolder, file, libraryLoader) { + @Override + protected byte[] transformBytecode(byte[] bytecode) { + if (LinkstoneRuntimeData.getFields().isEmpty() + && LinkstoneRuntimeData.getBoxes().isEmpty()) { + // There are no plugins installed that use a @LField or @LBox annotation + // so there's no need for runtime support + return bytecode; + } + ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); + + ClassVisitor cv = cw; + cv = new DirectFieldAccessReplaceVisitor(LinkstoneRuntimeData.getFields(), cv); + if (!FieldAccessorUtility.isSupported() || !MethodAccessorUtility.isSupported()) { + cv = new ReflectionReplaceVisitor(cv); + } + cv = new ClassInitInvokeVisitor(cv); + cv = new BoxPatchVisitor(LinkstoneRuntimeData.getBoxes(), cv); + + new ClassReader(bytecode).accept(cv, 0); + return cw.toByteArray(); + } + }; + } +} diff --git a/src/main/java/net/glowstone/util/linkstone/LinkstonePluginScanner.java b/src/main/java/net/glowstone/util/linkstone/LinkstonePluginScanner.java new file mode 100644 index 000000000..8f3ecdb16 --- /dev/null +++ b/src/main/java/net/glowstone/util/linkstone/LinkstonePluginScanner.java @@ -0,0 +1,59 @@ +package net.glowstone.util.linkstone; + +import net.glowstone.linkstone.annotations.LField; +import net.glowstone.linkstone.runtime.Boxes; +import net.glowstone.linkstone.runtime.FieldSet; +import net.glowstone.linkstone.runtime.collect.AnnotatedFieldCollectVisitor; +import net.glowstone.linkstone.runtime.collect.BoxCollectVisitor; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +public class LinkstonePluginScanner { + private final FieldSet fields; + private final Boxes boxes; + + public LinkstonePluginScanner(final FieldSet fields, final Boxes boxes) { + this.fields = fields; + this.boxes = boxes; + } + + /** + * Look through a list of plugins jar files and store all + * fields annotated with a {@link LField} annotation. + * + * @param pluginJars list of plugins jars to be scanned + */ + public void scanPlugins(List pluginJars) { + for (File pluginJar : pluginJars) { + try { + scanPlugin(pluginJar); + } catch (Throwable t) { + t.printStackTrace(); + } + } + } + + private void scanPlugin(File pluginJar) throws IOException { + ZipInputStream zin = new ZipInputStream(new FileInputStream(pluginJar)); + ZipEntry entry; + while ((entry = zin.getNextEntry()) != null) { + if (entry.isDirectory() || !entry.getName().endsWith(".class")) { + continue; + } + + ClassVisitor cv = new AnnotatedFieldCollectVisitor(this.fields); + cv = new BoxCollectVisitor(this.boxes, cv); + + new ClassReader(zin).accept(cv, ClassReader.SKIP_CODE); + zin.closeEntry(); + } + zin.close(); + } +}