@@ -39,10 +39,12 @@ public void onPacketPlayReceive(PacketPlayReceiveEvent event) {
3939
4040 BlockifyPosition position = new BlockifyPosition (wrapper .getBlockPosition ().getX (), wrapper .getBlockPosition ().getY (), wrapper .getBlockPosition ().getZ ());
4141
42- // Loop through all stages and views to find the block
43- for (Stage stage : stages ) {
44- for (View view : stage .getViews ()) {
45- if (view .hasBlock (position )) {
42+ // Find the block in any stage and view using streams
43+ stages .stream ()
44+ .flatMap (stage -> stage .getViews ().stream ())
45+ .filter (view -> view .hasBlock (position ))
46+ .findFirst ()
47+ .ifPresent (view -> {
4648 // Get block data from view
4749 BlockData blockData = view .getBlock (position );
4850
@@ -58,24 +60,23 @@ public void onPacketPlayReceive(PacketPlayReceiveEvent event) {
5860 // Block break functionality
5961 if (actionType == DiggingAction .FINISHED_DIGGING || canInstantBreak (player , blockData )) {
6062 Bukkit .getScheduler ().runTask (Blockify .getInstance (), () -> {
61- // Set block to air
62- view .setBlock (position , Material .AIR .createBlockData ());
63- Blockify .getInstance ().getBlockChangeManager ().sendBlockChange (view .getStage (), view .getStage ().getAudience (), position );
6463 // Call BlockifyBreakEvent
6564 BlockifyBreakEvent blockifyBreakEvent = new BlockifyBreakEvent (player , position , blockData , view , view .getStage ());
6665 blockifyBreakEvent .callEvent ();
66+
67+ // Set to air
68+ player .sendBlockChange (position .toLocation (player .getWorld ()), Material .AIR .createBlockData ());
69+ view .setBlock (position , Material .AIR .createBlockData ());
70+
6771 // If block is not cancelled, break the block, otherwise, revert the block
6872 if (blockifyBreakEvent .isCancelled ()) {
73+ System .out .println ("block break event is cancelled" );
6974 player .sendBlockChange (position .toLocation (player .getWorld ()), blockData );
7075 view .setBlock (position , blockData );
7176 }
7277 });
7378 }
74-
75- return ;
76- }
77- }
78- }
79+ });
7980 }
8081 }
8182
0 commit comments