mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-24 02:56:02 +01:00
Properly re-write BlockPlace listener
This commit is contained in:
parent
2448af7bcb
commit
30a514e783
@ -8,8 +8,8 @@ import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
|||||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.Chest;
|
import org.bukkit.block.Chest;
|
||||||
import org.bukkit.block.Sign;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -19,22 +19,16 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
|||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
*/
|
*/
|
||||||
public class BlockPlace implements Listener {
|
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)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public static void onBlockPlace(BlockPlaceEvent event) {
|
public static void onChestPlace(BlockPlaceEvent event) {
|
||||||
Block block = event.getBlockAgainst();
|
|
||||||
|
|
||||||
if (BlockUtil.isSign(block) && ChestShopSign.isValid((Sign) block.getState())) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Block placed = event.getBlockPlaced();
|
Block placed = event.getBlockPlaced();
|
||||||
|
|
||||||
if (!BlockUtil.isChest(placed) && placed.getType() != Material.DROPPER && placed.getType() != Material.HOPPER) {
|
if (!BlockUtil.isChest(placed)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (Permission.has(player, Permission.ADMIN)) {
|
if (Permission.has(player, Permission.ADMIN)) {
|
||||||
@ -46,20 +40,46 @@ public class BlockPlace implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!BlockUtil.isChest(placed)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Chest neighbor = uBlock.findNeighbor(placed);
|
Chest neighbor = uBlock.findNeighbor(placed);
|
||||||
|
|
||||||
if (neighbor == null) {
|
if (neighbor != null && !Security.canAccess(event.getPlayer(), neighbor.getBlock())) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Security.canAccess(event.getPlayer(), neighbor.getBlock())) {
|
|
||||||
event.getPlayer().sendMessage(Messages.prefix(Messages.ACCESS_DENIED));
|
event.getPlayer().sendMessage(Messages.prefix(Messages.ACCESS_DENIED));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public static void onPlaceAgainstSign(BlockPlaceEvent event) {
|
||||||
|
Block against = event.getBlockAgainst();
|
||||||
|
|
||||||
|
if (!ChestShopSign.isValid(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user