forked from ChestShop-authors/ChestShop-3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PreShopCreationEvent.java
190 lines (160 loc) · 3.92 KB
/
PreShopCreationEvent.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
package com.Acrobot.ChestShop.Events;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
/**
* Represents a state before shop is created
*
* @author Acrobot
*/
public class PreShopCreationEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Player creator;
private CreationOutcome outcome = CreationOutcome.SHOP_CREATED_SUCCESSFULLY;
private Sign sign;
private String[] signLines;
private final ItemStack itemStack;
public PreShopCreationEvent(Player creator, Sign sign, String[] signLines, ItemStack itemStack) {
this.creator = creator;
this.sign = sign;
this.signLines = signLines.clone();
this.itemStack = itemStack;
if (itemStack == null)
outcome = CreationOutcome.INVALID_ITEM;
}
public String getQuantityLine() {
return signLines[1];
}
public String setItemLine(String line) {
return signLines[3] = line;
}
public ItemStack getItemStack() {
return itemStack.clone();
}
/**
* Returns if event is cancelled
*
* @return Is event cancelled?
*/
public boolean isCancelled() {
return outcome != CreationOutcome.SHOP_CREATED_SUCCESSFULLY;
}
/**
* Returns the outcome of the event
*
* @return Event's outcome
*/
public CreationOutcome getOutcome() {
return outcome;
}
/**
* Sets the event's outcome
*
* @param outcome
* Outcome
*/
public void setOutcome(CreationOutcome outcome) {
this.outcome = outcome;
}
/**
* Sets the shop's creator
*
* @param creator
* Shop's creator
*/
public void setCreator(Player creator) {
this.creator = creator;
}
/**
* Sets the sign attached to the shop
*
* @param sign
* Shop sign
*/
public void setSign(Sign sign) {
this.sign = sign;
}
/**
* Sets the text on the sign
*
* @param signLines
* Text to set
*/
public void setSignLines(String[] signLines) {
this.signLines = signLines;
}
/**
* Sets one of the lines on the sign
*
* @param line
* Line number to set (0-3)
* @param text
* Text to set
*/
public void setSignLine(byte line, String text) {
this.signLines[line] = text;
}
/**
* Returns the shop's creator
*
* @return Shop's creator
*/
public Player getPlayer() {
return creator;
}
/**
* Returns the shop's sign
*
* @return Shop's sign
*/
public Sign getSign() {
return sign;
}
/**
* Returns the text on the sign
*
* @param line
* Line number (0-3)
* @return Text on the sign
*/
public String getSignLine(byte line) {
return signLines[line];
}
public String getOwnerName() {
return getSignLine((byte) 0);
}
public void setOwnerName(String name) {
this.setSignLine((byte) 0, name);
}
/**
* Returns the text on the sign
*
* @return Text on the sign
*/
public String[] getSignLines() {
return signLines;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
/**
* Possible outcomes
*/
public static enum CreationOutcome {
INVALID_ITEM, INVALID_PRICE, INVALID_QUANTITY,
SELL_PRICE_HIGHER_THAN_BUY_PRICE,
NO_CHEST,
NO_PERMISSION, NO_PERMISSION_FOR_TERRAIN, NO_PERMISSION_FOR_CHEST,
NOT_ENOUGH_MONEY,
/**
* For plugin use
*/
OTHER,
SHOP_CREATED_SUCCESSFULLY
}
}