From 1d0ba043361fa0cf67892ee7b9c4896ea7debb0a Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 7 Jan 2012 18:27:03 -0500 Subject: [PATCH] LWC integration --- src/com/massivecraft/factions/Conf.java | 2 + src/com/massivecraft/factions/FPlayer.java | 6 ++ src/com/massivecraft/factions/P.java | 30 +++++++--- .../factions/integration/LWCFeatures.java | 60 +++++++++++++++++++ 4 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 src/com/massivecraft/factions/integration/LWCFeatures.java diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index 05732208..4b618a80 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -70,6 +70,8 @@ public class Conf public static boolean removePlayerDataWhenBanned = true; public static boolean worldGuardChecking = false; + + public static boolean lwcIntegration = 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 d73d91dd..9967ac58 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -11,6 +11,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; @@ -791,6 +792,11 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator } } + if (LWCFeatures.getEnabled()&& ! forFaction.isSafeZone() && ! forFaction.isWarZone() && Board.getIdAt(flocation) != "0") + { + LWCFeatures.clearChests(location, this); + } + // announce success Set informTheseFPlayers = new HashSet(); informTheseFPlayers.add(this); diff --git a/src/com/massivecraft/factions/P.java b/src/com/massivecraft/factions/P.java index ac6324eb..c18d7fa4 100644 --- a/src/com/massivecraft/factions/P.java +++ b/src/com/massivecraft/factions/P.java @@ -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 // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/integration/LWCFeatures.java b/src/com/massivecraft/factions/integration/LWCFeatures.java new file mode 100644 index 00000000..6482d67d --- /dev/null +++ b/src/com/massivecraft/factions/integration/LWCFeatures.java @@ -0,0 +1,60 @@ +package com.massivecraft.factions.integration; + +import java.util.LinkedList; +import java.util.List; + +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.FPlayer; +import com.massivecraft.factions.FPlayers; +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 clearChests(Location location, FPlayer fPlayer) + { + 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(!fPlayer.getFaction().getFPlayers().contains(FPlayers.i.get(lwc.findProtection(chests.get(x)).getBukkitOwner()))) + lwc.findProtection(chests.get(x)).remove(); + } + } + } + + public static boolean getEnabled() + { + return isEnabled; + } +}