From c2f0f5ad513f04d1700d1be1f6cca34e7b2660d7 Mon Sep 17 00:00:00 2001 From: Patrick Date: Tue, 10 Jan 2012 19:09:15 -0500 Subject: [PATCH] Added unclaim and disband chest resets to LWC --- src/com/massivecraft/factions/Board.java | 10 +++++- src/com/massivecraft/factions/Conf.java | 3 ++ src/com/massivecraft/factions/FPlayer.java | 2 +- src/com/massivecraft/factions/Faction.java | 11 +++++++ .../factions/integration/LWCFeatures.java | 33 +++++++++++++++++-- 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/com/massivecraft/factions/Board.java b/src/com/massivecraft/factions/Board.java index 195cbbc5..fb3e9756 100644 --- a/src/com/massivecraft/factions/Board.java +++ b/src/com/massivecraft/factions/Board.java @@ -10,8 +10,8 @@ import java.util.Map.Entry; import java.util.TreeMap; import org.bukkit.ChatColor; - import com.google.gson.reflect.TypeToken; +import com.massivecraft.factions.integration.LWCFeatures; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.util.AsciiCompass; import com.massivecraft.factions.zcore.util.DiscUtil; @@ -87,6 +87,10 @@ public class Board Entry entry = iter.next(); if (entry.getValue().equals(factionId)) { + if(Conf.onUnclaimResetLwcLocks && LWCFeatures.getEnabled()) + { + LWCFeatures.clearAllChests(entry.getKey()); + } iter.remove(); } } @@ -126,6 +130,10 @@ public class Board Entry entry = iter.next(); if ( ! Factions.i.exists(entry.getValue())) { + if(Conf.onUnclaimResetLwcLocks && LWCFeatures.getEnabled()) + { + LWCFeatures.clearAllChests(entry.getKey()); + } P.p.log("Board cleaner removed "+entry.getValue()+" from "+entry.getKey()); iter.remove(); } diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index 4b618a80..1cae33fb 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -71,7 +71,10 @@ public class Conf public static boolean worldGuardChecking = false; + //LWC public static boolean lwcIntegration = false; + public static boolean onUnclaimResetLwcLocks = false; + public static boolean onCaptureResetLwcLocks = false; // server logging options public static boolean logFactionCreate = true; diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 9967ac58..73bb3f5e 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -794,7 +794,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator if (LWCFeatures.getEnabled()&& ! forFaction.isSafeZone() && ! forFaction.isWarZone() && Board.getIdAt(flocation) != "0") { - LWCFeatures.clearChests(location, this); + LWCFeatures.clearOtherChests(flocation, this.getFaction()); } // announce success diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index 45472c16..175bfac6 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -4,6 +4,7 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.Map.Entry; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -11,6 +12,7 @@ import org.bukkit.entity.Player; import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.integration.LWCFeatures; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; @@ -514,6 +516,11 @@ public class Faction extends Entity implements EconomyParticipator public void clearClaimOwnership(FLocation loc) { + if(Conf.onUnclaimResetLwcLocks && LWCFeatures.getEnabled()) + { + LWCFeatures.clearAllChests(loc); + Bukkit.getServer().broadcastMessage("boardclearat / clearclaim"); + } claimOwnership.remove(loc); } @@ -544,6 +551,10 @@ public class Faction extends Entity implements EconomyParticipator if (ownerData.isEmpty()) { + if(Conf.onUnclaimResetLwcLocks && LWCFeatures.getEnabled()) + { + LWCFeatures.clearAllChests(entry.getKey()); + } claimOwnership.remove(entry.getKey()); } } diff --git a/src/com/massivecraft/factions/integration/LWCFeatures.java b/src/com/massivecraft/factions/integration/LWCFeatures.java index 6482d67d..2c9e609c 100644 --- a/src/com/massivecraft/factions/integration/LWCFeatures.java +++ b/src/com/massivecraft/factions/integration/LWCFeatures.java @@ -3,6 +3,7 @@ package com.massivecraft.factions.integration; import java.util.LinkedList; import java.util.List; +import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; @@ -11,8 +12,9 @@ import org.bukkit.block.BlockState; import com.griefcraft.lwc.LWC; import com.griefcraft.lwc.LWCPlugin; -import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FPlayers; +import com.massivecraft.factions.Faction; import com.massivecraft.factions.P; public class LWCFeatures @@ -29,8 +31,34 @@ public class LWCFeatures P.p.log("Successfully hooked into LWC!"); } - public static void clearChests(Location location, FPlayer fPlayer) + public static void clearOtherChests(FLocation flocation, Faction faction) { + Location location = new Location(Bukkit.getWorld(flocation.getWorldName()), flocation.getX() * 16, 5, flocation.getZ() * 16); + Chunk chunk = location.getChunk(); + BlockState[] blocks = chunk.getTileEntities(); + List chests = new LinkedList(); + + for(int x = 0; x < blocks.length; x++) + { + if(blocks[x].getType() == Material.CHEST) + { + chests.add(blocks[x].getBlock()); + } + } + + for(int x = 0; x < chests.size(); x++) + { + if(lwc.findProtection(chests.get(x)) != null) + { + if(!faction.getFPlayers().contains(FPlayers.i.get(lwc.findProtection(chests.get(x)).getBukkitOwner()))) + lwc.findProtection(chests.get(x)).remove(); + } + } + } + + public static void clearAllChests(FLocation flocation) + { + Location location = new Location(Bukkit.getWorld(flocation.getWorldName()), flocation.getX() * 16, 5, flocation.getZ() * 16); Chunk chunk = location.getChunk(); BlockState[] blocks = chunk.getTileEntities(); List chests = new LinkedList(); @@ -47,7 +75,6 @@ public class LWCFeatures { if(lwc.findProtection(chests.get(x)) != null) { - if(!fPlayer.getFaction().getFPlayers().contains(FPlayers.i.get(lwc.findProtection(chests.get(x)).getBukkitOwner()))) lwc.findProtection(chests.get(x)).remove(); } }