-
-
Notifications
You must be signed in to change notification settings - Fork 178
/
SignCreate.java
48 lines (39 loc) · 1.53 KB
/
SignCreate.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
package com.Acrobot.ChestShop.Listeners.Block;
import com.Acrobot.Breeze.Utils.BlockUtil;
import com.Acrobot.Breeze.Utils.StringUtil;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.Utils.uBlock;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
/**
* @author Acrobot
*/
public class SignCreate implements Listener {
@EventHandler
public static void onSignChange(SignChangeEvent event) {
Block signBlock = event.getBlock();
String[] line = StringUtil.stripColourCodes(event.getLines());
if (!BlockUtil.isSign(signBlock)) {
return;
}
if (!ChestShopSign.isValidPreparedSign(line)) {
return;
}
PreShopCreationEvent preEvent = new PreShopCreationEvent(event.getPlayer(), (Sign) signBlock.getState(), line);
ChestShop.callEvent(preEvent);
if (preEvent.isCancelled()) {
return;
}
for (byte i = 0; i < event.getLines().length; ++i) {
event.setLine(i, preEvent.getSignLine(i));
}
ShopCreatedEvent postEvent = new ShopCreatedEvent(preEvent.getPlayer(), preEvent.getSign(), uBlock.findConnectedChest(preEvent.getSign()), preEvent.getSignLines());
ChestShop.callEvent(postEvent);
}
}