Merge pull request #77 from patrickfreed/1.6.x

LWC Chest Protection Integration

When a claimed territory is captured by another Faction, all LWC chests that are not occupied by members of the person who is claiming the territory's faction lose their protection.
This commit is contained in:
Brett Flannigan 2012-01-15 10:07:54 -08:00
commit 8321a3ec70
6 changed files with 140 additions and 9 deletions

View File

@ -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<FLocation, String> 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<FLocation, String> 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();
}

View File

@ -71,6 +71,11 @@ 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;
public static boolean logFactionDisband = true;

View File

@ -10,6 +10,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.integration.SpoutFeatures;
import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.struct.ChatMode;
@ -798,6 +799,11 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
}
}
if (LWCFeatures.getEnabled() && forFaction.isNormal() && Conf.onCaptureResetLwcLocks)
{
LWCFeatures.clearOtherChests(flocation, this.getFaction());
}
// announce success
Set<FPlayer> informTheseFPlayers = new HashSet<FPlayer>();
informTheseFPlayers.add(this);

View File

@ -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;
@ -535,6 +537,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);
}
@ -565,6 +572,10 @@ public class Faction extends Entity implements EconomyParticipator
if (ownerData.isEmpty())
{
if(Conf.onUnclaimResetLwcLocks && LWCFeatures.getEnabled())
{
LWCFeatures.clearAllChests(entry.getKey());
}
claimOwnership.remove(entry.getKey());
}
}

View File

@ -6,18 +6,26 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.bukkit.block.Block;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.plugin.Plugin;
import com.massivecraft.factions.cmd.*;
import com.earth2me.essentials.chat.EssentialsChat;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.griefcraft.lwc.LWCPlugin;
import com.massivecraft.factions.cmd.CmdAutoHelp;
import com.massivecraft.factions.cmd.FCmdRoot;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.EssentialsFeatures;
import com.massivecraft.factions.integration.LWCFeatures;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.integration.capi.CapiFeatures;
import com.massivecraft.factions.listeners.FactionsBlockListener;
import com.massivecraft.factions.listeners.FactionsChatEarlyListener;
import com.massivecraft.factions.listeners.FactionsEntityListener;
@ -27,13 +35,7 @@ import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.util.MapFLocToStringSetTypeAdapter;
import com.massivecraft.factions.util.MyLocationTypeAdapter;
import com.massivecraft.factions.zcore.MPlugin;
import com.nijiko.permissions.PermissionHandler;
import com.earth2me.essentials.chat.EssentialsChat;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.integration.EssentialsFeatures;
import com.massivecraft.factions.integration.capi.CapiFeatures;
public class P extends MPlugin
{
@ -94,6 +96,7 @@ public class P extends MPlugin
Econ.doSetup();
Econ.oldMoneyDoTransfer();
CapiFeatures.setup();
setupLWC();
if(Conf.worldGuardChecking)
{
@ -202,6 +205,17 @@ public class P extends MPlugin
}
}
private void setupLWC()
{
Plugin test = this.getServer().getPluginManager().getPlugin("LWC");
if(test != null && test.isEnabled() && Conf.lwcIntegration)
{
LWCFeatures.integrateLWC((LWCPlugin)test);
}
}
// -------------------------------------------- //
// Functions for other plugins to hook into
// -------------------------------------------- //

View File

@ -0,0 +1,87 @@
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;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import com.griefcraft.lwc.LWC;
import com.griefcraft.lwc.LWCPlugin;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
public class LWCFeatures
{
private static LWC lwc;
private static boolean isEnabled = false;
public static void integrateLWC(LWCPlugin test)
{
lwc = test.getLWC();
isEnabled = true;
P.p.log("Successfully hooked into LWC!");
}
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<Block> chests = new LinkedList<Block>();
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<Block> chests = new LinkedList<Block>();
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)
{
lwc.findProtection(chests.get(x)).remove();
}
}
}
public static boolean getEnabled()
{
return isEnabled;
}
}