Skip to content

Commit

Permalink
Fixed Custom Mining Speed firing event twice
Browse files Browse the repository at this point in the history
  • Loading branch information
Kooperlol committed Jun 7, 2024
1 parent 122c1de commit 9ed2d3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public boolean hasStage(String name) {
public List<Stage> getStages(Player player) {
List<Stage> stages = new ArrayList<>();
for (Stage stage : this.stages.values()) {
if (stage.getAudience().getPlayers().contains(player)) {
if (stage.getAudience().getPlayers().contains(player.getUniqueId())) {
stages.add(stage);
}
}
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/codes/kooper/blockify/utils/MiningUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public void handleCustomDigging(Player player, View view, DiggingAction actionTy
}
}

// Block break functionality
if (actionType == DiggingAction.FINISHED_DIGGING && blockStages.get(view).get(position).getStage() >= 9) {
// Block break functionality (CREATIVE)
if (actionType == DiggingAction.FINISHED_DIGGING && blockStages.get(view).get(position).getStage() >= 9 && player.getGameMode() == GameMode.CREATIVE) {
breakCustomBlock(player, position, blockData, view);
}
}
Expand All @@ -98,10 +98,10 @@ public void handleNormalDigging(Player player, View view, DiggingAction actionTy
if (actionType == DiggingAction.FINISHED_DIGGING || canInstantBreak(player, blockData)) {
Bukkit.getScheduler().runTask(Blockify.getInstance(), () -> {
// Call BlockifyBreakEvent
BlockifyBreakEvent ghostBreakEvent = new BlockifyBreakEvent(player, position.toPosition(), blockData, view, view.getStage());
ghostBreakEvent.callEvent();
BlockifyBreakEvent blockifyBreakEvent = new BlockifyBreakEvent(player, position.toPosition(), blockData, view, view.getStage());
blockifyBreakEvent.callEvent();
// If block is not cancelled, break the block, otherwise, revert the block
if (!ghostBreakEvent.isCancelled()) {
if (!blockifyBreakEvent.isCancelled()) {
Blockify.getInstance().getBlockChangeManager().sendBlockChange(view.getStage(), view.getStage().getAudience(), position, Material.AIR.createBlockData());
view.setBlock(position, Material.AIR.createBlockData());
} else {
Expand Down Expand Up @@ -148,11 +148,13 @@ public void updateBlockStage(Player player, BlockifyPosition position, BlockData
blockStage.setStage((byte) (blockStage.getStage() + 1));
// Update last updated time to current time
blockStage.setLastUpdated(System.currentTimeMillis());
// If block stage is greater than or equal to 9, break the block
if (blockStage.getStage() >= 9) {
// If block stage is 9, break the block
if (blockStage.getStage() == 9) {
breakCustomBlock(player, position, blockData, view);
player.spawnParticle(Particle.BLOCK_CRACK, position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5, 10, 0, 0, 0, blockData);
player.playSound(player.getLocation(), blockData.getSoundGroup().getBreakSound(), 1, 1);
Bukkit.getScheduler().runTask(Blockify.getInstance(), () -> {
player.spawnParticle(Particle.BLOCK_CRACK, position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5, 10, 0, 0, 0, blockData);
player.playSound(player.getLocation(), blockData.getSoundGroup().getBreakSound(), 1, 1);
});
}
}
// Send block break animation packet
Expand All @@ -175,14 +177,14 @@ public void breakCustomBlock(Player player, BlockifyPosition position, BlockData
// Run synchronously as using Spigot API
Bukkit.getScheduler().runTask(Blockify.getInstance(), () -> {
// Call BlockifyBreakEvent
BlockifyBreakEvent ghostBreakEvent = new BlockifyBreakEvent(player, position.toPosition(), blockData, view, view.getStage());
ghostBreakEvent.callEvent();
BlockifyBreakEvent blockifyBreakEvent = new BlockifyBreakEvent(player, position.toPosition(), blockData, view, view.getStage());
blockifyBreakEvent.callEvent();
// If block stage exists, cancel the task and remove it from the map
resetViewBlockAnimation(view, Set.of(position));
// Remove mining fatigue effect
player.removePotionEffect(PotionEffectType.SLOW_DIGGING);
// If block is not cancelled, break the block, otherwise, revert the block
if (!ghostBreakEvent.isCancelled()) {
if (!blockifyBreakEvent.isCancelled()) {
Blockify.getInstance().getBlockChangeManager().sendBlockChange(view.getStage(), view.getStage().getAudience(), position, Material.AIR.createBlockData());
view.setBlock(position, Material.AIR.createBlockData());
} else {
Expand Down

0 comments on commit 9ed2d3f

Please sign in to comment.