package com.Acrobot.ChestShop.Listeners.PostTransaction;

import com.Acrobot.Breeze.Utils.InventoryUtil;
import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Events.TransactionEvent;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.Utils.uBlock;
import org.bukkit.Material;
import org.bukkit.block.Chest;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

/**
 * @author Acrobot
 */
public class EmptyShopDeleter implements Listener {
    @EventHandler(priority = EventPriority.HIGHEST)
    public static void onTransaction(TransactionEvent event) {
        if (event.getTransactionType() != TransactionEvent.TransactionType.BUY) {
            return;
        }

        Inventory ownerInventory = event.getOwnerInventory();

        if (!shopShouldBeRemoved(ownerInventory, event.getStock())) {
            return;
        }

        Sign sign = event.getSign();
        sign.getBlock().setType(Material.AIR);

        if (Properties.REMOVE_EMPTY_CHESTS && !ChestShopSign.isAdminShop(ownerInventory) && InventoryUtil.isEmpty(ownerInventory)) {
            Chest connectedChest = uBlock.findConnectedChest(sign);
            connectedChest.getBlock().setType(Material.AIR);
        } else {
            ownerInventory.addItem(new ItemStack(Material.SIGN, 1));
        }
    }

    private static boolean shopShouldBeRemoved(Inventory inventory, ItemStack[] stock) {
        return Properties.REMOVE_EMPTY_SHOPS && !ChestShopSign.isAdminShop(inventory) && !InventoryUtil.hasItems(stock, inventory);
    }
}

@@ -132,31 +132,127 @@
 op.C
-onfiguration.Properties
+hestShop;%0Aimport com.Acrobot.ChestShop.Configuration.Properties;%0Aimport com.Acrobot.ChestShop.Events.ShopDestroyedEvent
 ;%0Aim
@@ -754,16 +754,17 @@
 tener %7B%0A
+%0A
     @Eve
@@ -1044,16 +1044,117 @@
 ntory();
+%0A        Sign sign = event.getSign();%0A        Chest connectedChest = uBlock.findConnectedChest(sign);
 %0A%0A      
@@ -1261,35 +1261,151 @@
    S
-ign sign = event.getSign();
+hopDestroyedEvent destroyedEvent = new ShopDestroyedEvent(null, event.getSign(), connectedChest);%0A        ChestShop.callEvent(destroyedEvent);%0A
 %0A   
@@ -1586,76 +1586,8 @@
 ) %7B%0A
-            Chest connectedChest = uBlock.findConnectedChest(sign);%0A
     

Add a ShopDestroyed hook