forked from ChestShop-authors/ChestShop-3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ChestChecker.java
48 lines (37 loc) · 1.42 KB
/
ChestChecker.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.PreShopCreation;
import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.NO_CHEST;
import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.NO_PERMISSION_FOR_CHEST;
import static com.Acrobot.ChestShop.Permission.ADMIN;
import org.bukkit.block.Container;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Security;
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.Utils.uBlock;
/**
* @author Acrobot
*/
public class ChestChecker implements Listener {
@EventHandler(priority = EventPriority.LOW)
public static void onPreShopCreation(PreShopCreationEvent event) {
if (ChestShopSign.isAdminShop(event.getSign())) {
return;
}
Container connectedChest = uBlock.findConnectedChest(event.getSign());
if (connectedChest == null) {
event.setOutcome(NO_CHEST);
return;
}
Player player = event.getPlayer();
if (Permission.has(player, ADMIN)) {
return;
}
if (!Security.canAccess(player, connectedChest.getBlock())) {
event.setOutcome(NO_PERMISSION_FOR_CHEST);
}
}
}