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

Commit e11d053

Browse files
author
Shynixn
committed
#99 Added includeBlocks and onProcessEntity functions to loader.
1 parent a2c9e27 commit e11d053

File tree

22 files changed

+244
-69
lines changed

22 files changed

+244
-69
lines changed

structureblocklib-api/src/main/java/com/github/shynixn/structureblocklib/api/block/StructureBlockLoadAbstract.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.github.shynixn.structureblocklib.api.enumeration.StructureRotation;
66
import org.jetbrains.annotations.NotNull;
77

8-
public interface StructureBlockLoadAbstract<L, V, B, W> extends StructureBlockConstructionAbstract<L> {
8+
public interface StructureBlockLoadAbstract<L, V, B, E, W> extends StructureBlockConstructionAbstract<L> {
99
/**
1010
* Sets the mirrorType of the structure when getting load.
1111
*
@@ -85,5 +85,5 @@ public interface StructureBlockLoadAbstract<L, V, B, W> extends StructureBlockCo
8585
* @return Loader.
8686
*/
8787
@NotNull
88-
StructureLoaderAbstract<L, V, B, W> loadStructure();
88+
StructureLoaderAbstract<L, V, B, E, W> loadStructure();
8989
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.github.shynixn.structureblocklib.api.entity;
2+
3+
import java.util.Optional;
4+
import java.util.function.Consumer;
5+
6+
/**
7+
* Represents an entity stored in a structure.
8+
*/
9+
public interface StructureEntity<Entity, Location> {
10+
/**
11+
* Tries to spawn an entity from the stored nbt data at the given location.
12+
*
13+
* @param location Target {@link Location}.
14+
* @return A valid entity or empty optional.
15+
*/
16+
Optional<Entity> spawnEntity(Location location);
17+
18+
/**
19+
* Generates a virtual entity, which is not added to the world but the data
20+
* can be extracted. This entity is destroyed after peeking.
21+
*
22+
* @return A valid entity or empty optional.
23+
*/
24+
Optional<Entity> getEntity();
25+
26+
/**
27+
* Gets the relative source location inside the structure.
28+
*
29+
* @return {@link Location}.
30+
*/
31+
Location getSourceLocation();
32+
33+
/**
34+
* Gets the nbt data of the stored entity in string format.
35+
*
36+
* @return NBT data.
37+
*/
38+
String getNbtData();
39+
}

structureblocklib-api/src/main/java/com/github/shynixn/structureblocklib/api/entity/StructureLoaderAbstract.java

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Interface fluent API to load structures from sources into
1515
* the world
1616
*/
17-
public interface StructureLoaderAbstract<L, V, B, W> {
17+
public interface StructureLoaderAbstract<L, V, B, E, W> {
1818
/**
1919
* Gets the target Location.
2020
*
@@ -32,6 +32,15 @@ public interface StructureLoaderAbstract<L, V, B, W> {
3232
*/
3333
boolean isIncludeEntitiesEnabled();
3434

35+
/**
36+
* Should blocks which may or may not be included in the
37+
* saved file be included in the loaded structure.
38+
* Default true.
39+
*
40+
* @return flag.
41+
*/
42+
boolean isIncludeBlocksEnabled();
43+
3544
/**
3645
* Gets the target mirror type.
3746
* Default StructureMirror.NONE.
@@ -76,7 +85,7 @@ public interface StructureLoaderAbstract<L, V, B, W> {
7685
* @return This instance.
7786
*/
7887
@NotNull
79-
StructureLoaderAbstract<L, V, B, W> at(@Nullable L location);
88+
StructureLoaderAbstract<L, V, B, E, W> at(@Nullable L location);
8089

8190
/**
8291
* Should entities which may or may not be included in the
@@ -86,7 +95,17 @@ public interface StructureLoaderAbstract<L, V, B, W> {
8695
* @param enabled Flag.
8796
* @return This instance.
8897
*/
89-
StructureLoaderAbstract<L, V, B, W> includeEntities(boolean enabled);
98+
StructureLoaderAbstract<L, V, B, E, W> includeEntities(boolean enabled);
99+
100+
/**
101+
* Should blocks which may or may not be included in the
102+
* saved file be included in the loaded structure.
103+
* Default true.
104+
*
105+
* @param enabled Flag.
106+
* @return This instance.
107+
*/
108+
StructureLoaderAbstract<L, V, B, E, W> includeBlocks(boolean enabled);
90109

91110
/**
92111
* Sets the target mirror type.
@@ -95,7 +114,7 @@ public interface StructureLoaderAbstract<L, V, B, W> {
95114
* @param mirror Mirror.
96115
* @return This instance.
97116
*/
98-
StructureLoaderAbstract<L, V, B, W> mirror(StructureMirror mirror);
117+
StructureLoaderAbstract<L, V, B, E, W> mirror(StructureMirror mirror);
99118

100119
/**
101120
* Sets the target rotation type.
@@ -104,7 +123,7 @@ public interface StructureLoaderAbstract<L, V, B, W> {
104123
* @param rotation Rotation.
105124
* @return This instance.
106125
*/
107-
StructureLoaderAbstract<L, V, B, W> rotation(StructureRotation rotation);
126+
StructureLoaderAbstract<L, V, B, E, W> rotation(StructureRotation rotation);
108127

109128
/**
110129
* Sets the target integrity.
@@ -115,7 +134,7 @@ public interface StructureLoaderAbstract<L, V, B, W> {
115134
* @param integrity Integrity.
116135
* @return This instance.
117136
*/
118-
StructureLoaderAbstract<L, V, B, W> integrity(float integrity);
137+
StructureLoaderAbstract<L, V, B, E, W> integrity(float integrity);
119138

120139
/**
121140
* Sets the target seed.
@@ -125,7 +144,7 @@ public interface StructureLoaderAbstract<L, V, B, W> {
125144
* @param seed Seed.
126145
* @return This instance.
127146
*/
128-
StructureLoaderAbstract<L, V, B, W> seed(long seed);
147+
StructureLoaderAbstract<L, V, B, E, W> seed(long seed);
129148

130149
/**
131150
* Attaches a new function to the structure processor which is called for each block being placed in the world.
@@ -137,7 +156,19 @@ public interface StructureLoaderAbstract<L, V, B, W> {
137156
* @return This instance.
138157
*/
139158
@NotNull
140-
StructureLoaderAbstract<L, V, B, W> onProcessBlock(Function<StructurePlacePart<B, W>, Boolean> onStructurePlace);
159+
StructureLoaderAbstract<L, V, B, E, W> onProcessBlock(Function<StructurePlacePart<B, W>, Boolean> onStructurePlace);
160+
161+
/**
162+
* Attaches a new function to the structure processor which is called for each entity being placed in the world.
163+
* If true, the entity is getting placed in the world. If false, the entity is not getting placed.
164+
* Multiple processor can be attached to a single structure load (e.g. executed in the order they are added).
165+
* If one processor returns false, subsequent processor are no longer being called.
166+
*
167+
* @param onStructurePlace A function being called for each entity being placed.
168+
* @return This instance.
169+
*/
170+
@NotNull
171+
StructureLoaderAbstract<L, V, B, E, W> onProcessEntity(Function<StructureEntity<E, L>, Boolean> onStructurePlace);
141172

142173
/**
143174
* Loads the structure blocks and entities from the given source and places

structureblocklib-api/src/main/java/com/github/shynixn/structureblocklib/api/entity/StructurePlaceMeta.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,27 @@ public interface StructurePlaceMeta {
1717
Position getLocation();
1818

1919
/**
20-
* Gets the processors when placing this structure.
20+
* Deprecated, use getBlockProcessors instead.
21+
*/
22+
@NotNull
23+
@Deprecated
24+
List<Function<?, Boolean>> getProcessors();
25+
26+
/**
27+
* Gets the block processors when placing this structure.
2128
*
2229
* @return processors.
2330
*/
2431
@NotNull
25-
List<Function<?, Boolean>> getProcessors();
32+
List<Function<?, Boolean>> getBlockProcessors();
33+
34+
/**
35+
* Gets the Entity processors when placing this structure.
36+
*
37+
* @return processors.
38+
*/
39+
@NotNull
40+
List<Function<?, Boolean>> getEntityProcessors();
2641

2742
/**
2843
* Should entities be loaded.
@@ -32,6 +47,14 @@ public interface StructurePlaceMeta {
3247
*/
3348
boolean isIncludeEntitiesEnabled();
3449

50+
/**
51+
* Should blocks be loaded.
52+
* Default false.
53+
*
54+
* @return flag.
55+
*/
56+
boolean isIncludeBlockEnabled();
57+
3558
/**
3659
* Gets the target mirror type.
3760
* Default StructureMirror.NONE.

structureblocklib-bukkit-api/src/main/java/com/github/shynixn/structureblocklib/api/bukkit/block/StructureBlockLoad.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import org.bukkit.Location;
55
import org.bukkit.World;
66
import org.bukkit.block.Block;
7+
import org.bukkit.entity.Entity;
78
import org.bukkit.util.Vector;
89

910
/**
1011
* Bukkit Wrapper for the StructureBlock.
1112
*/
12-
public interface StructureBlockLoad extends StructureBlockLoadAbstract<Location, Vector, Block, World>, StructureBlockConstruction {
13+
public interface StructureBlockLoad extends StructureBlockLoadAbstract<Location, Vector, Block, Entity, World>, StructureBlockConstruction {
1314
}

structureblocklib-bukkit-api/src/main/java/com/github/shynixn/structureblocklib/api/bukkit/entity/StructureLoader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import org.bukkit.Location;
55
import org.bukkit.World;
66
import org.bukkit.block.Block;
7+
import org.bukkit.entity.Entity;
78
import org.bukkit.util.Vector;
89

910
/**
1011
* Bukkit Wrapper for StructureLoader.
1112
*/
12-
public interface StructureLoader extends StructureLoaderAbstract<Location, Vector, Block, World> {
13+
public interface StructureLoader extends StructureLoaderAbstract<Location, Vector, Block, Entity, World> {
1314
}

structureblocklib-bukkit-core/bukkit-nms-109R2/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_9_R2/CraftStructureBlock.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
import org.bukkit.block.Block;
2020
import org.bukkit.craftbukkit.v1_9_R2.CraftWorld;
2121
import org.bukkit.craftbukkit.v1_9_R2.block.CraftBlockState;
22+
import org.bukkit.entity.Entity;
2223
import org.bukkit.util.Vector;
2324
import org.jetbrains.annotations.NotNull;
2425
import org.jetbrains.annotations.Nullable;
2526

2627
public class CraftStructureBlock extends CraftBlockState implements StructureBlockData, StructureBlockSave, StructureBlockLoad {
27-
public StructureBlockAbstractImpl<Location, Vector, Block, World> internalBlock;
28+
public StructureBlockAbstractImpl<Location, Vector, Block, Entity, World> internalBlock;
2829
public TypeConversionService conversionService;
2930
public TileEntityStructure tileEntityStructure;
3031

@@ -34,7 +35,7 @@ public class CraftStructureBlock extends CraftBlockState implements StructureBlo
3435
* @param structure dependency.
3536
* @param block dependency.
3637
*/
37-
public CraftStructureBlock(StructureBlockAbstractImpl<Location, Vector, Block, World> structure, TypeConversionService conversionService, Block block) {
38+
public CraftStructureBlock(StructureBlockAbstractImpl<Location, Vector, Block, Entity, World> structure, TypeConversionService conversionService, Block block) {
3839
super(block);
3940
final CraftWorld world = (CraftWorld) block.getWorld();
4041
this.internalBlock = structure;
@@ -407,7 +408,7 @@ public void setStructureMode(@NotNull StructureMode structureMode) {
407408
* @return New instance.
408409
*/
409410
@Override
410-
public @NotNull StructureLoaderAbstract<Location, Vector, Block, World> loadStructure() {
411+
public @NotNull StructureLoaderAbstract<Location, Vector, Block, Entity, World> loadStructure() {
411412
return internalBlock.loadStructure();
412413
}
413414

structureblocklib-bukkit-core/bukkit-nms-110R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_10_R1/CraftStructureBlock.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
import org.bukkit.block.Block;
2020
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
2121
import org.bukkit.craftbukkit.v1_10_R1.block.CraftBlockState;
22+
import org.bukkit.entity.Entity;
2223
import org.bukkit.util.Vector;
2324
import org.jetbrains.annotations.NotNull;
2425
import org.jetbrains.annotations.Nullable;
2526

2627
public class CraftStructureBlock extends CraftBlockState implements StructureBlockData, StructureBlockSave, StructureBlockLoad {
27-
public StructureBlockAbstractImpl<Location, Vector, Block, World> internalBlock;
28+
public StructureBlockAbstractImpl<Location, Vector, Block, Entity, World> internalBlock;
2829
public TypeConversionService conversionService;
2930
public TileEntityStructure tileEntityStructure;
3031

@@ -34,7 +35,7 @@ public class CraftStructureBlock extends CraftBlockState implements StructureBlo
3435
* @param structure dependency.
3536
* @param block dependency.
3637
*/
37-
public CraftStructureBlock(StructureBlockAbstractImpl<Location, Vector, Block, World> structure, TypeConversionService conversionService, Block block) {
38+
public CraftStructureBlock(StructureBlockAbstractImpl<Location, Vector, Block, Entity, World> structure, TypeConversionService conversionService, Block block) {
3839
super(block);
3940
final CraftWorld world = (CraftWorld) block.getWorld();
4041
this.internalBlock = structure;
@@ -411,7 +412,7 @@ public void setStructureMode(@NotNull StructureMode structureMode) {
411412
* @return New instance.
412413
*/
413414
@Override
414-
public @NotNull StructureLoaderAbstract<Location, Vector, Block, World> loadStructure() {
415+
public @NotNull StructureLoaderAbstract<Location, Vector, Block, Entity, World> loadStructure() {
415416
return internalBlock.loadStructure();
416417
}
417418

structureblocklib-bukkit-core/bukkit-nms-111R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_11_R1/CraftStructureBlock.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
import org.bukkit.block.Block;
2020
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
2121
import org.bukkit.craftbukkit.v1_11_R1.block.CraftBlockState;
22+
import org.bukkit.entity.Entity;
2223
import org.bukkit.util.Vector;
2324
import org.jetbrains.annotations.NotNull;
2425
import org.jetbrains.annotations.Nullable;
2526

2627
public class CraftStructureBlock extends CraftBlockState implements StructureBlockData, StructureBlockSave, StructureBlockLoad {
27-
public StructureBlockAbstractImpl<Location, Vector, Block, World> internalBlock;
28+
public StructureBlockAbstractImpl<Location, Vector, Block, Entity, World> internalBlock;
2829
public TypeConversionService conversionService;
2930
public TileEntityStructure tileEntityStructure;
3031

@@ -34,7 +35,7 @@ public class CraftStructureBlock extends CraftBlockState implements StructureBlo
3435
* @param structure dependency.
3536
* @param block dependency.
3637
*/
37-
public CraftStructureBlock(StructureBlockAbstractImpl<Location, Vector, Block, World> structure, TypeConversionService conversionService, Block block) {
38+
public CraftStructureBlock(StructureBlockAbstractImpl<Location, Vector, Block, Entity, World> structure, TypeConversionService conversionService, Block block) {
3839
super(block);
3940
final CraftWorld world = (CraftWorld) block.getWorld();
4041
this.internalBlock = structure;
@@ -411,7 +412,7 @@ public void setStructureMode(@NotNull StructureMode structureMode) {
411412
* @return New instance.
412413
*/
413414
@Override
414-
public @NotNull StructureLoaderAbstract<Location, Vector, Block, World> loadStructure() {
415+
public @NotNull StructureLoaderAbstract<Location, Vector, Block, Entity, World> loadStructure() {
415416
return internalBlock.loadStructure();
416417
}
417418

structureblocklib-bukkit-core/bukkit-nms-112R1/src/main/java/com/github/shynixn/structureblocklib/bukkit/v1_12_R1/CraftStructureBlock.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
import org.bukkit.block.Block;
2020
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
2121
import org.bukkit.craftbukkit.v1_12_R1.block.CraftBlockState;
22+
import org.bukkit.entity.Entity;
2223
import org.bukkit.util.Vector;
2324
import org.jetbrains.annotations.NotNull;
2425
import org.jetbrains.annotations.Nullable;
2526

2627
public class CraftStructureBlock extends CraftBlockState implements StructureBlockData, StructureBlockSave, StructureBlockLoad {
27-
public StructureBlockAbstractImpl<Location, Vector, Block, World> internalBlock;
28+
public StructureBlockAbstractImpl<Location, Vector, Block, Entity, World> internalBlock;
2829
public TypeConversionService conversionService;
2930
public TileEntityStructure tileEntityStructure;
3031

@@ -34,7 +35,7 @@ public class CraftStructureBlock extends CraftBlockState implements StructureBlo
3435
* @param structure dependency.
3536
* @param block dependency.
3637
*/
37-
public CraftStructureBlock(StructureBlockAbstractImpl<Location, Vector, Block, World> structure, TypeConversionService conversionService, Block block) {
38+
public CraftStructureBlock(StructureBlockAbstractImpl<Location, Vector, Block, Entity, World> structure, TypeConversionService conversionService, Block block) {
3839
super(block);
3940
final CraftWorld world = (CraftWorld) block.getWorld();
4041
this.internalBlock = structure;
@@ -411,7 +412,7 @@ public void setStructureMode(@NotNull StructureMode structureMode) {
411412
* @return New instance.
412413
*/
413414
@Override
414-
public @NotNull StructureLoaderAbstract<Location, Vector, Block, World> loadStructure() {
415+
public @NotNull StructureLoaderAbstract<Location, Vector, Block, Entity, World> loadStructure() {
415416
return internalBlock.loadStructure();
416417
}
417418

0 commit comments

Comments
 (0)