Skip to content

Commit 9ed2d3f

Browse files
committed
Fixed Custom Mining Speed firing event twice
1 parent 122c1de commit 9ed2d3f

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

src/main/java/codes/kooper/blockify/managers/StageManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public boolean hasStage(String name) {
6767
public List<Stage> getStages(Player player) {
6868
List<Stage> stages = new ArrayList<>();
6969
for (Stage stage : this.stages.values()) {
70-
if (stage.getAudience().getPlayers().contains(player)) {
70+
if (stage.getAudience().getPlayers().contains(player.getUniqueId())) {
7171
stages.add(stage);
7272
}
7373
}

src/main/java/codes/kooper/blockify/utils/MiningUtils.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public void handleCustomDigging(Player player, View view, DiggingAction actionTy
7878
}
7979
}
8080

81-
// Block break functionality
82-
if (actionType == DiggingAction.FINISHED_DIGGING && blockStages.get(view).get(position).getStage() >= 9) {
81+
// Block break functionality (CREATIVE)
82+
if (actionType == DiggingAction.FINISHED_DIGGING && blockStages.get(view).get(position).getStage() >= 9 && player.getGameMode() == GameMode.CREATIVE) {
8383
breakCustomBlock(player, position, blockData, view);
8484
}
8585
}
@@ -98,10 +98,10 @@ public void handleNormalDigging(Player player, View view, DiggingAction actionTy
9898
if (actionType == DiggingAction.FINISHED_DIGGING || canInstantBreak(player, blockData)) {
9999
Bukkit.getScheduler().runTask(Blockify.getInstance(), () -> {
100100
// Call BlockifyBreakEvent
101-
BlockifyBreakEvent ghostBreakEvent = new BlockifyBreakEvent(player, position.toPosition(), blockData, view, view.getStage());
102-
ghostBreakEvent.callEvent();
101+
BlockifyBreakEvent blockifyBreakEvent = new BlockifyBreakEvent(player, position.toPosition(), blockData, view, view.getStage());
102+
blockifyBreakEvent.callEvent();
103103
// If block is not cancelled, break the block, otherwise, revert the block
104-
if (!ghostBreakEvent.isCancelled()) {
104+
if (!blockifyBreakEvent.isCancelled()) {
105105
Blockify.getInstance().getBlockChangeManager().sendBlockChange(view.getStage(), view.getStage().getAudience(), position, Material.AIR.createBlockData());
106106
view.setBlock(position, Material.AIR.createBlockData());
107107
} else {
@@ -148,11 +148,13 @@ public void updateBlockStage(Player player, BlockifyPosition position, BlockData
148148
blockStage.setStage((byte) (blockStage.getStage() + 1));
149149
// Update last updated time to current time
150150
blockStage.setLastUpdated(System.currentTimeMillis());
151-
// If block stage is greater than or equal to 9, break the block
152-
if (blockStage.getStage() >= 9) {
151+
// If block stage is 9, break the block
152+
if (blockStage.getStage() == 9) {
153153
breakCustomBlock(player, position, blockData, view);
154-
player.spawnParticle(Particle.BLOCK_CRACK, position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5, 10, 0, 0, 0, blockData);
155-
player.playSound(player.getLocation(), blockData.getSoundGroup().getBreakSound(), 1, 1);
154+
Bukkit.getScheduler().runTask(Blockify.getInstance(), () -> {
155+
player.spawnParticle(Particle.BLOCK_CRACK, position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5, 10, 0, 0, 0, blockData);
156+
player.playSound(player.getLocation(), blockData.getSoundGroup().getBreakSound(), 1, 1);
157+
});
156158
}
157159
}
158160
// Send block break animation packet
@@ -175,14 +177,14 @@ public void breakCustomBlock(Player player, BlockifyPosition position, BlockData
175177
// Run synchronously as using Spigot API
176178
Bukkit.getScheduler().runTask(Blockify.getInstance(), () -> {
177179
// Call BlockifyBreakEvent
178-
BlockifyBreakEvent ghostBreakEvent = new BlockifyBreakEvent(player, position.toPosition(), blockData, view, view.getStage());
179-
ghostBreakEvent.callEvent();
180+
BlockifyBreakEvent blockifyBreakEvent = new BlockifyBreakEvent(player, position.toPosition(), blockData, view, view.getStage());
181+
blockifyBreakEvent.callEvent();
180182
// If block stage exists, cancel the task and remove it from the map
181183
resetViewBlockAnimation(view, Set.of(position));
182184
// Remove mining fatigue effect
183185
player.removePotionEffect(PotionEffectType.SLOW_DIGGING);
184186
// If block is not cancelled, break the block, otherwise, revert the block
185-
if (!ghostBreakEvent.isCancelled()) {
187+
if (!blockifyBreakEvent.isCancelled()) {
186188
Blockify.getInstance().getBlockChangeManager().sendBlockChange(view.getStage(), view.getStage().getAudience(), position, Material.AIR.createBlockData());
187189
view.setBlock(position, Material.AIR.createBlockData());
188190
} else {

0 commit comments

Comments
 (0)