forked from ChestShop-authors/ChestShop-3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ItemManager.java
50 lines (39 loc) · 1.54 KB
/
ItemManager.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
47
48
49
50
package com.Acrobot.ChestShop.Listeners.PostTransaction;
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY;
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.SELL;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import com.Acrobot.Breeze.Utils.InventoryUtil;
import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Events.TransactionEvent;
/**
* @author Acrobot
*/
public class ItemManager implements Listener {
@EventHandler
public static void shopItemRemover(TransactionEvent event) {
if (event.getTransactionType() != BUY) {
return;
}
removeItems(event.getOwnerInventory(), event.getStock());
addItems(event.getClientInventory(), event.getStock());
event.getClient().updateInventory();
}
@EventHandler
public static void inventoryItemRemover(TransactionEvent event) {
if (event.getTransactionType() != SELL) {
return;
}
removeItems(event.getClientInventory(), event.getStock());
addItems(event.getOwnerInventory(), event.getStock());
event.getClient().updateInventory();
}
private static void removeItems(Inventory inventory, ItemStack item) {
InventoryUtil.remove(item, inventory);
}
private static void addItems(Inventory inventory, ItemStack item) {
InventoryUtil.add(item, inventory, Properties.STACK_TO_64);
}
}