From cd1a13825e4cc3420597fe9bfb93561652c9da68 Mon Sep 17 00:00:00 2001 From: James Peters Date: Wed, 28 Jul 2021 21:19:04 +0100 Subject: [PATCH] Fixed #54 Call Block Break Event when removing storages by command. --- .../chests/storage/abstracts/StorageType.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/StorageType.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/StorageType.java index a23bae9..9251ba6 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/StorageType.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/StorageType.java @@ -11,6 +11,7 @@ import com.jamesdpeters.minecraft.chests.serialize.ConfigStorage; import com.jamesdpeters.minecraft.chests.serialize.LocationInfo; import com.jamesdpeters.minecraft.chests.serialize.PluginConfig; import com.jamesdpeters.minecraft.chests.storage.StorageUtils; +import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.GameMode; import org.bukkit.Location; @@ -27,6 +28,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerInteractEvent; @@ -269,10 +271,14 @@ public abstract class StorageType implements Listener public void removeStorage(Player player, String group) { T storage = getStorage(player.getUniqueId(), group); if (storage != null) { - storage.getLocations().forEach(location -> { + var locations = new ArrayList<>(storage.getLocations()); + locations.forEach(location -> { if (location != null) { Block block = location.getLocation().getBlock(); - block.breakNaturally(); + BlockBreakEvent bbe = new BlockBreakEvent(block, player); + Bukkit.getPluginManager().callEvent(bbe); + if (!bbe.isCancelled()) + block.breakNaturally(); } }); storage.dropInventory(player.getLocation());