forked from ChestShop-authors/ChestShop-3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SignSticker.java
89 lines (74 loc) · 2.95 KB
/
SignSticker.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
package com.Acrobot.ChestShop.Listeners.PostShopCreation;
import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE;
import com.Acrobot.Breeze.Utils.BlockUtil;
import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.Utils.uBlock;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
import org.bukkit.block.data.type.WallSign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
/**
* @author Acrobot
*/
public class SignSticker implements Listener {
@EventHandler
public static void onShopCreation(ShopCreatedEvent event) {
if (!Properties.STICK_SIGNS_TO_CHESTS) {
return;
}
if (ChestShopSign.isAdminShop(event.getSign().getLine(NAME_LINE))) {
return;
}
stickSign(event.getSign().getBlock(), event.getSignLines());
}
private static void stickSign(Block signBlock, String[] lines) {
Material signMaterial = signBlock.getType();
Material newSignMaterial = null;
if (signMaterial == Material.ACACIA_SIGN) {
newSignMaterial = Material.ACACIA_WALL_SIGN;
} else if (signMaterial == Material.BIRCH_SIGN) {
newSignMaterial = Material.BIRCH_WALL_SIGN;
} else if (signMaterial == Material.DARK_OAK_SIGN) {
newSignMaterial = Material.DARK_OAK_WALL_SIGN;
} else if (signMaterial == Material.JUNGLE_SIGN) {
newSignMaterial = Material.JUNGLE_WALL_SIGN;
} else if (signMaterial == Material.OAK_SIGN) {
newSignMaterial = Material.OAK_WALL_SIGN;
} else if (signMaterial == Material.SPRUCE_SIGN) {
newSignMaterial = Material.SPRUCE_WALL_SIGN;
} else if (signMaterial == Material.MANGROVE_SIGN) {
newSignMaterial = Material.MANGROVE_WALL_SIGN;
} else if (signMaterial == Material.CRIMSON_SIGN) {
newSignMaterial = Material.CRIMSON_WALL_SIGN;
} else if (signMaterial == Material.WARPED_SIGN) {
newSignMaterial = Material.WARPED_WALL_SIGN;
}
if (newSignMaterial == null) {
return;
}
BlockFace chestFace = null;
for (BlockFace face : uBlock.CHEST_EXTENSION_FACES) {
if (BlockUtil.isChest(signBlock.getRelative(face))) {
chestFace = face;
break;
}
}
if (chestFace == null) {
return;
}
WallSign wallSign = (WallSign) Bukkit.createBlockData(newSignMaterial);
wallSign.setFacing(chestFace.getOppositeFace());
signBlock.setBlockData(wallSign);
Sign sign = (Sign) signBlock.getState();
for (int i = 0; i < lines.length; ++i) {
sign.setLine(i, lines[i]);
}
sign.update(true);
}
}