mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-30 22:13:21 +01:00
Add a ShopDestroyed hook
This commit is contained in:
parent
207628ae62
commit
9dae38593d
@ -1,7 +1,9 @@
|
|||||||
package com.Acrobot.ChestShop.Listeners.PostTransaction;
|
package com.Acrobot.ChestShop.Listeners.PostTransaction;
|
||||||
|
|
||||||
import com.Acrobot.Breeze.Utils.InventoryUtil;
|
import com.Acrobot.Breeze.Utils.InventoryUtil;
|
||||||
|
import com.Acrobot.ChestShop.ChestShop;
|
||||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||||
|
import com.Acrobot.ChestShop.Events.ShopDestroyedEvent;
|
||||||
import com.Acrobot.ChestShop.Events.TransactionEvent;
|
import com.Acrobot.ChestShop.Events.TransactionEvent;
|
||||||
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
||||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||||
@ -18,6 +20,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
*/
|
*/
|
||||||
public class EmptyShopDeleter implements Listener {
|
public class EmptyShopDeleter implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public static void onTransaction(TransactionEvent event) {
|
public static void onTransaction(TransactionEvent event) {
|
||||||
if (event.getTransactionType() != TransactionEvent.TransactionType.BUY) {
|
if (event.getTransactionType() != TransactionEvent.TransactionType.BUY) {
|
||||||
@ -25,16 +28,19 @@ public class EmptyShopDeleter implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Inventory ownerInventory = event.getOwnerInventory();
|
Inventory ownerInventory = event.getOwnerInventory();
|
||||||
|
Sign sign = event.getSign();
|
||||||
|
Chest connectedChest = uBlock.findConnectedChest(sign);
|
||||||
|
|
||||||
if (!shopShouldBeRemoved(ownerInventory, event.getStock())) {
|
if (!shopShouldBeRemoved(ownerInventory, event.getStock())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sign sign = event.getSign();
|
ShopDestroyedEvent destroyedEvent = new ShopDestroyedEvent(null, event.getSign(), connectedChest);
|
||||||
|
ChestShop.callEvent(destroyedEvent);
|
||||||
|
|
||||||
sign.getBlock().setType(Material.AIR);
|
sign.getBlock().setType(Material.AIR);
|
||||||
|
|
||||||
if (Properties.REMOVE_EMPTY_CHESTS && !ChestShopSign.isAdminShop(ownerInventory) && InventoryUtil.isEmpty(ownerInventory)) {
|
if (Properties.REMOVE_EMPTY_CHESTS && !ChestShopSign.isAdminShop(ownerInventory) && InventoryUtil.isEmpty(ownerInventory)) {
|
||||||
Chest connectedChest = uBlock.findConnectedChest(sign);
|
|
||||||
connectedChest.getBlock().setType(Material.AIR);
|
connectedChest.getBlock().setType(Material.AIR);
|
||||||
} else {
|
} else {
|
||||||
ownerInventory.addItem(new ItemStack(Material.SIGN, 1));
|
ownerInventory.addItem(new ItemStack(Material.SIGN, 1));
|
||||||
|
Loading…
Reference in New Issue
Block a user