2012-05-10 16:32:25 +02:00
|
|
|
package com.Acrobot.ChestShop.Plugins;
|
|
|
|
|
2012-11-23 21:04:13 +01:00
|
|
|
import com.Acrobot.ChestShop.Configuration.Messages;
|
|
|
|
import com.Acrobot.ChestShop.Configuration.Properties;
|
2012-06-08 15:28:36 +02:00
|
|
|
import com.Acrobot.ChestShop.Events.Protection.ProtectBlockEvent;
|
|
|
|
import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent;
|
|
|
|
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
|
|
|
|
import com.Acrobot.ChestShop.Security;
|
2012-05-10 16:32:25 +02:00
|
|
|
import com.griefcraft.lwc.LWC;
|
|
|
|
import com.griefcraft.model.Protection;
|
|
|
|
import com.griefcraft.modules.limits.LimitsV2;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.block.Block;
|
2012-06-08 15:28:36 +02:00
|
|
|
import org.bukkit.block.Chest;
|
|
|
|
import org.bukkit.block.Sign;
|
2012-05-10 16:32:25 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.Event;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class LightweightChestProtection implements Listener {
|
|
|
|
private LWC lwc;
|
|
|
|
private LimitsV2 limitsModule;
|
|
|
|
|
2012-06-25 17:16:24 +02:00
|
|
|
public LightweightChestProtection() {
|
|
|
|
this.lwc = LWC.getInstance();
|
2012-05-10 16:32:25 +02:00
|
|
|
limitsModule = new LimitsV2();
|
|
|
|
}
|
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
@EventHandler
|
|
|
|
public static void onShopCreation(ShopCreatedEvent event) {
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
Sign sign = event.getSign();
|
|
|
|
Chest connectedChest = event.getChest();
|
|
|
|
|
2012-11-23 21:04:13 +01:00
|
|
|
if (Properties.PROTECT_SIGN_WITH_LWC) {
|
2012-06-08 15:28:36 +02:00
|
|
|
if (!Security.protect(player.getName(), sign.getBlock())) {
|
2012-11-23 21:04:13 +01:00
|
|
|
player.sendMessage(Messages.prefix(Messages.NOT_ENOUGH_PROTECTIONS));
|
2012-06-08 15:28:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-23 21:04:13 +01:00
|
|
|
if (Properties.PROTECT_CHEST_WITH_LWC && connectedChest != null && Security.protect(player.getName(), connectedChest.getBlock())) {
|
|
|
|
player.sendMessage(Messages.prefix(Messages.PROTECTED_SHOP));
|
2012-06-08 15:28:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-10 16:32:25 +02:00
|
|
|
@EventHandler
|
|
|
|
public void onProtectionCheck(ProtectionCheckEvent event) {
|
|
|
|
if (event.getResult() == Event.Result.DENY) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Block block = event.getBlock();
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
|
|
|
Protection protection = lwc.findProtection(block);
|
|
|
|
|
|
|
|
if (protection == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lwc.canAccessProtection(player, protection)) {
|
|
|
|
event.setResult(Event.Result.DENY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void onBlockProtect(ProtectBlockEvent event) {
|
|
|
|
if (event.isProtected()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Block block = event.getBlock();
|
2013-03-03 17:26:10 +01:00
|
|
|
Player player = Bukkit.getPlayerExact(event.getName());
|
2012-05-10 16:32:25 +02:00
|
|
|
|
|
|
|
if (player == null || limitsModule.hasReachedLimit(player, block.getType())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int x = block.getX();
|
|
|
|
int y = block.getY();
|
|
|
|
int z = block.getZ();
|
|
|
|
|
|
|
|
String worldName = block.getWorld().getName();
|
|
|
|
|
2012-12-31 02:46:42 +01:00
|
|
|
Protection existingProtection = lwc.getPhysicalDatabase().loadProtection(worldName, x, y, z);
|
|
|
|
|
|
|
|
if (existingProtection != null) {
|
|
|
|
event.setProtected(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-10 16:32:25 +02:00
|
|
|
Protection protection = lwc.getPhysicalDatabase().registerProtection(block.getTypeId(), Protection.Type.PRIVATE, worldName, event.getName(), "", x, y, z);
|
|
|
|
|
|
|
|
if (protection != null) {
|
|
|
|
event.setProtected(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|