Add SecureChests support and Fix Towny integration

This commit is contained in:
Acrobot 2012-07-26 13:44:57 +02:00
parent 47dc473163
commit a467e405c2
3 changed files with 67 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import org.bukkit.plugin.PluginManager;
import java.util.List;
import static com.Acrobot.ChestShop.Config.Property.TOWNY_INTEGRATION;
import static com.Acrobot.ChestShop.Config.Property.WORLDGUARD_INTEGRATION;
import static com.Acrobot.ChestShop.Config.Property.WORLDGUARD_USE_PROTECTION;
@ -79,12 +80,15 @@ public class Dependencies {
case SimpleChestLock:
listener = SimpleChestLock.getSimpleChestLock(plugin);
break;
case SecureChests:
listener = new SecureChests();
break;
//Terrain protection plugins
case Towny:
Towny towny = Towny.getTowny();
if (towny == null) {
if (towny == null || !Config.getBoolean(TOWNY_INTEGRATION)) {
return;
}
@ -148,6 +152,7 @@ public class Dependencies {
Lockette,
Deadbolt,
SimpleChestLock,
SecureChests,
OddItem,

View File

@ -0,0 +1,60 @@
package com.Acrobot.ChestShop.Plugins;
import com.Acrobot.ChestShop.Events.Protection.ProtectBlockEvent;
import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent;
import me.HAklowner.SecureChests.Lock;
import me.HAklowner.SecureChests.Managers.LockManager;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
/**
* @author Acrobot
*/
public class SecureChests implements Listener {
private LockManager lockManager;
public SecureChests() {
lockManager = me.HAklowner.SecureChests.SecureChests.getInstance().getLockManager();
}
@EventHandler
public void onProtectionCheck(ProtectionCheckEvent event) {
if (event.getResult() == Event.Result.DENY) {
return;
}
Block block = event.getBlock();
Lock lock = lockManager.getLock(block.getLocation());
if (!lock.isLocked()) {
return;
}
String owner = lock.getOwner();
if (!event.getPlayer().getName().equals(owner)) {
event.setResult(Event.Result.DENY);
}
}
@EventHandler
public void onBlockProtect(ProtectBlockEvent event) {
if (event.isProtected()) {
return;
}
Block block = event.getBlock();
String player = event.getName();
if (block == null || player == null) {
return;
}
Lock lock = lockManager.getLock(block.getLocation());
if (!lock.isLocked()) {
lock.lock(player);
}
}
}

View File

@ -14,7 +14,7 @@ description: >
softdepend: [LWC, Lockette, Deadbolt, OddItem, Towny, WorldGuard, Vault, Heroes,
iConomy, BOSEconomy, Essentials, SimpleChestLock]
iConomy, BOSEconomy, Essentials, SimpleChestLock, SecureChests]
commands:
iteminfo:
aliases: [iinfo]