Skip to content

Commit

Permalink
Merge pull request #90 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Release 2.7.1
  • Loading branch information
tastybento authored Jul 31, 2024
2 parents ab2d06e + 06d08c9 commit 92016ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>2.7.0</build.version>
<build.version>2.7.1</build.version>

<sonar.projectKey>BentoBoxWorld_Boxed</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/world/bentobox/boxed/listeners/NewAreaListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,21 @@ private void runStructurePrinter() {
* Build something in the queue. Structures are built one by one
*/
private void buildStructure() {
//BentoBox.getInstance().logDebug("buildStructure");
// Only kick off a build if there is something to build and something isn't
// already being built
if (!pasting && !itemsToBuild.isEmpty()) {
// Build item
//BentoBox.getInstance().logDebug("Build item");
StructureRecord item = itemsToBuild.poll();
placeStructure(item);
} else {
//BentoBox.getInstance().logDebug("Nothing to do");
}
}

private void placeStructure(StructureRecord item) {
//BentoBox.getInstance().logDebug("Placing structure");
// Set the semaphore - only paste one at a time
pasting = true;
// Place the structure - this cannot be done async
Expand Down Expand Up @@ -226,12 +231,14 @@ public void onChunkLoad(ChunkLoadEvent e) {
if (!(addon.inWorld(chunk.getWorld()))) {
return;
}
//BentoBox.getInstance().logDebug(e.getEventName());
Pair<Integer, Integer> chunkCoords = new Pair<Integer, Integer>(chunk.getX(), chunk.getZ());
if (pending.containsKey(chunkCoords)) {
Iterator<StructureRecord> it = pending.get(chunkCoords).iterator();
while (it.hasNext()) {
StructureRecord item = it.next();
if (item.location().getWorld().equals(e.getWorld())) {
//BentoBox.getInstance().logDebug("Placing structure in itemsToBuild " + item);
this.itemsToBuild.add(item);
it.remove();
}
Expand All @@ -240,6 +247,8 @@ public void onChunkLoad(ChunkLoadEvent e) {
ToBePlacedStructures tbd = new ToBePlacedStructures();
tbd.setReadyToBuild(pending);
toPlace.saveObjectAsync(tbd);
} else {
//BentoBox.getInstance().logDebug("Nothing to build in this chunk");
}
}

Expand Down Expand Up @@ -382,23 +391,28 @@ private void place(ConfigurationSection section, Location center, Environment en
int y = Integer.parseInt(coords[1].strip());
int z = Integer.parseInt(coords[2].strip()) + center.getBlockZ();
Location location = new Location(world, x, y, z);

//BentoBox.getInstance().logDebug("Structure " + name + " will be placed at " + location);
readyToBuild.computeIfAbsent(new Pair<>(x >> 4, z >> 4), k -> new ArrayList<>())
.add(new StructureRecord(name, "minecraft:" + name, location,
rotation, mirror, noMobs));
this.itemsToBuild
.add(new StructureRecord(name, "minecraft:" + name, location, rotation, mirror, noMobs));
} else {
addon.logError("Structure file syntax error: " + vector + ": " + Arrays.toString(coords));
}
}

// Load any todo's and add the ones from this new island to the list
ToBePlacedStructures tbd = this.loadToDos();
Map<Pair<Integer, Integer>, List<StructureRecord>> mergedMap = tbd.getReadyToBuild();
readyToBuild.forEach((key, value) -> mergedMap.merge(key, value, (list1, list2) -> {
list1.addAll(list2);
return list1;
}));

tbd.setReadyToBuild(readyToBuild);
//BentoBox.getInstance().logDebug("mergedMap size = " + mergedMap.size());
//BentoBox.getInstance().logDebug("readyToBuild size = " + readyToBuild.size());
// Save the list
tbd.setReadyToBuild(mergedMap);
toPlace.saveObjectAsync(tbd);
}

Expand Down Expand Up @@ -630,10 +644,12 @@ private static String nmsData(Block block) {

private ToBePlacedStructures loadToDos() {
if (!toPlace.objectExists(TODO)) {
//BentoBox.getInstance().logDebug("No TODO list");
return new ToBePlacedStructures();
}
ToBePlacedStructures list = toPlace.loadObject(TODO);
if (list == null) {
//BentoBox.getInstance().logDebug("TODO list is null");
return new ToBePlacedStructures();
}
if (!list.getReadyToBuild().isEmpty()) {
Expand Down

0 comments on commit 92016ed

Please sign in to comment.