Skip to content

Commit

Permalink
Fixed not detecting broken blocks when structure grows and destroys b…
Browse files Browse the repository at this point in the history
…locks (#2198)
  • Loading branch information
OmerBenGera committed Aug 30, 2024
1 parent d38e17f commit 78d05c9
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,20 @@ private void onBucketEmpty(PlayerBucketEmptyEvent e) {

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
private void onStructureGrow(StructureGrowEvent e) {
KeyMap<Integer> blockCounts = KeyMaps.createArrayMap(KeyIndicator.MATERIAL);
KeyMap<Integer> placedBlockCounts = KeyMaps.createArrayMap(KeyIndicator.MATERIAL);
KeyMap<Integer> brokenBlockCounts = KeyMaps.createArrayMap(KeyIndicator.MATERIAL);
e.getBlocks().forEach(blockState -> {
Key blockKey = Keys.of(blockState);
if (!Keys.of(blockState.getBlock()).equals(blockKey))
blockCounts.put(blockKey, blockCounts.getOrDefault(blockKey, 0) + 1);
Key placedBlockKey = Keys.of(blockState);
Key brokenBlockKey = Keys.of(blockState.getBlock());
if (!placedBlockKey.equals(brokenBlockKey)) {
if (!placedBlockKey.equals(ConstantKeys.AIR))
placedBlockCounts.put(placedBlockKey, placedBlockCounts.getOrDefault(placedBlockKey, 0) + 1);
if (!brokenBlockKey.equals(ConstantKeys.AIR))
brokenBlockCounts.put(brokenBlockKey, brokenBlockCounts.getOrDefault(brokenBlockKey, 0) + 1);
}
});
this.worldRecordService.get().recordMultiBlocksPlace(blockCounts, e.getLocation(), WorldRecordFlags.DIRTY_CHUNKS);
this.worldRecordService.get().recordMultiBlocksPlace(placedBlockCounts, e.getLocation(), WorldRecordFlags.DIRTY_CHUNKS);
this.worldRecordService.get().recordMultiBlocksBreak(brokenBlockCounts, e.getLocation(), WorldRecordFlags.DIRTY_CHUNKS);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
Expand Down

0 comments on commit 78d05c9

Please sign in to comment.