forked from ChestShop-authors/ChestShop-3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ChestShop.java
69 lines (56 loc) · 1.96 KB
/
ChestShop.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
package com.Acrobot.ChestShop.Plugins;
import static com.Acrobot.Breeze.Utils.BlockUtil.isChest;
import static com.Acrobot.Breeze.Utils.BlockUtil.isSign;
import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent;
import com.Acrobot.ChestShop.Permission;
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.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
/**
* @author Acrobot
*/
public class ChestShop implements Listener {
@EventHandler
public static void onProtectionCheck(ProtectionCheckEvent event) {
if (event.getResult() == Event.Result.DENY || event.isBuiltInProtectionIgnored()) {
return;
}
Block block = event.getBlock();
Player player = event.getPlayer();
if (!canAccess(player, block)) {
event.setResult(Event.Result.DENY);
}
}
public static boolean canAccess(Player player, Block block) {
if (Permission.has(player, Permission.ADMIN) || !canBeProtected(block)) {
return true;
}
if (isSign(block)) {
Sign sign = (Sign) block.getState();
if (!ChestShopSign.isChestShop(sign)) {
return true;
}
if (!isShopMember(player, sign)) {
return false;
}
}
if (isChest(block)) {
Sign sign = uBlock.getConnectedSign(block);
if (sign != null && !isShopMember(player, sign)) {
return false;
}
}
return true;
}
private static boolean canBeProtected(Block block) {
return isSign(block) || isChest(block);
}
private static boolean isShopMember(Player player, Sign sign) {
return ChestShopSign.isOwner(player, sign) || ChestShopSign.isAccessor(player, sign);
}
}