From 276470fe0a772cfdce046975195a537ce0cabdde Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 13:37:19 +0200 Subject: [PATCH 01/42] #73 Added 1.17 implementation. --- build.gradle | 30 +- gradle.properties | 2 - gradle/wrapper/gradle-wrapper.properties | 3 +- settings.gradle.kts | 3 +- .../api/enumeration/Version.java | 7 +- .../build.gradle.kts | 3 +- .../v1_16_R1/StructureWorldServiceImpl.java | 83 ---- .../unittest/TTypeConversionServiceImpl.java | 79 ---- .../bukkit-nms-116R2/build.gradle.kts | 7 - .../bukkit/v1_16_R2/CraftStructureBlock.java | 424 ------------------ .../StructureSerializationServiceImpl.java | 47 -- .../v1_16_R2/TypeConversionServiceImpl.java | 130 ------ .../test/java/helper/MockedProxyService.java | 106 ----- .../helper/MockedStructureWorldService.java | 29 -- .../CraftStructureBlockIT.java | 187 -------- .../TStructureSerializationServiceImpl.java | 61 --- .../unittest/TTypeConversionServiceImpl.java | 79 ---- .../build.gradle.kts | 6 +- .../bukkit/v1_17_R1}/CraftStructureBlock.java | 15 +- .../StructureSerializationServiceImpl.java | 8 +- .../v1_17_R1}/StructureWorldServiceImpl.java | 18 +- .../v1_17_R1}/TypeConversionServiceImpl.java | 46 +- .../test/java/helper/MockedProxyService.java | 0 .../helper/MockedStructureWorldService.java | 2 +- .../CraftStructureBlockIT.java | 29 +- .../TStructureSerializationServiceImpl.java | 6 +- .../unittest/TTypeConversionServiceImpl.java | 79 ++++ .../build.gradle.kts | 2 +- 28 files changed, 171 insertions(+), 1320 deletions(-) delete mode 100644 structureblocklib-bukkit-core/bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1/StructureWorldServiceImpl.java delete mode 100644 structureblocklib-bukkit-core/bukkit-nms-116R1/src/test/java/unittest/TTypeConversionServiceImpl.java delete mode 100644 structureblocklib-bukkit-core/bukkit-nms-116R2/build.gradle.kts delete mode 100644 structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/CraftStructureBlock.java delete mode 100644 structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/StructureSerializationServiceImpl.java delete mode 100644 structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/TypeConversionServiceImpl.java delete mode 100644 structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/helper/MockedProxyService.java delete mode 100644 structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/helper/MockedStructureWorldService.java delete mode 100644 structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/integrationtest/CraftStructureBlockIT.java delete mode 100644 structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/unittest/TStructureSerializationServiceImpl.java delete mode 100644 structureblocklib-bukkit-core/bukkit-nms-116R2/src/test/java/unittest/TTypeConversionServiceImpl.java rename structureblocklib-bukkit-core/{bukkit-nms-116R1 => bukkit-nms-117R1}/build.gradle.kts (52%) rename structureblocklib-bukkit-core/{bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1 => bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1}/CraftStructureBlock.java (95%) rename structureblocklib-bukkit-core/{bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1 => bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1}/StructureSerializationServiceImpl.java (86%) rename structureblocklib-bukkit-core/{bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2 => bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1}/StructureWorldServiceImpl.java (80%) rename structureblocklib-bukkit-core/{bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1 => bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1}/TypeConversionServiceImpl.java (75%) rename structureblocklib-bukkit-core/{bukkit-nms-116R1 => bukkit-nms-117R1}/src/test/java/helper/MockedProxyService.java (100%) rename structureblocklib-bukkit-core/{bukkit-nms-116R1 => bukkit-nms-117R1}/src/test/java/helper/MockedStructureWorldService.java (92%) rename structureblocklib-bukkit-core/{bukkit-nms-116R1 => bukkit-nms-117R1}/src/test/java/integrationtest/CraftStructureBlockIT.java (88%) rename structureblocklib-bukkit-core/{bukkit-nms-116R1 => bukkit-nms-117R1}/src/test/java/unittest/TStructureSerializationServiceImpl.java (91%) create mode 100644 structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/unittest/TTypeConversionServiceImpl.java diff --git a/build.gradle b/build.gradle index e4a5f558..075b19c2 100644 --- a/build.gradle +++ b/build.gradle @@ -8,15 +8,15 @@ buildscript { mavenCentral() } dependencies { - classpath group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin', version: kotlinVersion + classpath group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin', version: '1.3.72' classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.17" } } 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' @@ -47,20 +47,14 @@ subprojects { group 'com.github.shynixn.structureblocklib' version '2.1.1' - sourceCompatibility = 1.8 - apply plugin: 'kotlin-platform-jvm' apply plugin: 'signing' apply plugin: 'maven-publish' 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 { @@ -178,23 +172,11 @@ gradle.taskGraph.whenReady { taskGraph -> } 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) { diff --git a/gradle.properties b/gradle.properties index e1c8443a..7fc6f1ff 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1 @@ kotlin.code.style=official -javaVersion=1.8 -kotlinVersion=1.3.20 \ No newline at end of file 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-core/build.gradle.kts b/structureblocklib-bukkit-core/build.gradle.kts index 6660873d..ce2f0992 100644 --- a/structureblocklib-bukkit-core/build.gradle.kts +++ b/structureblocklib-bukkit-core/build.gradle.kts @@ -29,9 +29,8 @@ 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") 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/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-116R1/build.gradle.kts b/structureblocklib-bukkit-core/bukkit-nms-117R1/build.gradle.kts similarity index 52% rename from structureblocklib-bukkit-core/bukkit-nms-116R1/build.gradle.kts rename to structureblocklib-bukkit-core/bukkit-nms-117R1/build.gradle.kts index aa66a2f8..25cc1a2f 100644 --- a/structureblocklib-bukkit-core/bukkit-nms-116R1/build.gradle.kts +++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/build.gradle.kts @@ -1,7 +1,9 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + 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:spigot117R1:1.17.0-R1.0") + testCompile("org.spigotmc:spigot117R1:1.17.0-R1.0") } 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 95% 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..05066d7c 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,11 +10,16 @@ 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.BlockPosition; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.level.block.EnumBlockMirror; +import net.minecraft.world.level.block.EnumBlockRotation; +import net.minecraft.world.level.block.entity.TileEntityStructure; +import net.minecraft.world.level.block.state.properties.BlockPropertyStructureMode; 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; @@ -89,7 +94,7 @@ public boolean update(boolean force, boolean applyPhysics) { 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.load(compound); this.tileEntityStructure.update(); return result; } 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-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/StructureSerializationServiceImpl.java similarity index 86% rename from structureblocklib-bukkit-core/bukkit-nms-116R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R1/StructureSerializationServiceImpl.java rename to structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/StructureSerializationServiceImpl.java index 90c33818..1e65814b 100644 --- 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-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/StructureSerializationServiceImpl.java @@ -1,9 +1,9 @@ -package com.github.shynixn.structureblocklib.bukkit.v1_16_R1; +package com.github.shynixn.structureblocklib.bukkit.v1_17_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 net.minecraft.nbt.NBTCompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure; import java.io.IOException; import java.io.InputStream; 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-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/StructureWorldServiceImpl.java similarity index 80% rename from structureblocklib-bukkit-core/bukkit-nms-116R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_16_R2/StructureWorldServiceImpl.java rename to structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/StructureWorldServiceImpl.java index b1b3ab93..3b9ed3c5 100644 --- 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-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/StructureWorldServiceImpl.java @@ -1,12 +1,22 @@ -package com.github.shynixn.structureblocklib.bukkit.v1_16_R2; +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.BlockPosition; +import net.minecraft.util.MathHelper; +import net.minecraft.world.level.World; +import net.minecraft.world.level.WorldAccess; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.EnumBlockMirror; +import net.minecraft.world.level.block.EnumBlockRotation; +import net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure; +import net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructureInfo; +import net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructureProcessorRotation; import org.bukkit.Bukkit; -import net.minecraft.server.v1_16_R2.*; -import org.bukkit.craftbukkit.v1_16_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; import java.util.Random; @@ -59,7 +69,7 @@ public void placeStructureToWorld(StructurePlaceMeta meta, Object structure) thr info.a(random); } - definedStructure.a((WorldAccess) world, cornerBlock, info, new Random()); + definedStructure.a((WorldAccess) world, cornerBlock, cornerBlock, info, new Random(), 2); } /** 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 75% 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..9dd03983 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,12 @@ -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.EnumBlockMirror; +import net.minecraft.world.level.block.EnumBlockRotation; +import net.minecraft.world.level.block.state.properties.BlockPropertyStructureMode; public class TypeConversionServiceImpl implements TypeConversionService { /** @@ -19,11 +19,11 @@ public class TypeConversionServiceImpl implements TypeConversionService { public StructureMode convertToStructureMode(Object handle) { BlockPropertyStructureMode usageMode = (BlockPropertyStructureMode) handle; switch (usageMode) { - case DATA: + case d: return StructureMode.DATA; - case LOAD: + case b: return StructureMode.LOAD; - case SAVE: + case a: return StructureMode.SAVE; default: return StructureMode.CORNER; @@ -40,9 +40,9 @@ public StructureMode convertToStructureMode(Object handle) { public StructureMirror convertToStructureMirror(Object handle) { EnumBlockMirror mirror = (EnumBlockMirror) handle; switch (mirror) { - case FRONT_BACK: + case c: return StructureMirror.FRONT_BACK; - case LEFT_RIGHT: + case b: return StructureMirror.LEFT_RIGHT; default: return StructureMirror.NONE; @@ -59,11 +59,11 @@ public StructureMirror convertToStructureMirror(Object handle) { public StructureRotation convertToStructureRotation(Object handle) { EnumBlockRotation rotation = (EnumBlockRotation) handle; switch (rotation) { - case CLOCKWISE_90: + case b: return StructureRotation.ROTATION_90; - case CLOCKWISE_180: + case c: return StructureRotation.ROTATION_180; - case COUNTERCLOCKWISE_90: + case d: return StructureRotation.ROTATION_270; default: return StructureRotation.NONE; @@ -80,13 +80,13 @@ public StructureRotation convertToStructureRotation(Object handle) { public Object convertToStructureModeHandle(StructureMode mode) { switch (mode) { case SAVE: - return BlockPropertyStructureMode.SAVE; + return BlockPropertyStructureMode.a; case DATA: - return BlockPropertyStructureMode.DATA; + return BlockPropertyStructureMode.d; case LOAD: - return BlockPropertyStructureMode.LOAD; + return BlockPropertyStructureMode.b; default: - return BlockPropertyStructureMode.CORNER; + return BlockPropertyStructureMode.c; } } @@ -100,11 +100,11 @@ public Object convertToStructureModeHandle(StructureMode mode) { public Object convertToMirrorHandle(StructureMirror mirror) { switch (mirror) { case FRONT_BACK: - return EnumBlockMirror.FRONT_BACK; + return EnumBlockMirror.c; case LEFT_RIGHT: - return EnumBlockMirror.LEFT_RIGHT; + return EnumBlockMirror.b; default: - return EnumBlockMirror.NONE; + return EnumBlockMirror.a; } } @@ -118,13 +118,13 @@ public Object convertToMirrorHandle(StructureMirror mirror) { public Object convertToRotationHandle(StructureRotation rotation) { switch (rotation) { case ROTATION_90: - return EnumBlockRotation.CLOCKWISE_90; + return EnumBlockRotation.b; case ROTATION_180: - return EnumBlockRotation.CLOCKWISE_180; + return EnumBlockRotation.c; case ROTATION_270: - return EnumBlockRotation.COUNTERCLOCKWISE_90; + return EnumBlockRotation.d; default: - return EnumBlockRotation.NONE; + return EnumBlockRotation.a; } } } 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 92% 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..bec13e73 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.DefinedStructure; public class MockedStructureWorldService implements StructureWorldService { /** 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 88% 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..fc8b8eea 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,29 @@ 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.BlockPosition; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.level.block.EnumBlockMirror; +import net.minecraft.world.level.block.EnumBlockRotation; +import net.minecraft.world.level.block.entity.TileEntityStructure; +import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.block.state.properties.BlockPropertyStructureMode; 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 { @@ -123,14 +128,14 @@ public void update_ChangedStructureBlock_ShouldCorrectlyGenerateNBT() { 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(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(EnumBlockMirror.b.toString(), actual.getString("mirror")); + Assertions.assertEquals(EnumBlockRotation.b.toString(), actual.getString("rotation")); + Assertions.assertEquals(BlockPropertyStructureMode.a.toString(), actual.getString("mode")); Assertions.assertEquals("Mario", actual.getString("author")); Assertions.assertEquals("Thisismysavename", actual.getString("name")); Assertions.assertEquals("Thisismetadata", actual.getString("metadata")); @@ -151,7 +156,7 @@ private CraftStructureBlock createWithDependencies(ProxyService proxyService, Ti 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); + net.minecraft.world.level.World world = Mockito.mock(net.minecraft.world.level.World.class); Mockito.when(block.getPosition()).thenReturn(new BlockPosition(2, 2, 2)); Mockito.when(world.getTileEntity(Mockito.any(BlockPosition.class))).thenReturn(tileEntityStructure); 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 91% 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..7a322eb4 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,8 +1,8 @@ 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.NBTTagCompound; +import net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.Mockito; 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..b8ca5121 --- /dev/null +++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/unittest/TTypeConversionServiceImpl.java @@ -0,0 +1,79 @@ +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.EnumBlockMirror; +import net.minecraft.world.level.block.EnumBlockRotation; +import net.minecraft.world.level.block.state.properties.BlockPropertyStructureMode; +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.b, conversionService.convertToMirrorHandle(StructureMirror.LEFT_RIGHT)); + Assertions.assertEquals(EnumBlockMirror.c, conversionService.convertToMirrorHandle(StructureMirror.FRONT_BACK)); + Assertions.assertEquals(EnumBlockMirror.a, conversionService.convertToMirrorHandle(StructureMirror.NONE)); + Assertions.assertEquals(StructureMirror.LEFT_RIGHT, conversionService.convertToStructureMirror(EnumBlockMirror.b)); + Assertions.assertEquals(StructureMirror.FRONT_BACK, conversionService.convertToStructureMirror(EnumBlockMirror.c)); + Assertions.assertEquals(StructureMirror.NONE, conversionService.convertToStructureMirror(EnumBlockMirror.a)); + } + + /** + * 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.b, conversionService.convertToRotationHandle(StructureRotation.ROTATION_90)); + Assertions.assertEquals(EnumBlockRotation.c, conversionService.convertToRotationHandle(StructureRotation.ROTATION_180)); + Assertions.assertEquals(EnumBlockRotation.d, conversionService.convertToRotationHandle(StructureRotation.ROTATION_270)); + Assertions.assertEquals(EnumBlockRotation.a, conversionService.convertToRotationHandle(StructureRotation.NONE)); + Assertions.assertEquals(StructureRotation.ROTATION_90, conversionService.convertToStructureRotation(EnumBlockRotation.b)); + Assertions.assertEquals(StructureRotation.ROTATION_180, conversionService.convertToStructureRotation(EnumBlockRotation.c)); + Assertions.assertEquals(StructureRotation.ROTATION_270, conversionService.convertToStructureRotation(EnumBlockRotation.d)); + Assertions.assertEquals(StructureRotation.NONE, conversionService.convertToStructureRotation(EnumBlockRotation.a)); + } + + /** + * 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.c, conversionService.convertToStructureModeHandle(StructureMode.CORNER)); + Assertions.assertEquals(BlockPropertyStructureMode.a, conversionService.convertToStructureModeHandle(StructureMode.SAVE)); + Assertions.assertEquals(BlockPropertyStructureMode.d, conversionService.convertToStructureModeHandle(StructureMode.DATA)); + Assertions.assertEquals(BlockPropertyStructureMode.b, conversionService.convertToStructureModeHandle(StructureMode.LOAD)); + Assertions.assertEquals(StructureMode.CORNER, conversionService.convertToStructureMode(BlockPropertyStructureMode.c)); + Assertions.assertEquals(StructureMode.DATA, conversionService.convertToStructureMode(BlockPropertyStructureMode.d)); + Assertions.assertEquals(StructureMode.SAVE, conversionService.convertToStructureMode(BlockPropertyStructureMode.a)); + Assertions.assertEquals(StructureMode.LOAD, conversionService.convertToStructureMode(BlockPropertyStructureMode.b)); + } + + private TypeConversionService createWithDependencies() { + return new TypeConversionServiceImpl(); + } +} diff --git a/structureblocklib-bukkit-sample/build.gradle.kts b/structureblocklib-bukkit-sample/build.gradle.kts index 8ebf9d45..b511d7da 100644 --- a/structureblocklib-bukkit-sample/build.gradle.kts +++ b/structureblocklib-bukkit-sample/build.gradle.kts @@ -15,7 +15,7 @@ tasks.withType { archiveName = "$baseName-$version.$extension" // Change the output folder of the plugin. - // destinationDir = File("D:\\Benutzer\\Temp\\plugins") + // destinationDir = File("C:\\temp\\plugins") relocate("org.intellij", "com.github.shynixn.structureblocklib.lib.org.intellij") relocate("org.jetbrains", "com.github.shynixn.structureblocklib.lib.org.jetbrains") From 0c1092a35e07ebee4d0430a66085723f8b14bbe4 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 14:42:31 +0200 Subject: [PATCH 02/42] #73 Changed to mojang mappings for 1.17. --- .../TStructureSerializationServiceImpl.java | 8 +- .../TStructureSerializationServiceImpl.java | 8 +- .../TStructureSerializationServiceImpl.java | 8 +- .../TStructureSerializationServiceImpl.java | 8 +- .../TStructureSerializationServiceImpl.java | 8 +- .../TStructureSerializationServiceImpl.java | 8 +- .../TStructureSerializationServiceImpl.java | 8 +- .../TStructureSerializationServiceImpl.java | 8 +- .../bukkit-nms-117R1/build.gradle.kts | 7 +- .../bukkit/v1_17_R1/CraftStructureBlock.java | 62 +++++++------- .../StructureSerializationServiceImpl.java | 31 ++++--- .../v1_17_R1/StructureWorldServiceImpl.java | 61 +++++++------- .../v1_17_R1/TypeConversionServiceImpl.java | 49 ++++++----- .../helper/MockedStructureWorldService.java | 4 +- .../CraftStructureBlockIT.java | 84 +++++++++---------- .../TStructureSerializationServiceImpl.java | 26 +++--- .../unittest/TTypeConversionServiceImpl.java | 49 ++++++----- .../entity/StructureSaverAbstractImpl.java | 4 +- 18 files changed, 228 insertions(+), 213 deletions(-) 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/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/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/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/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/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/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-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-117R1/build.gradle.kts b/structureblocklib-bukkit-core/bukkit-nms-117R1/build.gradle.kts index 25cc1a2f..68be0867 100644 --- a/structureblocklib-bukkit-core/bukkit-nms-117R1/build.gradle.kts +++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/build.gradle.kts @@ -1,9 +1,8 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - dependencies { implementation(project(":structureblocklib-api")) implementation(project(":structureblocklib-core")) implementation(project(":structureblocklib-bukkit-api")) - compileOnly("org.spigotmc:spigot117R1:1.17.0-R1.0") - testCompile("org.spigotmc:spigot117R1:1.17.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-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/CraftStructureBlock.java b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/CraftStructureBlock.java index 05066d7c..f092da61 100644 --- a/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/CraftStructureBlock.java +++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/CraftStructureBlock.java @@ -10,12 +10,11 @@ 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.BlockPosition; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.level.block.EnumBlockMirror; -import net.minecraft.world.level.block.EnumBlockRotation; -import net.minecraft.world.level.block.entity.TileEntityStructure; -import net.minecraft.world.level.block.state.properties.BlockPropertyStructureMode; +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.block.Block; import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; @@ -27,7 +26,7 @@ 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. @@ -40,13 +39,13 @@ 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(); + CompoundTag compound = new CompoundTag(); compound = this.tileEntityStructure.save(compound); this.setSaveName(compound.getString("name")); this.setAuthor(compound.getString("author")); @@ -60,9 +59,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")))); } /** @@ -75,27 +74,28 @@ public CraftStructureBlock(StructureBlockAbstractImpl structur @Override public boolean update(boolean force, boolean applyPhysics) { final boolean result = super.update(force, applyPhysics); - NBTTagCompound compound = new NBTTagCompound(); + CompoundTag compound = new CompoundTag(); 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()); + 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.tileEntityStructure.load(compound); - this.tileEntityStructure.update(); + this.tileEntityStructure.setChanged(); + return result; } 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 index 1e65814b..a8c96b45 100644 --- 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 @@ -1,9 +1,8 @@ package com.github.shynixn.structureblocklib.bukkit.v1_17_R1; import com.github.shynixn.structureblocklib.api.service.StructureSerializationService; -import net.minecraft.nbt.NBTCompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure; +import net.minecraft.nbt.*; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import java.io.IOException; import java.io.InputStream; @@ -14,34 +13,34 @@ */ public class StructureSerializationServiceImpl implements StructureSerializationService { /** - * Deserializes the {@link InputStream} to an NMS handle of DefinedStructure. + * 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 DefinedStructure. + * @return A new NMS instance of StructureTemplate. */ @Override public Object deSerialize(InputStream inputStream) throws IOException { - NBTTagCompound nbttagcompound = NBTCompressedStreamTools.a(inputStream); - DefinedStructure var4 = new DefinedStructure(); - var4.b(nbttagcompound); - return var4; + CompoundTag compound = NbtIo.readCompressed(inputStream); + StructureTemplate template = new StructureTemplate(); + template.load(compound); + return template; } /** - * Serializes the NMS handle of DefinedStructure to an {@link OutputStream}. + * Serializes the NMS handle of StructureTemplate to an {@link OutputStream}. * This call is blocking. * - * @param definedStructure NMS handle. + * @param structureTemplate 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!"); + public void serialize(Object structureTemplate, OutputStream outputStream) throws IOException { + if (!(structureTemplate instanceof StructureTemplate)) { + throw new IllegalArgumentException("StructureTemplate has to be an NMS handle!"); } - NBTTagCompound nbttagcompound = (((DefinedStructure) definedStructure)).a(new NBTTagCompound()); - NBTCompressedStreamTools.a(nbttagcompound, outputStream); + 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 index 3b9ed3c5..03e60473 100644 --- 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 @@ -4,17 +4,16 @@ 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.BlockPosition; -import net.minecraft.util.MathHelper; -import net.minecraft.world.level.World; -import net.minecraft.world.level.WorldAccess; +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.EnumBlockMirror; -import net.minecraft.world.level.block.EnumBlockRotation; -import net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure; -import net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructureInfo; -import net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructureProcessorRotation; +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; @@ -43,33 +42,33 @@ public StructureWorldServiceImpl(TypeConversionService conversionService) { */ @Override public void placeStructureToWorld(StructurePlaceMeta meta, Object structure) throws Exception { - if (!(structure instanceof DefinedStructure)) { - throw new IllegalArgumentException("DefinedStructure has to be an NMS handle!"); + if (!(structure instanceof StructureTemplate)) { + throw new IllegalArgumentException("StructureTemplate 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())); + 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.b(); - float rotation = MathHelper.a(meta.getIntegrity(), 0.0F, 1.0F); - DefinedStructureProcessorRotation rotationProcessor = new DefinedStructureProcessorRotation(rotation); + 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.a(rotationProcessor); - info.a(random); + info.addProcessor(rotationProcessor); + info.setRandom(random); } - definedStructure.a((WorldAccess) world, cornerBlock, cornerBlock, info, new Random(), 2); + template.placeInWorld(world, cornerBlock, cornerBlock, info, new Random(), 2); } /** @@ -80,14 +79,14 @@ public void placeStructureToWorld(StructurePlaceMeta meta, Object structure) thr */ @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()); + 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); - DefinedStructure definedStructure = new DefinedStructure(); - definedStructure.a(world, cornerBlock, offsetBlock, meta.isIncludeEntitiesEnabled(), structureVoid); - definedStructure.a(meta.getAuthor()); - return definedStructure; + 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-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/TypeConversionServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/TypeConversionServiceImpl.java index 9dd03983..b8a436c9 100644 --- a/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/TypeConversionServiceImpl.java +++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/TypeConversionServiceImpl.java @@ -4,9 +4,8 @@ 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.world.level.block.EnumBlockMirror; -import net.minecraft.world.level.block.EnumBlockRotation; -import net.minecraft.world.level.block.state.properties.BlockPropertyStructureMode; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; public class TypeConversionServiceImpl implements TypeConversionService { /** @@ -17,13 +16,13 @@ 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 d: + case DATA: return StructureMode.DATA; - case b: + case LOAD: return StructureMode.LOAD; - case a: + case SAVE: return StructureMode.SAVE; default: return StructureMode.CORNER; @@ -38,11 +37,11 @@ public StructureMode convertToStructureMode(Object handle) { */ @Override public StructureMirror convertToStructureMirror(Object handle) { - EnumBlockMirror mirror = (EnumBlockMirror) handle; + Mirror mirror = (Mirror) handle; switch (mirror) { - case c: + case FRONT_BACK: return StructureMirror.FRONT_BACK; - case b: + case LEFT_RIGHT: return StructureMirror.LEFT_RIGHT; default: return StructureMirror.NONE; @@ -57,13 +56,13 @@ public StructureMirror convertToStructureMirror(Object handle) { */ @Override public StructureRotation convertToStructureRotation(Object handle) { - EnumBlockRotation rotation = (EnumBlockRotation) handle; + Rotation rotation = (Rotation) handle; switch (rotation) { - case b: + case CLOCKWISE_90: return StructureRotation.ROTATION_90; - case c: + case CLOCKWISE_180: return StructureRotation.ROTATION_180; - case d: + case COUNTERCLOCKWISE_90: return StructureRotation.ROTATION_270; default: return StructureRotation.NONE; @@ -80,13 +79,13 @@ public StructureRotation convertToStructureRotation(Object handle) { public Object convertToStructureModeHandle(StructureMode mode) { switch (mode) { case SAVE: - return BlockPropertyStructureMode.a; + return net.minecraft.world.level.block.state.properties.StructureMode.SAVE; case DATA: - return BlockPropertyStructureMode.d; + return net.minecraft.world.level.block.state.properties.StructureMode.DATA; case LOAD: - return BlockPropertyStructureMode.b; + return net.minecraft.world.level.block.state.properties.StructureMode.LOAD; default: - return BlockPropertyStructureMode.c; + 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.c; + return Mirror.FRONT_BACK; case LEFT_RIGHT: - return EnumBlockMirror.b; + return Mirror.LEFT_RIGHT; default: - return EnumBlockMirror.a; + return Mirror.NONE; } } @@ -118,13 +117,13 @@ public Object convertToMirrorHandle(StructureMirror mirror) { public Object convertToRotationHandle(StructureRotation rotation) { switch (rotation) { case ROTATION_90: - return EnumBlockRotation.b; + return Rotation.CLOCKWISE_90; case ROTATION_180: - return EnumBlockRotation.c; + return Rotation.CLOCKWISE_180; case ROTATION_270: - return EnumBlockRotation.d; + return Rotation.COUNTERCLOCKWISE_90; default: - return EnumBlockRotation.a; + return Rotation.NONE; } } } diff --git a/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/helper/MockedStructureWorldService.java b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/helper/MockedStructureWorldService.java index bec13e73..dcecc3a2 100644 --- a/structureblocklib-bukkit-core/bukkit-nms-117R1/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.world.level.levelgen.structure.templatesystem.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-117R1/src/test/java/integrationtest/CraftStructureBlockIT.java b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/integrationtest/CraftStructureBlockIT.java index fc8b8eea..f91dc8b9 100644 --- a/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/integrationtest/CraftStructureBlockIT.java +++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/integrationtest/CraftStructureBlockIT.java @@ -17,13 +17,11 @@ import com.github.shynixn.structureblocklib.core.entity.StructureSaverAbstractImpl; import helper.MockedProxyService; import helper.MockedStructureWorldService; -import net.minecraft.core.BlockPosition; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.level.block.EnumBlockMirror; -import net.minecraft.world.level.block.EnumBlockRotation; -import net.minecraft.world.level.block.entity.TileEntityStructure; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.block.state.properties.BlockPropertyStructureMode; +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; @@ -45,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); @@ -100,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); @@ -124,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(NBTTagCompound.class)); + }).when(structure).load(Mockito.any(CompoundTag.class)); classUnderTest.update(); - NBTTagCompound actual = wrap.item; + CompoundTag actual = wrap.item; // Assert - Assertions.assertEquals(EnumBlockMirror.b.toString(), actual.getString("mirror")); - Assertions.assertEquals(EnumBlockRotation.b.toString(), actual.getString("rotation")); - Assertions.assertEquals(BlockPropertyStructureMode.a.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")); @@ -152,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.world.level.World world = Mockito.mock(net.minecraft.world.level.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-117R1/src/test/java/unittest/TStructureSerializationServiceImpl.java b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/test/java/unittest/TStructureSerializationServiceImpl.java index 7a322eb4..52404e0c 100644 --- a/structureblocklib-bukkit-core/bukkit-nms-117R1/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_17_R1.StructureSerializationServiceImpl; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure; +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 index b8ca5121..2273bc42 100644 --- 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 @@ -5,9 +5,8 @@ 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.EnumBlockMirror; -import net.minecraft.world.level.block.EnumBlockRotation; -import net.minecraft.world.level.block.state.properties.BlockPropertyStructureMode; +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; @@ -23,12 +22,12 @@ public void convert_StructureMirror_ShouldCorrectlyConvert() { TypeConversionService conversionService = createWithDependencies(); // Assert - Assertions.assertEquals(EnumBlockMirror.b, conversionService.convertToMirrorHandle(StructureMirror.LEFT_RIGHT)); - Assertions.assertEquals(EnumBlockMirror.c, conversionService.convertToMirrorHandle(StructureMirror.FRONT_BACK)); - Assertions.assertEquals(EnumBlockMirror.a, conversionService.convertToMirrorHandle(StructureMirror.NONE)); - Assertions.assertEquals(StructureMirror.LEFT_RIGHT, conversionService.convertToStructureMirror(EnumBlockMirror.b)); - Assertions.assertEquals(StructureMirror.FRONT_BACK, conversionService.convertToStructureMirror(EnumBlockMirror.c)); - Assertions.assertEquals(StructureMirror.NONE, conversionService.convertToStructureMirror(EnumBlockMirror.a)); + 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)); } /** @@ -42,14 +41,14 @@ public void convert_StructureRotation_ShouldCorrectlyConvert() { TypeConversionService conversionService = createWithDependencies(); // Assert - Assertions.assertEquals(EnumBlockRotation.b, conversionService.convertToRotationHandle(StructureRotation.ROTATION_90)); - Assertions.assertEquals(EnumBlockRotation.c, conversionService.convertToRotationHandle(StructureRotation.ROTATION_180)); - Assertions.assertEquals(EnumBlockRotation.d, conversionService.convertToRotationHandle(StructureRotation.ROTATION_270)); - Assertions.assertEquals(EnumBlockRotation.a, conversionService.convertToRotationHandle(StructureRotation.NONE)); - Assertions.assertEquals(StructureRotation.ROTATION_90, conversionService.convertToStructureRotation(EnumBlockRotation.b)); - Assertions.assertEquals(StructureRotation.ROTATION_180, conversionService.convertToStructureRotation(EnumBlockRotation.c)); - Assertions.assertEquals(StructureRotation.ROTATION_270, conversionService.convertToStructureRotation(EnumBlockRotation.d)); - Assertions.assertEquals(StructureRotation.NONE, conversionService.convertToStructureRotation(EnumBlockRotation.a)); + 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)); } /** @@ -63,14 +62,14 @@ public void convert_StructureMode_ShouldCorrectlyConvert() { TypeConversionService conversionService = createWithDependencies(); // Assert - Assertions.assertEquals(BlockPropertyStructureMode.c, conversionService.convertToStructureModeHandle(StructureMode.CORNER)); - Assertions.assertEquals(BlockPropertyStructureMode.a, conversionService.convertToStructureModeHandle(StructureMode.SAVE)); - Assertions.assertEquals(BlockPropertyStructureMode.d, conversionService.convertToStructureModeHandle(StructureMode.DATA)); - Assertions.assertEquals(BlockPropertyStructureMode.b, conversionService.convertToStructureModeHandle(StructureMode.LOAD)); - Assertions.assertEquals(StructureMode.CORNER, conversionService.convertToStructureMode(BlockPropertyStructureMode.c)); - Assertions.assertEquals(StructureMode.DATA, conversionService.convertToStructureMode(BlockPropertyStructureMode.d)); - Assertions.assertEquals(StructureMode.SAVE, conversionService.convertToStructureMode(BlockPropertyStructureMode.a)); - Assertions.assertEquals(StructureMode.LOAD, conversionService.convertToStructureMode(BlockPropertyStructureMode.b)); + 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() { 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"; From fcc3605ec7316e2268ea395dc566c2f87d444451 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 16:16:50 +0200 Subject: [PATCH 03/42] #73 Changed to jdk 16 build and fixed bugs. --snapshot --- .../workflows/{main.yml => main-jdk16.yml} | 16 +++++- build.gradle | 7 +-- .../bukkit/v1_17_R1/CraftStructureBlock.java | 47 +++++++++++++++-- .../build.gradle.kts | 50 ++++++++++++++++-- .../build.gradle.kts | 52 +++++++++++++++++-- 5 files changed, 152 insertions(+), 20 deletions(-) rename .github/workflows/{main.yml => main-jdk16.yml} (89%) diff --git a/.github/workflows/main.yml b/.github/workflows/main-jdk16.yml similarity index 89% rename from .github/workflows/main.yml rename to .github/workflows/main-jdk16.yml index 555da25e..cc7bb033 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main-jdk16.yml @@ -24,7 +24,7 @@ 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 @@ -37,7 +37,7 @@ jobs: run: | chmod +x gradlew ./gradlew assemble || ./gradlew downloadDependencies - ./gradlew clean build shadowJar + ./gradlew clean build pluginJar - name: Publish Test Report run: | @@ -57,6 +57,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/build.gradle b/build.gradle index 075b19c2..9bfb2601 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,7 @@ tasks.register("printVersion") { subprojects { group 'com.github.shynixn.structureblocklib' - version '2.1.1' + version '2.2.0-SNAPSHOT' apply plugin: 'kotlin-platform-jvm' apply plugin: 'signing' @@ -222,12 +222,9 @@ task downloadDependencies(type: Exec) { 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" + text += " && java -jar BuildTools.jar --rev 1.17 --remapped" standardOutput = new ByteArrayOutputStream() diff --git a/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/CraftStructureBlock.java b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/CraftStructureBlock.java index f092da61..c6b0f8ee 100644 --- a/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/CraftStructureBlock.java +++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_17_R1/CraftStructureBlock.java @@ -14,6 +14,7 @@ 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 org.bukkit.block.Block; @@ -23,6 +24,8 @@ 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; @@ -46,7 +49,7 @@ public CraftStructureBlock(StructureBlockAbstractImpl structur } CompoundTag compound = new CompoundTag(); - compound = this.tileEntityStructure.save(compound); + compound = saveCompoundTileEntityStructure(this.tileEntityStructure, compound); this.setSaveName(compound.getString("name")); this.setAuthor(compound.getString("author")); this.setBlockNameMetaData(compound.getString("metadata")); @@ -75,7 +78,7 @@ public CraftStructureBlock(StructureBlockAbstractImpl structur public boolean update(boolean force, boolean applyPhysics) { final boolean result = super.update(force, applyPhysics); CompoundTag compound = new CompoundTag(); - compound = this.tileEntityStructure.save(compound); + compound = saveCompoundTileEntityStructure(this.tileEntityStructure, compound); compound.putString("name", this.getSaveName()); compound.putString("author", this.getAuthor()); compound.putString("metadata", this.getBlockNameMetaData()); @@ -93,8 +96,8 @@ public boolean update(boolean force, boolean applyPhysics) { compound.putString("rotation", conversionService.convertToRotationHandle(getRotationType()).toString()); compound.putString("mirror", conversionService.convertToMirrorHandle(getMirrorType()).toString()); compound.putString("mode", conversionService.convertToStructureModeHandle(getStructureMode()).toString()); - this.tileEntityStructure.load(compound); - this.tileEntityStructure.setChanged(); + this.loadCompoundTileEntityStructure(this.tileEntityStructure, compound); + this.setChangedTileEntityStructure(this.tileEntityStructure); return result; } @@ -426,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-plugin/build.gradle.kts b/structureblocklib-bukkit-plugin/build.gradle.kts index 8ebf9d45..4a2d71b3 100644 --- a/structureblocklib-bukkit-plugin/build.gradle.kts +++ b/structureblocklib-bukkit-plugin/build.gradle.kts @@ -1,4 +1,7 @@ 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") @@ -12,15 +15,52 @@ publishing { 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")) diff --git a/structureblocklib-bukkit-sample/build.gradle.kts b/structureblocklib-bukkit-sample/build.gradle.kts index b511d7da..3ac58a87 100644 --- a/structureblocklib-bukkit-sample/build.gradle.kts +++ b/structureblocklib-bukkit-sample/build.gradle.kts @@ -1,4 +1,7 @@ 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") @@ -12,13 +15,54 @@ publishing { 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("C:\\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 { From 47458cc803bbd581146ef4e43c5c5009d0c6f524 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 16:17:32 +0200 Subject: [PATCH 04/42] #73 Changed name. --snapshot --- .github/workflows/main-jdk16.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main-jdk16.yml b/.github/workflows/main-jdk16.yml index cc7bb033..fe4d123d 100644 --- a/.github/workflows/main-jdk16.yml +++ b/.github/workflows/main-jdk16.yml @@ -1,6 +1,6 @@ # This is a basic workflow to help you get started with Actions -name: CI +name: CI-JDK16 # Controls when the action will run. on: From 86f201ed20ed31060a61de22d7504e562c531e1d Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 20:00:51 +0200 Subject: [PATCH 05/42] #73 Added docker stages to resolve dependencies. --snapshot --- .../workflows/{main-jdk16.yml => main.yml} | 16 ++++- Dockerfile | 65 +++++++++++++++---- README.md | 59 +++++++++++------ build.gradle | 47 -------------- .../build.gradle.kts.jdk8.txt | 36 ++++++++++ structureblocklib-tools/ops.json | 8 +++ .../settings.gradle.kts.jdk8.txt | 15 +++++ 7 files changed, 165 insertions(+), 81 deletions(-) rename .github/workflows/{main-jdk16.yml => main.yml} (86%) create mode 100644 structureblocklib-tools/build.gradle.kts.jdk8.txt create mode 100644 structureblocklib-tools/ops.json create mode 100644 structureblocklib-tools/settings.gradle.kts.jdk8.txt diff --git a/.github/workflows/main-jdk16.yml b/.github/workflows/main.yml similarity index 86% rename from .github/workflows/main-jdk16.yml rename to .github/workflows/main.yml index fe4d123d..909dc681 100644 --- a/.github/workflows/main-jdk16.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ on: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" - Build: + Build-JDK16: # The type of runner that the job will run on runs-on: ubuntu-latest @@ -33,10 +33,22 @@ jobs: path: /home/runner/.m2/repository/org/spigotmc key: spigot-dependencies + - name: Build Spigot Dependencies + if: hashFiles('~/m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar') == '' + 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 pluginJar - name: Publish Test Report diff --git a/Dockerfile b/Dockerfile index 9469bbe2..04b1373b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,55 @@ -FROM openjdk:8 - -WORKDIR /minecraft +# 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 -COPY ["structureblocklib-tools", "structureblocklib-bukkit-sample/build/libs", "./"] +# 2. Resolve minecraft-dependencies for 1.17 - Latest +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 -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 +# 3. Build plugin for 1.8 - 1.16 with jdk8 +FROM openjdk:8 AS plugin-jdk8 +WORKDIR /tmp +RUN apt-get update +RUN apt-get install maven -y +RUN apt-get install dos2unix -y +COPY --from=dependencies-jdk8 /home/.m2/ /home/.m2/ +COPY . /tmp +RUN dos2unix gradlew && ./gradlew printVersion > version.txt +RUN cp ./structureblocklib-tools/settings.gradle.kts.jdk8.txt ./settings.gradle.kts && ./structureblocklib-tools/build.gradle.kts.jdk8.txt ./structureblocklib-bukkit-core/build.gradle.kts +RUN ./gradlew build shadowJar pluginJar --no-daemon -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. Run plugin for 1.8 - 1.16 with jdk8 +FROM openjdk:8 +# Location where the server is running. +WORKDIR /app +RUN echo "eula=true" > eula.txt +COPY --from=plugin-jdk8 /tmp/version.txt . +RUN export PLUGIN_VERSION=$(cat version.txt) +COPY --from=dependencies-jdk8 /tmp/spigot-1.16.4.jar . +COPY --from=dependencies-jdk8 /tmp/structureblocklib-bukkit-sample/build/libs/structureblocklib-bukkit-sample-$PLUGIN_VERSION.jar /app/plugins/ +COPY ./structureblocklib-tools/world-1.14/ /app/ +COPY ./structureblocklib-tools/ops.json /app/ +# Port of the Minecraft Server. +EXPOSE 25565 +# Port for Remote Debugging +EXPOSE 5005 +CMD ["sh","-c","java -DIReallyKnowWhatIAmDoingISwear -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar spigot-1.16.4.jar"] diff --git a/README.md b/README.md index ace417e9..cc89e0a6 100644 --- a/README.md +++ b/README.md @@ -203,26 +203,47 @@ dependencies { ## 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 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 your minecraft server + +#### Option 2 + +* 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 9bfb2601..87f5b590 100644 --- a/build.gradle +++ b/build.gradle @@ -187,50 +187,3 @@ task generateJavaDocPages(type: org.jetbrains.dokka.gradle.DokkaTask) { , 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.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" - text += " && java -jar BuildTools.jar --rev 1.17 --remapped" - - standardOutput = new ByteArrayOutputStream() - - if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) { - commandLine 'cmd', '/c', text - } else { - commandLine 'sh', '-c', text - } -} diff --git a/structureblocklib-tools/build.gradle.kts.jdk8.txt b/structureblocklib-tools/build.gradle.kts.jdk8.txt new file mode 100644 index 00000000..b1cc7055 --- /dev/null +++ b/structureblocklib-tools/build.gradle.kts.jdk8.txt @@ -0,0 +1,36 @@ +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")!!) + } +} + +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")) + implementation(project(":structureblocklib-core")) + implementation(project(":structureblocklib-bukkit-api")) + implementation(project(":structureblocklib-bukkit-core:bukkit-nms-109R2")) + implementation(project(":structureblocklib-bukkit-core:bukkit-nms-110R1")) + implementation(project(":structureblocklib-bukkit-core:bukkit-nms-111R1")) + implementation(project(":structureblocklib-bukkit-core:bukkit-nms-112R1")) + 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-116R3")) + + compileOnly("org.spigotmc:spigot114R1:1.14.4-R1.0") + testCompile("org.spigotmc:spigot112R1:1.12.0-R1.0") +} 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 diff --git a/structureblocklib-tools/settings.gradle.kts.jdk8.txt b/structureblocklib-tools/settings.gradle.kts.jdk8.txt new file mode 100644 index 00000000..7e1c4358 --- /dev/null +++ b/structureblocklib-tools/settings.gradle.kts.jdk8.txt @@ -0,0 +1,15 @@ +rootProject.name = "structureblocklib-root" +include("structureblocklib-api") +include("structureblocklib-core") +include("structureblocklib-bukkit-api") +include("structureblocklib-bukkit-core") +include("structureblocklib-bukkit-plugin") +include("structureblocklib-bukkit-sample") +include("structureblocklib-bukkit-core:bukkit-nms-109R2") +include("structureblocklib-bukkit-core:bukkit-nms-110R1") +include("structureblocklib-bukkit-core:bukkit-nms-111R1") +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-116R3") From 43a1fcac289c55903910f6f4f575285002665df9 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 20:11:18 +0200 Subject: [PATCH 06/42] #73 Fixed dependencies. --snapshot --- .github/workflows/main.yml | 2 +- structureblocklib-bukkit-api/build.gradle.kts | 2 +- structureblocklib-bukkit-core/build.gradle.kts | 4 ++-- .../bukkit-nms-109R2/build.gradle.kts | 4 ++-- .../bukkit-nms-110R1/build.gradle.kts | 4 ++-- .../bukkit-nms-111R1/build.gradle.kts | 4 ++-- .../bukkit-nms-112R1/build.gradle.kts | 4 ++-- .../bukkit-nms-113R2/build.gradle.kts | 4 ++-- .../bukkit-nms-114R1/build.gradle.kts | 4 ++-- .../bukkit-nms-115R1/build.gradle.kts | 4 ++-- .../bukkit-nms-116R3/build.gradle.kts | 4 ++-- .../bukkit-nms-117R1/build.gradle.kts | 1 - structureblocklib-bukkit-plugin/build.gradle.kts | 2 +- structureblocklib-bukkit-sample/build.gradle.kts | 2 +- 14 files changed, 22 insertions(+), 23 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 909dc681..198676c8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,6 @@ # This is a basic workflow to help you get started with Actions -name: CI-JDK16 +name: CI # Controls when the action will run. on: diff --git a/structureblocklib-bukkit-api/build.gradle.kts b/structureblocklib-bukkit-api/build.gradle.kts index 0605f204..dee9188a 100644 --- a/structureblocklib-bukkit-api/build.gradle.kts +++ b/structureblocklib-bukkit-api/build.gradle.kts @@ -20,5 +20,5 @@ tasks.withType { 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 ce2f0992..098bdca8 100644 --- a/structureblocklib-bukkit-core/build.gradle.kts +++ b/structureblocklib-bukkit-core/build.gradle.kts @@ -32,6 +32,6 @@ dependencies { 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-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-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-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-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-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-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-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-117R1/build.gradle.kts b/structureblocklib-bukkit-core/bukkit-nms-117R1/build.gradle.kts index 68be0867..2046b07b 100644 --- a/structureblocklib-bukkit-core/bukkit-nms-117R1/build.gradle.kts +++ b/structureblocklib-bukkit-core/bukkit-nms-117R1/build.gradle.kts @@ -2,7 +2,6 @@ dependencies { implementation(project(":structureblocklib-api")) implementation(project(":structureblocklib-core")) implementation(project(":structureblocklib-bukkit-api")) - 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-plugin/build.gradle.kts b/structureblocklib-bukkit-plugin/build.gradle.kts index 4a2d71b3..5d42b267 100644 --- a/structureblocklib-bukkit-plugin/build.gradle.kts +++ b/structureblocklib-bukkit-plugin/build.gradle.kts @@ -66,5 +66,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/build.gradle.kts b/structureblocklib-bukkit-sample/build.gradle.kts index 3ac58a87..a2cfcc79 100644 --- a/structureblocklib-bukkit-sample/build.gradle.kts +++ b/structureblocklib-bukkit-sample/build.gradle.kts @@ -70,5 +70,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") } From 9ba1a33095dd92fedb0a1680181469c49d2eafae Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 20:48:47 +0200 Subject: [PATCH 07/42] #73 Init cache. --- .github/workflows/main.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 198676c8..6a480bcf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,11 +46,6 @@ jobs: 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 clean build pluginJar - - name: Publish Test Report run: | ./gradlew jacocoTestReport From 09a95aa5ecd1b41f48c8dd1ec527f0af82fd5eae Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 21:29:28 +0200 Subject: [PATCH 08/42] #73 Init cache. --- .github/workflows/main.yml | 4 ---- structureblocklib-bukkit-plugin/build.gradle.kts | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6a480bcf..cbfc5688 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,10 +46,6 @@ jobs: docker cp structureblocklib-dependencies-jdk16:/root/.m2/repository/org/spigotmc ~/.m2/repository/org/ docker rm -f structureblocklib-dependencies-jdk16 - - 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')" env: diff --git a/structureblocklib-bukkit-plugin/build.gradle.kts b/structureblocklib-bukkit-plugin/build.gradle.kts index 5d42b267..c92a711b 100644 --- a/structureblocklib-bukkit-plugin/build.gradle.kts +++ b/structureblocklib-bukkit-plugin/build.gradle.kts @@ -57,7 +57,7 @@ tasks.register("pluginJar", Exec::class.java) { if (System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("windows")) { commandLine = listOf("cmd", "/c", obsMapping.replace("\$HOME", "%userprofile%")) } else { - commandLine = listOf("sh", "-c", obsMapping) + commandLine = listOf("sh", "-c", obsMapping.replace("\$HOME", "~")) } } From c2499f57e067a725ff9e18422a55ebfd3729cb26 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 22:04:06 +0200 Subject: [PATCH 09/42] #73 Init cache. --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cbfc5688..c9ab84e4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,10 +31,10 @@ jobs: uses: actions/cache@v2 with: path: /home/runner/.m2/repository/org/spigotmc - key: spigot-dependencies + key: spigot-dependency - name: Build Spigot Dependencies - if: hashFiles('~/m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar') == '' + if: hashFiles("~/m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar") == '' run: | mkdir -p ~/.m2/repository/org/spigotmc/ docker build --target dependencies-jdk8 -t structureblocklib-dependencies-jdk8 . From e349fad0f18ee521a9dfb302d3191fa182d27b62 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 22:04:58 +0200 Subject: [PATCH 10/42] #73 Init cache. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c9ab84e4..684ae6af 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,7 @@ jobs: key: spigot-dependency - name: Build Spigot Dependencies - if: hashFiles("~/m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar") == '' + if: hashFiles('~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar') == '' run: | mkdir -p ~/.m2/repository/org/spigotmc/ docker build --target dependencies-jdk8 -t structureblocklib-dependencies-jdk8 . From a1619a006cefac5b891dd63373a6d9849989b1d2 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 22:40:36 +0200 Subject: [PATCH 11/42] #73 Init cache. --- .github/workflows/main.yml | 4 ++++ README.md | 1 + 2 files changed, 5 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 684ae6af..b0200a4c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,6 +33,10 @@ jobs: path: /home/runner/.m2/repository/org/spigotmc key: spigot-dependency + - name: Demo + run: | + ls ~/.m2/repository/org/spigotmc/spigot + - name: Build Spigot Dependencies if: hashFiles('~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar') == '' run: | diff --git a/README.md b/README.md index cc89e0a6..ed6a1e49 100644 --- a/README.md +++ b/README.md @@ -232,6 +232,7 @@ docker rm -f structureblocklib-dependencies-jdk16 * 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 From 88c33be0fd2dba21fae9b6363347b3a420493fb9 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 22:43:15 +0200 Subject: [PATCH 12/42] #73 Init cache. --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b0200a4c..0ea87568 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,8 @@ jobs: - name: Demo run: | - ls ~/.m2/repository/org/spigotmc/spigot + demo=hashFiles("~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar") + echo $demo - name: Build Spigot Dependencies if: hashFiles('~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar') == '' From 737f8f6de1592eb29427d9d145307ebd963adc09 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 22:44:27 +0200 Subject: [PATCH 13/42] #73 Init cache. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0ea87568..7656b6e6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: - name: Demo run: | - demo=hashFiles("~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar") + demo=hashFiles('~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar') echo $demo - name: Build Spigot Dependencies From dc929a2dfd7758f5c54d927d538d0c23adeaa562 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 22:46:42 +0200 Subject: [PATCH 14/42] #73 Init cache. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7656b6e6..3e0b9d76 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: - name: Demo run: | - demo=hashFiles('~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar') + demo="test -x ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar" echo $demo - name: Build Spigot Dependencies From 2613e950ab34bd5ff3b25953efa08ce607410e19 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 22:48:24 +0200 Subject: [PATCH 15/42] #73 Init cache. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3e0b9d76..e9cec199 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: - name: Demo run: | - demo="test -x ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar" + demo=$("test -x ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar") echo $demo - name: Build Spigot Dependencies From f9e27cdb0e72b399f3104b4637027a351c824991 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 22:50:00 +0200 Subject: [PATCH 16/42] #73 Init cache. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e9cec199..3d8bf0c9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: - name: Demo run: | - demo=$("test -x ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar") + demo=$(test -x ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar) echo $demo - name: Build Spigot Dependencies From 8e739a82fad1822e362f93234001c98b972c031e Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 22:51:47 +0200 Subject: [PATCH 17/42] #73 Init cache. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3d8bf0c9..53c9add7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: - name: Demo run: | - demo=$(test -x ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar) + demo=$(test -f "~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar") echo $demo - name: Build Spigot Dependencies From b3f0dbff38a0eefc1844d947b810cd74e8e2a085 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 22:52:39 +0200 Subject: [PATCH 18/42] #73 Init cache. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 53c9add7..a49e74cc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: - name: Demo run: | - demo=$(test -f "~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar") + demo=$(test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar) echo $demo - name: Build Spigot Dependencies From fe34064cad387734e5096f4e4ad2e12099e236c5 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 22:54:01 +0200 Subject: [PATCH 19/42] #73 Init cache. --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a49e74cc..2c5dd54e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,8 +35,8 @@ jobs: - name: Demo run: | - demo=$(test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar) - echo $demo + test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar && echo "Yes" + test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar || echo "No" - name: Build Spigot Dependencies if: hashFiles('~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar') == '' From f6f66d01e1b9f74d4299aaa0a415f946fee121b7 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 22:54:57 +0200 Subject: [PATCH 20/42] #73 Init cache. --- .github/workflows/main.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2c5dd54e..fbffe9cf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,6 +26,11 @@ jobs: with: java-version: '16' + - name: Demo + run: | + test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar && echo "Yes" + test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar || echo "No" + - name: Cache Spigot Dependencies id: cache-spigot-dependencies uses: actions/cache@v2 From 49e1bf68b282499cf6e6c9ae4125cf125a795969 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 22:56:20 +0200 Subject: [PATCH 21/42] #73 Init cache. --- .github/workflows/main.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fbffe9cf..1d65be38 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,11 +26,6 @@ jobs: with: java-version: '16' - - name: Demo - run: | - test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar && echo "Yes" - test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar || echo "No" - - name: Cache Spigot Dependencies id: cache-spigot-dependencies uses: actions/cache@v2 @@ -38,13 +33,8 @@ jobs: path: /home/runner/.m2/repository/org/spigotmc key: spigot-dependency - - name: Demo - run: | - test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar && echo "Yes" - test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar || echo "No" - - name: Build Spigot Dependencies - if: hashFiles('~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar') == '' + if: test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar run: | mkdir -p ~/.m2/repository/org/spigotmc/ docker build --target dependencies-jdk8 -t structureblocklib-dependencies-jdk8 . From b08fc0fed5efbcbb40dc0426948938e9986255f0 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 22:56:41 +0200 Subject: [PATCH 22/42] #73 Init cache. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1d65be38..bce59f81 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,7 @@ jobs: key: spigot-dependency - name: Build Spigot Dependencies - if: test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar + if: $(test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar) run: | mkdir -p ~/.m2/repository/org/spigotmc/ docker build --target dependencies-jdk8 -t structureblocklib-dependencies-jdk8 . From 3dd7996cd03486e50b858f2faa45fb64c4da7403 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 22:57:33 +0200 Subject: [PATCH 23/42] #73 Init cache. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bce59f81..2ae48c00 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,7 @@ jobs: key: spigot-dependency - name: Build Spigot Dependencies - if: $(test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar) + if: ${{ test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar }} run: | mkdir -p ~/.m2/repository/org/spigotmc/ docker build --target dependencies-jdk8 -t structureblocklib-dependencies-jdk8 . From fabd8da651ea781959710d2565782e2b804ce8ba Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 23:03:33 +0200 Subject: [PATCH 24/42] #73 Init cache. --- .github/workflows/main.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2ae48c00..9574cd96 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,8 +33,12 @@ jobs: path: /home/runner/.m2/repository/org/spigotmc key: spigot-dependency + - name: Demo + 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: ${{ test -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar }} + if: ${{ env.DEPENDENCIES == 'true' }} run: | mkdir -p ~/.m2/repository/org/spigotmc/ docker build --target dependencies-jdk8 -t structureblocklib-dependencies-jdk8 . @@ -47,7 +51,7 @@ jobs: docker rm -f structureblocklib-dependencies-jdk16 - 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 }} From ac6c807f2ac447e396701431710a465e5240d656 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 23:05:22 +0200 Subject: [PATCH 25/42] #73 Init cache. --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9574cd96..99549086 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,6 +36,7 @@ jobs: - name: Demo 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 + echo ${{ env.DEPENDENCIES }} - name: Build Spigot Dependencies if: ${{ env.DEPENDENCIES == 'true' }} From 464b9fba5df4720570c07a5234ffc0a7e6f5818e Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 23:06:39 +0200 Subject: [PATCH 26/42] #73 Init cache. --- .github/workflows/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 99549086..decf1cbc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,6 +38,10 @@ jobs: 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 echo ${{ env.DEPENDENCIES }} + - name: Demo2 + run: | + echo ${{ env.DEPENDENCIES }} + - name: Build Spigot Dependencies if: ${{ env.DEPENDENCIES == 'true' }} run: | From d2a5d70fe9de7184e60f56b92f2e1e5dec3617aa Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 23:09:48 +0200 Subject: [PATCH 27/42] #73 Init cache. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index decf1cbc..9e16c369 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -43,7 +43,7 @@ jobs: echo ${{ env.DEPENDENCIES }} - name: Build Spigot Dependencies - if: ${{ env.DEPENDENCIES == 'true' }} + if: "contains(env.DEPENDENCIES, 'true')" run: | mkdir -p ~/.m2/repository/org/spigotmc/ docker build --target dependencies-jdk8 -t structureblocklib-dependencies-jdk8 . From 86181a46fc9e272ed6f6ecc29f81155a8483b6d8 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 11 Jun 2021 23:11:40 +0200 Subject: [PATCH 28/42] #73 Init cache. --- .github/workflows/main.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9e16c369..e4d75aad 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,17 +33,12 @@ jobs: path: /home/runner/.m2/repository/org/spigotmc key: spigot-dependency - - name: Demo + - name: Test dependency 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 - echo ${{ env.DEPENDENCIES }} - - - name: Demo2 - run: | - echo ${{ env.DEPENDENCIES }} - name: Build Spigot Dependencies - if: "contains(env.DEPENDENCIES, 'true')" + if: ${{ env.DEPENDENCIES != 'true' }} run: | mkdir -p ~/.m2/repository/org/spigotmc/ docker build --target dependencies-jdk8 -t structureblocklib-dependencies-jdk8 . From c28246ab904b9f891f4a8a7bf04eef6f007ad83f Mon Sep 17 00:00:00 2001 From: Shynixn Date: Sat, 12 Jun 2021 00:28:44 +0200 Subject: [PATCH 29/42] #73 Demo snapshot. --snapshot --- .github/workflows/main.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e4d75aad..d226ff5b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,7 +33,7 @@ jobs: path: /home/runner/.m2/repository/org/spigotmc key: spigot-dependency - - name: Test dependency + - name: Test Spigot Dependency 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 @@ -50,6 +50,16 @@ jobs: 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 clean build pluginJar + + - name: Publish Test Report + run: | + ./gradlew jacocoTestReport + bash <(curl -s https://codecov.io/bash) + - name: Publish Release to Maven Central if: ${{ github.ref == 'refs/heads/main' }} env: From fd3c167bcb0ad4ce36bacf3daccd8ff1c7a67f94 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Sat, 12 Jun 2021 00:38:23 +0200 Subject: [PATCH 30/42] #73 Demo snapshot. --snapshot --- structureblocklib-bukkit-plugin/build.gradle.kts | 2 +- structureblocklib-bukkit-sample/build.gradle.kts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/structureblocklib-bukkit-plugin/build.gradle.kts b/structureblocklib-bukkit-plugin/build.gradle.kts index c92a711b..1f5e8a82 100644 --- a/structureblocklib-bukkit-plugin/build.gradle.kts +++ b/structureblocklib-bukkit-plugin/build.gradle.kts @@ -51,7 +51,7 @@ tasks.register("pluginJar", Exec::class.java) { 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" + + "chmod +x ${file.absolutePath} && 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")) { diff --git a/structureblocklib-bukkit-sample/build.gradle.kts b/structureblocklib-bukkit-sample/build.gradle.kts index a2cfcc79..f5dc4868 100644 --- a/structureblocklib-bukkit-sample/build.gradle.kts +++ b/structureblocklib-bukkit-sample/build.gradle.kts @@ -55,7 +55,7 @@ tasks.register("pluginJar", Exec::class.java) { 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" + + "chmod +x ${file.absolutePath} && 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")) { From 22d9c33c3570560cc4ad78b5ff50b326afeb4c6e Mon Sep 17 00:00:00 2001 From: Shynixn Date: Sat, 12 Jun 2021 00:51:06 +0200 Subject: [PATCH 31/42] #73 Demo snapshot. --snapshot --- structureblocklib-bukkit-sample/build.gradle.kts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/structureblocklib-bukkit-sample/build.gradle.kts b/structureblocklib-bukkit-sample/build.gradle.kts index f5dc4868..8139356a 100644 --- a/structureblocklib-bukkit-sample/build.gradle.kts +++ b/structureblocklib-bukkit-sample/build.gradle.kts @@ -43,10 +43,16 @@ tasks.register("pluginJar", Exec::class.java) { 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()) + try{ + Files.copy(it, file.toPath()) + }catch (e : Exception){ + e.printStackTrace() + } } + println("Downloaded " + file.absolutePath) } + println("Download") val shadowJar = tasks.findByName("shadowJar")!! as ShadowJar val obfArchiveName = "${shadowJar.baseName}-${shadowJar.version}-obfuscated.${shadowJar.extension}" val archiveName = "${shadowJar.baseName}-${shadowJar.version}.${shadowJar.extension}" From 8f4c759c3509e90f35ba3da28a5f57cec6d2cc63 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Sat, 12 Jun 2021 01:24:55 +0200 Subject: [PATCH 32/42] #73 Demo snapshot. --snapshot --- structureblocklib-bukkit-plugin/build.gradle.kts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/structureblocklib-bukkit-plugin/build.gradle.kts b/structureblocklib-bukkit-plugin/build.gradle.kts index 1f5e8a82..5e9a4a56 100644 --- a/structureblocklib-bukkit-plugin/build.gradle.kts +++ b/structureblocklib-bukkit-plugin/build.gradle.kts @@ -39,10 +39,16 @@ tasks.register("pluginJar", Exec::class.java) { 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()) + try{ + Files.copy(it, file.toPath()) + }catch (e : Exception){ + e.printStackTrace() + } } + println("Downloaded " + file.absolutePath) } + println("Download") val shadowJar = tasks.findByName("shadowJar")!! as ShadowJar val obfArchiveName = "${shadowJar.baseName}-${shadowJar.version}-obfuscated.${shadowJar.extension}" val archiveName = "${shadowJar.baseName}-${shadowJar.version}.${shadowJar.extension}" From e95b4983ac047a75bca53a33245cbff11b665213 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Sat, 12 Jun 2021 01:29:26 +0200 Subject: [PATCH 33/42] #73 Demo snapshot. --snapshot --- .github/workflows/main.yml | 2 +- structureblocklib-bukkit-plugin/build.gradle.kts | 10 ++-------- structureblocklib-bukkit-sample/build.gradle.kts | 10 ++-------- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d226ff5b..7415b042 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -53,7 +53,7 @@ jobs: - name: Build Java Application run: | chmod +x gradlew - ./gradlew clean build pluginJar + ./gradlew build pluginJar - name: Publish Test Report run: | diff --git a/structureblocklib-bukkit-plugin/build.gradle.kts b/structureblocklib-bukkit-plugin/build.gradle.kts index 5e9a4a56..c92a711b 100644 --- a/structureblocklib-bukkit-plugin/build.gradle.kts +++ b/structureblocklib-bukkit-plugin/build.gradle.kts @@ -39,16 +39,10 @@ tasks.register("pluginJar", Exec::class.java) { 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 { - try{ - Files.copy(it, file.toPath()) - }catch (e : Exception){ - e.printStackTrace() - } + Files.copy(it, file.toPath()) } - println("Downloaded " + file.absolutePath) } - println("Download") val shadowJar = tasks.findByName("shadowJar")!! as ShadowJar val obfArchiveName = "${shadowJar.baseName}-${shadowJar.version}-obfuscated.${shadowJar.extension}" val archiveName = "${shadowJar.baseName}-${shadowJar.version}.${shadowJar.extension}" @@ -57,7 +51,7 @@ tasks.register("pluginJar", Exec::class.java) { val targetJarFile = File(buildDir, "libs/$archiveName") val obsMapping = - "chmod +x ${file.absolutePath} && 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 \"$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")) { diff --git a/structureblocklib-bukkit-sample/build.gradle.kts b/structureblocklib-bukkit-sample/build.gradle.kts index 8139356a..a2cfcc79 100644 --- a/structureblocklib-bukkit-sample/build.gradle.kts +++ b/structureblocklib-bukkit-sample/build.gradle.kts @@ -43,16 +43,10 @@ tasks.register("pluginJar", Exec::class.java) { 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 { - try{ - Files.copy(it, file.toPath()) - }catch (e : Exception){ - e.printStackTrace() - } + Files.copy(it, file.toPath()) } - println("Downloaded " + file.absolutePath) } - println("Download") val shadowJar = tasks.findByName("shadowJar")!! as ShadowJar val obfArchiveName = "${shadowJar.baseName}-${shadowJar.version}-obfuscated.${shadowJar.extension}" val archiveName = "${shadowJar.baseName}-${shadowJar.version}.${shadowJar.extension}" @@ -61,7 +55,7 @@ tasks.register("pluginJar", Exec::class.java) { val targetJarFile = File(destinationDir, archiveName) val obsMapping = - "chmod +x ${file.absolutePath} && 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 \"$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")) { From d51860dc910045f8460eef7c6abad493d62f3bbe Mon Sep 17 00:00:00 2001 From: Shynixn Date: Sat, 12 Jun 2021 01:37:14 +0200 Subject: [PATCH 34/42] #73 Demo snapshot. --snapshot --- structureblocklib-bukkit-plugin/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structureblocklib-bukkit-plugin/build.gradle.kts b/structureblocklib-bukkit-plugin/build.gradle.kts index c92a711b..5d42b267 100644 --- a/structureblocklib-bukkit-plugin/build.gradle.kts +++ b/structureblocklib-bukkit-plugin/build.gradle.kts @@ -57,7 +57,7 @@ tasks.register("pluginJar", Exec::class.java) { if (System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("windows")) { commandLine = listOf("cmd", "/c", obsMapping.replace("\$HOME", "%userprofile%")) } else { - commandLine = listOf("sh", "-c", obsMapping.replace("\$HOME", "~")) + commandLine = listOf("sh", "-c", obsMapping) } } From e54cadbafd078bda13e9dbc80c365d55a31475ad Mon Sep 17 00:00:00 2001 From: Shynixn Date: Sat, 12 Jun 2021 11:00:24 +0200 Subject: [PATCH 35/42] #73 Upgraded dokka version. --snapshot --- build.gradle | 25 ++++++++++++------------- gradle.properties | 1 + 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 87f5b590..b21f23cd 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { classpath group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin', version: '1.3.72' - classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.17" + classpath "org.jetbrains.dokka:dokka-gradle-plugin:1.4.32" } } @@ -19,8 +19,6 @@ plugins { 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") { @@ -83,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' } @@ -180,10 +178,11 @@ task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) { } 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')) + 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 7fc6f1ff..47e8cf5a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,2 @@ kotlin.code.style=official +org.gradle.jvmargs=-Xms4g From 3ac6bcc48e3233934570515818b1abc295c650eb Mon Sep 17 00:00:00 2001 From: Shynixn Date: Sat, 12 Jun 2021 11:04:59 +0200 Subject: [PATCH 36/42] #73 Fixed key file. --snapshot --- .github/workflows/main.yml | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7415b042..3c08caaa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,7 +33,7 @@ jobs: path: /home/runner/.m2/repository/org/spigotmc key: spigot-dependency - - name: Test 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 diff --git a/build.gradle b/build.gradle index b21f23cd..9fe391a8 100644 --- a/build.gradle +++ b/build.gradle @@ -165,7 +165,7 @@ 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.secretKeyRingFile" = System.getenv('SIGNING_KEY_FILE') } } From ecfe9d2999da85a1da116538da62423fb04e8894 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Sat, 12 Jun 2021 11:09:34 +0200 Subject: [PATCH 37/42] #73 Fixed key file. --snapshot --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 9fe391a8..4635dd3d 100644 --- a/build.gradle +++ b/build.gradle @@ -163,8 +163,8 @@ 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.keyId" = System.getenv('SIGNING_KEY_ID') + ext."signing.password" = System.getenv('SIGNING_KEY_PASSWORD') ext."signing.secretKeyRingFile" = System.getenv('SIGNING_KEY_FILE') } } From 343ade328e2cff8acc20c76f1f3103ffc200e5a2 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Sat, 12 Jun 2021 12:11:14 +0200 Subject: [PATCH 38/42] #73 Fixed publication settings. --snapshot --- structureblocklib-bukkit-api/build.gradle.kts | 9 +-------- structureblocklib-bukkit-core/build.gradle.kts | 8 +------- structureblocklib-bukkit-plugin/build.gradle.kts | 8 +------- structureblocklib-bukkit-sample/build.gradle.kts | 8 +------- 4 files changed, 4 insertions(+), 29 deletions(-) diff --git a/structureblocklib-bukkit-api/build.gradle.kts b/structureblocklib-bukkit-api/build.gradle.kts index dee9188a..5b4d727e 100644 --- a/structureblocklib-bukkit-api/build.gradle.kts +++ b/structureblocklib-bukkit-api/build.gradle.kts @@ -1,19 +1,12 @@ 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") } diff --git a/structureblocklib-bukkit-core/build.gradle.kts b/structureblocklib-bukkit-core/build.gradle.kts index 098bdca8..61272b09 100644 --- a/structureblocklib-bukkit-core/build.gradle.kts +++ b/structureblocklib-bukkit-core/build.gradle.kts @@ -1,13 +1,7 @@ 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 { diff --git a/structureblocklib-bukkit-plugin/build.gradle.kts b/structureblocklib-bukkit-plugin/build.gradle.kts index 5d42b267..d696045d 100644 --- a/structureblocklib-bukkit-plugin/build.gradle.kts +++ b/structureblocklib-bukkit-plugin/build.gradle.kts @@ -4,13 +4,7 @@ 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 { diff --git a/structureblocklib-bukkit-sample/build.gradle.kts b/structureblocklib-bukkit-sample/build.gradle.kts index a2cfcc79..dac7eff4 100644 --- a/structureblocklib-bukkit-sample/build.gradle.kts +++ b/structureblocklib-bukkit-sample/build.gradle.kts @@ -4,13 +4,7 @@ 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 { From f6de1e09c284c7f47c9f00395b0aea3741a047ae Mon Sep 17 00:00:00 2001 From: Shynixn Date: Sat, 12 Jun 2021 12:20:29 +0200 Subject: [PATCH 39/42] #73 Fixed javadocs. --snapshot --- .../core/entity/StructureLoaderAbstractImpl.java | 4 ++-- .../structureblocklib/core/entity/StructurePlaceMetaImpl.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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. */ From c9d9cfabc0e60ab8daa504aa33331805a7906466 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Sat, 12 Jun 2021 13:00:24 +0200 Subject: [PATCH 40/42] #73 Fixed publication settings. --snapshot --- .../build.gradle.kts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/structureblocklib-bukkit-core/build.gradle.kts b/structureblocklib-bukkit-core/build.gradle.kts index 61272b09..25df1015 100644 --- a/structureblocklib-bukkit-core/build.gradle.kts +++ b/structureblocklib-bukkit-core/build.gradle.kts @@ -1,4 +1,7 @@ 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 ("7.0.0") @@ -12,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")) From 84b54cd9f576b880f10f4d18d539db95fb2e8775 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Sat, 12 Jun 2021 13:46:15 +0200 Subject: [PATCH 41/42] #73 Fixed docker file. --- .dockerignore | 8 ++++++++ Dockerfile | 42 +++++++++++++++++++++++------------------- README.md | 11 ++++++----- 3 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 .dockerignore 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/Dockerfile b/Dockerfile index 04b1373b..767fc004 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,8 +14,9 @@ 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"] -# 2. Resolve minecraft-dependencies for 1.17 - Latest +# 2. Resolve minecraft-dependencies for 1.17 - latest with jdk16 FROM adoptopenjdk/openjdk16 AS dependencies-jdk16 WORKDIR /tmp RUN apt-get update @@ -25,31 +26,34 @@ 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 -# 3. Build plugin for 1.8 - 1.16 with jdk8 -FROM openjdk:8 AS plugin-jdk8 +# 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 /home/.m2/ /home/.m2/ +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 dos2unix gradlew && ./gradlew printVersion > version.txt -RUN cp ./structureblocklib-tools/settings.gradle.kts.jdk8.txt ./settings.gradle.kts && ./structureblocklib-tools/build.gradle.kts.jdk8.txt ./structureblocklib-bukkit-core/build.gradle.kts -RUN ./gradlew build shadowJar pluginJar --no-daemon +RUN chmod +x gradlew +RUN dos2unix gradlew +RUN ./gradlew build pluginJar --no-daemon -# 4. Run plugin for 1.8 - 1.16 with jdk8 -FROM openjdk:8 -# Location where the server is running. -WORKDIR /app -RUN echo "eula=true" > eula.txt -COPY --from=plugin-jdk8 /tmp/version.txt . -RUN export PLUGIN_VERSION=$(cat version.txt) -COPY --from=dependencies-jdk8 /tmp/spigot-1.16.4.jar . -COPY --from=dependencies-jdk8 /tmp/structureblocklib-bukkit-sample/build/libs/structureblocklib-bukkit-sample-$PLUGIN_VERSION.jar /app/plugins/ -COPY ./structureblocklib-tools/world-1.14/ /app/ -COPY ./structureblocklib-tools/ops.json /app/ +# 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-SNAPSHOT +# 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 -CMD ["sh","-c","java -DIReallyKnowWhatIAmDoingISwear -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar spigot-1.16.4.jar"] +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 ed6a1e49..7cff5450 100644 --- a/README.md +++ b/README.md @@ -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 @@ -207,7 +208,7 @@ dependencies { * 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 correctly installed in your local Maven cache. +* 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. @@ -235,7 +236,7 @@ docker rm -f structureblocklib-dependencies-jdk16 * Run the ``pluginJar`` task to generate a plugin.jar file. * Run your minecraft server -#### Option 2 +#### Option 2 :whale: * Run the provided docker file. * The source code is copied to a new docker container and built to a plugin. @@ -243,7 +244,7 @@ docker rm -f structureblocklib-dependencies-jdk16 ````sh docker build -t structureblocklib . -docker run --name=structureblocklib -p 25565:25565 -p 5005:5005 structureblocklib" +docker run --name=structureblocklib -p 25565:25565 -p 5005:5005 structureblocklib ```` ## Licence From 4928ad78ff09cd04e79648961e3764729587a28d Mon Sep 17 00:00:00 2001 From: Shynixn Date: Sat, 12 Jun 2021 13:52:29 +0200 Subject: [PATCH 42/42] #73 Updated config files. --- .github/workflows/main.yml | 2 +- Dockerfile | 2 +- README.md | 16 ++++----- build.gradle | 2 +- .../src/main/resources/plugin.yml | 2 +- .../src/main/resources/plugin.yml | 2 +- .../build.gradle.kts.jdk8.txt | 36 ------------------- .../settings.gradle.kts.jdk8.txt | 15 -------- 8 files changed, 13 insertions(+), 64 deletions(-) delete mode 100644 structureblocklib-tools/build.gradle.kts.jdk8.txt delete mode 100644 structureblocklib-tools/settings.gradle.kts.jdk8.txt diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3c08caaa..66ce4a16 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ on: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" - Build-JDK16: + Build: # The type of runner that the job will run on runs-on: ubuntu-latest diff --git a/Dockerfile b/Dockerfile index 767fc004..339f96ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,7 +42,7 @@ RUN ./gradlew build pluginJar --no-daemon # 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-SNAPSHOT +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. diff --git a/README.md b/README.md index 7cff5450..f8c028ba 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ | branch | status | version | download | | ------------- | ------------- | -------- | --------| -| master | [![Build Status](https://img.shields.io/travis/Shynixn/StructureBlockLib/master.svg?style=flat-square)](https://travis-ci.org/Shynixn/StructureBlockLib) |![GitHub license](https://img.shields.io/nexus/r/https/oss.sonatype.org/com.github.shynixn.structureblocklib/structureblocklib-bukkit-plugin.svg?style=flat-square) |[Download latest release](https://github.com/Shynixn/StructureBlockLib/releases)| -| development | [![Build Status](https://img.shields.io/travis/Shynixn/StructureBlockLib/development.svg?style=flat-square)](https://travis-ci.org/Shynixn/StructureBlockLib)|![GitHub license](https://img.shields.io/nexus/s/https/oss.sonatype.org/com.github.shynixn.structureblocklib/structureblocklib-bukkit-plugin.svg?style=flat-square) | [Download snapshots](https://oss.sonatype.org/content/repositories/snapshots/com/github/shynixn/structureblocklib/structureblocklib-bukkit-plugin/) | +| master | [![Build Status](https://github.com/Shynixn/StructureBlockLib/workflows/CI/badge.svg?branch=master)](https://github.com/Shynixn/StructureBlockLib/actions) |![GitHub license](https://img.shields.io/nexus/r/https/oss.sonatype.org/com.github.shynixn.structureblocklib/structureblocklib-bukkit-plugin.svg?style=flat-square) |[Download latest release](https://github.com/Shynixn/StructureBlockLib/releases)| +| development | [![Build Status](https://github.com/Shynixn/StructureBlockLib/workflows/CI/badge.svg?branch=development)](https://github.com/Shynixn/StructureBlockLib/actions)|![GitHub license](https://img.shields.io/nexus/s/https/oss.sonatype.org/com.github.shynixn.structureblocklib/structureblocklib-bukkit-plugin.svg?style=flat-square) | [Download snapshots](https://oss.sonatype.org/content/repositories/snapshots/com/github/shynixn/structureblocklib/structureblocklib-bukkit-plugin/) | JavaDocs: https://shynixn.github.io/StructureBlockLib/apidocs/ @@ -29,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 ``` @@ -37,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") } ``` @@ -183,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 ``` @@ -197,8 +197,8 @@ 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") } ``` diff --git a/build.gradle b/build.gradle index 4635dd3d..1ba249a9 100644 --- a/build.gradle +++ b/build.gradle @@ -44,7 +44,7 @@ tasks.register("printVersion") { subprojects { group 'com.github.shynixn.structureblocklib' - version '2.2.0-SNAPSHOT' + version '2.2.0' apply plugin: 'kotlin-platform-jvm' apply plugin: 'signing' 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/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-tools/build.gradle.kts.jdk8.txt b/structureblocklib-tools/build.gradle.kts.jdk8.txt deleted file mode 100644 index b1cc7055..00000000 --- a/structureblocklib-tools/build.gradle.kts.jdk8.txt +++ /dev/null @@ -1,36 +0,0 @@ -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")!!) - } -} - -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")) - implementation(project(":structureblocklib-core")) - implementation(project(":structureblocklib-bukkit-api")) - implementation(project(":structureblocklib-bukkit-core:bukkit-nms-109R2")) - implementation(project(":structureblocklib-bukkit-core:bukkit-nms-110R1")) - implementation(project(":structureblocklib-bukkit-core:bukkit-nms-111R1")) - implementation(project(":structureblocklib-bukkit-core:bukkit-nms-112R1")) - 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-116R3")) - - compileOnly("org.spigotmc:spigot114R1:1.14.4-R1.0") - testCompile("org.spigotmc:spigot112R1:1.12.0-R1.0") -} diff --git a/structureblocklib-tools/settings.gradle.kts.jdk8.txt b/structureblocklib-tools/settings.gradle.kts.jdk8.txt deleted file mode 100644 index 7e1c4358..00000000 --- a/structureblocklib-tools/settings.gradle.kts.jdk8.txt +++ /dev/null @@ -1,15 +0,0 @@ -rootProject.name = "structureblocklib-root" -include("structureblocklib-api") -include("structureblocklib-core") -include("structureblocklib-bukkit-api") -include("structureblocklib-bukkit-core") -include("structureblocklib-bukkit-plugin") -include("structureblocklib-bukkit-sample") -include("structureblocklib-bukkit-core:bukkit-nms-109R2") -include("structureblocklib-bukkit-core:bukkit-nms-110R1") -include("structureblocklib-bukkit-core:bukkit-nms-111R1") -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-116R3")