2012-08-10 21:44:32 +02:00
|
|
|
package com.Acrobot.ChestShop.Listeners.PreTransaction;
|
2012-08-10 18:56:16 +02:00
|
|
|
|
|
|
|
import com.Acrobot.Breeze.Utils.InventoryUtil;
|
2017-09-06 15:19:34 +02:00
|
|
|
import com.Acrobot.ChestShop.Database.Item;
|
2012-08-10 18:56:16 +02:00
|
|
|
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.inventory.Inventory;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
import static com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome.NOT_ENOUGH_SPACE_IN_CHEST;
|
|
|
|
import static com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome.NOT_ENOUGH_SPACE_IN_INVENTORY;
|
|
|
|
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY;
|
|
|
|
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.SELL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class StockFittingChecker implements Listener {
|
|
|
|
@EventHandler
|
|
|
|
public static void onSellCheck(PreTransactionEvent event) {
|
|
|
|
if (event.isCancelled() || event.getTransactionType() != SELL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Inventory shopInventory = event.getOwnerInventory();
|
|
|
|
ItemStack[] stock = event.getStock();
|
|
|
|
|
2018-01-05 18:30:06 +01:00
|
|
|
if (!InventoryUtil.fits(stock, shopInventory)) {
|
2012-08-10 18:56:16 +02:00
|
|
|
event.setCancelled(NOT_ENOUGH_SPACE_IN_CHEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public static void onBuyCheck(PreTransactionEvent event) {
|
|
|
|
if (event.isCancelled() || event.getTransactionType() != BUY) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Inventory clientInventory = event.getClientInventory();
|
|
|
|
ItemStack[] stock = event.getStock();
|
|
|
|
|
2018-01-05 18:30:06 +01:00
|
|
|
if (!InventoryUtil.fits(stock, clientInventory)) {
|
2012-08-10 18:56:16 +02:00
|
|
|
event.setCancelled(NOT_ENOUGH_SPACE_IN_INVENTORY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|