2012-06-08 15:28:36 +02:00
|
|
|
package com.Acrobot.ChestShop.Listeners.Block;
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
import com.Acrobot.Breeze.Utils.BlockUtil;
|
2012-11-23 21:04:13 +01:00
|
|
|
import com.Acrobot.ChestShop.Configuration.Messages;
|
2012-06-25 17:16:57 +02:00
|
|
|
import com.Acrobot.ChestShop.Permission;
|
2012-05-10 16:32:25 +02:00
|
|
|
import com.Acrobot.ChestShop.Security;
|
2012-06-08 15:28:36 +02:00
|
|
|
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
2012-01-09 22:39:38 +01:00
|
|
|
import com.Acrobot.ChestShop.Utils.uBlock;
|
|
|
|
import org.bukkit.Material;
|
2011-05-15 18:16:25 +02:00
|
|
|
import org.bukkit.block.Block;
|
2013-03-24 20:58:09 +01:00
|
|
|
import org.bukkit.block.BlockFace;
|
2012-06-25 17:16:57 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2012-02-16 19:09:37 +01:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
2011-05-15 18:16:25 +02:00
|
|
|
import org.bukkit.event.block.BlockPlaceEvent;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
2012-05-10 16:32:25 +02:00
|
|
|
public class BlockPlace implements Listener {
|
2013-03-24 20:58:09 +01:00
|
|
|
private static BlockFace[] SEARCH_DIRECTIONS = {BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.UP, BlockFace.DOWN};
|
2012-01-09 22:39:38 +01:00
|
|
|
|
2013-03-24 20:58:09 +01:00
|
|
|
@EventHandler(ignoreCancelled = true)
|
|
|
|
public static void onChestPlace(BlockPlaceEvent event) {
|
2012-01-09 22:39:38 +01:00
|
|
|
Block placed = event.getBlockPlaced();
|
2012-05-10 16:32:25 +02:00
|
|
|
|
2013-03-24 20:58:09 +01:00
|
|
|
if (!BlockUtil.isChest(placed)) {
|
2012-06-25 17:16:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
|
|
|
if (Permission.has(player, Permission.ADMIN)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Security.canAccess(player, placed)) {
|
2012-11-23 21:04:13 +01:00
|
|
|
event.getPlayer().sendMessage(Messages.prefix(Messages.ACCESS_DENIED));
|
2012-06-25 17:16:57 +02:00
|
|
|
event.setCancelled(true);
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
2012-06-25 17:16:57 +02:00
|
|
|
|
2018-01-11 18:28:45 +01:00
|
|
|
Block neighbor = uBlock.findNeighbor(placed);
|
2013-03-24 20:58:09 +01:00
|
|
|
|
2018-01-11 18:28:45 +01:00
|
|
|
if (neighbor != null && !Security.canAccess(event.getPlayer(), neighbor)) {
|
2013-03-24 20:58:09 +01:00
|
|
|
event.getPlayer().sendMessage(Messages.prefix(Messages.ACCESS_DENIED));
|
|
|
|
event.setCancelled(true);
|
2013-03-24 00:53:06 +01:00
|
|
|
}
|
|
|
|
|
2013-03-24 20:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(ignoreCancelled = true)
|
|
|
|
public static void onPlaceAgainstSign(BlockPlaceEvent event) {
|
|
|
|
Block against = event.getBlockAgainst();
|
2012-06-25 17:16:57 +02:00
|
|
|
|
2013-03-24 20:58:09 +01:00
|
|
|
if (!ChestShopSign.isValid(against)) {
|
2012-06-25 17:16:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-24 20:58:09 +01:00
|
|
|
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;
|
2012-06-25 17:16:57 +02:00
|
|
|
}
|
|
|
|
|
2013-03-24 20:58:09 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
|
|
|
}
|