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-01-09 22:39:38 +01:00
|
|
|
import com.Acrobot.ChestShop.Config.Config;
|
|
|
|
import com.Acrobot.ChestShop.Config.Language;
|
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;
|
2012-01-09 22:39:38 +01:00
|
|
|
import org.bukkit.block.Chest;
|
2011-05-15 18:16:25 +02:00
|
|
|
import org.bukkit.block.Sign;
|
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 {
|
|
|
|
@EventHandler(ignoreCancelled = true)
|
2012-02-16 19:09:37 +01:00
|
|
|
public static void onBlockPlace(BlockPlaceEvent event) {
|
2011-05-15 18:16:25 +02:00
|
|
|
Block block = event.getBlockAgainst();
|
2012-05-10 16:32:25 +02:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
if (BlockUtil.isSign(block) && ChestShopSign.isValid((Sign) block.getState())) {
|
2011-05-15 18:16:25 +02:00
|
|
|
event.setCancelled(true);
|
2012-01-09 22:39:38 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Block placed = event.getBlockPlaced();
|
2012-05-10 16:32:25 +02:00
|
|
|
|
2012-06-25 17:16:57 +02:00
|
|
|
if (placed.getType() != Material.CHEST) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
|
|
|
if (Permission.has(player, Permission.ADMIN)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Security.canAccess(player, placed)) {
|
|
|
|
event.getPlayer().sendMessage(Config.getLocal(Language.ACCESS_DENIED));
|
|
|
|
event.setCancelled(true);
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
2012-06-25 17:16:57 +02:00
|
|
|
|
|
|
|
Chest neighbor = uBlock.findNeighbor(placed);
|
|
|
|
|
|
|
|
if (neighbor == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Security.canAccess(event.getPlayer(), neighbor.getBlock())) {
|
|
|
|
event.getPlayer().sendMessage(Config.getLocal(Language.ACCESS_DENIED));
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
|
|
|
}
|