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 #100 from Shynixn/development
Browse files Browse the repository at this point in the history
Merge changes to Master --release
  • Loading branch information
Shynixn authored Jun 5, 2022
2 parents 2343f85 + 381791d commit c164037
Show file tree
Hide file tree
Showing 44 changed files with 835 additions and 122 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.6.0
ENV PLUGIN_VERSION=2.7.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
90 changes: 81 additions & 9 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.6.0</version>
<version>2.7.0</version>
<scope>provided</scope>
</dependency>
```
**Gradle**

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

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

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

```java
// Minimal configuration
Expand All @@ -178,6 +178,78 @@ StructureBlockLibApi.INSTANCE
.onResult(e -> plugin.getLogger().log(Level.INFO, ChatColor.GREEN + "Loaded structure 'mystructure'."));
```

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

```java
// Minimal configuration
Plugin plugin;

StructureBlockLibApi.INSTANCE
.loadStructure(plugin)
.at(new Location(Bukkit.getWorld("world"), 100, 100, 100))
.includeEntities(true)
.onProcessEntity(part -> {
// onProcessEntity is called for every entity before it is placed.
if (part.getEntity().isPresent()) {
if (part.getEntity().get().getType() == EntityType.COW) {
// When the entity in the structure file equals COW, we do not want to place it -> return false.
return false;
}
}

// When the entity 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'."));
```

##### Load entities in memory and iterate them

```java
List<StructureEntity<Entity, Location>> entities = new ArrayList<>();
StructureBlockLibApi.INSTANCE
.loadStructure(plugin)
.at(player.getLocation()) // We do need an existing world.
.includeEntities(false) // Do not place entities.
.includeBlocks(false) // Do not place blocks.
.onProcessEntity(entity -> {
entities.add(entity);
return false;
})
.loadFromWorld("world", "me", "mystructure")
.onException(c -> c.printStackTrace())
.onResult(e -> {
for (StructureEntity<Entity, Location> structureEntity : entities) {
// Do something with the entities
structureEntity.spawnEntity(player.getLocation().add(-3, 0, 0));
}
});
```

##### Load blocks in memory and iterate them

```java
List<StructurePlacePart<Block, World>> blocks = new ArrayList<>();
StructureBlockLibApi.INSTANCE
.loadStructure(plugin)
.at(player.getLocation()) // We do need an existing world.
.includeEntities(false) // Do not place entities.
.includeBlocks(false) // Do not place blocks.
.onProcessBlock(part -> {
blocks.add(part);
return false;
})
.loadFromWorld("world", "me", "mystructure")
.onException(c -> c.printStackTrace())
.onResult(e -> {
for (StructurePlacePart<Block, World> structureBlock : blocks) {
// Do something with the blocks
System.out.println(structureBlock.getSourceBlock().getType());
}
});
```

##### Modify and use an existing structure block
```java
Expand Down Expand Up @@ -205,8 +277,8 @@ structureBlock.update();
**plugin.yml**
```yaml
libraries:
- com.github.shynixn.structureblocklib:structureblocklib-bukkit-api:2.6.0
- com.github.shynixn.structureblocklib:structureblocklib-bukkit-core:2.6.0
- com.github.shynixn.structureblocklib:structureblocklib-bukkit-api:2.7.0
- com.github.shynixn.structureblocklib:structureblocklib-bukkit-core:2.7.0
```
### For version < 1.17
Expand All @@ -225,22 +297,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.6.0</version>
<version>2.7.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.shynixn.structureblocklib</groupId>
<artifactId>structureblocklib-bukkit-core</artifactId>
<version>2.6.0</version>
<version>2.7.0</version>
<scope>compile</scope>
</dependency>
```
**Gradle**

```xml
dependencies {
implementation("com.github.shynixn.structureblocklib:structureblocklib-bukkit-api:2.6.0")
implementation("com.github.shynixn.structureblocklib:structureblocklib-bukkit-core:2.6.0")
implementation("com.github.shynixn.structureblocklib:structureblocklib-bukkit-api:2.7.0")
implementation("com.github.shynixn.structureblocklib:structureblocklib-bukkit-core:2.7.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.6.0'
version '2.7.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, B, W> extends StructureBlockConstructionAbstract<L> {
public interface StructureBlockLoadAbstract<L, V, B, E, 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, B, W> extends StructureBlockCo
* @return Loader.
*/
@NotNull
StructureLoaderAbstract<L, V, B, W> loadStructure();
StructureLoaderAbstract<L, V, B, E, W> loadStructure();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.github.shynixn.structureblocklib.api.entity;

import java.util.Optional;
import java.util.function.Consumer;

/**
* Represents an entity stored in a structure.
*/
public interface StructureEntity<Entity, Location> {
/**
* Tries to spawn an entity from the stored nbt data at the given location.
*
* @param location Target {@link Location}.
* @return A valid entity or empty optional.
*/
Optional<Entity> spawnEntity(Location location);

/**
* Generates a virtual entity, which is not added to the world but the data
* can be extracted. This entity is destroyed after peeking.
*
* @return A valid entity or empty optional.
*/
Optional<Entity> getEntity();

/**
* Gets the relative source location inside the structure.
*
* @return {@link Location}.
*/
Location getSourceLocation();

/**
* Gets the nbt data of the stored entity in string format.
*
* @return NBT data.
*/
String getNbtData();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Interface fluent API to load structures from sources into
* the world
*/
public interface StructureLoaderAbstract<L, V, B, W> {
public interface StructureLoaderAbstract<L, V, B, E, W> {
/**
* Gets the target Location.
*
Expand All @@ -32,6 +32,15 @@ public interface StructureLoaderAbstract<L, V, B, W> {
*/
boolean isIncludeEntitiesEnabled();

/**
* Should blocks which may or may not be included in the
* saved file be included in the loaded structure.
* Default true.
*
* @return flag.
*/
boolean isIncludeBlocksEnabled();

/**
* Gets the target mirror type.
* Default StructureMirror.NONE.
Expand Down Expand Up @@ -76,7 +85,7 @@ public interface StructureLoaderAbstract<L, V, B, W> {
* @return This instance.
*/
@NotNull
StructureLoaderAbstract<L, V, B, W> at(@Nullable L location);
StructureLoaderAbstract<L, V, B, E, W> at(@Nullable L location);

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

/**
* Should blocks which may or may not be included in the
* saved file be included in the loaded structure.
* Default true.
*
* @param enabled Flag.
* @return This instance.
*/
StructureLoaderAbstract<L, V, B, E, W> includeBlocks(boolean enabled);

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

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

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

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

/**
* Attaches a new function to the structure processor which is called for each block being placed in the world.
Expand All @@ -137,7 +156,19 @@ public interface StructureLoaderAbstract<L, V, B, W> {
* @return This instance.
*/
@NotNull
StructureLoaderAbstract<L, V, B, W> onProcessBlock(Function<StructurePlacePart<B, W>, Boolean> onStructurePlace);
StructureLoaderAbstract<L, V, B, E, W> onProcessBlock(Function<StructurePlacePart<B, W>, Boolean> onStructurePlace);

/**
* Attaches a new function to the structure processor which is called for each entity being placed in the world.
* If true, the entity is getting placed in the world. If false, the entity 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 entity being placed.
* @return This instance.
*/
@NotNull
StructureLoaderAbstract<L, V, B, E, W> onProcessEntity(Function<StructureEntity<E, L>, 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 @@ -17,12 +17,27 @@ public interface StructurePlaceMeta {
Position getLocation();

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

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

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

/**
* Should entities be loaded.
Expand All @@ -32,6 +47,14 @@ public interface StructurePlaceMeta {
*/
boolean isIncludeEntitiesEnabled();

/**
* Should blocks be loaded.
* Default false.
*
* @return flag.
*/
boolean isIncludeBlockEnabled();

/**
* Gets the target mirror type.
* Default StructureMirror.NONE.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;

/**
* Bukkit Wrapper for the StructureBlock.
*/
public interface StructureBlockLoad extends StructureBlockLoadAbstract<Location, Vector, Block, World>, StructureBlockConstruction {
public interface StructureBlockLoad extends StructureBlockLoadAbstract<Location, Vector, Block, Entity, World>, StructureBlockConstruction {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;

/**
* Bukkit Wrapper for StructureLoader.
*/
public interface StructureLoader extends StructureLoaderAbstract<Location, Vector, Block, World> {
public interface StructureLoader extends StructureLoaderAbstract<Location, Vector, Block, Entity, World> {
}
Loading

0 comments on commit c164037

Please sign in to comment.