11package codes .kooper .blockify .protocol ;
22
33import codes .kooper .blockify .Blockify ;
4- import codes .kooper .blockify .events .BlockifyBreakEvent ;
54import codes .kooper .blockify .events .BlockifyInteractEvent ;
65import codes .kooper .blockify .models .Stage ;
76import codes .kooper .blockify .models .View ;
1615import com .github .retrooper .packetevents .wrapper .play .server .WrapperPlayServerBlockChange ;
1716import io .github .retrooper .packetevents .util .SpigotConversionUtil ;
1817import org .bukkit .Bukkit ;
19- import org .bukkit .GameMode ;
20- import org .bukkit .Material ;
2118import org .bukkit .block .data .BlockData ;
2219import org .bukkit .entity .Player ;
2320
@@ -59,26 +56,11 @@ public void onPacketPlayReceive(PacketPlayReceiveEvent event) {
5956 return ;
6057 }
6158
62- if (actionType == DiggingAction .START_DIGGING ) {
63- if (canInstantBreak (player , blockData )) {
64- actionType = DiggingAction .FINISHED_DIGGING ;
65- }
66- }
67-
68- // Block break functionality
69- if (actionType == DiggingAction .FINISHED_DIGGING ) {
70- Bukkit .getScheduler ().runTask (Blockify .getInstance (), () -> {
71- // Call BlockifyBreakEvent
72- BlockifyBreakEvent ghostBreakEvent = new BlockifyBreakEvent (player , position .toPosition (), blockData , view , view .getStage ());
73- ghostBreakEvent .callEvent ();
74- // If block is not cancelled, break the block, otherwise, revert the block
75- if (!ghostBreakEvent .isCancelled ()) {
76- Blockify .getInstance ().getBlockChangeManager ().sendBlockChange (view .getStage (), view .getStage ().getAudience (), position , Material .AIR .createBlockData ());
77- view .setBlock (position , Material .AIR .createBlockData ());
78- } else {
79- player .sendBlockChange (position .toLocation (player .getWorld ()), blockData );
80- }
81- });
59+ // Check if player has custom mining speed, if so, handle custom digging, else handle normal digging
60+ if (view .getStage ().getAudience ().getMiningSpeed (player .getUniqueId ()) != 1 ) {
61+ Blockify .getInstance ().getMiningUtils ().handleCustomDigging (player , view , actionType , blockData , position );
62+ } else {
63+ Blockify .getInstance ().getMiningUtils ().handleNormalDigging (player , view , actionType , blockData , position );
8264 }
8365
8466 return ;
@@ -88,15 +70,4 @@ public void onPacketPlayReceive(PacketPlayReceiveEvent event) {
8870 }
8971 }
9072
91- /**
92- * Check if player can instantly break block
93- *
94- * @param player Player who is digging
95- * @param blockData BlockData of the block
96- * @return boolean
97- */
98- public boolean canInstantBreak (Player player , BlockData blockData ) {
99- return blockData .getDestroySpeed (player .getInventory ().getItemInMainHand (), true ) >= blockData .getMaterial ().getHardness () * 30 || player .getGameMode () == GameMode .CREATIVE ;
100- }
101-
102- }
73+ }
0 commit comments