From a467e405c2ededacf1a17e8dc762cd618fdbc5cf Mon Sep 17 00:00:00 2001 From: Acrobot Date: Thu, 26 Jul 2012 13:44:57 +0200 Subject: [PATCH] Add SecureChests support and Fix Towny integration --- com/Acrobot/ChestShop/Dependencies.java | 7 ++- .../ChestShop/Plugins/SecureChests.java | 60 +++++++++++++++++++ plugin.yml | 2 +- 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 com/Acrobot/ChestShop/Plugins/SecureChests.java diff --git a/com/Acrobot/ChestShop/Dependencies.java b/com/Acrobot/ChestShop/Dependencies.java index 0e36020..04cc1f6 100644 --- a/com/Acrobot/ChestShop/Dependencies.java +++ b/com/Acrobot/ChestShop/Dependencies.java @@ -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, diff --git a/com/Acrobot/ChestShop/Plugins/SecureChests.java b/com/Acrobot/ChestShop/Plugins/SecureChests.java new file mode 100644 index 0000000..c2647d3 --- /dev/null +++ b/com/Acrobot/ChestShop/Plugins/SecureChests.java @@ -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); + } + } +} diff --git a/plugin.yml b/plugin.yml index 2533150..5d4ca14 100644 --- a/plugin.yml +++ b/plugin.yml @@ -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]