2012-05-10 16:32:25 +02:00
|
|
|
package com.Acrobot.ChestShop.Plugins;
|
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent;
|
|
|
|
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
2012-08-10 19:01:52 +02:00
|
|
|
import com.Acrobot.ChestShop.Utils.uBlock;
|
2012-05-10 16:32:25 +02:00
|
|
|
import com.Acrobot.ChestShop.Utils.uName;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.Chest;
|
|
|
|
import org.bukkit.block.Sign;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.Event;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
|
2012-12-22 21:04:48 +01:00
|
|
|
import static com.Acrobot.Breeze.Utils.BlockUtil.isChest;
|
|
|
|
import static com.Acrobot.Breeze.Utils.BlockUtil.isSign;
|
|
|
|
|
2012-05-10 16:32:25 +02:00
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class ChestShop implements Listener {
|
|
|
|
@EventHandler
|
|
|
|
public static void onProtectionCheck(ProtectionCheckEvent event) {
|
2012-09-12 12:35:48 +02:00
|
|
|
if (event.getResult() == Event.Result.DENY || event.isBuiltInProtectionIgnored()) {
|
2012-05-10 16:32:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Block block = event.getBlock();
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
|
|
|
if (!canAccess(player, block)) {
|
|
|
|
event.setResult(Event.Result.DENY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean canAccess(Player player, Block block) {
|
|
|
|
if (!canBeProtected(block)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSign(block)) {
|
|
|
|
Sign sign = (Sign) block.getState();
|
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
if (!ChestShopSign.isValid(sign)) {
|
2012-05-10 16:32:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isShopMember(player, sign)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isChest(block)) {
|
2012-08-10 19:01:52 +02:00
|
|
|
Sign sign = uBlock.getConnectedSign((Chest) block.getState());
|
2012-05-10 16:32:25 +02:00
|
|
|
|
|
|
|
if (sign != null && !isShopMember(player, sign)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean canBeProtected(Block block) {
|
|
|
|
return isSign(block) || isChest(block);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean isShopMember(Player player, Sign sign) {
|
|
|
|
return uName.canUseName(player, sign.getLine(0));
|
|
|
|
}
|
|
|
|
}
|