forked from ChestShop-authors/ChestShop-3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PreTransactionEvent.java
217 lines (177 loc) · 4.74 KB
/
PreTransactionEvent.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package com.Acrobot.ChestShop.Events;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import static com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome.TRANSACTION_SUCCESFUL;
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType;
/**
* Represents a state before transaction occurs
*
* @author Acrobot
*/
public class PreTransactionEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private final Player client;
private OfflinePlayer owner;
private final TransactionType transactionType;
private final Sign sign;
private Inventory ownerInventory;
private Inventory clientInventory;
private ItemStack items;
private double price;
private TransactionOutcome transactionOutcome = TRANSACTION_SUCCESFUL;
public PreTransactionEvent(Inventory ownerInventory, Inventory clientInventory, ItemStack items, double price, Player client, OfflinePlayer owner, Sign sign, TransactionType type) {
this.ownerInventory = ownerInventory;
this.clientInventory = (clientInventory == null ? client.getInventory() : clientInventory);
this.items = items;
this.price = price;
this.client = client;
this.owner = owner;
this.sign = sign;
this.transactionType = type;
}
/**
* @return Shop's sign
*/
public Sign getSign() {
return sign;
}
/**
* @return Total price of the items
*/
public double getPrice() {
return price;
}
/**
* Sets the price of the items
*
* @param price
* Price of the items
*/
public void setPrice(double price) {
this.price = price;
}
/**
* Sets the stock
*
* @param stock
* Stock
*/
public void setStock(ItemStack stock) {
items = stock;
}
/**
* @return Stock available
*/
public ItemStack getStock() {
return items;
}
/**
* @return Shop's client
*/
public Player getClient() {
return client;
}
/**
* @return Shop's owner
*/
public OfflinePlayer getOwner() {
return owner;
}
/**
* Sets the shop's owner
*
* @param owner
* Shop owner
*/
public void setOwner(OfflinePlayer owner) {
this.owner = owner;
}
/**
* @return Owner's inventory
*/
public Inventory getOwnerInventory() {
return ownerInventory;
}
/**
* Sets the owner's inventory
*
* @param ownerInventory
* Onwer's inventory
*/
public void setOwnerInventory(Inventory ownerInventory) {
this.ownerInventory = ownerInventory;
}
/**
* Sets the client's inventory
*
* @param clientInventory
* Client's inventory
*/
public void setClientInventory(Inventory clientInventory) {
this.clientInventory = clientInventory;
}
/**
* @return Client's inventory
*/
public Inventory getClientInventory() {
return clientInventory;
}
/**
* @return Transaction's type
*/
public TransactionType getTransactionType() {
return transactionType;
}
/**
* @return Is the transaction cancelled?
*/
public boolean isCancelled() {
return transactionOutcome != TRANSACTION_SUCCESFUL;
}
/**
* @return Transaction's outcome
*/
public TransactionOutcome getTransactionOutcome() {
return transactionOutcome;
}
/**
* Sets the outcome of the transaction
*
* @param reason
* Transction's outcome
*/
public void setCancelled(TransactionOutcome reason) {
transactionOutcome = reason;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public enum TransactionOutcome {
SHOP_DOES_NOT_BUY_THIS_ITEM,
SHOP_DOES_NOT_SELL_THIS_ITEM,
CLIENT_DOES_NOT_HAVE_PERMISSION,
CLIENT_DOES_NOT_HAVE_ENOUGH_MONEY,
SHOP_DOES_NOT_HAVE_ENOUGH_MONEY,
CLIENT_DEPOSIT_FAILED,
SHOP_DEPOSIT_FAILED,
NOT_ENOUGH_SPACE_IN_CHEST,
NOT_ENOUGH_SPACE_IN_INVENTORY,
NOT_ENOUGH_STOCK_IN_CHEST,
NOT_ENOUGH_STOCK_IN_INVENTORY,
INVALID_SHOP,
SPAM_CLICKING_PROTECTION,
CREATIVE_MODE_PROTECTION,
SHOP_IS_RESTRICTED,
OTHER, // For plugin use!
TRANSACTION_SUCCESFUL
}
}