diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 00000000..5288df0d
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,8 @@
+.github/*
+.gradle/*
+.idea/*
+build/*
+docs/*
+Dockerfile
+.dockerignore
+README.md
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 555da25e..66ce4a16 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -24,27 +24,44 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
- java-version: '8'
+ java-version: '16'
- name: Cache Spigot Dependencies
id: cache-spigot-dependencies
uses: actions/cache@v2
with:
path: /home/runner/.m2/repository/org/spigotmc
- key: spigot-dependencies
+ key: spigot-dependency
+
+ - name: Validate Spigot Dependencies
+ run: |
+ test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar && echo "DEPENDENCIES=true" >> $GITHUB_ENV
+
+ - name: Build Spigot Dependencies
+ if: ${{ env.DEPENDENCIES != 'true' }}
+ run: |
+ mkdir -p ~/.m2/repository/org/spigotmc/
+ docker build --target dependencies-jdk8 -t structureblocklib-dependencies-jdk8 .
+ docker create --name structureblocklib-dependencies-jdk8 structureblocklib-dependencies-jdk8 bash
+ docker cp structureblocklib-dependencies-jdk8:/root/.m2/repository/org/spigotmc ~/.m2/repository/org/
+ docker rm -f structureblocklib-dependencies-jdk8
+ docker build --target dependencies-jdk16 -t structureblocklib-dependencies-jdk16 .
+ docker create --name structureblocklib-dependencies-jdk16 structureblocklib-dependencies-jdk16 bash
+ docker cp structureblocklib-dependencies-jdk16:/root/.m2/repository/org/spigotmc ~/.m2/repository/org/
+ docker rm -f structureblocklib-dependencies-jdk16
- name: Build Java Application
run: |
chmod +x gradlew
- ./gradlew assemble || ./gradlew downloadDependencies
- ./gradlew clean build shadowJar
+ ./gradlew build pluginJar
- name: Publish Test Report
run: |
./gradlew jacocoTestReport
bash <(curl -s https://codecov.io/bash)
+
- name: Publish Release to Maven Central
- if: "contains(github.event.head_commit.message, '--release') && contains(github.ref, 'master')"
+ if: ${{ github.ref == 'refs/heads/main' }}
env:
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
@@ -57,6 +74,18 @@ jobs:
./gradlew clean publishToNexus
./gradlew closeAndReleaseRepository
+ - name: Publish Snapshot
+ if: "contains(github.event.head_commit.message, '--snapshot')"
+ env:
+ SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
+ SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
+ SIGNING_KEY_FILE: ${{ secrets.SIGNING_KEY_FILE }}
+ SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
+ SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
+ run: |
+ gpg2 --batch --cipher-algo AES256 --passphrase ${{ secrets.SIGNING_KEY_PASSWORD }} travis_secret_key.gpg
+ ./gradlew publish > /dev/null
+
- name: Create Github Release
if: "contains(github.event.head_commit.message, '--release') && contains(github.ref, 'master')"
id: create_release
diff --git a/Dockerfile b/Dockerfile
index 9469bbe2..339f96ca 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,16 +1,59 @@
-FROM openjdk:8
+# This docker file uses multi-stage builds.
+# 1. Resolve minecraft-dependencies for 1.8 - 1.16 with jdk8
+FROM openjdk:8 AS dependencies-jdk8
+WORKDIR /tmp
+RUN apt-get update
+RUN apt-get install maven -y
+RUN wget "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"
+RUN java -jar BuildTools.jar --rev 1.9.4
+RUN java -jar BuildTools.jar --rev 1.10
+RUN java -jar BuildTools.jar --rev 1.11
+RUN java -jar BuildTools.jar --rev 1.12
+RUN java -jar BuildTools.jar --rev 1.16.4
+RUN java -jar BuildTools.jar --rev 1.13.2
+RUN java -jar BuildTools.jar --rev 1.14.4
+RUN java -jar BuildTools.jar --rev 1.15
+RUN java -jar BuildTools.jar --rev 1.16.4
+CMD ["sh","-c","/bin/bash"]
-WORKDIR /minecraft
+# 2. Resolve minecraft-dependencies for 1.17 - latest with jdk16
+FROM adoptopenjdk/openjdk16 AS dependencies-jdk16
+WORKDIR /tmp
+RUN apt-get update
+RUN apt-get install maven -y
+RUN apt-get install wget -y
+RUN apt-get install git -y
+RUN wget "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"
+RUN java -jar BuildTools.jar --rev 1.17 --remapped
-COPY ["structureblocklib-tools", "structureblocklib-bukkit-sample/build/libs", "./"]
+# 3. Build plugin for 1.8 - 1.17 with jdk16
+FROM adoptopenjdk/openjdk16 AS plugin-jdk16
+WORKDIR /tmp
+RUN apt-get update
+RUN apt-get install maven -y
+RUN apt-get install dos2unix -y
+COPY --from=dependencies-jdk8 /root/.m2/repository/org/spigotmc /root/.m2/repository/org/spigotmc/
+COPY --from=dependencies-jdk16 /root/.m2/repository/org/spigotmc /root/.m2/repository/org/spigotmc/
+COPY . /tmp
+RUN chmod +x gradlew
+RUN dos2unix gradlew
+RUN ./gradlew build pluginJar --no-daemon
-RUN wget "https://hub.spigotmc.org/jenkins/job/BuildTools/lastStableBuild/artifact/target/BuildTools.jar" && \
- java -Xmx1024M -jar BuildTools.jar --rev "1.15" && \
- echo "eula=true" > eula.txt
-
-CMD rm -r plugins/PetBlocks -f && \
- rm -r world -f && \
- rm -r world_nether -f && \
- rm -r world_the_end -f && \
- cp -r world-1.14/world . && \
- java -Xmx1024M -Xmx1024M -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar spigot-1.15.jar
\ No newline at end of file
+# 4. Launch a minecraft server with jdk16 and plugin
+FROM adoptopenjdk/openjdk16
+# Change to the current plugin version present in build.gradle
+ENV PLUGIN_VERSION=2.2.0
+# Change to the server version you want to test.
+ENV SERVER_VERSION=1.17-R0.1-SNAPSHOT/spigot-1.17-R0.1-SNAPSHOT.jar
+# Port of the Minecraft Server.
+EXPOSE 25565
+# Port for Remote Debugging
+EXPOSE 5005
+WORKDIR /app
+RUN apt-get update
+RUN echo "eula=true" > eula.txt && mkdir plugins
+COPY ./structureblocklib-tools/world-1.14 /app/
+COPY ./structureblocklib-tools/ops.json /app/
+COPY --from=dependencies-jdk16 /root/.m2/repository/org/spigotmc/spigot/$SERVER_VERSION /app/spigot.jar
+COPY --from=plugin-jdk16 /tmp/structureblocklib-bukkit-sample/build/libs/structureblocklib-bukkit-sample-$PLUGIN_VERSION.jar /app/plugins/Structureblocklib.jar
+CMD ["sh","-c","java -DIReallyKnowWhatIAmDoingISwear -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar spigot.jar"]
diff --git a/README.md b/README.md
index ace417e9..f8c028ba 100644
--- a/README.md
+++ b/README.md
@@ -2,8 +2,8 @@
| branch | status | version | download |
| ------------- | ------------- | -------- | --------|
-| master | [](https://travis-ci.org/Shynixn/StructureBlockLib) | |[Download latest release](https://github.com/Shynixn/StructureBlockLib/releases)|
-| development | [](https://travis-ci.org/Shynixn/StructureBlockLib)| | [Download snapshots](https://oss.sonatype.org/content/repositories/snapshots/com/github/shynixn/structureblocklib/structureblocklib-bukkit-plugin/) |
+| master | [](https://github.com/Shynixn/StructureBlockLib/actions) | |[Download latest release](https://github.com/Shynixn/StructureBlockLib/releases)|
+| development | [](https://github.com/Shynixn/StructureBlockLib/actions)| | [Download snapshots](https://oss.sonatype.org/content/repositories/snapshots/com/github/shynixn/structureblocklib/structureblocklib-bukkit-plugin/) |
JavaDocs: https://shynixn.github.io/StructureBlockLib/apidocs/
@@ -13,11 +13,12 @@ StructureBlockLib is a bukkit API and implementation for handling structures on
## Features
-* Full blown Bukkit Api for the StructureBlock.
+* Bukkit API for the StructureBlock.
* API to save or load structures without an actual structure block.
* Asynchronous implementation and API.
* Fluent API.
-* Version support 1.9.R1 - 1.16.R3
+* Version support 1.9.R1 - 1.17.R1
+* Java support 8 - Latest
## Installation
@@ -28,7 +29,7 @@ StructureBlockLib is a bukkit API and implementation for handling structures on
com.github.shynixn.structureblocklib
structureblocklib-bukkit-api
- 2.1.0
+ 2.2.0
provided
```
@@ -36,7 +37,7 @@ StructureBlockLib is a bukkit API and implementation for handling structures on
```xml
dependencies {
- compileOnly("com.github.shynixn.structureblocklib:structureblocklib-bukkit-api:2.1.0")
+ compileOnly("com.github.shynixn.structureblocklib:structureblocklib-bukkit-api:2.2.0")
}
```
@@ -182,13 +183,13 @@ go with the option above instead. There are several tutorials on spigotmc.org.
com.github.shynixn.structureblocklib
structureblocklib-bukkit-api
- 2.1.0
+ 2.2.0
compile
com.github.shynixn.structureblocklib
structureblocklib-bukkit-core
- 2.1.0
+ 2.2.0
compile
```
@@ -196,33 +197,55 @@ go with the option above instead. There are several tutorials on spigotmc.org.
```xml
dependencies {
- implementation("com.github.shynixn.structureblocklib:structureblocklib-bukkit-api:2.1.0")
- implementation("com.github.shynixn.structureblocklib:structureblocklib-bukkit-core:2.1.0")
+ implementation("com.github.shynixn.structureblocklib:structureblocklib-bukkit-api:2.2.0")
+ implementation("com.github.shynixn.structureblocklib:structureblocklib-bukkit-core:2.2.0")
}
```
## Contributing
-* Fork the StructureBlockLib project on github and clone it to your local environment.
-* Install Java 8 (later versions are not supported by the ``downloadDependencies`` task)
-* Install Apache Maven
-* Make sure ``java`` points to a Java 8 installation (``java -version``)
-* Make sure ``$JAVA_HOME`` points to a Java 8 installation
-* Make sure ``mvn`` points to a Maven installation (``mvn --version``)
-* Execute gradle sync for dependencies
-* Install the additional spigot dependencies by executing the following gradle task (this task can take a very long time)
-
-```xml
-[./gradlew|gradlew.bat] downloadDependencies
-```
-
-(If the downloadDependencies task fails for some reason, you can manually download [BuildTools.jar](https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar) and execute [the commands on this page](https://github.com/Shynixn/StructureBlockLib/blob/8a9bf2a402ba30118205ec400b7d1ab6562ecbf8/build.gradle#L224).)
+### Setting up development environment
-* Build the module files by executing the following gradle task.
-
-```xml
-[./gradlew|gradlew.bat] shadowJar
-```
+* Install Java 16 or higher
+* Fork the StructureBlockLib project on github and clone it to your local environment.
+* StructureBlockLib requires spigot server implementations from 1.9.4 to 1.17 to be correctly installed in your local Maven cache.
+ As this requires multiple java version to build different versions, a Dockerfile is provided to build these dependencies in a docker container
+ and then copy it to your local Maven cache.
+
+Note: If using Windows, execute the commands using Git Bash.
+````sh
+mkdir -p ~/.m2/repository/org/spigotmc/
+docker build --target dependencies-jdk8 -t structureblocklib-dependencies-jdk8 .
+docker create --name structureblocklib-dependencies-jdk8 structureblocklib-dependencies-jdk8 bash
+docker cp structureblocklib-dependencies-jdk8:/root/.m2/repository/org/spigotmc ~/.m2/repository/org/
+docker rm -f structureblocklib-dependencies-jdk8
+docker build --target dependencies-jdk16 -t structureblocklib-dependencies-jdk16 .
+docker create --name structureblocklib-dependencies-jdk16 structureblocklib-dependencies-jdk16 bash
+docker cp structureblocklib-dependencies-jdk16:/root/.m2/repository/org/spigotmc ~/.m2/repository/org/
+docker rm -f structureblocklib-dependencies-jdk16
+````
+
+* Open the project with an IDE, gradle sync for dependencies.
+
+### Testing
+
+#### Option 1
+
+* Setup your own minecraft server
+* Change ``// val destinationDir = File("C:/temp/plugins")`` to your plugins folder in the ``structureblocklib-bukkit-sample/build.gradle.kts`` file.
+* Run the ``pluginJar`` task to generate a plugin.jar file.
+* Run your minecraft server
+
+#### Option 2 :whale:
+
+* Run the provided docker file.
+* The source code is copied to a new docker container and built to a plugin.
+* This plugin is installed on a new minecraft server which is accessible on the host machine on the default port on ``localhost``.
+
+````sh
+docker build -t structureblocklib .
+docker run --name=structureblocklib -p 25565:25565 -p 5005:5005 structureblocklib
+````
## Licence
diff --git a/build.gradle b/build.gradle
index e4a5f558..1ba249a9 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,19 +8,17 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin', version: kotlinVersion
- classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.17"
+ classpath group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin', version: '1.3.72'
+ classpath "org.jetbrains.dokka:dokka-gradle-plugin:1.4.32"
}
}
plugins {
- id 'org.jetbrains.kotlin.jvm' version '1.3.31'
- id 'io.codearte.nexus-staging' version '0.22.0'
- id "de.marcphilipp.nexus-publish" version '0.4.0'
+ id 'org.jetbrains.kotlin.jvm' version '1.3.72'
+ id 'io.codearte.nexus-staging' version '0.20.0'
+ id "de.marcphilipp.nexus-publish" version '0.2.0'
}
-apply plugin: 'org.jetbrains.dokka'
-
repositories {
mavenCentral()
mavenLocal()
@@ -37,6 +35,7 @@ nexusStaging {
allprojects {
apply plugin: 'jacoco'
+ apply plugin: 'org.jetbrains.dokka'
}
tasks.register("printVersion") {
@@ -45,9 +44,7 @@ tasks.register("printVersion") {
subprojects {
group 'com.github.shynixn.structureblocklib'
- version '2.1.1'
-
- sourceCompatibility = 1.8
+ version '2.2.0'
apply plugin: 'kotlin-platform-jvm'
apply plugin: 'signing'
@@ -55,12 +52,8 @@ subprojects {
apply plugin: 'java-library'
apply plugin: "de.marcphilipp.nexus-publish"
- compileKotlin {
- kotlinOptions.jvmTarget = "1.8"
- }
- compileTestKotlin {
- kotlinOptions.jvmTarget = "1.8"
- }
+ sourceCompatibility = 1.8
+ targetCompatibility = 1.8
jacocoTestReport {
reports {
@@ -89,12 +82,11 @@ subprojects {
classifier = 'sources'
}
- task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
- outputFormat = 'javadoc'
- outputDirectory = "$buildDir/javadoc"
+ tasks.named("dokkaHtml") {
+ outputDirectory = file("$buildDir/javadoc")
}
- task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
+ task javadocJar(type: Jar, dependsOn: dokkaHtml) {
from javadoc
classifier = 'javadoc'
}
@@ -171,87 +163,26 @@ subprojects {
gradle.taskGraph.whenReady { taskGraph ->
if (project.findProperty("signing.keyId") == null) {
- ext."signing.keyId" = System.getenv('SIGNING_KEYID')
- ext."signing.password" = System.getenv('SIGNING_KEYPASSWORD')
- ext."signing.secretKeyRingFile" = '/home/travis/build/Shynixn/StructureBlockLib/travis_secret_key'
+ ext."signing.keyId" = System.getenv('SIGNING_KEY_ID')
+ ext."signing.password" = System.getenv('SIGNING_KEY_PASSWORD')
+ ext."signing.secretKeyRingFile" = System.getenv('SIGNING_KEY_FILE')
}
}
task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
- additionalSourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs)
- sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs)
- classDirectories = files(subprojects.sourceSets.main.output)
- executionData = files(subprojects.jacocoTestReport.executionData)
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
- onlyIf = {
- true
- }
- doFirst {
- executionData = files(executionData.findAll {
- it.exists()
- })
- }
}
task generateJavaDocPages(type: org.jetbrains.dokka.gradle.DokkaTask) {
- outputFormat = 'javadoc'
- outputDirectory = "docs/apidocs"
- sourceDirs = files(new File(this.projectDir as File, '/structureblocklib-bukkit-api/src/main/java')
- , new File(this.projectDir as File, '/structureblocklib-bukkit-core/src/main/java')
- , new File(this.projectDir as File, '/structureblocklib-bukkit-plugin/src/main/java')
- , new File(this.projectDir as File, '/structureblocklib-bukkit-sample/src/main/java'))
-}
-
-task downloadDependencies(type: Exec) {
- def build = new File('build')
-
- if (!build.exists()) {
- build.mkdir()
- }
-
- def folder = new File(build, 'buildtools')
-
- if (!folder.exists()) {
- folder.mkdir()
- }
-
- def file = new File(folder, "BuildTools.jar")
-
- if (!file.exists()) {
- new URL('https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar').withInputStream { i -> file.withOutputStream { it << i } }
- }
-
- def text = "cd build/buildtools"
- text += " && java -jar BuildTools.jar --rev 1.9.4"
- text += " && mvn install:install-file -Dfile=spigot-1.9.4.jar -DgroupId=org.spigotmc -DartifactId=spigot19R2 -Dversion=1.9.4-R2.0 -Dpackaging=jar"
- text += " && java -jar BuildTools.jar --rev 1.10"
- text += " && mvn install:install-file -Dfile=spigot-1.10.2.jar -DgroupId=org.spigotmc -DartifactId=spigot110R1 -Dversion=1.10.2-R1.0 -Dpackaging=jar"
- text += " && java -jar BuildTools.jar --rev 1.11"
- text += " && mvn install:install-file -Dfile=spigot-1.11.jar -DgroupId=org.spigotmc -DartifactId=spigot111R1 -Dversion=1.11.0-R1.0 -Dpackaging=jar"
- text += " && java -jar BuildTools.jar --rev 1.12"
- text += " && mvn install:install-file -Dfile=spigot-1.12.jar -DgroupId=org.spigotmc -DartifactId=spigot112R1 -Dversion=1.12.0-R1.0 -Dpackaging=jar"
- text += " && java -jar BuildTools.jar --rev 1.13.2"
- text += " && mvn install:install-file -Dfile=spigot-1.13.2.jar -DgroupId=org.spigotmc -DartifactId=spigot113R2 -Dversion=1.13.2-R2.0 -Dpackaging=jar"
- text += " && java -jar BuildTools.jar --rev 1.14.4"
- text += " && mvn install:install-file -Dfile=spigot-1.14.4.jar -DgroupId=org.spigotmc -DartifactId=spigot114R1 -Dversion=1.14.4-R1.0 -Dpackaging=jar"
- text += " && java -jar BuildTools.jar --rev 1.15"
- text += " && mvn install:install-file -Dfile=spigot-1.15.jar -DgroupId=org.spigotmc -DartifactId=spigot115R1 -Dversion=1.15.0-R1.0 -Dpackaging=jar"
- text += " && java -jar BuildTools.jar --rev 1.16.1"
- text += " && mvn install:install-file -Dfile=spigot-1.16.1.jar -DgroupId=org.spigotmc -DartifactId=spigot116R1 -Dversion=1.16.0-R1.0 -Dpackaging=jar"
- text += " && java -jar BuildTools.jar --rev 1.16.2"
- text += " && mvn install:install-file -Dfile=spigot-1.16.2.jar -DgroupId=org.spigotmc -DartifactId=spigot116R2 -Dversion=1.16.2-R2.0 -Dpackaging=jar"
- text += " && java -jar BuildTools.jar --rev 1.16.4"
- text += " && mvn install:install-file -Dfile=spigot-1.16.4.jar -DgroupId=org.spigotmc -DartifactId=spigot116R3 -Dversion=1.16.4-R3.0 -Dpackaging=jar"
-
- standardOutput = new ByteArrayOutputStream()
-
- if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
- commandLine 'cmd', '/c', text
- } else {
- commandLine 'sh', '-c', text
+ dokkaSourceSets {
+ named("main") {
+ outputDirectory = file("docs/apidocs")
+ sourceRoots.from(file("/structureblocklib-api/src/main/java"))
+ sourceRoots.from(file("/structureblocklib-bukkit-api/src/main/java"))
+ }
}
}
diff --git a/gradle.properties b/gradle.properties
index e1c8443a..47e8cf5a 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,3 +1,2 @@
kotlin.code.style=official
-javaVersion=1.8
-kotlinVersion=1.3.20
\ No newline at end of file
+org.gradle.jvmargs=-Xms4g
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 267df926..0f80bbf5 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,5 @@
-#Fri May 31 15:17:59 CEST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
diff --git a/settings.gradle.kts b/settings.gradle.kts
index f5559c67..29be3887 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -12,6 +12,5 @@ include("structureblocklib-bukkit-core:bukkit-nms-112R1")
include("structureblocklib-bukkit-core:bukkit-nms-113R2")
include("structureblocklib-bukkit-core:bukkit-nms-114R1")
include("structureblocklib-bukkit-core:bukkit-nms-115R1")
-include("structureblocklib-bukkit-core:bukkit-nms-116R1")
-include("structureblocklib-bukkit-core:bukkit-nms-116R2")
include("structureblocklib-bukkit-core:bukkit-nms-116R3")
+include("structureblocklib-bukkit-core:bukkit-nms-117R1")
diff --git a/structureblocklib-api/src/main/java/com/github/shynixn/structureblocklib/api/enumeration/Version.java b/structureblocklib-api/src/main/java/com/github/shynixn/structureblocklib/api/enumeration/Version.java
index 132d1123..31f3d9c2 100644
--- a/structureblocklib-api/src/main/java/com/github/shynixn/structureblocklib/api/enumeration/Version.java
+++ b/structureblocklib-api/src/main/java/com/github/shynixn/structureblocklib/api/enumeration/Version.java
@@ -54,7 +54,12 @@ public enum Version {
/**
* Version 1.16.4 - 1.16.4.
*/
- VERSION_1_16_R3("v1_16_R3", "1.16.4", 1.164);
+ VERSION_1_16_R3("v1_16_R3", "1.16.4", 1.164),
+
+ /**
+ * Version 1.17.0 - 1.17.0.
+ */
+ VERSION_1_17_R1("v1_17_R1", "1.17.0", 1.170);
private final String bukkitId;
private final String id;
diff --git a/structureblocklib-bukkit-api/build.gradle.kts b/structureblocklib-bukkit-api/build.gradle.kts
index 0605f204..5b4d727e 100644
--- a/structureblocklib-bukkit-api/build.gradle.kts
+++ b/structureblocklib-bukkit-api/build.gradle.kts
@@ -1,24 +1,17 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
- id("com.github.johnrengelman.shadow") version ("2.0.4")
-}
-
-publishing {
- publications {
- (findByName("mavenJava") as MavenPublication).artifact(tasks.findByName("shadowJar")!!)
- }
+ id("com.github.johnrengelman.shadow") version ("7.0.0")
}
tasks.withType {
dependsOn("jar")
archiveName = "$baseName-$version.$extension"
-
relocate("org.intellij", "com.github.shynixn.structureblocklib.lib.org.intellij")
relocate("org.jetbrains", "com.github.shynixn.structureblocklib.lib.org.jetbrains")
}
dependencies {
implementation(project(":structureblocklib-api"))
- compileOnly("org.spigotmc:spigot114R1:1.14.4-R1.0")
+ compileOnly("org.spigotmc:spigot:1.14.4-R0.1-SNAPSHOT")
}
diff --git a/structureblocklib-bukkit-core/build.gradle.kts b/structureblocklib-bukkit-core/build.gradle.kts
index 6660873d..25df1015 100644
--- a/structureblocklib-bukkit-core/build.gradle.kts
+++ b/structureblocklib-bukkit-core/build.gradle.kts
@@ -1,13 +1,10 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
+import java.net.URL
+import java.nio.file.Files
+import java.util.*
plugins {
- id("com.github.johnrengelman.shadow") version("2.0.4")
-}
-
-publishing {
- publications {
- (findByName("mavenJava") as MavenPublication).artifact(tasks.findByName("shadowJar")!!)
- }
+ id("com.github.johnrengelman.shadow") version ("7.0.0")
}
tasks.withType {
@@ -18,6 +15,47 @@ tasks.withType {
relocate("org.jetbrains", "com.github.shynixn.structureblocklib.lib.org.jetbrains")
}
+tasks.register("pluginJar", Exec::class.java) {
+ dependsOn("shadowJar")
+ workingDir = buildDir
+
+ if (!workingDir.exists()) {
+ workingDir.mkdir();
+ }
+
+ val folder = File(workingDir, "mapping")
+
+ if (!folder.exists()) {
+ folder.mkdir()
+ }
+
+ val file = File(folder, "SpecialSources.jar")
+
+ if (!file.exists()) {
+ URL("https://repo.maven.apache.org/maven2/net/md-5/SpecialSource/1.10.0/SpecialSource-1.10.0-shaded.jar").openStream()
+ .use {
+ Files.copy(it, file.toPath())
+ }
+ }
+
+ val shadowJar = tasks.findByName("shadowJar")!! as ShadowJar
+ val obfArchiveName = "${shadowJar.baseName}-${shadowJar.version}-obfuscated.${shadowJar.extension}"
+ val archiveName = "${shadowJar.baseName}-${shadowJar.version}.${shadowJar.extension}"
+ val sourceJarFile = File(buildDir, "libs/" + shadowJar.archiveName)
+ val obfJarFile = File(buildDir, "libs/$obfArchiveName")
+ val targetJarFile = File(buildDir, "libs/$archiveName")
+
+ val obsMapping =
+ "java -jar ${file.absolutePath} -i \"$sourceJarFile\" -o \"$obfJarFile\" -m \"\$HOME/.m2/repository/org/spigotmc/minecraft-server/1.17-R0.1-SNAPSHOT/minecraft-server-1.17-R0.1-SNAPSHOT-maps-mojang.txt\" --reverse" +
+ "&& java -jar ${file.absolutePath} -i \"$obfJarFile\" -o \"$targetJarFile\" -m \"\$HOME/.m2/repository/org/spigotmc/minecraft-server/1.17-R0.1-SNAPSHOT/minecraft-server-1.17-R0.1-SNAPSHOT-maps-spigot.csrg\""
+
+ if (System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("windows")) {
+ commandLine = listOf("cmd", "/c", obsMapping.replace("\$HOME", "%userprofile%"))
+ } else {
+ commandLine = listOf("sh", "-c", obsMapping)
+ }
+}
+
dependencies {
implementation(project(":structureblocklib-api"))
implementation(project(":structureblocklib-core"))
@@ -29,10 +67,9 @@ dependencies {
implementation(project(":structureblocklib-bukkit-core:bukkit-nms-113R2"))
implementation(project(":structureblocklib-bukkit-core:bukkit-nms-114R1"))
implementation(project(":structureblocklib-bukkit-core:bukkit-nms-115R1"))
- implementation(project(":structureblocklib-bukkit-core:bukkit-nms-116R1"))
- implementation(project(":structureblocklib-bukkit-core:bukkit-nms-116R2"))
implementation(project(":structureblocklib-bukkit-core:bukkit-nms-116R3"))
+ implementation(project(":structureblocklib-bukkit-core:bukkit-nms-117R1"))
- compileOnly("org.spigotmc:spigot114R1:1.14.4-R1.0")
- testCompile("org.spigotmc:spigot112R1:1.12.0-R1.0")
+ compileOnly("org.spigotmc:spigot:1.14.4-R0.1-SNAPSHOT")
+ testCompile("org.spigotmc:spigot:1.12-R0.1-SNAPSHOT")
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-109R2/build.gradle.kts b/structureblocklib-bukkit-core/bukkit-nms-109R2/build.gradle.kts
index 219c991c..60c0f37e 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-109R2/build.gradle.kts
+++ b/structureblocklib-bukkit-core/bukkit-nms-109R2/build.gradle.kts
@@ -2,6 +2,6 @@ dependencies {
implementation(project(":structureblocklib-api"))
implementation(project(":structureblocklib-core"))
implementation(project(":structureblocklib-bukkit-api"))
- compileOnly("org.spigotmc:spigot19R2:1.9.4-R2.0")
- testCompile("org.spigotmc:spigot19R2:1.9.4-R2.0")
+ compileOnly("org.spigotmc:spigot:1.9.4-R0.1-SNAPSHOT")
+ testCompile("org.spigotmc:spigot:1.9.4-R0.1-SNAPSHOT")
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-109R2/src/test/java/unittest/TStructureSerializationServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-109R2/src/test/java/unittest/TStructureSerializationServiceImpl.java
index d32e8648..7e621477 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-109R2/src/test/java/unittest/TStructureSerializationServiceImpl.java
+++ b/structureblocklib-bukkit-core/bukkit-nms-109R2/src/test/java/unittest/TStructureSerializationServiceImpl.java
@@ -25,15 +25,17 @@ public void serialize_ValidDefinedStructure_ShouldCorrectlySerialize() {
DefinedStructure definedStructure = Mockito.mock(DefinedStructure.class);
Mockito.when(definedStructure.a(Mockito.any(NBTTagCompound.class)))
.thenReturn(new NBTTagCompound());
- String expected = "H4sIAAAAAAAAAONiYGAAAHg/+U4EAAAA";
+ byte[] expected = new byte[]{
+ 31, -117, 8, 0, 0, 0, 0, 0, 0, -1, -29, 98, 96, 96, 0, 0, 120, 63, -7, 78, 4, 0, 0, 0
+ };
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
// Act
classUnderTest.serialize(definedStructure, outputStream);
- String actual = Base64.getEncoder().encodeToString(outputStream.toByteArray());
+ byte[] actual = outputStream.toByteArray();
// Assert.
- Assertions.assertEquals(expected, actual);
+ Assertions.assertArrayEquals(expected, actual);
} catch (IOException e) {
Assertions.fail(e);
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-110R1/build.gradle.kts b/structureblocklib-bukkit-core/bukkit-nms-110R1/build.gradle.kts
index c9cebc47..02a4975e 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-110R1/build.gradle.kts
+++ b/structureblocklib-bukkit-core/bukkit-nms-110R1/build.gradle.kts
@@ -2,6 +2,6 @@ dependencies {
implementation(project(":structureblocklib-api"))
implementation(project(":structureblocklib-core"))
implementation(project(":structureblocklib-bukkit-api"))
- compileOnly("org.spigotmc:spigot110R1:1.10.2-R1.0")
- testCompile("org.spigotmc:spigot110R1:1.10.2-R1.0")
+ compileOnly("org.spigotmc:spigot:1.10.2-R0.1-SNAPSHOT")
+ testCompile("org.spigotmc:spigot:1.10.2-R0.1-SNAPSHOT")
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-110R1/src/test/java/unittest/TStructureSerializationServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-110R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
index 2b121592..13f3d487 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-110R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
+++ b/structureblocklib-bukkit-core/bukkit-nms-110R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
@@ -24,15 +24,17 @@ public void serialize_ValidDefinedStructure_ShouldCorrectlySerialize() {
DefinedStructure definedStructure = Mockito.mock(DefinedStructure.class);
Mockito.when(definedStructure.a(Mockito.any(NBTTagCompound.class)))
.thenReturn(new NBTTagCompound());
- String expected = "H4sIAAAAAAAAAONiYGAAAHg/+U4EAAAA";
+ byte[] expected = new byte[]{
+ 31, -117, 8, 0, 0, 0, 0, 0, 0, -1, -29, 98, 96, 96, 0, 0, 120, 63, -7, 78, 4, 0, 0, 0
+ };
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
// Act
classUnderTest.serialize(definedStructure, outputStream);
- String actual = Base64.getEncoder().encodeToString(outputStream.toByteArray());
+ byte[] actual = outputStream.toByteArray();
// Assert.
- Assertions.assertEquals(expected, actual);
+ Assertions.assertArrayEquals(expected, actual);
} catch (IOException e) {
Assertions.fail(e);
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-111R1/build.gradle.kts b/structureblocklib-bukkit-core/bukkit-nms-111R1/build.gradle.kts
index e5dc3001..11b215e2 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-111R1/build.gradle.kts
+++ b/structureblocklib-bukkit-core/bukkit-nms-111R1/build.gradle.kts
@@ -2,6 +2,6 @@ dependencies {
implementation(project(":structureblocklib-api"))
implementation(project(":structureblocklib-core"))
implementation(project(":structureblocklib-bukkit-api"))
- compileOnly("org.spigotmc:spigot111R1:1.11.0-R1.0")
- testCompile("org.spigotmc:spigot111R1:1.11.0-R1.0")
+ compileOnly("org.spigotmc:spigot:1.11-R0.1-SNAPSHOT")
+ testCompile("org.spigotmc:spigot:1.11-R0.1-SNAPSHOT")
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-111R1/src/test/java/unittest/TStructureSerializationServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-111R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
index 35b1ffaa..5f0cc6b8 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-111R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
+++ b/structureblocklib-bukkit-core/bukkit-nms-111R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
@@ -24,15 +24,17 @@ public void serialize_ValidDefinedStructure_ShouldCorrectlySerialize() {
DefinedStructure definedStructure = Mockito.mock(DefinedStructure.class);
Mockito.when(definedStructure.a(Mockito.any(NBTTagCompound.class)))
.thenReturn(new NBTTagCompound());
- String expected = "H4sIAAAAAAAAAONiYGAAAHg/+U4EAAAA";
+ byte[] expected = new byte[]{
+ 31, -117, 8, 0, 0, 0, 0, 0, 0, -1, -29, 98, 96, 96, 0, 0, 120, 63, -7, 78, 4, 0, 0, 0
+ };
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
// Act
classUnderTest.serialize(definedStructure, outputStream);
- String actual = Base64.getEncoder().encodeToString(outputStream.toByteArray());
+ byte[] actual = outputStream.toByteArray();
// Assert.
- Assertions.assertEquals(expected, actual);
+ Assertions.assertArrayEquals(expected, actual);
} catch (IOException e) {
Assertions.fail(e);
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-112R1/build.gradle.kts b/structureblocklib-bukkit-core/bukkit-nms-112R1/build.gradle.kts
index 430e303e..f4702a6a 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-112R1/build.gradle.kts
+++ b/structureblocklib-bukkit-core/bukkit-nms-112R1/build.gradle.kts
@@ -2,6 +2,6 @@ dependencies {
implementation(project(":structureblocklib-api"))
implementation(project(":structureblocklib-core"))
implementation(project(":structureblocklib-bukkit-api"))
- compileOnly("org.spigotmc:spigot112R1:1.12.0-R1.0")
- testCompile("org.spigotmc:spigot112R1:1.12.0-R1.0")
+ compileOnly("org.spigotmc:spigot:1.12-R0.1-SNAPSHOT")
+ testCompile("org.spigotmc:spigot:1.12-R0.1-SNAPSHOT")
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-112R1/src/test/java/unittest/TStructureSerializationServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-112R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
index 7a3786ca..dac8ed0c 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-112R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
+++ b/structureblocklib-bukkit-core/bukkit-nms-112R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
@@ -24,15 +24,17 @@ public void serialize_ValidDefinedStructure_ShouldCorrectlySerialize() {
DefinedStructure definedStructure = Mockito.mock(DefinedStructure.class);
Mockito.when(definedStructure.a(Mockito.any(NBTTagCompound.class)))
.thenReturn(new NBTTagCompound());
- String expected = "H4sIAAAAAAAAAONiYGAAAHg/+U4EAAAA";
+ byte[] expected = new byte[]{
+ 31, -117, 8, 0, 0, 0, 0, 0, 0, -1, -29, 98, 96, 96, 0, 0, 120, 63, -7, 78, 4, 0, 0, 0
+ };
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
// Act
classUnderTest.serialize(definedStructure, outputStream);
- String actual = Base64.getEncoder().encodeToString(outputStream.toByteArray());
+ byte[] actual = outputStream.toByteArray();
// Assert.
- Assertions.assertEquals(expected, actual);
+ Assertions.assertArrayEquals(expected, actual);
} catch (IOException e) {
Assertions.fail(e);
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-113R2/build.gradle.kts b/structureblocklib-bukkit-core/bukkit-nms-113R2/build.gradle.kts
index 75bb8b1a..32db3345 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-113R2/build.gradle.kts
+++ b/structureblocklib-bukkit-core/bukkit-nms-113R2/build.gradle.kts
@@ -2,6 +2,6 @@ dependencies {
implementation(project(":structureblocklib-api"))
implementation(project(":structureblocklib-core"))
implementation(project(":structureblocklib-bukkit-api"))
- compileOnly("org.spigotmc:spigot113R2:1.13.2-R2.0")
- testCompile("org.spigotmc:spigot113R2:1.13.2-R2.0")
+ compileOnly("org.spigotmc:spigot:1.13.2-R0.1-SNAPSHOT")
+ testCompile("org.spigotmc:spigot:1.13.2-R0.1-SNAPSHOT")
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-113R2/src/test/java/unittest/TStructureSerializationServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-113R2/src/test/java/unittest/TStructureSerializationServiceImpl.java
index 6bf885f1..1a6a6ab3 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-113R2/src/test/java/unittest/TStructureSerializationServiceImpl.java
+++ b/structureblocklib-bukkit-core/bukkit-nms-113R2/src/test/java/unittest/TStructureSerializationServiceImpl.java
@@ -24,15 +24,17 @@ public void serialize_ValidDefinedStructure_ShouldCorrectlySerialize() {
DefinedStructure definedStructure = Mockito.mock(DefinedStructure.class);
Mockito.when(definedStructure.a(Mockito.any(NBTTagCompound.class)))
.thenReturn(new NBTTagCompound());
- String expected = "H4sIAAAAAAAAAONiYGAAAHg/+U4EAAAA";
+ byte[] expected = new byte[]{
+ 31, -117, 8, 0, 0, 0, 0, 0, 0, -1, -29, 98, 96, 96, 0, 0, 120, 63, -7, 78, 4, 0, 0, 0
+ };
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
// Act
classUnderTest.serialize(definedStructure, outputStream);
- String actual = Base64.getEncoder().encodeToString(outputStream.toByteArray());
+ byte[] actual = outputStream.toByteArray();
// Assert.
- Assertions.assertEquals(expected, actual);
+ Assertions.assertArrayEquals(expected, actual);
} catch (IOException e) {
Assertions.fail(e);
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-114R1/build.gradle.kts b/structureblocklib-bukkit-core/bukkit-nms-114R1/build.gradle.kts
index 968d7696..5da5bb41 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-114R1/build.gradle.kts
+++ b/structureblocklib-bukkit-core/bukkit-nms-114R1/build.gradle.kts
@@ -2,6 +2,6 @@ dependencies {
implementation(project(":structureblocklib-api"))
implementation(project(":structureblocklib-core"))
implementation(project(":structureblocklib-bukkit-api"))
- compileOnly("org.spigotmc:spigot114R1:1.14.4-R1.0")
- testCompile("org.spigotmc:spigot114R1:1.14.4-R1.0")
+ compileOnly("org.spigotmc:spigot:1.14.4-R0.1-SNAPSHOT")
+ testCompile("org.spigotmc:spigot:1.14.4-R0.1-SNAPSHOT")
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-114R1/src/test/java/unittest/TStructureSerializationServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-114R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
index 4f391c9a..50ee3904 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-114R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
+++ b/structureblocklib-bukkit-core/bukkit-nms-114R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
@@ -24,15 +24,17 @@ public void serialize_ValidDefinedStructure_ShouldCorrectlySerialize() {
DefinedStructure definedStructure = Mockito.mock(DefinedStructure.class);
Mockito.when(definedStructure.a(Mockito.any(NBTTagCompound.class)))
.thenReturn(new NBTTagCompound());
- String expected = "H4sIAAAAAAAAAONiYGAAAHg/+U4EAAAA";
+ byte[] expected = new byte[]{
+ 31, -117, 8, 0, 0, 0, 0, 0, 0, -1, -29, 98, 96, 96, 0, 0, 120, 63, -7, 78, 4, 0, 0, 0
+ };
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
// Act
classUnderTest.serialize(definedStructure, outputStream);
- String actual = Base64.getEncoder().encodeToString(outputStream.toByteArray());
+ byte[] actual = outputStream.toByteArray();
// Assert.
- Assertions.assertEquals(expected, actual);
+ Assertions.assertArrayEquals(expected, actual);
} catch (IOException e) {
Assertions.fail(e);
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-115R1/build.gradle.kts b/structureblocklib-bukkit-core/bukkit-nms-115R1/build.gradle.kts
index 806c7691..3768fe70 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-115R1/build.gradle.kts
+++ b/structureblocklib-bukkit-core/bukkit-nms-115R1/build.gradle.kts
@@ -2,6 +2,6 @@ dependencies {
implementation(project(":structureblocklib-api"))
implementation(project(":structureblocklib-core"))
implementation(project(":structureblocklib-bukkit-api"))
- compileOnly("org.spigotmc:spigot115R1:1.15.0-R1.0")
- testCompile("org.spigotmc:spigot115R1:1.15.0-R1.0")
+ compileOnly("org.spigotmc:spigot:1.15-R0.1-SNAPSHOT")
+ testCompile("org.spigotmc:spigot:1.15-R0.1-SNAPSHOT")
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-115R1/src/test/java/unittest/TStructureSerializationServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-115R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
index 6496f8e7..0e0a255a 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-115R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
+++ b/structureblocklib-bukkit-core/bukkit-nms-115R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
@@ -24,15 +24,17 @@ public void serialize_ValidDefinedStructure_ShouldCorrectlySerialize() {
DefinedStructure definedStructure = Mockito.mock(DefinedStructure.class);
Mockito.when(definedStructure.a(Mockito.any(NBTTagCompound.class)))
.thenReturn(new NBTTagCompound());
- String expected = "H4sIAAAAAAAAAONiYGAAAHg/+U4EAAAA";
+ byte[] expected = new byte[]{
+ 31, -117, 8, 0, 0, 0, 0, 0, 0, -1, -29, 98, 96, 96, 0, 0, 120, 63, -7, 78, 4, 0, 0, 0
+ };
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
// Act
classUnderTest.serialize(definedStructure, outputStream);
- String actual = Base64.getEncoder().encodeToString(outputStream.toByteArray());
+ byte[] actual = outputStream.toByteArray();
// Assert.
- Assertions.assertEquals(expected, actual);
+ Assertions.assertArrayEquals(expected, actual);
} catch (IOException e) {
Assertions.fail(e);
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1/StructureSerializationServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1/StructureSerializationServiceImpl.java
deleted file mode 100644
index 90c33818..00000000
--- a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1/StructureSerializationServiceImpl.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.github.shynixn.structureblocklib.bukkit.v1_16_R1;
-
-import com.github.shynixn.structureblocklib.api.service.StructureSerializationService;
-import net.minecraft.server.v1_16_R1.DefinedStructure;
-import net.minecraft.server.v1_16_R1.NBTCompressedStreamTools;
-import net.minecraft.server.v1_16_R1.NBTTagCompound;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * Serialization service.
- */
-public class StructureSerializationServiceImpl implements StructureSerializationService {
- /**
- * Deserializes the {@link InputStream} to an NMS handle of DefinedStructure.
- * This call is blocking.
- *
- * @param inputStream Opened inputStream. Does not close the stream after processing.
- * @return A new NMS instance of DefinedStructure.
- */
- @Override
- public Object deSerialize(InputStream inputStream) throws IOException {
- NBTTagCompound nbttagcompound = NBTCompressedStreamTools.a(inputStream);
- DefinedStructure var4 = new DefinedStructure();
- var4.b(nbttagcompound);
- return var4;
- }
-
- /**
- * Serializes the NMS handle of DefinedStructure to an {@link OutputStream}.
- * This call is blocking.
- *
- * @param definedStructure NMS handle.
- * @param outputStream Opened outputStream. Does not close the stream after processing.
- */
- @Override
- public void serialize(Object definedStructure, OutputStream outputStream) throws IOException {
- if (!(definedStructure instanceof DefinedStructure)) {
- throw new IllegalArgumentException("DefinedStructure has to be an NMS handle!");
- }
-
- NBTTagCompound nbttagcompound = (((DefinedStructure) definedStructure)).a(new NBTTagCompound());
- NBTCompressedStreamTools.a(nbttagcompound, outputStream);
- }
-}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1/StructureWorldServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1/StructureWorldServiceImpl.java
deleted file mode 100644
index aedef8dc..00000000
--- a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1/StructureWorldServiceImpl.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.github.shynixn.structureblocklib.bukkit.v1_16_R1;
-
-import com.github.shynixn.structureblocklib.api.entity.StructurePlaceMeta;
-import com.github.shynixn.structureblocklib.api.entity.StructureReadMeta;
-import com.github.shynixn.structureblocklib.api.service.StructureWorldService;
-import com.github.shynixn.structureblocklib.api.service.TypeConversionService;
-import org.bukkit.Bukkit;
-import net.minecraft.server.v1_16_R1.*;
-import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
-
-import java.util.Random;
-
-/**
- * Implementation to interact with structures in the world.
- */
-public class StructureWorldServiceImpl implements StructureWorldService {
- private final TypeConversionService conversionService;
-
- /**
- * Creates a new service with dependencies.
- *
- * @param conversionService dependency.
- */
- public StructureWorldServiceImpl(TypeConversionService conversionService) {
- this.conversionService = conversionService;
- }
-
- /**
- * Places the blocks in the world defined by the given structure.
- *
- * @param meta Meta data to describe the placement.
- * @param structure NMS structure.
- */
- @Override
- public void placeStructureToWorld(StructurePlaceMeta meta, Object structure) throws Exception {
- if (!(structure instanceof DefinedStructure)) {
- throw new IllegalArgumentException("DefinedStructure has to be an NMS handle!");
- }
-
- DefinedStructure definedStructure = (DefinedStructure) structure;
- World world = ((CraftWorld) Bukkit.getWorld(meta.getLocation().getWorldName())).getHandle();
- BlockPosition cornerBlock = new BlockPosition((int) meta.getLocation().getX(), (int) meta.getLocation().getY(), (int) meta.getLocation().getZ());
- DefinedStructureInfo info = new DefinedStructureInfo();
- info.a(!meta.isIncludeEntitiesEnabled());
- info.a((EnumBlockMirror) conversionService.convertToMirrorHandle(meta.getMirrorType()));
- info.a((EnumBlockRotation) conversionService.convertToRotationHandle(meta.getRotationType()));
-
- if (meta.getIntegrity() < 1.0F) {
- info.b();
- float rotation = MathHelper.a(meta.getIntegrity(), 0.0F, 1.0F);
- DefinedStructureProcessorRotation rotationProcessor = new DefinedStructureProcessorRotation(rotation);
- Random random = new Random();
-
- if (meta.getSeed() != 0L) {
- random = new Random(meta.getSeed());
- }
-
- info.a(rotationProcessor);
- info.a(random);
- }
-
- definedStructure.a(world, cornerBlock, info, new Random());
- }
-
- /**
- * Reads the blocks in the world into an NMS Structure definition.
- *
- * @param meta Meta data to describe the block selection.
- * @return A new NMS Structure definition.
- */
- @Override
- public Object readStructureFromWorld(StructureReadMeta meta) throws Exception {
- World world = ((CraftWorld) Bukkit.getWorld(meta.getLocation().getWorldName())).getHandle();
- BlockPosition cornerBlock = new BlockPosition((int) meta.getLocation().getX(), (int) meta.getLocation().getY(), (int) meta.getLocation().getZ());
- BlockPosition offsetBlock = new BlockPosition((int) meta.getOffset().getX(), (int) meta.getOffset().getY(), (int) meta.getOffset().getZ());
- Block structureVoid = (Block) Blocks.class.getDeclaredField(meta.getStructureVoidTypeName()).get(null);
-
- DefinedStructure definedStructure = new DefinedStructure();
- definedStructure.a(world, cornerBlock, offsetBlock, meta.isIncludeEntitiesEnabled(), structureVoid);
- definedStructure.a(meta.getAuthor());
- return definedStructure;
- }
-}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/test/java/unittest/TTypeConversionServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-116R1/src/test/java/unittest/TTypeConversionServiceImpl.java
deleted file mode 100644
index 84246091..00000000
--- a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/test/java/unittest/TTypeConversionServiceImpl.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package unittest;
-
-import com.github.shynixn.structureblocklib.api.enumeration.StructureMirror;
-import com.github.shynixn.structureblocklib.api.enumeration.StructureMode;
-import com.github.shynixn.structureblocklib.api.enumeration.StructureRotation;
-import com.github.shynixn.structureblocklib.api.service.TypeConversionService;
-import com.github.shynixn.structureblocklib.bukkit.v1_16_R1.TypeConversionServiceImpl;
-import net.minecraft.server.v1_16_R1.BlockPropertyStructureMode;
-import net.minecraft.server.v1_16_R1.EnumBlockMirror;
-import net.minecraft.server.v1_16_R1.EnumBlockRotation;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-public class TTypeConversionServiceImpl {
- /**
- * Given StructureMirror
- * when convert is called
- * then value should be correctly converted.
- */
- @Test
- public void convert_StructureMirror_ShouldCorrectlyConvert() {
- // Arrange
- TypeConversionService conversionService = createWithDependencies();
-
- // Assert
- Assertions.assertEquals(EnumBlockMirror.LEFT_RIGHT, conversionService.convertToMirrorHandle(StructureMirror.LEFT_RIGHT));
- Assertions.assertEquals(EnumBlockMirror.FRONT_BACK, conversionService.convertToMirrorHandle(StructureMirror.FRONT_BACK));
- Assertions.assertEquals(EnumBlockMirror.NONE, conversionService.convertToMirrorHandle(StructureMirror.NONE));
- Assertions.assertEquals(StructureMirror.LEFT_RIGHT, conversionService.convertToStructureMirror(EnumBlockMirror.LEFT_RIGHT));
- Assertions.assertEquals(StructureMirror.FRONT_BACK, conversionService.convertToStructureMirror(EnumBlockMirror.FRONT_BACK));
- Assertions.assertEquals(StructureMirror.NONE, conversionService.convertToStructureMirror(EnumBlockMirror.NONE));
- }
-
- /**
- * Given StructureRotation
- * when convert is called
- * then value should be correctly converted.
- */
- @Test
- public void convert_StructureRotation_ShouldCorrectlyConvert() {
- // Arrange
- TypeConversionService conversionService = createWithDependencies();
-
- // Assert
- Assertions.assertEquals(EnumBlockRotation.CLOCKWISE_90, conversionService.convertToRotationHandle(StructureRotation.ROTATION_90));
- Assertions.assertEquals(EnumBlockRotation.CLOCKWISE_180, conversionService.convertToRotationHandle(StructureRotation.ROTATION_180));
- Assertions.assertEquals(EnumBlockRotation.COUNTERCLOCKWISE_90, conversionService.convertToRotationHandle(StructureRotation.ROTATION_270));
- Assertions.assertEquals(EnumBlockRotation.NONE, conversionService.convertToRotationHandle(StructureRotation.NONE));
- Assertions.assertEquals(StructureRotation.ROTATION_90, conversionService.convertToStructureRotation(EnumBlockRotation.CLOCKWISE_90));
- Assertions.assertEquals(StructureRotation.ROTATION_180, conversionService.convertToStructureRotation(EnumBlockRotation.CLOCKWISE_180));
- Assertions.assertEquals(StructureRotation.ROTATION_270, conversionService.convertToStructureRotation(EnumBlockRotation.COUNTERCLOCKWISE_90));
- Assertions.assertEquals(StructureRotation.NONE, conversionService.convertToStructureRotation(EnumBlockRotation.NONE));
- }
-
- /**
- * Given StructureMode
- * when convert is called
- * then value should be correctly converted.
- */
- @Test
- public void convert_StructureMode_ShouldCorrectlyConvert() {
- // Arrange
- TypeConversionService conversionService = createWithDependencies();
-
- // Assert
- Assertions.assertEquals(BlockPropertyStructureMode.CORNER, conversionService.convertToStructureModeHandle(StructureMode.CORNER));
- Assertions.assertEquals(BlockPropertyStructureMode.SAVE, conversionService.convertToStructureModeHandle(StructureMode.SAVE));
- Assertions.assertEquals(BlockPropertyStructureMode.DATA, conversionService.convertToStructureModeHandle(StructureMode.DATA));
- Assertions.assertEquals(BlockPropertyStructureMode.LOAD, conversionService.convertToStructureModeHandle(StructureMode.LOAD));
- Assertions.assertEquals(StructureMode.CORNER, conversionService.convertToStructureMode(BlockPropertyStructureMode.CORNER));
- Assertions.assertEquals(StructureMode.DATA, conversionService.convertToStructureMode(BlockPropertyStructureMode.DATA));
- Assertions.assertEquals(StructureMode.SAVE, conversionService.convertToStructureMode(BlockPropertyStructureMode.SAVE));
- Assertions.assertEquals(StructureMode.LOAD, conversionService.convertToStructureMode(BlockPropertyStructureMode.LOAD));
- }
-
- private TypeConversionService createWithDependencies() {
- return new TypeConversionServiceImpl();
- }
-}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R2/build.gradle.kts b/structureblocklib-bukkit-core/bukkit-nms-116R2/build.gradle.kts
deleted file mode 100644
index 06c79ee3..00000000
--- a/structureblocklib-bukkit-core/bukkit-nms-116R2/build.gradle.kts
+++ /dev/null
@@ -1,7 +0,0 @@
-dependencies {
- implementation(project(":structureblocklib-api"))
- implementation(project(":structureblocklib-core"))
- implementation(project(":structureblocklib-bukkit-api"))
- compileOnly("org.spigotmc:spigot116R2:1.16.2-R2.0")
- testCompile("org.spigotmc:spigot116R2:1.16.2-R2.0")
-}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/CraftStructureBlock.java b/structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/CraftStructureBlock.java
deleted file mode 100644
index 8297cebf..00000000
--- a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/CraftStructureBlock.java
+++ /dev/null
@@ -1,424 +0,0 @@
-package com.github.shynixn.structureblocklib.bukkit.v1_16_R2;
-
-import com.github.shynixn.structureblocklib.api.bukkit.block.StructureBlockData;
-import com.github.shynixn.structureblocklib.api.bukkit.block.StructureBlockLoad;
-import com.github.shynixn.structureblocklib.api.bukkit.block.StructureBlockSave;
-import com.github.shynixn.structureblocklib.api.entity.StructureLoaderAbstract;
-import com.github.shynixn.structureblocklib.api.entity.StructureSaverAbstract;
-import com.github.shynixn.structureblocklib.api.enumeration.StructureMirror;
-import com.github.shynixn.structureblocklib.api.enumeration.StructureMode;
-import com.github.shynixn.structureblocklib.api.enumeration.StructureRotation;
-import com.github.shynixn.structureblocklib.api.service.TypeConversionService;
-import com.github.shynixn.structureblocklib.core.block.StructureBlockAbstractImpl;
-import org.bukkit.Location;
-import org.bukkit.block.Block;
-import net.minecraft.server.v1_16_R2.*;
-import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
-import org.bukkit.craftbukkit.v1_16_R2.block.CraftBlockState;
-import org.bukkit.util.Vector;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-public class CraftStructureBlock extends CraftBlockState implements StructureBlockData, StructureBlockSave, StructureBlockLoad {
- public StructureBlockAbstractImpl internalBlock;
- public TypeConversionService conversionService;
- public TileEntityStructure tileEntityStructure;
-
- /**
- * Creates a new instance with dependencies.
- *
- * @param structure dependency.
- * @param block dependency.
- */
- public CraftStructureBlock(StructureBlockAbstractImpl structure, TypeConversionService conversionService, Block block) {
- super(block);
- final CraftWorld world = (CraftWorld) block.getWorld();
- this.internalBlock = structure;
- this.conversionService = conversionService;
- this.tileEntityStructure = (TileEntityStructure) world.getHandle().getTileEntity(new BlockPosition(this.getX(), this.getY(), this.getZ()));
-
- if (tileEntityStructure == null) {
- throw new IllegalArgumentException("The block at " + world.getName() + " " + this.getX() + " " + this.getY() + " " + this.getZ() + " is not a StructureBlock.");
- }
-
- NBTTagCompound compound = new NBTTagCompound();
- compound = this.tileEntityStructure.save(compound);
- this.setSaveName(compound.getString("name"));
- this.setAuthor(compound.getString("author"));
- this.setBlockNameMetaData(compound.getString("metadata"));
- this.setStructureLocation(new Location(block.getWorld(), compound.getInt("posX"), compound.getInt("posY"), compound.getInt("posZ")));
- this.setSizeX(compound.getInt("sizeX"));
- this.setSizeY(compound.getInt("sizeY"));
- this.setSizeZ(compound.getInt("sizeZ"));
- this.setIncludeEntities(!compound.getBoolean("ignoreEntities"));
- this.setBoundingBoxVisible(compound.getBoolean("showboundingbox"));
- this.setInvisibleBlocksEnabled(compound.getBoolean("showair"));
- this.setIntegrity(compound.getFloat("integrity"));
- this.setSeed(compound.getLong("seed"));
- this.setMirrorType(conversionService.convertToStructureMirror(EnumBlockMirror.valueOf(compound.getString("mirror"))));
- this.setRotationType(conversionService.convertToStructureRotation(EnumBlockRotation.valueOf(compound.getString("rotation"))));
- this.setStructureMode(conversionService.convertToStructureMode(BlockPropertyStructureMode.valueOf(compound.getString("mode"))));
- }
-
- /**
- * Updates the craft changes to the minecraft world.
- *
- * @param force force update.
- * @param applyPhysics apply physics.
- * @return success.
- */
- @Override
- public boolean update(boolean force, boolean applyPhysics) {
- final boolean result = super.update(force, applyPhysics);
- NBTTagCompound compound = new NBTTagCompound();
- compound = this.tileEntityStructure.save(compound);
- compound.setString("name", this.getSaveName());
- compound.setString("author", this.getAuthor());
- compound.setString("metadata", this.getBlockNameMetaData());
- compound.setInt("posX", this.getStructureLocation().getBlockX());
- compound.setInt("posY", this.getStructureLocation().getBlockY());
- compound.setInt("posZ", this.getStructureLocation().getBlockZ());
- compound.setInt("sizeX", this.getSizeX());
- compound.setInt("sizeY", this.getSizeY());
- compound.setInt("sizeZ", this.getSizeZ());
- compound.setBoolean("showboundingbox", this.isBoundingBoxVisible());
- compound.setBoolean("showair", this.isInvisibleBlocksEnabled());
- compound.setBoolean("ignoreEntities", !this.isIncludeEntitiesEnabled());
- compound.setFloat("integrity", this.getIntegrity());
- compound.setLong("seed", this.getSeed());
- compound.setString("rotation", conversionService.convertToRotationHandle(getRotationType()).toString());
- compound.setString("mirror", conversionService.convertToMirrorHandle(getMirrorType()).toString());
- compound.setString("mode", conversionService.convertToStructureModeHandle(getStructureMode()).toString());
- this.tileEntityStructure.load(null, compound);
- this.tileEntityStructure.update();
- return result;
- }
-
-
- /**
- * Sets the mirrorType of the structure when getting load.
- *
- * @param mirrorType mirrorType.
- */
- @Override
- public void setMirrorType(@NotNull StructureMirror mirrorType) {
- this.internalBlock.setMirrorType(mirrorType);
- }
-
- /**
- * Sets the rotation of the structure when getting load.
- *
- * @param rotation rotation.
- */
- @Override
- public void setRotationType(@NotNull StructureRotation rotation) {
- this.internalBlock.setRotationType(rotation);
- }
-
- /**
- * Returns the rotation of the structure when getting load.
- *
- * @return rotation.
- */
- @Override
- public @NotNull StructureRotation getRotationType() {
- return internalBlock.getRotationType();
- }
-
- /**
- * Returns the mirrorType of the structure when getting load.
- *
- * @return mirrorType.
- */
- @Override
- public @NotNull StructureMirror getMirrorType() {
- return internalBlock.getMirrorType();
- }
-
- /**
- * Sets the boundingBoxVisibility.
- *
- * @param visible visible.
- */
- @Override
- public void setBoundingBoxVisible(boolean visible) {
- this.internalBlock.setBoundingBoxVisible(visible);
- }
-
- /**
- * Returns if the boundingBox is visible.
- *
- * @return visible.
- */
- @Override
- public boolean isBoundingBoxVisible() {
- return this.internalBlock.isBoundingBoxVisible();
- }
-
- /**
- * Sets the integrity of the structure.
- *
- * @param integrity integrity.
- */
- @Override
- public void setIntegrity(float integrity) {
- this.internalBlock.setIntegrity(integrity);
- }
-
- /**
- * Returns the integrity of the structure.
- *
- * @return integrity.
- */
- @Override
- public float getIntegrity() {
- return this.internalBlock.getIntegrity();
- }
-
- /**
- * Sets the seed of the structure.
- *
- * @param seed seed.
- */
- @Override
- public void setSeed(long seed) {
- this.internalBlock.setSeed(seed);
- }
-
- /**
- * Returns the seed of the structure.
- *
- * @return seed.
- */
- @Override
- public long getSeed() {
- return internalBlock.getSeed();
- }
-
- /**
- * Sets the author of the structure.
- *
- * @param author author.
- */
- @Override
- public void setAuthor(@Nullable String author) {
- this.internalBlock.setAuthor(author);
- }
-
- /**
- * Returns the author of the structure.
- *
- * @return author.
- */
- @Override
- public @Nullable String getAuthor() {
- return this.internalBlock.getAuthor();
- }
-
- /**
- * Changes the location of the structure.
- *
- * @param location location.
- */
- @Override
- public void setStructureLocation(@Nullable Location location) {
- this.internalBlock.setStructureLocation(location);
- }
-
- /**
- * Returns the location of the structure.
- *
- * @return location.
- */
- @Nullable
- @Override
- public Location getStructureLocation() {
- return this.internalBlock.getStructureLocation();
- }
-
- /**
- * Should entities which may or may not be included in the
- * saved file be included in the loaded/saved structure.
- * Default false.
- *
- * @param flag flag.
- */
- @Override
- public void setIncludeEntities(boolean flag) {
- this.internalBlock.setIncludeEntities(flag);
- }
-
- /**
- * Should entities which may or may not be included in the
- * saved file be included in the loaded/saved structure.
- * Default false.
- *
- * @return false.
- */
- @Override
- public boolean isIncludeEntitiesEnabled() {
- return internalBlock.isIncludeEntitiesEnabled();
- }
-
- /**
- * Changes the size of the structure in X direction.
- *
- * @param sizeX sizeX.
- */
- @Override
- public void setSizeX(int sizeX) {
- this.internalBlock.setSizeX(sizeX);
- }
-
- /**
- * Changes the size of the structure in Y direction.
- *
- * @param sizeY sizeY.
- */
- @Override
- public void setSizeY(int sizeY) {
- this.internalBlock.setSizeY(sizeY);
- }
-
- /**
- * Changes the size of the structure in Z direction.
- *
- * @param sizeZ sizeZ.
- */
- @Override
- public void setSizeZ(int sizeZ) {
- this.internalBlock.setSizeZ(sizeZ);
- }
-
- /**
- * Returns the size of the structure in X direction.
- *
- * @return xSize.
- */
- @Override
- public int getSizeX() {
- return this.internalBlock.getSizeX();
- }
-
- /**
- * Returns the size of the structure in Y direction.
- *
- * @return ySize.
- */
- @Override
- public int getSizeY() {
- return internalBlock.getSizeY();
- }
-
- /**
- * Returns the size of the structure in Z direction.
- *
- * @return zSize.
- */
- @Override
- public int getSizeZ() {
- return internalBlock.getSizeZ();
- }
-
- /**
- * Sets the name of the save.
- *
- * @param name name.
- */
- @Override
- public void setSaveName(@Nullable String name) {
- this.internalBlock.setSaveName(name);
- }
-
- /**
- * Returns the name of the save.
- *
- * @return name.
- */
- @Override
- public @Nullable String getSaveName() {
- return internalBlock.getSaveName();
- }
-
- /**
- * Sets custom meta data. Please use the minecraft documentation to find out more.
- *
- * @param blockNameMetaData customMeta.
- */
- @Override
- public void setBlockNameMetaData(@Nullable String blockNameMetaData) {
- this.internalBlock.setBlockNameMetaData(blockNameMetaData);
- }
-
- /**
- * Returns the custom meta data.
- *
- * @return customMeta
- */
- @Override
- public @Nullable String getBlockNameMetaData() {
- return internalBlock.getBlockNameMetaData();
- }
-
- /**
- * Sets if invisibleBlocks should be visible.
- *
- * @param flag flag.
- */
- @Override
- public void setInvisibleBlocksEnabled(boolean flag) {
- this.internalBlock.setInvisibleBlocksEnabled(flag);
- }
-
- /**
- * Returns if invisibleBlocks are visible.
- *
- * @return visible
- */
- @Override
- public boolean isInvisibleBlocksEnabled() {
- return internalBlock.isInvisibleBlocksEnabled();
- }
-
- /**
- * Changes the type of the structureBlock.
- *
- * @param structureMode structureMode.
- */
- @Override
- public void setStructureMode(@NotNull StructureMode structureMode) {
- this.internalBlock.setStructureMode(structureMode);
- }
-
- /**
- * Returns the type of the structureBlock.
- *
- * @return structureMode.
- */
- @Override
- public @NotNull StructureMode getStructureMode() {
- return internalBlock.getStructureMode();
- }
-
- /**
- * Creates a new instance of {@link StructureLoaderAbstract} which
- * contains the current block properties.
- *
- * @return New instance.
- */
- @Override
- public @NotNull StructureLoaderAbstract loadStructure() {
- return internalBlock.loadStructure();
- }
-
- /**
- * Creates a new instance of {@link StructureSaverAbstract} which
- * contains the current block properties.
- *
- * @return New instance.
- */
- @Override
- public @NotNull StructureSaverAbstract saveStructure() {
- return internalBlock.saveStructure();
- }
-}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/StructureSerializationServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/StructureSerializationServiceImpl.java
deleted file mode 100644
index 2b645140..00000000
--- a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/StructureSerializationServiceImpl.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.github.shynixn.structureblocklib.bukkit.v1_16_R2;
-
-import com.github.shynixn.structureblocklib.api.service.StructureSerializationService;
-import net.minecraft.server.v1_16_R2.DefinedStructure;
-import net.minecraft.server.v1_16_R2.NBTCompressedStreamTools;
-import net.minecraft.server.v1_16_R2.NBTTagCompound;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * Serialization service.
- */
-public class StructureSerializationServiceImpl implements StructureSerializationService {
- /**
- * Deserializes the {@link InputStream} to an NMS handle of DefinedStructure.
- * This call is blocking.
- *
- * @param inputStream Opened inputStream. Does not close the stream after processing.
- * @return A new NMS instance of DefinedStructure.
- */
- @Override
- public Object deSerialize(InputStream inputStream) throws IOException {
- NBTTagCompound nbttagcompound = NBTCompressedStreamTools.a(inputStream);
- DefinedStructure var4 = new DefinedStructure();
- var4.b(nbttagcompound);
- return var4;
- }
-
- /**
- * Serializes the NMS handle of DefinedStructure to an {@link OutputStream}.
- * This call is blocking.
- *
- * @param definedStructure NMS handle.
- * @param outputStream Opened outputStream. Does not close the stream after processing.
- */
- @Override
- public void serialize(Object definedStructure, OutputStream outputStream) throws IOException {
- if (!(definedStructure instanceof DefinedStructure)) {
- throw new IllegalArgumentException("DefinedStructure has to be an NMS handle!");
- }
-
- NBTTagCompound nbttagcompound = (((DefinedStructure) definedStructure)).a(new NBTTagCompound());
- NBTCompressedStreamTools.a(nbttagcompound, outputStream);
- }
-}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/StructureWorldServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/StructureWorldServiceImpl.java
deleted file mode 100644
index b1b3ab93..00000000
--- a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/StructureWorldServiceImpl.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.github.shynixn.structureblocklib.bukkit.v1_16_R2;
-
-import com.github.shynixn.structureblocklib.api.entity.StructurePlaceMeta;
-import com.github.shynixn.structureblocklib.api.entity.StructureReadMeta;
-import com.github.shynixn.structureblocklib.api.service.StructureWorldService;
-import com.github.shynixn.structureblocklib.api.service.TypeConversionService;
-import org.bukkit.Bukkit;
-import net.minecraft.server.v1_16_R2.*;
-import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
-
-import java.util.Random;
-
-/**
- * Implementation to interact with structures in the world.
- */
-public class StructureWorldServiceImpl implements StructureWorldService {
- private final TypeConversionService conversionService;
-
- /**
- * Creates a new service with dependencies.
- *
- * @param conversionService dependency.
- */
- public StructureWorldServiceImpl(TypeConversionService conversionService) {
- this.conversionService = conversionService;
- }
-
- /**
- * Places the blocks in the world defined by the given structure.
- *
- * @param meta Meta data to describe the placement.
- * @param structure NMS structure.
- */
- @Override
- public void placeStructureToWorld(StructurePlaceMeta meta, Object structure) throws Exception {
- if (!(structure instanceof DefinedStructure)) {
- throw new IllegalArgumentException("DefinedStructure has to be an NMS handle!");
- }
-
- DefinedStructure definedStructure = (DefinedStructure) structure;
- World world = ((CraftWorld) Bukkit.getWorld(meta.getLocation().getWorldName())).getHandle();
- BlockPosition cornerBlock = new BlockPosition((int) meta.getLocation().getX(), (int) meta.getLocation().getY(), (int) meta.getLocation().getZ());
- DefinedStructureInfo info = new DefinedStructureInfo();
- info.a(!meta.isIncludeEntitiesEnabled());
- info.a((EnumBlockMirror) conversionService.convertToMirrorHandle(meta.getMirrorType()));
- info.a((EnumBlockRotation) conversionService.convertToRotationHandle(meta.getRotationType()));
-
- if (meta.getIntegrity() < 1.0F) {
- info.b();
- float rotation = MathHelper.a(meta.getIntegrity(), 0.0F, 1.0F);
- DefinedStructureProcessorRotation rotationProcessor = new DefinedStructureProcessorRotation(rotation);
- Random random = new Random();
-
- if (meta.getSeed() != 0L) {
- random = new Random(meta.getSeed());
- }
-
- info.a(rotationProcessor);
- info.a(random);
- }
-
- definedStructure.a((WorldAccess) world, cornerBlock, info, new Random());
- }
-
- /**
- * Reads the blocks in the world into an NMS Structure definition.
- *
- * @param meta Meta data to describe the block selection.
- * @return A new NMS Structure definition.
- */
- @Override
- public Object readStructureFromWorld(StructureReadMeta meta) throws Exception {
- World world = ((CraftWorld) Bukkit.getWorld(meta.getLocation().getWorldName())).getHandle();
- BlockPosition cornerBlock = new BlockPosition((int) meta.getLocation().getX(), (int) meta.getLocation().getY(), (int) meta.getLocation().getZ());
- BlockPosition offsetBlock = new BlockPosition((int) meta.getOffset().getX(), (int) meta.getOffset().getY(), (int) meta.getOffset().getZ());
- Block structureVoid = (Block) Blocks.class.getDeclaredField(meta.getStructureVoidTypeName()).get(null);
-
- DefinedStructure definedStructure = new DefinedStructure();
- definedStructure.a(world, cornerBlock, offsetBlock, meta.isIncludeEntitiesEnabled(), structureVoid);
- definedStructure.a(meta.getAuthor());
- return definedStructure;
- }
-}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/TypeConversionServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/TypeConversionServiceImpl.java
deleted file mode 100644
index 2d9b07c9..00000000
--- a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/TypeConversionServiceImpl.java
+++ /dev/null
@@ -1,130 +0,0 @@
-package com.github.shynixn.structureblocklib.bukkit.v1_16_R2;
-
-import com.github.shynixn.structureblocklib.api.enumeration.StructureMirror;
-import com.github.shynixn.structureblocklib.api.enumeration.StructureMode;
-import com.github.shynixn.structureblocklib.api.enumeration.StructureRotation;
-import com.github.shynixn.structureblocklib.api.service.TypeConversionService;
-import net.minecraft.server.v1_16_R2.BlockPropertyStructureMode;
-import net.minecraft.server.v1_16_R2.EnumBlockMirror;
-import net.minecraft.server.v1_16_R2.EnumBlockRotation;
-
-public class TypeConversionServiceImpl implements TypeConversionService {
- /**
- * Converts the given handle to a {@link StructureMode}.
- *
- * @param handle NMS handle.
- * @return {@link StructureMode}.
- */
- @Override
- public StructureMode convertToStructureMode(Object handle) {
- BlockPropertyStructureMode usageMode = (BlockPropertyStructureMode) handle;
- switch (usageMode) {
- case DATA:
- return StructureMode.DATA;
- case LOAD:
- return StructureMode.LOAD;
- case SAVE:
- return StructureMode.SAVE;
- default:
- return StructureMode.CORNER;
- }
- }
-
- /**
- * Converts the given handle to a {@link StructureMirror}.
- *
- * @param handle NMS handle.
- * @return {@link StructureMirror}.
- */
- @Override
- public StructureMirror convertToStructureMirror(Object handle) {
- EnumBlockMirror mirror = (EnumBlockMirror) handle;
- switch (mirror) {
- case FRONT_BACK:
- return StructureMirror.FRONT_BACK;
- case LEFT_RIGHT:
- return StructureMirror.LEFT_RIGHT;
- default:
- return StructureMirror.NONE;
- }
- }
-
- /**
- * Converts the given handle to a {@link StructureRotation}.
- *
- * @param handle NMS handle.
- * @return {@link StructureRotation}.
- */
- @Override
- public StructureRotation convertToStructureRotation(Object handle) {
- EnumBlockRotation rotation = (EnumBlockRotation) handle;
- switch (rotation) {
- case CLOCKWISE_90:
- return StructureRotation.ROTATION_90;
- case CLOCKWISE_180:
- return StructureRotation.ROTATION_180;
- case COUNTERCLOCKWISE_90:
- return StructureRotation.ROTATION_270;
- default:
- return StructureRotation.NONE;
- }
- }
-
- /**
- * Converts the given {@link StructureMode} to a handle.
- *
- * @param mode {@link StructureMode}.
- * @return NMS handle.
- */
- @Override
- public Object convertToStructureModeHandle(StructureMode mode) {
- switch (mode) {
- case SAVE:
- return BlockPropertyStructureMode.SAVE;
- case DATA:
- return BlockPropertyStructureMode.DATA;
- case LOAD:
- return BlockPropertyStructureMode.LOAD;
- default:
- return BlockPropertyStructureMode.CORNER;
- }
- }
-
- /**
- * Converts the given {@link StructureMirror} to a handle.
- *
- * @param mirror {@link StructureMirror}.
- * @return NMS handle.
- */
- @Override
- public Object convertToMirrorHandle(StructureMirror mirror) {
- switch (mirror) {
- case FRONT_BACK:
- return EnumBlockMirror.FRONT_BACK;
- case LEFT_RIGHT:
- return EnumBlockMirror.LEFT_RIGHT;
- default:
- return EnumBlockMirror.NONE;
- }
- }
-
- /**
- * Converts the given {@link StructureRotation} to a handle.
- *
- * @param rotation {@link StructureRotation}.
- * @return NMS handle.
- */
- @Override
- public Object convertToRotationHandle(StructureRotation rotation) {
- switch (rotation) {
- case ROTATION_90:
- return EnumBlockRotation.CLOCKWISE_90;
- case ROTATION_180:
- return EnumBlockRotation.CLOCKWISE_180;
- case ROTATION_270:
- return EnumBlockRotation.COUNTERCLOCKWISE_90;
- default:
- return EnumBlockRotation.NONE;
- }
- }
-}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/helper/MockedProxyService.java b/structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/helper/MockedProxyService.java
deleted file mode 100644
index fa09db3c..00000000
--- a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/helper/MockedProxyService.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package helper;
-
-import com.github.shynixn.structureblocklib.api.entity.Position;
-import com.github.shynixn.structureblocklib.api.enumeration.Version;
-import com.github.shynixn.structureblocklib.api.service.ProxyService;
-import com.github.shynixn.structureblocklib.core.entity.PositionImpl;
-import org.bukkit.Location;
-import org.bukkit.World;
-import org.bukkit.util.Vector;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.mockito.Mockito;
-
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-public class MockedProxyService implements ProxyService {
- private ExecutorService executor = Executors.newFixedThreadPool(1);
- public Queue concurrentList = new ConcurrentLinkedQueue();
-
- /**
- * Converts the given position to a location.
- *
- * @param position position.
- * @return location.
- */
- @Override
- public @Nullable L toLocation(@Nullable Position position) {
- return (L) new Location(Mockito.mock(World.class), position.getX(), position.getY(), position.getZ());
- }
-
- /**
- * Converts the given position to a vector.
- *
- * @param position position.
- * @return vector.
- */
- @Override
- public @Nullable V toVector(@Nullable Position position) {
- return (V) new Vector(position.getX(), position.getY(), position.getZ());
- }
-
- /**
- * Converts the given location to a position.
- *
- * @param location Location.
- * @return position.
- */
- @Override
- public @Nullable Position toPosition(@Nullable L location) {
- if (location == null) {
- return null;
- }
-
- Position position = new PositionImpl();
-
- if (location instanceof Location) {
- Location l = (Location) location;
- position.setWorldName(l.getWorld().getName());
- position.setX(l.getX());
- position.setY(l.getY());
- position.setZ(l.getZ());
- }
-
- if (location instanceof Vector) {
- Vector l = (Vector) location;
- position.setX(l.getX());
- position.setY(l.getY());
- position.setZ(l.getZ());
- }
-
- return position;
- }
-
- /**
- * Runs an async task.
- *
- * @param runnable Runnable.
- */
- @Override
- public void runAsyncTask(@NotNull Runnable runnable) {
- executor.submit(runnable);
- }
-
- /**
- * Runs a sync task.
- *
- * @param runnable Runnable.
- */
- @Override
- public void runSyncTask(@NotNull Runnable runnable) {
- concurrentList.add(runnable);
- }
-
- /**
- * Gets the running minecraft version.
- *
- * @return version.
- */
- @Override
- public Version getServerVersion() {
- return Version.VERSION_UNKNOWN;
- }
-}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/helper/MockedStructureWorldService.java b/structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/helper/MockedStructureWorldService.java
deleted file mode 100644
index 602b1591..00000000
--- a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/helper/MockedStructureWorldService.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package helper;
-
-import com.github.shynixn.structureblocklib.api.entity.StructurePlaceMeta;
-import com.github.shynixn.structureblocklib.api.entity.StructureReadMeta;
-import com.github.shynixn.structureblocklib.api.service.StructureWorldService;
-import net.minecraft.server.v1_16_R2.DefinedStructure;
-
-public class MockedStructureWorldService implements StructureWorldService {
- /**
- * Places the blocks in the world defined by the given structure.
- *
- * @param meta Meta data to describe the placement.
- * @param structure NMS structure.
- */
- @Override
- public void placeStructureToWorld(StructurePlaceMeta meta, Object structure) throws Exception {
- }
-
- /**
- * Reads the blocks in the world into an NMS Structure definition.
- *
- * @param meta Meta data to describe the block selection.
- * @return A new NMS Structure definition.
- */
- @Override
- public Object readStructureFromWorld(StructureReadMeta meta) throws Exception {
- return new DefinedStructure();
- }
-}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/integrationtest/CraftStructureBlockIT.java b/structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/integrationtest/CraftStructureBlockIT.java
deleted file mode 100644
index 70fd13b6..00000000
--- a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/integrationtest/CraftStructureBlockIT.java
+++ /dev/null
@@ -1,187 +0,0 @@
-package integrationtest;
-
-import com.github.shynixn.structureblocklib.api.entity.StructureLoaderAbstract;
-import com.github.shynixn.structureblocklib.api.entity.StructureSaverAbstract;
-import com.github.shynixn.structureblocklib.api.enumeration.StructureMirror;
-import com.github.shynixn.structureblocklib.api.enumeration.StructureMode;
-import com.github.shynixn.structureblocklib.api.enumeration.StructureRotation;
-import com.github.shynixn.structureblocklib.api.service.ProxyService;
-import com.github.shynixn.structureblocklib.api.service.StructureSerializationService;
-import com.github.shynixn.structureblocklib.api.service.StructureWorldService;
-import com.github.shynixn.structureblocklib.api.service.TypeConversionService;
-import com.github.shynixn.structureblocklib.bukkit.v1_16_R2.CraftStructureBlock;
-import com.github.shynixn.structureblocklib.bukkit.v1_16_R2.StructureSerializationServiceImpl;
-import com.github.shynixn.structureblocklib.bukkit.v1_16_R2.TypeConversionServiceImpl;
-import com.github.shynixn.structureblocklib.core.block.StructureBlockAbstractImpl;
-import com.github.shynixn.structureblocklib.core.entity.StructureLoaderAbstractImpl;
-import com.github.shynixn.structureblocklib.core.entity.StructureSaverAbstractImpl;
-import helper.MockedProxyService;
-import helper.MockedStructureWorldService;
-import net.minecraft.server.v1_16_R2.*;
-import org.bukkit.Location;
-import org.bukkit.Material;
-import org.bukkit.World;
-import org.bukkit.block.Block;
-import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
-import org.bukkit.craftbukkit.v1_16_R2.block.CraftBlock;
-import org.bukkit.util.Vector;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-
-public class CraftStructureBlockIT {
- /**
- * Given a structure block with a title entity structure including nbt tags
- * when creating a structure block
- * all nbt tags should be correctly retried.
- */
- // @Test Disabled because Jacoco patches the Mojang static methods to over sized methods
- // which lets Java crash. Run it without javacoco enabled
- public void create_NBTTags_ShouldCorrectlyRetrieve() {
- // Arrange
- MockedProxyService proxyService = new MockedProxyService();
- NBTTagCompound compound = new NBTTagCompound();
- compound.setString("author", "Mario");
- compound.setString("mirror", "LEFT_RIGHT");
- compound.setString("rotation", "CLOCKWISE_90");
- compound.setString("mode", "SAVE");
- compound.setString("name", "Thisismysavename");
- compound.setString("metadata", "Thisismetadata");
- compound.setInt("posX", 50);
- compound.setInt("posY", 550);
- compound.setInt("posZ", -30);
- compound.setInt("sizeX", 20);
- compound.setInt("sizeY", -40);
- compound.setInt("sizeZ", -70);
- compound.setBoolean("ignoreEntities", true);
- compound.setBoolean("showboundingbox", true);
- compound.setBoolean("showair", true);
- compound.setFloat("integrity", 0.4F);
- compound.setLong("seed", 50L);
-
- TileEntityStructure structure = Mockito.mock(TileEntityStructure.class);
- Mockito.when(structure.save(Mockito.any(NBTTagCompound.class))).thenReturn(compound);
-
- // Act
- CraftStructureBlock classUnderTest = createWithDependencies(proxyService, structure);
-
- // Assert
- Assertions.assertEquals(StructureMirror.LEFT_RIGHT, classUnderTest.getMirrorType());
- Assertions.assertEquals(StructureRotation.ROTATION_90, classUnderTest.getRotationType());
- Assertions.assertEquals(StructureMode.SAVE, classUnderTest.getStructureMode());
- Assertions.assertEquals("Mario", classUnderTest.getAuthor());
- Assertions.assertEquals("Thisismysavename", classUnderTest.getSaveName());
- Assertions.assertEquals("Thisismetadata", classUnderTest.getBlockNameMetaData());
- Assertions.assertEquals(50, classUnderTest.getStructureLocation().getBlockX());
- Assertions.assertEquals(550, classUnderTest.getStructureLocation().getBlockY());
- Assertions.assertEquals(-30, classUnderTest.getStructureLocation().getBlockZ());
- Assertions.assertEquals(20, classUnderTest.getSizeX());
- Assertions.assertEquals(-40, classUnderTest.getSizeY());
- Assertions.assertEquals(-70, classUnderTest.getSizeZ());
- Assertions.assertFalse(classUnderTest.isIncludeEntitiesEnabled());
- Assertions.assertTrue(classUnderTest.isBoundingBoxVisible());
- Assertions.assertTrue(classUnderTest.isInvisibleBlocksEnabled());
- Assertions.assertEquals(0.4F, classUnderTest.getIntegrity());
- Assertions.assertEquals(50L, classUnderTest.getSeed());
- }
-
- /**
- * Given a structure block with changed properties
- * when updating the minecraft world
- * all properties should be transferred as nbt tags.
- */
- // @Test Disabled because Jacoco patches the Mojang static methods to over sized methods
- // which lets Java crash. Run it without javacoco enabled
- public void update_ChangedStructureBlock_ShouldCorrectlyGenerateNBT() {
- // Arrange
- MockedProxyService proxyService = new MockedProxyService();
- NBTTagCompound input = new NBTTagCompound();
- input.setString("mirror", "LEFT_RIGHT");
- input.setString("rotation", "CLOCKWISE_90");
- input.setString("mode", "SAVE");
- TileEntityStructure structure = Mockito.mock(TileEntityStructure.class);
- Mockito.when(structure.save(Mockito.any(NBTTagCompound.class))).thenReturn(input);
- CraftStructureBlock classUnderTest = createWithDependencies(proxyService, structure);
- classUnderTest.setMirrorType(StructureMirror.LEFT_RIGHT);
- classUnderTest.setRotationType(StructureRotation.ROTATION_90);
- classUnderTest.setStructureMode(StructureMode.SAVE);
- classUnderTest.setAuthor("Mario");
- classUnderTest.setSaveName("Thisismysavename");
- classUnderTest.setBlockNameMetaData("Thisismetadata");
- classUnderTest.setStructureLocation(new Location(Mockito.mock(World.class), 50, 500, -30));
- classUnderTest.setSizeX(20);
- classUnderTest.setSizeY(-40);
- classUnderTest.setSizeZ(-70);
- classUnderTest.setIncludeEntities(true);
- classUnderTest.setBoundingBoxVisible(true);
- classUnderTest.setInvisibleBlocksEnabled(true);
- classUnderTest.setIntegrity(0.4F);
- classUnderTest.setSeed(50L);
-
- // Act
- Wrap wrap = new Wrap<>();
- Mockito.doAnswer(invocation -> {
- wrap.item = invocation.getArgument(0);
- return null;
- }).when(structure).load(Mockito.any(IBlockData.class), Mockito.any(NBTTagCompound.class));
- classUnderTest.update();
- NBTTagCompound actual = wrap.item;
-
- // Assert
- Assertions.assertEquals(EnumBlockMirror.LEFT_RIGHT.toString(), actual.getString("mirror"));
- Assertions.assertEquals(EnumBlockRotation.CLOCKWISE_90.toString(), actual.getString("rotation"));
- Assertions.assertEquals(BlockPropertyStructureMode.SAVE.toString(), actual.getString("mode"));
- Assertions.assertEquals("Mario", actual.getString("author"));
- Assertions.assertEquals("Thisismysavename", actual.getString("name"));
- Assertions.assertEquals("Thisismetadata", actual.getString("metadata"));
- Assertions.assertEquals(50, actual.getInt("posX"));
- Assertions.assertEquals(500, actual.getInt("posY"));
- Assertions.assertEquals(-30, actual.getInt("posZ"));
- Assertions.assertEquals(20, actual.getInt("sizeX"));
- Assertions.assertEquals(-40, actual.getInt("sizeY"));
- Assertions.assertEquals(-70, actual.getInt("sizeZ"));
- Assertions.assertFalse(actual.getBoolean("ignoreEntities"));
- Assertions.assertTrue(actual.getBoolean("showboundingbox"));
- Assertions.assertTrue(actual.getBoolean("showair"));
- Assertions.assertEquals(0.4F, actual.getFloat("integrity"));
- Assertions.assertEquals(50L, actual.getLong("seed"));
- }
-
- private CraftStructureBlock createWithDependencies(ProxyService proxyService, TileEntityStructure tileEntityStructure) {
- CraftWorld craftWorld = Mockito.mock(CraftWorld.class);
- CraftBlock block = Mockito.mock(CraftBlock.class);
- Mockito.when(block.getWorld()).thenReturn(craftWorld);
- net.minecraft.server.v1_16_R2.World world = Mockito.mock(net.minecraft.server.v1_16_R2.World.class);
- Mockito.when(block.getPosition()).thenReturn(new BlockPosition(2, 2, 2));
- Mockito.when(world.getTileEntity(Mockito.any(BlockPosition.class))).thenReturn(tileEntityStructure);
-
- StructureWorldService worldService = new MockedStructureWorldService();
- StructureSerializationService serializationService = new StructureSerializationServiceImpl();
- StructureLoaderAbstract structureLoader = new StructureLoaderAbstractImpl<>(proxyService, serializationService, worldService);
- StructureSaverAbstract structureSaver = new StructureSaverAbstractImpl<>(proxyService, serializationService, worldService);
- StructureBlockAbstractImpl vector = new StructureBlockAbstractImpl<>(proxyService, structureLoader, structureSaver);
- TypeConversionService conversionService = new TypeConversionServiceImpl();
-
- return new WrappedCraftStructureBlock(vector, conversionService, block);
- }
-
- private static class WrappedCraftStructureBlock extends CraftStructureBlock {
- public WrappedCraftStructureBlock(StructureBlockAbstractImpl structure, TypeConversionService conversionService, Block block) {
- super(structure, conversionService, block);
- }
-
- @Override
- public CraftBlock getBlock() {
- return Mockito.mock(CraftBlock.class);
- }
-
- @Override
- public Material getType() {
- return Material.APPLE;
- }
- }
-
- private static class Wrap {
- public T item;
- }
-}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/unittest/TStructureSerializationServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/unittest/TStructureSerializationServiceImpl.java
deleted file mode 100644
index 7fa3194f..00000000
--- a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/unittest/TStructureSerializationServiceImpl.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package unittest;
-
-import com.github.shynixn.structureblocklib.bukkit.v1_16_R2.StructureSerializationServiceImpl;
-import net.minecraft.server.v1_16_R2.DefinedStructure;
-import net.minecraft.server.v1_16_R2.NBTTagCompound;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.Base64;
-
-public class TStructureSerializationServiceImpl {
- /**
- * Given a valid defined Structure
- * when serialize is called
- * then the content should be written to the output stream.
- */
- @Test
- public void serialize_ValidDefinedStructure_ShouldCorrectlySerialize() {
- // Arrange
- StructureSerializationServiceImpl classUnderTest = createWithDependencies();
- DefinedStructure definedStructure = Mockito.mock(DefinedStructure.class);
- Mockito.when(definedStructure.a(Mockito.any(NBTTagCompound.class)))
- .thenReturn(new NBTTagCompound());
- String expected = "H4sIAAAAAAAAAONiYGAAAHg/+U4EAAAA";
-
- try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
- // Act
- classUnderTest.serialize(definedStructure, outputStream);
- String actual = Base64.getEncoder().encodeToString(outputStream.toByteArray());
-
- // Assert.
- Assertions.assertEquals(expected, actual);
- } catch (IOException e) {
- Assertions.fail(e);
- }
- }
- /**
- * Given a invalid defined Structure
- * when serialize is called
- * then an exception should be thrown.
- */
- @Test
- public void seSerialize_InvalidDefinedStructure_ShouldThrowException() {
- // Arrange
- StructureSerializationServiceImpl classUnderTest = createWithDependencies();
- DefinedStructure definedStructure = Mockito.mock(DefinedStructure.class);
- Mockito.when(definedStructure.a(Mockito.any(NBTTagCompound.class)))
- .thenReturn(new NBTTagCompound());
-
- Assertions.assertThrows(IllegalArgumentException.class, () -> {
- classUnderTest.serialize("NotReal", new ByteArrayOutputStream());
- });
- }
-
- private StructureSerializationServiceImpl createWithDependencies() {
- return new StructureSerializationServiceImpl();
- }
-}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/unittest/TTypeConversionServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/unittest/TTypeConversionServiceImpl.java
deleted file mode 100644
index 93d0f7c4..00000000
--- a/structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/unittest/TTypeConversionServiceImpl.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package unittest;
-
-import com.github.shynixn.structureblocklib.api.enumeration.StructureMirror;
-import com.github.shynixn.structureblocklib.api.enumeration.StructureMode;
-import com.github.shynixn.structureblocklib.api.enumeration.StructureRotation;
-import com.github.shynixn.structureblocklib.api.service.TypeConversionService;
-import com.github.shynixn.structureblocklib.bukkit.v1_16_R2.TypeConversionServiceImpl;
-import net.minecraft.server.v1_16_R2.BlockPropertyStructureMode;
-import net.minecraft.server.v1_16_R2.EnumBlockMirror;
-import net.minecraft.server.v1_16_R2.EnumBlockRotation;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-public class TTypeConversionServiceImpl {
- /**
- * Given StructureMirror
- * when convert is called
- * then value should be correctly converted.
- */
- @Test
- public void convert_StructureMirror_ShouldCorrectlyConvert() {
- // Arrange
- TypeConversionService conversionService = createWithDependencies();
-
- // Assert
- Assertions.assertEquals(EnumBlockMirror.LEFT_RIGHT, conversionService.convertToMirrorHandle(StructureMirror.LEFT_RIGHT));
- Assertions.assertEquals(EnumBlockMirror.FRONT_BACK, conversionService.convertToMirrorHandle(StructureMirror.FRONT_BACK));
- Assertions.assertEquals(EnumBlockMirror.NONE, conversionService.convertToMirrorHandle(StructureMirror.NONE));
- Assertions.assertEquals(StructureMirror.LEFT_RIGHT, conversionService.convertToStructureMirror(EnumBlockMirror.LEFT_RIGHT));
- Assertions.assertEquals(StructureMirror.FRONT_BACK, conversionService.convertToStructureMirror(EnumBlockMirror.FRONT_BACK));
- Assertions.assertEquals(StructureMirror.NONE, conversionService.convertToStructureMirror(EnumBlockMirror.NONE));
- }
-
- /**
- * Given StructureRotation
- * when convert is called
- * then value should be correctly converted.
- */
- @Test
- public void convert_StructureRotation_ShouldCorrectlyConvert() {
- // Arrange
- TypeConversionService conversionService = createWithDependencies();
-
- // Assert
- Assertions.assertEquals(EnumBlockRotation.CLOCKWISE_90, conversionService.convertToRotationHandle(StructureRotation.ROTATION_90));
- Assertions.assertEquals(EnumBlockRotation.CLOCKWISE_180, conversionService.convertToRotationHandle(StructureRotation.ROTATION_180));
- Assertions.assertEquals(EnumBlockRotation.COUNTERCLOCKWISE_90, conversionService.convertToRotationHandle(StructureRotation.ROTATION_270));
- Assertions.assertEquals(EnumBlockRotation.NONE, conversionService.convertToRotationHandle(StructureRotation.NONE));
- Assertions.assertEquals(StructureRotation.ROTATION_90, conversionService.convertToStructureRotation(EnumBlockRotation.CLOCKWISE_90));
- Assertions.assertEquals(StructureRotation.ROTATION_180, conversionService.convertToStructureRotation(EnumBlockRotation.CLOCKWISE_180));
- Assertions.assertEquals(StructureRotation.ROTATION_270, conversionService.convertToStructureRotation(EnumBlockRotation.COUNTERCLOCKWISE_90));
- Assertions.assertEquals(StructureRotation.NONE, conversionService.convertToStructureRotation(EnumBlockRotation.NONE));
- }
-
- /**
- * Given StructureMode
- * when convert is called
- * then value should be correctly converted.
- */
- @Test
- public void convert_StructureMode_ShouldCorrectlyConvert() {
- // Arrange
- TypeConversionService conversionService = createWithDependencies();
-
- // Assert
- Assertions.assertEquals(BlockPropertyStructureMode.CORNER, conversionService.convertToStructureModeHandle(StructureMode.CORNER));
- Assertions.assertEquals(BlockPropertyStructureMode.SAVE, conversionService.convertToStructureModeHandle(StructureMode.SAVE));
- Assertions.assertEquals(BlockPropertyStructureMode.DATA, conversionService.convertToStructureModeHandle(StructureMode.DATA));
- Assertions.assertEquals(BlockPropertyStructureMode.LOAD, conversionService.convertToStructureModeHandle(StructureMode.LOAD));
- Assertions.assertEquals(StructureMode.CORNER, conversionService.convertToStructureMode(BlockPropertyStructureMode.CORNER));
- Assertions.assertEquals(StructureMode.DATA, conversionService.convertToStructureMode(BlockPropertyStructureMode.DATA));
- Assertions.assertEquals(StructureMode.SAVE, conversionService.convertToStructureMode(BlockPropertyStructureMode.SAVE));
- Assertions.assertEquals(StructureMode.LOAD, conversionService.convertToStructureMode(BlockPropertyStructureMode.LOAD));
- }
-
- private TypeConversionService createWithDependencies() {
- return new TypeConversionServiceImpl();
- }
-}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R3/build.gradle.kts b/structureblocklib-bukkit-core/bukkit-nms-116R3/build.gradle.kts
index 4a5f034a..426eb3cc 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-116R3/build.gradle.kts
+++ b/structureblocklib-bukkit-core/bukkit-nms-116R3/build.gradle.kts
@@ -2,6 +2,6 @@ dependencies {
implementation(project(":structureblocklib-api"))
implementation(project(":structureblocklib-core"))
implementation(project(":structureblocklib-bukkit-api"))
- compileOnly("org.spigotmc:spigot116R3:1.16.4-R3.0")
- testCompile("org.spigotmc:spigot116R3:1.16.4-R3.0")
+ compileOnly("org.spigotmc:spigot:1.16.4-R0.1-SNAPSHOT")
+ testCompile("org.spigotmc:spigot:1.16.4-R0.1-SNAPSHOT")
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R3/src/test/java/unittest/TStructureSerializationServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-116R3/src/test/java/unittest/TStructureSerializationServiceImpl.java
index ac76b759..af1a1e18 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-116R3/src/test/java/unittest/TStructureSerializationServiceImpl.java
+++ b/structureblocklib-bukkit-core/bukkit-nms-116R3/src/test/java/unittest/TStructureSerializationServiceImpl.java
@@ -24,15 +24,17 @@ public void serialize_ValidDefinedStructure_ShouldCorrectlySerialize() {
DefinedStructure definedStructure = Mockito.mock(DefinedStructure.class);
Mockito.when(definedStructure.a(Mockito.any(NBTTagCompound.class)))
.thenReturn(new NBTTagCompound());
- String expected = "H4sIAAAAAAAAAONiYGAAAHg/+U4EAAAA";
+ byte[] expected = new byte[]{
+ 31, -117, 8, 0, 0, 0, 0, 0, 0, -1, -29, 98, 96, 96, 0, 0, 120, 63, -7, 78, 4, 0, 0, 0
+ };
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
// Act
classUnderTest.serialize(definedStructure, outputStream);
- String actual = Base64.getEncoder().encodeToString(outputStream.toByteArray());
+ byte[] actual = outputStream.toByteArray();
// Assert.
- Assertions.assertEquals(expected, actual);
+ Assertions.assertArrayEquals(expected, actual);
} catch (IOException e) {
Assertions.fail(e);
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R1/build.gradle.kts b/structureblocklib-bukkit-core/bukkit-nms-117R1/build.gradle.kts
similarity index 55%
rename from structureblocklib-bukkit-core/bukkit-nms-116R1/build.gradle.kts
rename to structureblocklib-bukkit-core/bukkit-nms-117R1/build.gradle.kts
index aa66a2f8..2046b07b 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-116R1/build.gradle.kts
+++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/build.gradle.kts
@@ -2,6 +2,6 @@ dependencies {
implementation(project(":structureblocklib-api"))
implementation(project(":structureblocklib-core"))
implementation(project(":structureblocklib-bukkit-api"))
- compileOnly("org.spigotmc:spigot116R1:1.16.0-R1.0")
- testCompile("org.spigotmc:spigot116R1:1.16.0-R1.0")
+ compileOnly("org.spigotmc:spigot:1.17-R0.1-SNAPSHOT:remapped-mojang")
+ testCompile("org.spigotmc:spigot:1.17-R0.1-SNAPSHOT:remapped-mojang")
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1/CraftStructureBlock.java b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/CraftStructureBlock.java
similarity index 74%
rename from structureblocklib-bukkit-core/bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1/CraftStructureBlock.java
rename to structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/CraftStructureBlock.java
index b9a1135d..c6b0f8ee 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1/CraftStructureBlock.java
+++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/CraftStructureBlock.java
@@ -1,4 +1,4 @@
-package com.github.shynixn.structureblocklib.bukkit.v1_16_R1;
+package com.github.shynixn.structureblocklib.bukkit.v1_17_R1;
import com.github.shynixn.structureblocklib.api.bukkit.block.StructureBlockData;
import com.github.shynixn.structureblocklib.api.bukkit.block.StructureBlockLoad;
@@ -10,19 +10,26 @@
import com.github.shynixn.structureblocklib.api.enumeration.StructureRotation;
import com.github.shynixn.structureblocklib.api.service.TypeConversionService;
import com.github.shynixn.structureblocklib.core.block.StructureBlockAbstractImpl;
+import net.minecraft.core.BlockPos;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.world.level.block.Mirror;
+import net.minecraft.world.level.block.Rotation;
+import net.minecraft.world.level.block.entity.BlockEntity;
+import net.minecraft.world.level.block.entity.StructureBlockEntity;
import org.bukkit.Location;
-import net.minecraft.server.v1_16_R1.*;
import org.bukkit.block.Block;
-import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
-import org.bukkit.craftbukkit.v1_16_R1.block.CraftBlockState;
+import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
+import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlockState;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.lang.reflect.Method;
+
public class CraftStructureBlock extends CraftBlockState implements StructureBlockData, StructureBlockSave, StructureBlockLoad {
public StructureBlockAbstractImpl internalBlock;
public TypeConversionService conversionService;
- public TileEntityStructure tileEntityStructure;
+ public StructureBlockEntity tileEntityStructure;
/**
* Creates a new instance with dependencies.
@@ -35,14 +42,14 @@ public CraftStructureBlock(StructureBlockAbstractImpl structur
final CraftWorld world = (CraftWorld) block.getWorld();
this.internalBlock = structure;
this.conversionService = conversionService;
- this.tileEntityStructure = (TileEntityStructure) world.getHandle().getTileEntity(new BlockPosition(this.getX(), this.getY(), this.getZ()));
+ this.tileEntityStructure = (StructureBlockEntity) world.getHandle().getTileEntity(new BlockPos(this.getX(), this.getY(), this.getZ()), true);
if (tileEntityStructure == null) {
throw new IllegalArgumentException("The block at " + world.getName() + " " + this.getX() + " " + this.getY() + " " + this.getZ() + " is not a StructureBlock.");
}
- NBTTagCompound compound = new NBTTagCompound();
- compound = this.tileEntityStructure.save(compound);
+ CompoundTag compound = new CompoundTag();
+ compound = saveCompoundTileEntityStructure(this.tileEntityStructure, compound);
this.setSaveName(compound.getString("name"));
this.setAuthor(compound.getString("author"));
this.setBlockNameMetaData(compound.getString("metadata"));
@@ -55,9 +62,9 @@ public CraftStructureBlock(StructureBlockAbstractImpl structur
this.setInvisibleBlocksEnabled(compound.getBoolean("showair"));
this.setIntegrity(compound.getFloat("integrity"));
this.setSeed(compound.getLong("seed"));
- this.setMirrorType(conversionService.convertToStructureMirror(EnumBlockMirror.valueOf(compound.getString("mirror"))));
- this.setRotationType(conversionService.convertToStructureRotation(EnumBlockRotation.valueOf(compound.getString("rotation"))));
- this.setStructureMode(conversionService.convertToStructureMode(BlockPropertyStructureMode.valueOf(compound.getString("mode"))));
+ this.setMirrorType(conversionService.convertToStructureMirror(Mirror.valueOf(compound.getString("mirror"))));
+ this.setRotationType(conversionService.convertToStructureRotation(Rotation.valueOf(compound.getString("rotation"))));
+ this.setStructureMode(conversionService.convertToStructureMode(net.minecraft.world.level.block.state.properties.StructureMode.valueOf(compound.getString("mode"))));
}
/**
@@ -70,27 +77,28 @@ public CraftStructureBlock(StructureBlockAbstractImpl structur
@Override
public boolean update(boolean force, boolean applyPhysics) {
final boolean result = super.update(force, applyPhysics);
- NBTTagCompound compound = new NBTTagCompound();
- compound = this.tileEntityStructure.save(compound);
- compound.setString("name", this.getSaveName());
- compound.setString("author", this.getAuthor());
- compound.setString("metadata", this.getBlockNameMetaData());
- compound.setInt("posX", this.getStructureLocation().getBlockX());
- compound.setInt("posY", this.getStructureLocation().getBlockY());
- compound.setInt("posZ", this.getStructureLocation().getBlockZ());
- compound.setInt("sizeX", this.getSizeX());
- compound.setInt("sizeY", this.getSizeY());
- compound.setInt("sizeZ", this.getSizeZ());
- compound.setBoolean("showboundingbox", this.isBoundingBoxVisible());
- compound.setBoolean("showair", this.isInvisibleBlocksEnabled());
- compound.setBoolean("ignoreEntities", !this.isIncludeEntitiesEnabled());
- compound.setFloat("integrity", this.getIntegrity());
- compound.setLong("seed", this.getSeed());
- compound.setString("rotation", conversionService.convertToRotationHandle(getRotationType()).toString());
- compound.setString("mirror", conversionService.convertToMirrorHandle(getMirrorType()).toString());
- compound.setString("mode", conversionService.convertToStructureModeHandle(getStructureMode()).toString());
- this.tileEntityStructure.load(null, compound);
- this.tileEntityStructure.update();
+ CompoundTag compound = new CompoundTag();
+ compound = saveCompoundTileEntityStructure(this.tileEntityStructure, compound);
+ compound.putString("name", this.getSaveName());
+ compound.putString("author", this.getAuthor());
+ compound.putString("metadata", this.getBlockNameMetaData());
+ compound.putInt("posX", this.getStructureLocation().getBlockX());
+ compound.putInt("posY", this.getStructureLocation().getBlockY());
+ compound.putInt("posZ", this.getStructureLocation().getBlockZ());
+ compound.putInt("sizeX", this.getSizeX());
+ compound.putInt("sizeY", this.getSizeY());
+ compound.putInt("sizeZ", this.getSizeZ());
+ compound.putBoolean("showboundingbox", this.isBoundingBoxVisible());
+ compound.putBoolean("showair", this.isInvisibleBlocksEnabled());
+ compound.putBoolean("ignoreEntities", !this.isIncludeEntitiesEnabled());
+ compound.putFloat("integrity", this.getIntegrity());
+ compound.putLong("seed", this.getSeed());
+ compound.putString("rotation", conversionService.convertToRotationHandle(getRotationType()).toString());
+ compound.putString("mirror", conversionService.convertToMirrorHandle(getMirrorType()).toString());
+ compound.putString("mode", conversionService.convertToStructureModeHandle(getStructureMode()).toString());
+ this.loadCompoundTileEntityStructure(this.tileEntityStructure, compound);
+ this.setChangedTileEntityStructure(this.tileEntityStructure);
+
return result;
}
@@ -421,4 +429,40 @@ public void setStructureMode(@NotNull StructureMode structureMode) {
public @NotNull StructureSaverAbstract saveStructure() {
return internalBlock.saveStructure();
}
+
+ /**
+ * The mapping for StructureBlockEntity save is broken in spigot. This is a workaround.
+ */
+ private CompoundTag saveCompoundTileEntityStructure(StructureBlockEntity tileEntityStructure, CompoundTag compoundTag) {
+ try {
+ Method method = StructureBlockEntity.class.getDeclaredMethod("save", CompoundTag.class);
+ return (CompoundTag) method.invoke(tileEntityStructure, compoundTag);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * The mapping for StructureBlockEntity load is broken in spigot. This is a workaround.
+ */
+ private void loadCompoundTileEntityStructure(StructureBlockEntity tileEntityStructure, CompoundTag compoundTag) {
+ try {
+ Method method = StructureBlockEntity.class.getDeclaredMethod("load", CompoundTag.class);
+ method.invoke(tileEntityStructure, compoundTag);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * The mapping for StructureBlockEntity setChanged is broken in spigot. This is a workaround.
+ */
+ private void setChangedTileEntityStructure(StructureBlockEntity tileEntityStructure) {
+ try {
+ Method method = BlockEntity.class.getDeclaredMethod("update");
+ method.invoke(tileEntityStructure);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/StructureSerializationServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/StructureSerializationServiceImpl.java
new file mode 100644
index 00000000..a8c96b45
--- /dev/null
+++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/StructureSerializationServiceImpl.java
@@ -0,0 +1,46 @@
+package com.github.shynixn.structureblocklib.bukkit.v1_17_R1;
+
+import com.github.shynixn.structureblocklib.api.service.StructureSerializationService;
+import net.minecraft.nbt.*;
+import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Serialization service.
+ */
+public class StructureSerializationServiceImpl implements StructureSerializationService {
+ /**
+ * Deserializes the {@link InputStream} to an NMS handle of StructureTemplate.
+ * This call is blocking.
+ *
+ * @param inputStream Opened inputStream. Does not close the stream after processing.
+ * @return A new NMS instance of StructureTemplate.
+ */
+ @Override
+ public Object deSerialize(InputStream inputStream) throws IOException {
+ CompoundTag compound = NbtIo.readCompressed(inputStream);
+ StructureTemplate template = new StructureTemplate();
+ template.load(compound);
+ return template;
+ }
+
+ /**
+ * Serializes the NMS handle of StructureTemplate to an {@link OutputStream}.
+ * This call is blocking.
+ *
+ * @param structureTemplate NMS handle.
+ * @param outputStream Opened outputStream. Does not close the stream after processing.
+ */
+ @Override
+ public void serialize(Object structureTemplate, OutputStream outputStream) throws IOException {
+ if (!(structureTemplate instanceof StructureTemplate)) {
+ throw new IllegalArgumentException("StructureTemplate has to be an NMS handle!");
+ }
+
+ CompoundTag compound = (((StructureTemplate) structureTemplate)).save(new CompoundTag());
+ NbtIo.writeCompressed(compound, outputStream);
+ }
+}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/StructureWorldServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/StructureWorldServiceImpl.java
new file mode 100644
index 00000000..03e60473
--- /dev/null
+++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/StructureWorldServiceImpl.java
@@ -0,0 +1,92 @@
+package com.github.shynixn.structureblocklib.bukkit.v1_17_R1;
+
+import com.github.shynixn.structureblocklib.api.entity.StructurePlaceMeta;
+import com.github.shynixn.structureblocklib.api.entity.StructureReadMeta;
+import com.github.shynixn.structureblocklib.api.service.StructureWorldService;
+import com.github.shynixn.structureblocklib.api.service.TypeConversionService;
+import net.minecraft.core.BlockPos;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.util.Mth;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.Blocks;
+import net.minecraft.world.level.block.Mirror;
+import net.minecraft.world.level.block.Rotation;
+import net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProcessor;
+import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
+import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
+
+import java.util.Random;
+
+/**
+ * Implementation to interact with structures in the world.
+ */
+public class StructureWorldServiceImpl implements StructureWorldService {
+ private final TypeConversionService conversionService;
+
+ /**
+ * Creates a new service with dependencies.
+ *
+ * @param conversionService dependency.
+ */
+ public StructureWorldServiceImpl(TypeConversionService conversionService) {
+ this.conversionService = conversionService;
+ }
+
+ /**
+ * Places the blocks in the world defined by the given structure.
+ *
+ * @param meta Meta data to describe the placement.
+ * @param structure NMS structure.
+ */
+ @Override
+ public void placeStructureToWorld(StructurePlaceMeta meta, Object structure) throws Exception {
+ if (!(structure instanceof StructureTemplate)) {
+ throw new IllegalArgumentException("StructureTemplate has to be an NMS handle!");
+ }
+
+ StructureTemplate template = (StructureTemplate) structure;
+ ServerLevel world = ((CraftWorld) Bukkit.getWorld(meta.getLocation().getWorldName())).getHandle();
+ BlockPos cornerBlock = new BlockPos((int) meta.getLocation().getX(), (int) meta.getLocation().getY(), (int) meta.getLocation().getZ());
+ StructurePlaceSettings info = new StructurePlaceSettings();
+ info.setIgnoreEntities(!meta.isIncludeEntitiesEnabled());
+ info.setMirror((Mirror) conversionService.convertToMirrorHandle(meta.getMirrorType()));
+ info.setRotation((Rotation) conversionService.convertToRotationHandle(meta.getRotationType()));
+
+ if (meta.getIntegrity() < 1.0F) {
+ info.clearProcessors();
+ float rotation = Mth.clamp(meta.getIntegrity(), 0.0F, 1.0F);
+ BlockRotProcessor rotationProcessor = new BlockRotProcessor(rotation);
+ Random random = new Random();
+
+ if (meta.getSeed() != 0L) {
+ random = new Random(meta.getSeed());
+ }
+
+ info.addProcessor(rotationProcessor);
+ info.setRandom(random);
+ }
+
+ template.placeInWorld(world, cornerBlock, cornerBlock, info, new Random(), 2);
+ }
+
+ /**
+ * Reads the blocks in the world into an NMS Structure definition.
+ *
+ * @param meta Meta data to describe the block selection.
+ * @return A new NMS Structure definition.
+ */
+ @Override
+ public Object readStructureFromWorld(StructureReadMeta meta) throws Exception {
+ ServerLevel world = ((CraftWorld) Bukkit.getWorld(meta.getLocation().getWorldName())).getHandle();
+ BlockPos cornerBlock = new BlockPos((int) meta.getLocation().getX(), (int) meta.getLocation().getY(), (int) meta.getLocation().getZ());
+ BlockPos offsetBlock = new BlockPos((int) meta.getOffset().getX(), (int) meta.getOffset().getY(), (int) meta.getOffset().getZ());
+ Block structureVoid = (Block) Blocks.class.getDeclaredField(meta.getStructureVoidTypeName()).get(null);
+
+ StructureTemplate template = new StructureTemplate();
+ template.fillFromWorld(world, cornerBlock, offsetBlock, meta.isIncludeEntitiesEnabled(), structureVoid);
+ template.setAuthor(meta.getAuthor());
+ return template;
+ }
+}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1/TypeConversionServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/TypeConversionServiceImpl.java
similarity index 74%
rename from structureblocklib-bukkit-core/bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1/TypeConversionServiceImpl.java
rename to structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/TypeConversionServiceImpl.java
index e8581915..b8a436c9 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1/TypeConversionServiceImpl.java
+++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/TypeConversionServiceImpl.java
@@ -1,12 +1,11 @@
-package com.github.shynixn.structureblocklib.bukkit.v1_16_R1;
+package com.github.shynixn.structureblocklib.bukkit.v1_17_R1;
import com.github.shynixn.structureblocklib.api.enumeration.StructureMirror;
import com.github.shynixn.structureblocklib.api.enumeration.StructureMode;
import com.github.shynixn.structureblocklib.api.enumeration.StructureRotation;
import com.github.shynixn.structureblocklib.api.service.TypeConversionService;
-import net.minecraft.server.v1_16_R1.BlockPropertyStructureMode;
-import net.minecraft.server.v1_16_R1.EnumBlockMirror;
-import net.minecraft.server.v1_16_R1.EnumBlockRotation;
+import net.minecraft.world.level.block.Mirror;
+import net.minecraft.world.level.block.Rotation;
public class TypeConversionServiceImpl implements TypeConversionService {
/**
@@ -17,7 +16,7 @@ public class TypeConversionServiceImpl implements TypeConversionService {
*/
@Override
public StructureMode convertToStructureMode(Object handle) {
- BlockPropertyStructureMode usageMode = (BlockPropertyStructureMode) handle;
+ net.minecraft.world.level.block.state.properties.StructureMode usageMode = (net.minecraft.world.level.block.state.properties.StructureMode) handle;
switch (usageMode) {
case DATA:
return StructureMode.DATA;
@@ -38,7 +37,7 @@ public StructureMode convertToStructureMode(Object handle) {
*/
@Override
public StructureMirror convertToStructureMirror(Object handle) {
- EnumBlockMirror mirror = (EnumBlockMirror) handle;
+ Mirror mirror = (Mirror) handle;
switch (mirror) {
case FRONT_BACK:
return StructureMirror.FRONT_BACK;
@@ -57,7 +56,7 @@ public StructureMirror convertToStructureMirror(Object handle) {
*/
@Override
public StructureRotation convertToStructureRotation(Object handle) {
- EnumBlockRotation rotation = (EnumBlockRotation) handle;
+ Rotation rotation = (Rotation) handle;
switch (rotation) {
case CLOCKWISE_90:
return StructureRotation.ROTATION_90;
@@ -80,13 +79,13 @@ public StructureRotation convertToStructureRotation(Object handle) {
public Object convertToStructureModeHandle(StructureMode mode) {
switch (mode) {
case SAVE:
- return BlockPropertyStructureMode.SAVE;
+ return net.minecraft.world.level.block.state.properties.StructureMode.SAVE;
case DATA:
- return BlockPropertyStructureMode.DATA;
+ return net.minecraft.world.level.block.state.properties.StructureMode.DATA;
case LOAD:
- return BlockPropertyStructureMode.LOAD;
+ return net.minecraft.world.level.block.state.properties.StructureMode.LOAD;
default:
- return BlockPropertyStructureMode.CORNER;
+ return net.minecraft.world.level.block.state.properties.StructureMode.CORNER;
}
}
@@ -100,11 +99,11 @@ public Object convertToStructureModeHandle(StructureMode mode) {
public Object convertToMirrorHandle(StructureMirror mirror) {
switch (mirror) {
case FRONT_BACK:
- return EnumBlockMirror.FRONT_BACK;
+ return Mirror.FRONT_BACK;
case LEFT_RIGHT:
- return EnumBlockMirror.LEFT_RIGHT;
+ return Mirror.LEFT_RIGHT;
default:
- return EnumBlockMirror.NONE;
+ return Mirror.NONE;
}
}
@@ -118,13 +117,13 @@ public Object convertToMirrorHandle(StructureMirror mirror) {
public Object convertToRotationHandle(StructureRotation rotation) {
switch (rotation) {
case ROTATION_90:
- return EnumBlockRotation.CLOCKWISE_90;
+ return Rotation.CLOCKWISE_90;
case ROTATION_180:
- return EnumBlockRotation.CLOCKWISE_180;
+ return Rotation.CLOCKWISE_180;
case ROTATION_270:
- return EnumBlockRotation.COUNTERCLOCKWISE_90;
+ return Rotation.COUNTERCLOCKWISE_90;
default:
- return EnumBlockRotation.NONE;
+ return Rotation.NONE;
}
}
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/test/java/helper/MockedProxyService.java b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/helper/MockedProxyService.java
similarity index 100%
rename from structureblocklib-bukkit-core/bukkit-nms-116R1/src/test/java/helper/MockedProxyService.java
rename to structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/helper/MockedProxyService.java
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/test/java/helper/MockedStructureWorldService.java b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/helper/MockedStructureWorldService.java
similarity index 88%
rename from structureblocklib-bukkit-core/bukkit-nms-116R1/src/test/java/helper/MockedStructureWorldService.java
rename to structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/helper/MockedStructureWorldService.java
index b41f41d0..dcecc3a2 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/test/java/helper/MockedStructureWorldService.java
+++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/helper/MockedStructureWorldService.java
@@ -3,7 +3,7 @@
import com.github.shynixn.structureblocklib.api.entity.StructurePlaceMeta;
import com.github.shynixn.structureblocklib.api.entity.StructureReadMeta;
import com.github.shynixn.structureblocklib.api.service.StructureWorldService;
-import net.minecraft.server.v1_16_R1.DefinedStructure;
+import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
public class MockedStructureWorldService implements StructureWorldService {
/**
@@ -24,6 +24,6 @@ public void placeStructureToWorld(StructurePlaceMeta meta, Object structure) thr
*/
@Override
public Object readStructureFromWorld(StructureReadMeta meta) throws Exception {
- return new DefinedStructure();
+ return new StructureTemplate();
}
}
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/test/java/integrationtest/CraftStructureBlockIT.java b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/integrationtest/CraftStructureBlockIT.java
similarity index 74%
rename from structureblocklib-bukkit-core/bukkit-nms-116R1/src/test/java/integrationtest/CraftStructureBlockIT.java
rename to structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/integrationtest/CraftStructureBlockIT.java
index bd0eaa9f..f91dc8b9 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/test/java/integrationtest/CraftStructureBlockIT.java
+++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/integrationtest/CraftStructureBlockIT.java
@@ -9,24 +9,27 @@
import com.github.shynixn.structureblocklib.api.service.StructureSerializationService;
import com.github.shynixn.structureblocklib.api.service.StructureWorldService;
import com.github.shynixn.structureblocklib.api.service.TypeConversionService;
-import com.github.shynixn.structureblocklib.bukkit.v1_16_R1.CraftStructureBlock;
-import com.github.shynixn.structureblocklib.bukkit.v1_16_R1.StructureSerializationServiceImpl;
-import com.github.shynixn.structureblocklib.bukkit.v1_16_R1.TypeConversionServiceImpl;
+import com.github.shynixn.structureblocklib.bukkit.v1_17_R1.CraftStructureBlock;
+import com.github.shynixn.structureblocklib.bukkit.v1_17_R1.StructureSerializationServiceImpl;
+import com.github.shynixn.structureblocklib.bukkit.v1_17_R1.TypeConversionServiceImpl;
import com.github.shynixn.structureblocklib.core.block.StructureBlockAbstractImpl;
import com.github.shynixn.structureblocklib.core.entity.StructureLoaderAbstractImpl;
import com.github.shynixn.structureblocklib.core.entity.StructureSaverAbstractImpl;
import helper.MockedProxyService;
import helper.MockedStructureWorldService;
+import net.minecraft.core.BlockPos;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.world.level.block.Mirror;
+import net.minecraft.world.level.block.Rotation;
+import net.minecraft.world.level.block.entity.StructureBlockEntity;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
-import net.minecraft.server.v1_16_R1.*;
import org.bukkit.block.Block;
-import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
-import org.bukkit.craftbukkit.v1_16_R1.block.CraftBlock;
+import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
+import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock;
import org.bukkit.util.Vector;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
public class CraftStructureBlockIT {
@@ -40,27 +43,27 @@ public class CraftStructureBlockIT {
public void create_NBTTags_ShouldCorrectlyRetrieve() {
// Arrange
MockedProxyService proxyService = new MockedProxyService();
- NBTTagCompound compound = new NBTTagCompound();
- compound.setString("author", "Mario");
- compound.setString("mirror", "LEFT_RIGHT");
- compound.setString("rotation", "CLOCKWISE_90");
- compound.setString("mode", "SAVE");
- compound.setString("name", "Thisismysavename");
- compound.setString("metadata", "Thisismetadata");
- compound.setInt("posX", 50);
- compound.setInt("posY", 550);
- compound.setInt("posZ", -30);
- compound.setInt("sizeX", 20);
- compound.setInt("sizeY", -40);
- compound.setInt("sizeZ", -70);
- compound.setBoolean("ignoreEntities", true);
- compound.setBoolean("showboundingbox", true);
- compound.setBoolean("showair", true);
- compound.setFloat("integrity", 0.4F);
- compound.setLong("seed", 50L);
+ CompoundTag compound = new CompoundTag();
+ compound.putString("author", "Mario");
+ compound.putString("mirror", "LEFT_RIGHT");
+ compound.putString("rotation", "CLOCKWISE_90");
+ compound.putString("mode", "SAVE");
+ compound.putString("name", "Thisismysavename");
+ compound.putString("metadata", "Thisismetadata");
+ compound.putInt("posX", 50);
+ compound.putInt("posY", 550);
+ compound.putInt("posZ", -30);
+ compound.putInt("sizeX", 20);
+ compound.putInt("sizeY", -40);
+ compound.putInt("sizeZ", -70);
+ compound.putBoolean("ignoreEntities", true);
+ compound.putBoolean("showboundingbox", true);
+ compound.putBoolean("showair", true);
+ compound.putFloat("integrity", 0.4F);
+ compound.putLong("seed", 50L);
- TileEntityStructure structure = Mockito.mock(TileEntityStructure.class);
- Mockito.when(structure.save(Mockito.any(NBTTagCompound.class))).thenReturn(compound);
+ StructureBlockEntity structure = Mockito.mock(StructureBlockEntity.class);
+ Mockito.when(structure.save(Mockito.any(CompoundTag.class))).thenReturn(compound);
// Act
CraftStructureBlock classUnderTest = createWithDependencies(proxyService, structure);
@@ -95,12 +98,12 @@ public void create_NBTTags_ShouldCorrectlyRetrieve() {
public void update_ChangedStructureBlock_ShouldCorrectlyGenerateNBT() {
// Arrange
MockedProxyService proxyService = new MockedProxyService();
- NBTTagCompound input = new NBTTagCompound();
- input.setString("mirror", "LEFT_RIGHT");
- input.setString("rotation", "CLOCKWISE_90");
- input.setString("mode", "SAVE");
- TileEntityStructure structure = Mockito.mock(TileEntityStructure.class);
- Mockito.when(structure.save(Mockito.any(NBTTagCompound.class))).thenReturn(input);
+ CompoundTag input = new CompoundTag();
+ input.putString("mirror", "LEFT_RIGHT");
+ input.putString("rotation", "CLOCKWISE_90");
+ input.putString("mode", "SAVE");
+ StructureBlockEntity structure = Mockito.mock(StructureBlockEntity.class);
+ Mockito.when(structure.save(Mockito.any(CompoundTag.class))).thenReturn(input);
CraftStructureBlock classUnderTest = createWithDependencies(proxyService, structure);
classUnderTest.setMirrorType(StructureMirror.LEFT_RIGHT);
classUnderTest.setRotationType(StructureRotation.ROTATION_90);
@@ -119,18 +122,18 @@ public void update_ChangedStructureBlock_ShouldCorrectlyGenerateNBT() {
classUnderTest.setSeed(50L);
// Act
- Wrap wrap = new Wrap<>();
+ Wrap wrap = new Wrap<>();
Mockito.doAnswer(invocation -> {
wrap.item = invocation.getArgument(0);
return null;
- }).when(structure).load(Mockito.any(IBlockData.class), Mockito.any(NBTTagCompound.class));
+ }).when(structure).load(Mockito.any(CompoundTag.class));
classUnderTest.update();
- NBTTagCompound actual = wrap.item;
+ CompoundTag actual = wrap.item;
// Assert
- Assertions.assertEquals(EnumBlockMirror.LEFT_RIGHT.toString(), actual.getString("mirror"));
- Assertions.assertEquals(EnumBlockRotation.CLOCKWISE_90.toString(), actual.getString("rotation"));
- Assertions.assertEquals(BlockPropertyStructureMode.SAVE.toString(), actual.getString("mode"));
+ Assertions.assertEquals(Mirror.LEFT_RIGHT.toString(), actual.getString("mirror"));
+ Assertions.assertEquals(Rotation.CLOCKWISE_90.toString(), actual.getString("rotation"));
+ Assertions.assertEquals(StructureMode.SAVE.toString(), actual.getString("mode"));
Assertions.assertEquals("Mario", actual.getString("author"));
Assertions.assertEquals("Thisismysavename", actual.getString("name"));
Assertions.assertEquals("Thisismetadata", actual.getString("metadata"));
@@ -147,13 +150,13 @@ public void update_ChangedStructureBlock_ShouldCorrectlyGenerateNBT() {
Assertions.assertEquals(50L, actual.getLong("seed"));
}
- private CraftStructureBlock createWithDependencies(ProxyService proxyService, TileEntityStructure tileEntityStructure) {
+ private CraftStructureBlock createWithDependencies(ProxyService proxyService,StructureBlockEntity tileEntityStructure) {
CraftWorld craftWorld = Mockito.mock(CraftWorld.class);
CraftBlock block = Mockito.mock(CraftBlock.class);
Mockito.when(block.getWorld()).thenReturn(craftWorld);
- net.minecraft.server.v1_16_R1.World world = Mockito.mock( net.minecraft.server.v1_16_R1.World.class);
- Mockito.when(block.getPosition()).thenReturn(new BlockPosition(2, 2, 2));
- Mockito.when(world.getTileEntity(Mockito.any(BlockPosition.class))).thenReturn(tileEntityStructure);
+ net.minecraft.world.level.Level world = Mockito.mock(net.minecraft.world.level.Level.class);
+ Mockito.when(block.getPosition()).thenReturn(new BlockPos(2, 2, 2));
+ Mockito.when(world.getTileEntity(Mockito.any(BlockPos.class), Mockito.any(Boolean.class))).thenReturn(tileEntityStructure);
StructureWorldService worldService = new MockedStructureWorldService();
StructureSerializationService serializationService = new StructureSerializationServiceImpl();
diff --git a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/test/java/unittest/TStructureSerializationServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
similarity index 62%
rename from structureblocklib-bukkit-core/bukkit-nms-116R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
rename to structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
index 8bd842c6..52404e0c 100644
--- a/structureblocklib-bukkit-core/bukkit-nms-116R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
+++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/unittest/TStructureSerializationServiceImpl.java
@@ -1,14 +1,15 @@
package unittest;
-import com.github.shynixn.structureblocklib.bukkit.v1_16_R1.StructureSerializationServiceImpl;
-import net.minecraft.server.v1_16_R1.DefinedStructure;
-import net.minecraft.server.v1_16_R1.NBTTagCompound;
+import com.github.shynixn.structureblocklib.bukkit.v1_17_R1.StructureSerializationServiceImpl;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class TStructureSerializationServiceImpl {
@@ -21,22 +22,25 @@ public class TStructureSerializationServiceImpl {
public void serialize_ValidDefinedStructure_ShouldCorrectlySerialize() {
// Arrange
StructureSerializationServiceImpl classUnderTest = createWithDependencies();
- DefinedStructure definedStructure = Mockito.mock(DefinedStructure.class);
- Mockito.when(definedStructure.a(Mockito.any(NBTTagCompound.class)))
- .thenReturn(new NBTTagCompound());
- String expected = "H4sIAAAAAAAAAONiYGAAAHg/+U4EAAAA";
+ StructureTemplate definedStructure = Mockito.mock(StructureTemplate.class);
+ Mockito.when(definedStructure.save(Mockito.any(CompoundTag.class)))
+ .thenReturn(new CompoundTag());
+ byte[] expected = new byte[]{
+ 31, -117, 8, 0, 0, 0, 0, 0, 0, -1, -29, 98, 96, 96, 0, 0, 120, 63, -7, 78, 4, 0, 0, 0
+ };
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
// Act
classUnderTest.serialize(definedStructure, outputStream);
- String actual = Base64.getEncoder().encodeToString(outputStream.toByteArray());
+ byte[] actual = outputStream.toByteArray();
// Assert.
- Assertions.assertEquals(expected, actual);
+ Assertions.assertArrayEquals(expected, actual);
} catch (IOException e) {
Assertions.fail(e);
}
}
+
/**
* Given a invalid defined Structure
* when serialize is called
@@ -46,9 +50,9 @@ public void serialize_ValidDefinedStructure_ShouldCorrectlySerialize() {
public void seSerialize_InvalidDefinedStructure_ShouldThrowException() {
// Arrange
StructureSerializationServiceImpl classUnderTest = createWithDependencies();
- DefinedStructure definedStructure = Mockito.mock(DefinedStructure.class);
- Mockito.when(definedStructure.a(Mockito.any(NBTTagCompound.class)))
- .thenReturn(new NBTTagCompound());
+ StructureTemplate definedStructure = Mockito.mock(StructureTemplate.class);
+ Mockito.when(definedStructure.save(Mockito.any(CompoundTag.class)))
+ .thenReturn(new CompoundTag());
Assertions.assertThrows(IllegalArgumentException.class, () -> {
classUnderTest.serialize("NotReal", new ByteArrayOutputStream());
diff --git a/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/unittest/TTypeConversionServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/unittest/TTypeConversionServiceImpl.java
new file mode 100644
index 00000000..2273bc42
--- /dev/null
+++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/unittest/TTypeConversionServiceImpl.java
@@ -0,0 +1,78 @@
+package unittest;
+
+import com.github.shynixn.structureblocklib.api.enumeration.StructureMirror;
+import com.github.shynixn.structureblocklib.api.enumeration.StructureMode;
+import com.github.shynixn.structureblocklib.api.enumeration.StructureRotation;
+import com.github.shynixn.structureblocklib.api.service.TypeConversionService;
+import com.github.shynixn.structureblocklib.bukkit.v1_17_R1.TypeConversionServiceImpl;
+import net.minecraft.world.level.block.Mirror;
+import net.minecraft.world.level.block.Rotation;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TTypeConversionServiceImpl {
+ /**
+ * Given StructureMirror
+ * when convert is called
+ * then value should be correctly converted.
+ */
+ @Test
+ public void convert_StructureMirror_ShouldCorrectlyConvert() {
+ // Arrange
+ TypeConversionService conversionService = createWithDependencies();
+
+ // Assert
+ Assertions.assertEquals(Mirror.LEFT_RIGHT, conversionService.convertToMirrorHandle(StructureMirror.LEFT_RIGHT));
+ Assertions.assertEquals(Mirror.FRONT_BACK, conversionService.convertToMirrorHandle(StructureMirror.FRONT_BACK));
+ Assertions.assertEquals(Mirror.NONE, conversionService.convertToMirrorHandle(StructureMirror.NONE));
+ Assertions.assertEquals(StructureMirror.LEFT_RIGHT, conversionService.convertToStructureMirror(Mirror.LEFT_RIGHT));
+ Assertions.assertEquals(StructureMirror.FRONT_BACK, conversionService.convertToStructureMirror(Mirror.FRONT_BACK));
+ Assertions.assertEquals(StructureMirror.NONE, conversionService.convertToStructureMirror(Mirror.NONE));
+ }
+
+ /**
+ * Given StructureRotation
+ * when convert is called
+ * then value should be correctly converted.
+ */
+ @Test
+ public void convert_StructureRotation_ShouldCorrectlyConvert() {
+ // Arrange
+ TypeConversionService conversionService = createWithDependencies();
+
+ // Assert
+ Assertions.assertEquals(Rotation.CLOCKWISE_90, conversionService.convertToRotationHandle(StructureRotation.ROTATION_90));
+ Assertions.assertEquals(Rotation.CLOCKWISE_180, conversionService.convertToRotationHandle(StructureRotation.ROTATION_180));
+ Assertions.assertEquals(Rotation.COUNTERCLOCKWISE_90, conversionService.convertToRotationHandle(StructureRotation.ROTATION_270));
+ Assertions.assertEquals(Rotation.NONE, conversionService.convertToRotationHandle(StructureRotation.NONE));
+ Assertions.assertEquals(StructureRotation.ROTATION_90, conversionService.convertToStructureRotation(Rotation.CLOCKWISE_90));
+ Assertions.assertEquals(StructureRotation.ROTATION_180, conversionService.convertToStructureRotation(Rotation.CLOCKWISE_180));
+ Assertions.assertEquals(StructureRotation.ROTATION_270, conversionService.convertToStructureRotation(Rotation.COUNTERCLOCKWISE_90));
+ Assertions.assertEquals(StructureRotation.NONE, conversionService.convertToStructureRotation(Rotation.NONE));
+ }
+
+ /**
+ * Given StructureMode
+ * when convert is called
+ * then value should be correctly converted.
+ */
+ @Test
+ public void convert_StructureMode_ShouldCorrectlyConvert() {
+ // Arrange
+ TypeConversionService conversionService = createWithDependencies();
+
+ // Assert
+ Assertions.assertEquals(net.minecraft.world.level.block.state.properties.StructureMode.CORNER, conversionService.convertToStructureModeHandle(StructureMode.CORNER));
+ Assertions.assertEquals(net.minecraft.world.level.block.state.properties.StructureMode.SAVE, conversionService.convertToStructureModeHandle(StructureMode.SAVE));
+ Assertions.assertEquals(net.minecraft.world.level.block.state.properties.StructureMode.DATA, conversionService.convertToStructureModeHandle(StructureMode.DATA));
+ Assertions.assertEquals(net.minecraft.world.level.block.state.properties.StructureMode.LOAD, conversionService.convertToStructureModeHandle(StructureMode.LOAD));
+ Assertions.assertEquals(StructureMode.CORNER, conversionService.convertToStructureMode(net.minecraft.world.level.block.state.properties.StructureMode.CORNER));
+ Assertions.assertEquals(StructureMode.DATA, conversionService.convertToStructureMode(net.minecraft.world.level.block.state.properties.StructureMode.DATA));
+ Assertions.assertEquals(StructureMode.SAVE, conversionService.convertToStructureMode(net.minecraft.world.level.block.state.properties.StructureMode.SAVE));
+ Assertions.assertEquals(StructureMode.LOAD, conversionService.convertToStructureMode(net.minecraft.world.level.block.state.properties.StructureMode.LOAD));
+ }
+
+ private TypeConversionService createWithDependencies() {
+ return new TypeConversionServiceImpl();
+ }
+}
diff --git a/structureblocklib-bukkit-plugin/build.gradle.kts b/structureblocklib-bukkit-plugin/build.gradle.kts
index 8ebf9d45..d696045d 100644
--- a/structureblocklib-bukkit-plugin/build.gradle.kts
+++ b/structureblocklib-bukkit-plugin/build.gradle.kts
@@ -1,30 +1,64 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
+import java.net.URL
+import java.nio.file.Files
+import java.util.*
plugins {
- id("com.github.johnrengelman.shadow") version ("2.0.4")
-}
-
-publishing {
- publications {
- (findByName("mavenJava") as MavenPublication).artifact(tasks.findByName("shadowJar")!!)
- }
+ id("com.github.johnrengelman.shadow") version ("7.0.0")
}
tasks.withType {
dependsOn("jar")
- archiveName = "$baseName-$version.$extension"
-
- // Change the output folder of the plugin.
- // destinationDir = File("D:\\Benutzer\\Temp\\plugins")
-
+ archiveName = "${baseName}-${version}-mojangmapping.${extension}"
relocate("org.intellij", "com.github.shynixn.structureblocklib.lib.org.intellij")
relocate("org.jetbrains", "com.github.shynixn.structureblocklib.lib.org.jetbrains")
}
+tasks.register("pluginJar", Exec::class.java) {
+ dependsOn("shadowJar")
+ workingDir = buildDir
+
+ if (!workingDir.exists()) {
+ workingDir.mkdir();
+ }
+
+ val folder = File(workingDir, "mapping")
+
+ if (!folder.exists()) {
+ folder.mkdir()
+ }
+
+ val file = File(folder, "SpecialSources.jar")
+
+ if (!file.exists()) {
+ URL("https://repo.maven.apache.org/maven2/net/md-5/SpecialSource/1.10.0/SpecialSource-1.10.0-shaded.jar").openStream()
+ .use {
+ Files.copy(it, file.toPath())
+ }
+ }
+
+ val shadowJar = tasks.findByName("shadowJar")!! as ShadowJar
+ val obfArchiveName = "${shadowJar.baseName}-${shadowJar.version}-obfuscated.${shadowJar.extension}"
+ val archiveName = "${shadowJar.baseName}-${shadowJar.version}.${shadowJar.extension}"
+ val sourceJarFile = File(buildDir, "libs/" + shadowJar.archiveName)
+ val obfJarFile = File(buildDir, "libs/$obfArchiveName")
+ val targetJarFile = File(buildDir, "libs/$archiveName")
+
+ val obsMapping =
+ "java -jar ${file.absolutePath} -i \"$sourceJarFile\" -o \"$obfJarFile\" -m \"\$HOME/.m2/repository/org/spigotmc/minecraft-server/1.17-R0.1-SNAPSHOT/minecraft-server-1.17-R0.1-SNAPSHOT-maps-mojang.txt\" --reverse" +
+ "&& java -jar ${file.absolutePath} -i \"$obfJarFile\" -o \"$targetJarFile\" -m \"\$HOME/.m2/repository/org/spigotmc/minecraft-server/1.17-R0.1-SNAPSHOT/minecraft-server-1.17-R0.1-SNAPSHOT-maps-spigot.csrg\""
+
+ if (System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("windows")) {
+ commandLine = listOf("cmd", "/c", obsMapping.replace("\$HOME", "%userprofile%"))
+ } else {
+ commandLine = listOf("sh", "-c", obsMapping)
+ }
+}
+
dependencies {
implementation(project(":structureblocklib-api"))
implementation(project(":structureblocklib-core"))
implementation(project(":structureblocklib-bukkit-api"))
implementation(project(":structureblocklib-bukkit-core"))
- compileOnly("org.spigotmc:spigot114R1:1.14.4-R1.0")
+ compileOnly("org.spigotmc:spigot:1.14.4-R0.1-SNAPSHOT")
}
diff --git a/structureblocklib-bukkit-plugin/src/main/resources/plugin.yml b/structureblocklib-bukkit-plugin/src/main/resources/plugin.yml
index f5bb20cf..75aed35f 100644
--- a/structureblocklib-bukkit-plugin/src/main/resources/plugin.yml
+++ b/structureblocklib-bukkit-plugin/src/main/resources/plugin.yml
@@ -1,4 +1,4 @@
name: StructureBlockLib
-version: 2.1.0
+version: 2.2.0
author: Shynixn
main: com.github.shynixn.structureblocklib.bukkit.plugin.StructureBlockLibPlugin
diff --git a/structureblocklib-bukkit-sample/build.gradle.kts b/structureblocklib-bukkit-sample/build.gradle.kts
index 8ebf9d45..dac7eff4 100644
--- a/structureblocklib-bukkit-sample/build.gradle.kts
+++ b/structureblocklib-bukkit-sample/build.gradle.kts
@@ -1,24 +1,62 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
+import java.net.URL
+import java.nio.file.Files
+import java.util.*
plugins {
- id("com.github.johnrengelman.shadow") version ("2.0.4")
-}
-
-publishing {
- publications {
- (findByName("mavenJava") as MavenPublication).artifact(tasks.findByName("shadowJar")!!)
- }
+ id("com.github.johnrengelman.shadow") version ("7.0.0")
}
tasks.withType {
dependsOn("jar")
- archiveName = "$baseName-$version.$extension"
+ archiveName = "${baseName}-${version}-mojangmapping.${extension}"
+ relocate("org.intellij", "com.github.shynixn.structureblocklib.lib.org.intellij")
+ relocate("org.jetbrains", "com.github.shynixn.structureblocklib.lib.org.jetbrains")
+}
+tasks.register("pluginJar", Exec::class.java) {
// Change the output folder of the plugin.
- // destinationDir = File("D:\\Benutzer\\Temp\\plugins")
+ // val destinationDir = File("C:/temp/plugins")
+ val destinationDir = File(buildDir, "libs")
- relocate("org.intellij", "com.github.shynixn.structureblocklib.lib.org.intellij")
- relocate("org.jetbrains", "com.github.shynixn.structureblocklib.lib.org.jetbrains")
+ dependsOn("shadowJar")
+ workingDir = buildDir
+
+ if (!workingDir.exists()) {
+ workingDir.mkdir();
+ }
+
+ val folder = File(workingDir, "mapping")
+
+ if (!folder.exists()) {
+ folder.mkdir()
+ }
+
+ val file = File(folder, "SpecialSources.jar")
+
+ if (!file.exists()) {
+ URL("https://repo.maven.apache.org/maven2/net/md-5/SpecialSource/1.10.0/SpecialSource-1.10.0-shaded.jar").openStream()
+ .use {
+ Files.copy(it, file.toPath())
+ }
+ }
+
+ val shadowJar = tasks.findByName("shadowJar")!! as ShadowJar
+ val obfArchiveName = "${shadowJar.baseName}-${shadowJar.version}-obfuscated.${shadowJar.extension}"
+ val archiveName = "${shadowJar.baseName}-${shadowJar.version}.${shadowJar.extension}"
+ val sourceJarFile = File(buildDir, "libs/" + shadowJar.archiveName)
+ val obfJarFile = File(buildDir, "libs/$obfArchiveName")
+ val targetJarFile = File(destinationDir, archiveName)
+
+ val obsMapping =
+ "java -jar ${file.absolutePath} -i \"$sourceJarFile\" -o \"$obfJarFile\" -m \"\$HOME/.m2/repository/org/spigotmc/minecraft-server/1.17-R0.1-SNAPSHOT/minecraft-server-1.17-R0.1-SNAPSHOT-maps-mojang.txt\" --reverse" +
+ "&& java -jar ${file.absolutePath} -i \"$obfJarFile\" -o \"$targetJarFile\" -m \"\$HOME/.m2/repository/org/spigotmc/minecraft-server/1.17-R0.1-SNAPSHOT/minecraft-server-1.17-R0.1-SNAPSHOT-maps-spigot.csrg\""
+
+ if (System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("windows")) {
+ commandLine = listOf("cmd", "/c", obsMapping.replace("\$HOME", "%userprofile%"))
+ } else {
+ commandLine = listOf("sh", "-c", obsMapping)
+ }
}
dependencies {
@@ -26,5 +64,5 @@ dependencies {
implementation(project(":structureblocklib-core"))
implementation(project(":structureblocklib-bukkit-api"))
implementation(project(":structureblocklib-bukkit-core"))
- compileOnly("org.spigotmc:spigot114R1:1.14.4-R1.0")
+ compileOnly("org.spigotmc:spigot:1.14.4-R0.1-SNAPSHOT")
}
diff --git a/structureblocklib-bukkit-sample/src/main/resources/plugin.yml b/structureblocklib-bukkit-sample/src/main/resources/plugin.yml
index 611ad31d..3036faa7 100644
--- a/structureblocklib-bukkit-sample/src/main/resources/plugin.yml
+++ b/structureblocklib-bukkit-sample/src/main/resources/plugin.yml
@@ -1,5 +1,5 @@
name: StructureBlockLibSample
-version: 2.1.0
+version: 2.2.0
author: Shynixn
main: com.github.shynixn.structureblocklib.bukkit.plugin.StructureBlockLibSamplePlugin
commands:
diff --git a/structureblocklib-core/src/main/java/com/github/shynixn/structureblocklib/core/entity/StructureLoaderAbstractImpl.java b/structureblocklib-core/src/main/java/com/github/shynixn/structureblocklib/core/entity/StructureLoaderAbstractImpl.java
index 51a70691..7799b925 100644
--- a/structureblocklib-core/src/main/java/com/github/shynixn/structureblocklib/core/entity/StructureLoaderAbstractImpl.java
+++ b/structureblocklib-core/src/main/java/com/github/shynixn/structureblocklib/core/entity/StructureLoaderAbstractImpl.java
@@ -94,7 +94,7 @@ public StructureRotation getRotationType() {
* Gets the target integrity.
* Default 1.0.
* 1.0 -> Every block which is present in the structure file is placed in the world.
- * <1.0 -> Blocks get randomly removed by loading depending on the given {@code getSeed}.
+ * smnaller 1.0 -> Blocks get randomly removed by loading depending on the given {@code getSeed}.
*
* @return integrity.
*/
@@ -173,7 +173,7 @@ public StructureLoaderAbstract rotation(StructureRotation rotation) {
* Sets the target integrity.
* Default 1.0.
* 1.0 -> Every block which is present in the structure file is placed in the world.
- * <1.0 -> Blocks get randomly removed by loading depending on the given {@code setSeed}.
+ * smaller 1.0 -> Blocks get randomly removed by loading depending on the given {@code setSeed}.
*
* @param integrity Integrity.
* @return This instance.
diff --git a/structureblocklib-core/src/main/java/com/github/shynixn/structureblocklib/core/entity/StructurePlaceMetaImpl.java b/structureblocklib-core/src/main/java/com/github/shynixn/structureblocklib/core/entity/StructurePlaceMetaImpl.java
index a106194a..718dd546 100644
--- a/structureblocklib-core/src/main/java/com/github/shynixn/structureblocklib/core/entity/StructurePlaceMetaImpl.java
+++ b/structureblocklib-core/src/main/java/com/github/shynixn/structureblocklib/core/entity/StructurePlaceMetaImpl.java
@@ -51,7 +51,7 @@ public StructureRotation getRotationType() {
* Gets the target integrity.
* Default 1.0.
* 1.0 -> Every block which is present in the structure file is placed in the world.
- * <1.0 -> Blocks get randomly removed by loading depending on the given {@code getSeed}.
+ * smaller 1.0 -> Blocks get randomly removed by loading depending on the given {@code getSeed}.
*
* @return integrity.
*/
diff --git a/structureblocklib-core/src/main/java/com/github/shynixn/structureblocklib/core/entity/StructureSaverAbstractImpl.java b/structureblocklib-core/src/main/java/com/github/shynixn/structureblocklib/core/entity/StructureSaverAbstractImpl.java
index 64710657..3a194dbc 100644
--- a/structureblocklib-core/src/main/java/com/github/shynixn/structureblocklib/core/entity/StructureSaverAbstractImpl.java
+++ b/structureblocklib-core/src/main/java/com/github/shynixn/structureblocklib/core/entity/StructureSaverAbstractImpl.java
@@ -46,7 +46,9 @@ public StructureSaverAbstractImpl(ProxyService proxyService, StructureSerializat
this.serializationService = serializationService;
this.worldService = worldService;
- if (proxyService.getServerVersion().isVersionSameOrGreaterThan(Version.VERSION_1_13_R2)) {
+ if (proxyService.getServerVersion().isVersionSameOrGreaterThan(Version.VERSION_1_17_R1)) {
+ structureVoid = "jb";
+ } else if (proxyService.getServerVersion().isVersionSameOrGreaterThan(Version.VERSION_1_13_R2)) {
structureVoid = "STRUCTURE_VOID";
} else if (proxyService.getServerVersion().isVersionSameOrGreaterThan(Version.VERSION_1_10_R1)) {
structureVoid = "dj";
diff --git a/structureblocklib-tools/ops.json b/structureblocklib-tools/ops.json
new file mode 100644
index 00000000..aefd5628
--- /dev/null
+++ b/structureblocklib-tools/ops.json
@@ -0,0 +1,8 @@
+[
+ {
+ "uuid": "dd6f3d9b-86e6-497f-b22a-2fc99e046e65",
+ "name": "Shynixn",
+ "level": 4,
+ "bypassesPlayerLimit": false
+ }
+]
\ No newline at end of file