Clean up some LWC stuff.

This commit is contained in:
Olof Larsson 2013-04-18 17:42:49 +02:00
parent ede66bac6b
commit 26a59fb01c
2 changed files with 43 additions and 57 deletions

View File

@ -1,6 +1,6 @@
package com.massivecraft.factions.integration; package com.massivecraft.factions.integration;
import java.util.LinkedList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -12,6 +12,7 @@ import org.bukkit.block.BlockState;
import com.griefcraft.lwc.LWC; import com.griefcraft.lwc.LWC;
import com.griefcraft.lwc.LWCPlugin; import com.griefcraft.lwc.LWCPlugin;
import com.griefcraft.model.Protection;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
@ -36,41 +37,30 @@ public class LWCFeatures
return ConfServer.lwcIntegration && lwc != null; return ConfServer.lwcIntegration && lwc != null;
} }
public static void clearOtherChests(PS chunkPs, Faction faction)
{
Chunk chunk = null;
try
{
chunk = chunkPs.asBukkitChunk(true);
}
catch (Exception e)
{
return;
}
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(FPlayer.get(lwc.findProtection(chests.get(x)).getOwner())))
lwc.findProtection(chests.get(x)).remove();
}
}
}
public static void clearAllChests(PS chunkPs) public static void clearAllChests(PS chunkPs)
{ {
for (Protection protection : getProtectionsInChunk(chunkPs))
{
protection.remove();
}
}
public static void clearOtherChests(PS chunkPs, Faction faction)
{
for (Protection protection : getProtectionsInChunk(chunkPs))
{
FPlayer owner = FPlayer.get(protection.getOwner());
if (faction.getFPlayers().contains(owner)) continue;
protection.remove();
}
}
public static List<Protection> getProtectionsInChunk(PS chunkPs)
{
List<Protection> ret = new ArrayList<Protection>();
// Get the chunk
Chunk chunk = null; Chunk chunk = null;
try try
{ {
@ -78,26 +68,22 @@ public class LWCFeatures
} }
catch (Exception e) catch (Exception e)
{ {
return; return ret;
} }
BlockState[] blocks = chunk.getTileEntities(); for (BlockState blockState : chunk.getTileEntities())
List<Block> chests = new LinkedList<Block>();
for (int x = 0; x < blocks.length; x++)
{ {
if(blocks[x].getType() == Material.CHEST) // TODO: Can something else be protected by LWC? Or is it really only chests?
{ if (blockState.getType() != Material.CHEST) continue;
chests.add(blocks[x].getBlock()); Block block = blockState.getBlock();
}
Protection protection = lwc.findProtection(block);
if (protection == null) continue;
ret.add(protection);
} }
for (int x = 0; x < chests.size(); x++) return ret;
{
if(lwc.findProtection(chests.get(x)) != null)
{
lwc.findProtection(chests.get(x)).remove();
}
}
} }
} }

View File

@ -139,7 +139,7 @@ public class FactionsListenerMain implements Listener
if (fplayer.hasFaction() && fplayer.getFaction().getFlag(FFlag.PERMANENT) && containsCommand(command, ConfServer.permanentFactionMemberDenyCommands)) if (fplayer.hasFaction() && fplayer.getFaction().getFlag(FFlag.PERMANENT) && containsCommand(command, ConfServer.permanentFactionMemberDenyCommands))
{ {
fplayer.msg("<b>You can't use \"<h>%s<b>\" as member of a permanent faction.", command); fplayer.msg("<b>You can't use \"<h>/%s<b>\" as member of a permanent faction.", command);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -149,14 +149,14 @@ public class FactionsListenerMain implements Listener
if (rel == Rel.NEUTRAL && containsCommand(command, ConfServer.territoryNeutralDenyCommands)) if (rel == Rel.NEUTRAL && containsCommand(command, ConfServer.territoryNeutralDenyCommands))
{ {
fplayer.msg("<b>You can't use \"<h>%s<b>\" in neutral territory.", command); fplayer.msg("<b>You can't use \"<h>/%s<b>\" in neutral territory.", command);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (rel == Rel.ENEMY && containsCommand(command, ConfServer.territoryEnemyDenyCommands)) if (rel == Rel.ENEMY && containsCommand(command, ConfServer.territoryEnemyDenyCommands))
{ {
fplayer.msg("<b>You can't use \"<h>%s<b>\" in enemy territory.", command); fplayer.msg("<b>You can't use \"<h>/%s<b>\" in enemy territory.", command);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -168,13 +168,13 @@ public class FactionsListenerMain implements Listener
needle = Txt.removeLeadingCommandDust(needle); needle = Txt.removeLeadingCommandDust(needle);
needle = needle.toLowerCase(); needle = needle.toLowerCase();
for (String string : haystack) for (String straw : haystack)
{ {
if (string == null) continue; if (straw == null) continue;
string = Txt.removeLeadingCommandDust(string); straw = Txt.removeLeadingCommandDust(straw);
string = string.toLowerCase(); straw = straw.toLowerCase();
if (needle.startsWith(string)) return true; if (needle.startsWith(straw)) return true;
} }
return false; return false;