Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #98 from Shynixn/development
Browse files Browse the repository at this point in the history
Merge changes to Master --release
  • Loading branch information
Shynixn authored Apr 30, 2022
2 parents dd640d9 + a2c9e27 commit 553ed01
Show file tree
Hide file tree
Showing 44 changed files with 745 additions and 109 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ RUN ./gradlew build pluginJar --no-daemon
# 4. Launch a minecraft server with jdk17 and plugin
FROM amazoncorretto:17
# Change to the current plugin version present in build.gradle
ENV PLUGIN_VERSION=2.5.0
ENV PLUGIN_VERSION=2.6.0
# Change to the server version you want to test.
ENV SERVER_VERSION=spigot-1.18.2.jar
# Port of the Minecraft Server.
Expand Down
41 changes: 33 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ Support development with a small tip :heart: :coffee:.
<dependency>
<groupId>com.github.shynixn.structureblocklib</groupId>
<artifactId>structureblocklib-bukkit-api</artifactId>
<version>2.5.0</version>
<version>2.6.0</version>
<scope>provided</scope>
</dependency>
```
**Gradle**

```xml
dependencies {
compileOnly("com.github.shynixn.structureblocklib:structureblocklib-bukkit-api:2.5.0")
compileOnly("com.github.shynixn.structureblocklib:structureblocklib-bukkit-api:2.6.0")
}
```

Expand Down Expand Up @@ -154,6 +154,31 @@ StructureBlockLibApi.INSTANCE
.onResult(e -> plugin.getLogger().log(Level.INFO, ChatColor.GREEN + "Loaded structure 'mystructure'."));
```

#### Load a structure on your server and manipulate the blocks

```java
// Minimal configuration
Plugin plugin;

StructureBlockLibApi.INSTANCE
.loadStructure(plugin)
.at(new Location(Bukkit.getWorld("world"), 100, 100, 100))
.onProcessBlock(part -> {
// onProcessBlock is called for every block before it is placed.
if (part.getSourceBlock().getBlockData().getMaterial() == Material.AIR) {
// When the block in the structure file equals AIR, we do not want to place it -> return false.
return false;
}

// When the block in the structure file is something else, we do want to place it -> return true.
return true;
})
.loadFromWorld("world", "me", "mystructure")
.onException(e -> plugin.getLogger().log(Level.SEVERE, "Failed to load structure.", e))
.onResult(e -> plugin.getLogger().log(Level.INFO, ChatColor.GREEN + "Loaded structure 'mystructure'."));
```


##### Modify and use an existing structure block
```java
Plugin plugin;
Expand All @@ -180,8 +205,8 @@ structureBlock.update();
**plugin.yml**
```yaml
libraries:
- com.github.shynixn.structureblocklib:structureblocklib-bukkit-api:2.5.0
- com.github.shynixn.structureblocklib:structureblocklib-bukkit-core:2.5.0
- com.github.shynixn.structureblocklib:structureblocklib-bukkit-api:2.6.0
- com.github.shynixn.structureblocklib:structureblocklib-bukkit-core:2.6.0
```
### For version < 1.17
Expand All @@ -200,22 +225,22 @@ go with the option above instead. There are several tutorials on spigotmc.org.
<dependency>
<groupId>com.github.shynixn.structureblocklib</groupId>
<artifactId>structureblocklib-bukkit-api</artifactId>
<version>2.5.0</version>
<version>2.6.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.shynixn.structureblocklib</groupId>
<artifactId>structureblocklib-bukkit-core</artifactId>
<version>2.5.0</version>
<version>2.6.0</version>
<scope>compile</scope>
</dependency>
```
**Gradle**

