forked from ChestShop-authors/ChestShop-3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
StockFittingChecker.java
46 lines (38 loc) · 1.6 KB
/
StockFittingChecker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.Acrobot.ChestShop.Listeners.PreTransaction;
import com.Acrobot.Breeze.Utils.InventoryUtil;
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();
if (!InventoryUtil.fits(stock, shopInventory)) {
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();
if (!InventoryUtil.fits(stock, clientInventory)) {
event.setCancelled(NOT_ENOUGH_SPACE_IN_INVENTORY);
}
}
}