2012-01-15 12:41:33 -06:00
|
|
|
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;
|
2012-02-22 11:43:53 -06:00
|
|
|
import org.bukkit.plugin.Plugin;
|
2012-01-15 12:41:33 -06:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.BlockState;
|
|
|
|
|
|
|
|
import com.griefcraft.lwc.LWC;
|
|
|
|
import com.griefcraft.lwc.LWCPlugin;
|
2013-04-09 13:15:25 +02:00
|
|
|
import com.massivecraft.factions.ConfServer;
|
2012-01-15 12:41:33 -06:00
|
|
|
import com.massivecraft.factions.FLocation;
|
2013-04-09 13:22:23 +02:00
|
|
|
import com.massivecraft.factions.FPlayerColl;
|
2012-01-15 12:41:33 -06:00
|
|
|
import com.massivecraft.factions.Faction;
|
2013-04-09 13:00:09 +02:00
|
|
|
import com.massivecraft.factions.Factions;
|
2012-01-15 12:41:33 -06:00
|
|
|
|
|
|
|
public class LWCFeatures
|
|
|
|
{
|
|
|
|
private static LWC lwc;
|
2012-02-22 11:43:53 -06:00
|
|
|
|
|
|
|
public static void setup()
|
2012-01-15 12:41:33 -06:00
|
|
|
{
|
2012-02-22 11:43:53 -06:00
|
|
|
Plugin test = Bukkit.getServer().getPluginManager().getPlugin("LWC");
|
|
|
|
if(test == null || !test.isEnabled()) return;
|
|
|
|
|
|
|
|
lwc = ((LWCPlugin)test).getLWC();
|
2013-04-09 13:15:25 +02:00
|
|
|
Factions.get().log("Successfully hooked into LWC!"+(ConfServer.lwcIntegration ? "" : " Integration is currently disabled, though (\"lwcIntegration\")."));
|
2012-01-15 12:41:33 -06:00
|
|
|
}
|
|
|
|
|
2012-02-19 08:23:13 -06:00
|
|
|
public static boolean getEnabled()
|
|
|
|
{
|
2013-04-09 13:15:25 +02:00
|
|
|
return ConfServer.lwcIntegration && lwc != null;
|
2012-02-19 08:23:13 -06:00
|
|
|
}
|
|
|
|
|
2012-01-15 12:41:33 -06:00
|
|
|
public static void clearOtherChests(FLocation flocation, Faction faction)
|
|
|
|
{
|
|
|
|
Location location = new Location(Bukkit.getWorld(flocation.getWorldName()), flocation.getX() * 16, 5, flocation.getZ() * 16);
|
2012-02-19 08:23:13 -06:00
|
|
|
if (location.getWorld() == null) return; // world not loaded or something? cancel out to prevent error
|
2012-01-15 12:41:33 -06:00
|
|
|
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)
|
|
|
|
{
|
2013-04-09 13:22:23 +02:00
|
|
|
if(!faction.getFPlayers().contains(FPlayerColl.i.get(lwc.findProtection(chests.get(x)).getOwner())))
|
2012-01-15 12:41:33 -06:00
|
|
|
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);
|
2012-02-19 08:23:13 -06:00
|
|
|
if (location.getWorld() == null) return; // world not loaded or something? cancel out to prevent error
|
2012-01-15 12:41:33 -06:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|