```xml
dependencies {
implementation("com.github.shynixn.structureblocklib:structureblocklib-bukkit-api:2.5.0")
implementation("com.github.shynixn.structureblocklib:structureblocklib-bukkit-core:2.5.0")
implementation("com.github.shynixn.structureblocklib:structureblocklib-bukkit-api:2.6.0")
implementation("com.github.shynixn.structureblocklib:structureblocklib-bukkit-core:2.6.0")
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ tasks.register("printVersion") {

subprojects {
group 'com.github.shynixn.structureblocklib'
version '2.5.0'
version '2.6.0'

apply plugin: 'kotlin-platform-jvm'
apply plugin: 'signing'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.github.shynixn.structureblocklib.api.enumeration.StructureRotation;
import org.jetbrains.annotations.NotNull;

public interface StructureBlockLoadAbstract<L, V> extends StructureBlockConstructionAbstract<L> {
public interface StructureBlockLoadAbstract<L, V, B, W> extends StructureBlockConstructionAbstract<L> {
/**
* Sets the mirrorType of the structure when getting load.
*
Expand Down Expand Up @@ -85,5 +85,5 @@ public interface StructureBlockLoadAbstract<L, V> extends StructureBlockConstruc
* @return Loader.
*/
@NotNull
StructureLoaderAbstract<L, V> loadStructure();
StructureLoaderAbstract<L, V, B, W> loadStructure();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
import java.io.File;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.function.Function;

/**
* Interface fluent API to load structures from sources into
* the world
*/
public interface StructureLoaderAbstract<L, V> {
public interface StructureLoaderAbstract<L, V, B, W> {
/**
* Gets the target Location.
*
Expand Down Expand Up @@ -75,7 +76,7 @@ public interface StructureLoaderAbstract<L, V> {
* @return This instance.
*/
@NotNull
StructureLoaderAbstract<L, V> at(@Nullable L location);
StructureLoaderAbstract<L, V, B, W> at(@Nullable L location);

/**
* Should entities which may or may not be included in the
Expand All @@ -85,7 +86,7 @@ public interface StructureLoaderAbstract<L, V> {
* @param enabled Flag.
* @return This instance.
*/
StructureLoaderAbstract<L, V> includeEntities(boolean enabled);
StructureLoaderAbstract<L, V, B, W> includeEntities(boolean enabled);

/**
* Sets the target mirror type.
Expand All @@ -94,7 +95,7 @@ public interface StructureLoaderAbstract<L, V> {
* @param mirror Mirror.
* @return This instance.
*/
StructureLoaderAbstract<L, V> mirror(StructureMirror mirror);
StructureLoaderAbstract<L, V, B, W> mirror(StructureMirror mirror);

/**
* Sets the target rotation type.
Expand All @@ -103,7 +104,7 @@ public interface StructureLoaderAbstract<L, V> {
* @param rotation Rotation.
* @return This instance.
*/
StructureLoaderAbstract<L, V> rotation(StructureRotation rotation);
StructureLoaderAbstract<L, V, B, W> rotation(StructureRotation rotation);

/**
* Sets the target integrity.
Expand All @@ -114,7 +115,7 @@ public interface StructureLoaderAbstract<L, V> {
* @param integrity Integrity.
* @return This instance.
*/
StructureLoaderAbstract<L, V> integrity(float integrity);
StructureLoaderAbstract<L, V, B, W> integrity(float integrity);

/**
* Sets the target seed.
Expand All @@ -124,7 +125,19 @@ public interface StructureLoaderAbstract<L, V> {
* @param seed Seed.
* @return This instance.
*/
StructureLoaderAbstract<L, V> seed(long seed);
StructureLoaderAbstract<L, V, B, W> seed(long seed);

/**
* Attaches a new function to the structure processor which is called for each block being placed in the world.
* If true, the block is getting placed in the world. If false, the block is not getting placed.
* Multiple processor can be attached to a single structure load (e.g. executed in the order they are added).
* If one processor returns false, subsequent processor are no longer being called.
*
* @param onStructurePlace A function being called for each block being placed.
* @return This instance.
*/
@NotNull
StructureLoaderAbstract<L, V, B, W> onProcessBlock(Function<StructurePlacePart<B, W>, Boolean> onStructurePlace);

/**
* Loads the structure blocks and entities from the given source and places
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.github.shynixn.structureblocklib.api.enumeration.StructureRotation;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.function.Function;

public interface StructurePlaceMeta {
/**
* Gets the source Location.
Expand All @@ -13,6 +16,14 @@ public interface StructurePlaceMeta {
@NotNull
Position getLocation();

/**
* Gets the processors when placing this structure.
*
* @return processors.
*/
@NotNull
List<Function<?, Boolean>> getProcessors();

/**
* Should entities be loaded.
* Default false.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.shynixn.structureblocklib.api.entity;

import org.jetbrains.annotations.NotNull;

/**
* Represents a part of the structure.
*/
public interface StructurePlacePart<Block, World> {
/**
* Gets currently processed block from the structure source.
* The location of the block is relative to the position in the structure.
*
* @return {@link Block}.
*/
@NotNull
Block getSourceBlock();

/**
* Gets target block in the world where the source block is placed.
*
* @return {@link Block}.
*/
@NotNull
Block getTargetBlock();

/**
* Gets the world where the structure is placed.
*
* @return {@link World}.
*/
@NotNull
World getWorld();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.github.shynixn.structureblocklib.api.block.StructureBlockLoadAbstract;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.util.Vector;

/**
* Bukkit Wrapper for the StructureBlock.
*/
public interface StructureBlockLoad extends StructureBlockLoadAbstract<Location, Vector>, StructureBlockConstruction {
public interface StructureBlockLoad extends StructureBlockLoadAbstract<Location, Vector, Block, World>, StructureBlockConstruction {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.github.shynixn.structureblocklib.api.entity.StructureLoaderAbstract;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.util.Vector;

/**
* Bukkit Wrapper for StructureLoader.
*/
public interface StructureLoader extends StructureLoaderAbstract<Location, Vector> {
public interface StructureLoader extends StructureLoaderAbstract<Location, Vector, Block, World> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.server.v1_9_R2.NBTTagCompound;
import net.minecraft.server.v1_9_R2.TileEntityStructure;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_9_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_9_R2.block.CraftBlockState;
Expand All @@ -23,7 +24,7 @@
import org.jetbrains.annotations.Nullable;

public class CraftStructureBlock extends CraftBlockState implements StructureBlockData, StructureBlockSave, StructureBlockLoad {
public StructureBlockAbstractImpl<Location, Vector> internalBlock;
public StructureBlockAbstractImpl<Location, Vector, Block, World> internalBlock;
public TypeConversionService conversionService;
public TileEntityStructure tileEntityStructure;

Expand All @@ -33,7 +34,7 @@ public class CraftStructureBlock extends CraftBlockState implements StructureBlo
* @param structure dependency.
* @param block dependency.
*/
public CraftStructureBlock(StructureBlockAbstractImpl<Location, Vector> structure, TypeConversionService conversionService, Block block) {
public CraftStructureBlock(StructureBlockAbstractImpl<Location, Vector, Block, World> structure, TypeConversionService conversionService, Block block) {
super(block);
final CraftWorld world = (CraftWorld) block.getWorld();
this.internalBlock = structure;
Expand Down Expand Up @@ -406,7 +407,7 @@ public void setStructureMode(@NotNull StructureMode structureMode) {
* @return New instance.
*/
@Override
public @NotNull StructureLoaderAbstract<Location, Vector> loadStructure() {
public @NotNull StructureLoaderAbstract<Location, Vector, Block, World> loadStructure() {
return internalBlock.loadStructure();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,16 @@ private CraftStructureBlock createWithDependencies(ProxyService proxyService, Ti

StructureWorldService worldService = new MockedStructureWorldService();
StructureSerializationService serializationService = new StructureSerializationServiceImpl();
StructureLoaderAbstract<Location, Vector> structureLoader = new StructureLoaderAbstractImpl<>(proxyService, serializationService, worldService);
StructureLoaderAbstract<Location, Vector, Block, World> structureLoader = new StructureLoaderAbstractImpl<>(proxyService, serializationService, worldService);
StructureSaverAbstract<Location, Vector> structureSaver = new StructureSaverAbstractImpl<>(proxyService, serializationService, worldService);
StructureBlockAbstractImpl<Location, Vector> vector = new StructureBlockAbstractImpl<>(proxyService, structureLoader, structureSaver);
StructureBlockAbstractImpl<Location, Vector, Block, World> 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<Location, Vector> structure, TypeConversionService conversionService, Block block) {
public WrappedCraftStructureBlock(StructureBlockAbstractImpl<Location, Vector, Block, World> structure, TypeConversionService conversionService, Block block) {
super(structure, conversionService, block);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.server.v1_10_R1.NBTTagCompound;
import net.minecraft.server.v1_10_R1.TileEntityStructure;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_10_R1.block.CraftBlockState;
Expand All @@ -23,7 +24,7 @@
import org.jetbrains.annotations.Nullable;

public class CraftStructureBlock extends CraftBlockState implements StructureBlockData, StructureBlockSave, StructureBlockLoad {
public StructureBlockAbstractImpl<Location, Vector> internalBlock;
public StructureBlockAbstractImpl<Location, Vector, Block, World> internalBlock;
public TypeConversionService conversionService;
public TileEntityStructure tileEntityStructure;

Expand All @@ -33,7 +34,7 @@ public class CraftStructureBlock extends CraftBlockState implements StructureBlo
* @param structure dependency.
* @param block dependency.
*/
public CraftStructureBlock(StructureBlockAbstractImpl<Location, Vector> structure, TypeConversionService conversionService, Block block) {
public CraftStructureBlock(StructureBlockAbstractImpl<Location, Vector, Block, World> structure, TypeConversionService conversionService, Block block) {
super(block);
final CraftWorld world = (CraftWorld) block.getWorld();
this.internalBlock = structure;
Expand Down Expand Up @@ -410,7 +411,7 @@ public void setStructureMode(@NotNull StructureMode structureMode) {
* @return New instance.
*/
@Override
public @NotNull StructureLoaderAbstract<Location, Vector> loadStructure() {
public @NotNull StructureLoaderAbstract<Location, Vector, Block, World> loadStructure() {
return internalBlock.loadStructure();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ private CraftStructureBlock createWithDependencies(ProxyService proxyService, Ti

StructureWorldService worldService = new MockedStructureWorldService();
StructureSerializationService serializationService = new StructureSerializationServiceImpl();
StructureLoaderAbstract<Location, Vector> structureLoader = new StructureLoaderAbstractImpl<>(proxyService, serializationService, worldService);
StructureLoaderAbstract<Location, Vector, Block, World> structureLoader = new StructureLoaderAbstractImpl<>(proxyService, serializationService, worldService);
StructureSaverAbstract<Location, Vector> structureSaver = new StructureSaverAbstractImpl<>(proxyService, serializationService, worldService);
StructureBlockAbstractImpl<Location, Vector> vector = new StructureBlockAbstractImpl<>(proxyService, structureLoader, structureSaver);
StructureBlockAbstractImpl<Location, Vector, Block, World> 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<Location, Vector> structure, TypeConversionService conversionService, Block block) {
public WrappedCraftStructureBlock(StructureBlockAbstractImpl<Location, Vector, Block, World> structure, TypeConversionService conversionService, Block block) {
super(structure, conversionService, block);
}

Expand Down
Loading

0 comments on commit 553ed01

Please sign in to comment.