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

Commit 6518b44

Browse files
authored
chore: merge #12
Fix threading issue with SchematicChunkLoader
2 parents fe86b6c + a6ec0e6 commit 6518b44

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

src/main/java/net/crystalgames/scaffolding/instance/SchematicChunkLoader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import net.minestom.server.utils.chunk.ChunkUtils;
1313
import org.jetbrains.annotations.NotNull;
1414
import org.jetbrains.annotations.Nullable;
15+
import space.vectrix.flare.fastutil.Long2ObjectSyncMap;
1516

1617
import java.util.ArrayList;
18+
import java.util.Collection;
1719
import java.util.List;
1820
import java.util.concurrent.CompletableFuture;
1921
import java.util.function.Function;
@@ -23,11 +25,11 @@
2325
public class SchematicChunkLoader implements IChunkLoader {
2426

2527
private final @NotNull Function<@NotNull Chunk, @NotNull CompletableFuture<Void>> saveHandler;
26-
private final Long2ObjectMap<ChunkBatch> batches = new Long2ObjectOpenHashMap<>();
28+
private final Long2ObjectMap<ChunkBatch> batches = Long2ObjectSyncMap.hashmap();
2729

2830
private SchematicChunkLoader(
2931
@NotNull Function<@NotNull Chunk, @NotNull CompletableFuture<Void>> saveHandler,
30-
@NotNull List<Schematic> schematics,
32+
@NotNull Collection<Schematic> schematics,
3133
int offsetX,
3234
int offsetY,
3335
int offsetZ
@@ -137,5 +139,4 @@ private Builder() {
137139
return new SchematicChunkLoader(handler, List.copyOf(schematics), xOffset, yOffset, zOffset);
138140
}
139141
}
140-
141142
}

src/main/java/net/crystalgames/scaffolding/region/Region.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package net.crystalgames.scaffolding.region;
22

3+
import net.minestom.server.coordinate.Point;
34
import net.minestom.server.coordinate.Pos;
45
import net.minestom.server.instance.Instance;
56

6-
public record Region(Instance instance, Pos lower, Pos upper) {
7+
public record Region(Instance instance, Point lower, Point upper) {
78

89
public int sizeX() {
910
return (upper.blockX() - lower.blockX()) + 1;

src/main/java/net/crystalgames/scaffolding/schematic/Schematic.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.crystalgames.scaffolding.schematic;
22

33
import net.crystalgames.scaffolding.region.Region;
4+
import net.minestom.server.coordinate.Point;
45
import net.minestom.server.coordinate.Pos;
56
import net.minestom.server.instance.Instance;
67
import net.minestom.server.instance.block.Block;
@@ -17,16 +18,16 @@
1718

1819
public interface Schematic {
1920

20-
default void read(InputStream inputStream) throws IOException, NBTException {
21+
default void read(@NotNull InputStream inputStream) throws IOException, NBTException {
2122
NBTReader reader = new NBTReader(inputStream, CompressedProcesser.GZIP);
2223
read((NBTCompound) reader.readNamed().getSecond());
2324
reader.close();
2425
inputStream.close();
2526
}
26-
void read(NBTCompound nbtTag) throws NBTException;
27+
void read(@NotNull NBTCompound nbtTag) throws NBTException;
28+
void write(@NotNull OutputStream outputStream, @NotNull Region region) throws IOException;
2729

28-
void write(OutputStream outputStream, Region region) throws IOException;
29-
CompletableFuture<Region> build(Instance instance, Pos position);
30+
CompletableFuture<Region> build(Instance instance, Point position);
3031

3132
short getWidth();
3233
short getHeight();

src/main/java/net/crystalgames/scaffolding/schematic/impl/MCEditSchematic.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.crystalgames.scaffolding.region.Region;
44
import net.crystalgames.scaffolding.schematic.Schematic;
5+
import net.minestom.server.coordinate.Point;
56
import net.minestom.server.coordinate.Pos;
67
import net.minestom.server.instance.Instance;
78
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
@@ -34,7 +35,7 @@ public class MCEditSchematic implements Schematic {
3435
private int offsetZ;
3536

3637
@Override
37-
public void read(NBTCompound nbtTag) throws NBTException {
38+
public void read(@NotNull NBTCompound nbtTag) throws NBTException {
3839
if (!nbtTag.containsKey("Blocks")) throw new NBTException("Invalid Schematic: No Blocks");
3940

4041
readSizes(nbtTag);
@@ -113,12 +114,12 @@ public void readBlocks() {
113114
}
114115

115116
@Override
116-
public void write(OutputStream outputStream, Region region) {
117+
public void write(@NotNull OutputStream outputStream, @NotNull Region region) {
117118
// TODO: Complete
118119
}
119120

120121
@Override
121-
public CompletableFuture<Region> build(Instance instance, Pos position) {
122+
public CompletableFuture<Region> build(Instance instance, Point position) {
122123
if (!read) throw new IllegalStateException("Schematic not read");
123124
CompletableFuture<Region> future = new CompletableFuture<>();
124125
CompletableFuture.runAsync(() -> {

src/main/java/net/crystalgames/scaffolding/schematic/impl/SpongeSchematic.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.crystalgames.scaffolding.region.Region;
44
import net.crystalgames.scaffolding.schematic.Schematic;
5+
import net.minestom.server.coordinate.Point;
56
import net.minestom.server.coordinate.Pos;
67
import net.minestom.server.instance.Instance;
78
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
@@ -33,7 +34,7 @@ public class SpongeSchematic implements Schematic {
3334
private int offsetZ;
3435

3536
@Override
36-
public void read(NBTCompound nbtTag) throws NBTException {
37+
public void read(@NotNull NBTCompound nbtTag) throws NBTException {
3738
readSizes(nbtTag);
3839
readBlockPalette(nbtTag);
3940
readOffsets(nbtTag);
@@ -133,12 +134,12 @@ private void readBlocks() throws NBTException {
133134
}
134135

135136
@Override
136-
public void write(OutputStream outputStream, Region region) {
137+
public void write(@NotNull OutputStream outputStream, @NotNull Region region) {
137138
// TODO: Complete
138139
}
139140

140141
@Override
141-
public CompletableFuture<Region> build(Instance instance, Pos position) {
142+
public CompletableFuture<Region> build(Instance instance, Point position) {
142143
if (!read) throw new IllegalStateException("Schematic not read");
143144
CompletableFuture<Region> future = new CompletableFuture<>();
144145
CompletableFuture.runAsync(() -> {

0 commit comments

Comments
 (0)