forked from ChestShop-authors/ChestShop-3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
BlockPlace.java
85 lines (66 loc) · 2.57 KB
/
BlockPlace.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
package com.Acrobot.ChestShop.Listeners.Block;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import com.Acrobot.Breeze.Utils.BlockUtil;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Security;
import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.Utils.uBlock;
/**
* @author Acrobot
*/
public class BlockPlace implements Listener {
private static BlockFace[] SEARCH_DIRECTIONS = { BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.UP, BlockFace.DOWN };
@EventHandler(ignoreCancelled = true)
public static void onChestPlace(BlockPlaceEvent event) {
Block placed = event.getBlockPlaced();
if (!BlockUtil.isChest(placed)) {
return;
}
Player player = event.getPlayer();
if (Permission.has(player, Permission.ADMIN)) {
return;
}
if (!Security.canAccess(player, placed)) {
event.getPlayer().sendMessage(Messages.prefix(Messages.ACCESS_DENIED));
event.setCancelled(true);
}
Block neighbor = uBlock.getConnectedChest(placed);
if (neighbor != null && !Security.canAccess(event.getPlayer(), neighbor)) {
event.getPlayer().sendMessage(Messages.prefix(Messages.ACCESS_DENIED));
event.setCancelled(true);
}
}
@EventHandler(ignoreCancelled = true)
public static void onPlaceAgainstSign(BlockPlaceEvent event) {
Block against = event.getBlockAgainst();
if (!ChestShopSign.isLegacyValid(against)) {
return;
}
event.setCancelled(true);
}
@EventHandler(ignoreCancelled = true)
public static void onHopperDropperPlace(BlockPlaceEvent event) {
Block placed = event.getBlockPlaced();
if (placed.getType() != Material.HOPPER && placed.getType() != Material.DROPPER) {
return;
}
for (BlockFace face : SEARCH_DIRECTIONS) {
Block relative = placed.getRelative(face);
if (!BlockUtil.isChest(relative)) {
continue;
}
if (!Security.canAccess(event.getPlayer(), relative)) {
event.getPlayer().sendMessage(Messages.prefix(Messages.ACCESS_DENIED));
event.setCancelled(true);
return;
}
}
}
}