(courtesy of patrickfreed) 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:
Brettflan 2012-01-15 12:41:33 -06:00
parent c19f3405bf
commit de14985d1e
7 changed files with 118 additions and 2 deletions

BIN
lib/LWC.jar Normal file

Binary file not shown.

View File

@ -2,7 +2,7 @@ name: Factions
version: 1.7_dev version: 1.7_dev
main: com.massivecraft.factions.P main: com.massivecraft.factions.P
authors: [Olof Larsson, Brett Flannigan] authors: [Olof Larsson, Brett Flannigan]
softdepend: [PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, iChat, LocalAreaChat, nChat, ChatManager, CAPI, AuthMe, Register, Spout, WorldEdit, WorldGuard] softdepend: [PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, iChat, LocalAreaChat, LWC, nChat, ChatManager, CAPI, AuthMe, Register, Spout, WorldEdit, WorldGuard]
commands: commands:
factions: factions:
description: Reference command for Factions. description: Reference command for Factions.

View File

@ -14,6 +14,7 @@ import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.integration.LWCFeatures;
import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.util.AsciiCompass; import com.massivecraft.factions.util.AsciiCompass;
import com.massivecraft.factions.zcore.util.DiscUtil; import com.massivecraft.factions.zcore.util.DiscUtil;
@ -67,6 +68,9 @@ public class Board
public static void removeAt(FLocation flocation) public static void removeAt(FLocation flocation)
{ {
if(Conf.onUnclaimResetLwcLocks && LWCFeatures.getEnabled())
LWCFeatures.clearAllChests(flocation);
flocationIds.remove(flocation); flocationIds.remove(flocation);
} }
@ -78,6 +82,9 @@ public class Board
Entry<FLocation, String> entry = iter.next(); Entry<FLocation, String> entry = iter.next();
if (entry.getValue().equals(factionId)) if (entry.getValue().equals(factionId))
{ {
if(Conf.onUnclaimResetLwcLocks && LWCFeatures.getEnabled())
LWCFeatures.clearAllChests(entry.getKey());
iter.remove(); iter.remove();
} }
} }
@ -117,6 +124,9 @@ public class Board
Entry<FLocation, String> entry = iter.next(); Entry<FLocation, String> entry = iter.next();
if ( ! Factions.i.exists(entry.getValue())) 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()); P.p.log("Board cleaner removed "+entry.getValue()+" from "+entry.getKey());
iter.remove(); iter.remove();
} }

View File

@ -82,6 +82,11 @@ public class Conf
public static boolean worldGuardChecking = false; public static boolean worldGuardChecking = false;
//LWC
public static boolean lwcIntegration = false;
public static boolean onUnclaimResetLwcLocks = false;
public static boolean onCaptureResetLwcLocks = false;
// server logging options // server logging options
public static boolean logFactionCreate = true; public static boolean logFactionCreate = true;
public static boolean logFactionDisband = 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.EconomyParticipator;
import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.LWCFeatures;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.struct.ChatMode; import com.massivecraft.factions.struct.ChatMode;
@ -643,7 +644,10 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
} }
} }
if (LWCFeatures.getEnabled() && forFaction.isNormal() && Conf.onCaptureResetLwcLocks)
LWCFeatures.clearOtherChests(flocation, this.getFaction());
// announce success // announce success
Set<FPlayer> informTheseFPlayers = new HashSet<FPlayer>(); Set<FPlayer> informTheseFPlayers = new HashSet<FPlayer>();
informTheseFPlayers.add(this); informTheseFPlayers.add(this);

View File

@ -21,6 +21,7 @@ import com.massivecraft.factions.adapters.LocationTypeAdapter;
import com.massivecraft.factions.adapters.RelTypeAdapter; import com.massivecraft.factions.adapters.RelTypeAdapter;
import com.massivecraft.factions.cmd.*; import com.massivecraft.factions.cmd.*;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.LWCFeatures;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.listeners.FactionsBlockListener; import com.massivecraft.factions.listeners.FactionsBlockListener;
@ -34,6 +35,7 @@ import com.massivecraft.factions.struct.FPerm;
import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.struct.Rel;
import com.massivecraft.factions.zcore.MPlugin; import com.massivecraft.factions.zcore.MPlugin;
import com.griefcraft.lwc.LWCPlugin;
import com.nijiko.permissions.PermissionHandler; import com.nijiko.permissions.PermissionHandler;
import com.earth2me.essentials.chat.EssentialsChat; import com.earth2me.essentials.chat.EssentialsChat;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
@ -100,6 +102,7 @@ public class P extends MPlugin
Econ.doSetup(); Econ.doSetup();
Econ.oldMoneyDoTransfer(); Econ.oldMoneyDoTransfer();
CapiFeatures.setup(); CapiFeatures.setup();
setupLWC();
if(Conf.worldGuardChecking) if(Conf.worldGuardChecking)
{ {
@ -213,6 +216,14 @@ public class P extends MPlugin
} }
} }
private void setupLWC()
{
Plugin test = this.getServer().getPluginManager().getPlugin("LWC");
if(test != null && test.isEnabled())
LWCFeatures.integrateLWC((LWCPlugin)test);
}
// -------------------------------------------- // // -------------------------------------------- //
// Functions for other plugins to hook into // Functions for other plugins to hook into
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -0,0 +1,86 @@
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.Conf;
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;
public static void integrateLWC(LWCPlugin test)
{
lwc = test.getLWC();
P.p.log("Successfully hooked into LWC!"+(Conf.lwcIntegration ? "" : " Integration is currently disabled, though (\"lwcIntegration\")."));
}
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 Conf.lwcIntegration && lwc != null;
}
}