diff --git a/src/com/massivecraft/factions/integration/LWCFeatures.java b/src/com/massivecraft/factions/integration/LWCFeatures.java index 0fd2d5c0..06935274 100644 --- a/src/com/massivecraft/factions/integration/LWCFeatures.java +++ b/src/com/massivecraft/factions/integration/LWCFeatures.java @@ -1,6 +1,6 @@ package com.massivecraft.factions.integration; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; @@ -12,6 +12,7 @@ import org.bukkit.block.BlockState; import com.griefcraft.lwc.LWC; import com.griefcraft.lwc.LWCPlugin; +import com.griefcraft.model.Protection; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; @@ -36,41 +37,30 @@ public class LWCFeatures 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 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(!faction.getFPlayers().contains(FPlayer.get(lwc.findProtection(chests.get(x)).getOwner()))) - lwc.findProtection(chests.get(x)).remove(); - } - } - } 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 getProtectionsInChunk(PS chunkPs) + { + List ret = new ArrayList(); + + // Get the chunk Chunk chunk = null; try { @@ -78,26 +68,22 @@ public class LWCFeatures } catch (Exception e) { - return; + return ret; } - BlockState[] blocks = chunk.getTileEntities(); - List chests = new LinkedList(); - - for (int x = 0; x < blocks.length; x++) + for (BlockState blockState : chunk.getTileEntities()) { - if(blocks[x].getType() == Material.CHEST) - { - chests.add(blocks[x].getBlock()); - } + // TODO: Can something else be protected by LWC? Or is it really only chests? + if (blockState.getType() != Material.CHEST) continue; + Block block = blockState.getBlock(); + + Protection protection = lwc.findProtection(block); + if (protection == null) continue; + + ret.add(protection); } - for (int x = 0; x < chests.size(); x++) - { - if(lwc.findProtection(chests.get(x)) != null) - { - lwc.findProtection(chests.get(x)).remove(); - } - } + return ret; } + } diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index 84ad4442..f87be980 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -139,7 +139,7 @@ public class FactionsListenerMain implements Listener if (fplayer.hasFaction() && fplayer.getFaction().getFlag(FFlag.PERMANENT) && containsCommand(command, ConfServer.permanentFactionMemberDenyCommands)) { - fplayer.msg("You can't use \"%s\" as member of a permanent faction.", command); + fplayer.msg("You can't use \"/%s\" as member of a permanent faction.", command); event.setCancelled(true); return; } @@ -149,14 +149,14 @@ public class FactionsListenerMain implements Listener if (rel == Rel.NEUTRAL && containsCommand(command, ConfServer.territoryNeutralDenyCommands)) { - fplayer.msg("You can't use \"%s\" in neutral territory.", command); + fplayer.msg("You can't use \"/%s\" in neutral territory.", command); event.setCancelled(true); return; } if (rel == Rel.ENEMY && containsCommand(command, ConfServer.territoryEnemyDenyCommands)) { - fplayer.msg("You can't use \"%s\" in enemy territory.", command); + fplayer.msg("You can't use \"/%s\" in enemy territory.", command); event.setCancelled(true); return; } @@ -168,13 +168,13 @@ public class FactionsListenerMain implements Listener needle = Txt.removeLeadingCommandDust(needle); needle = needle.toLowerCase(); - for (String string : haystack) + for (String straw : haystack) { - if (string == null) continue; - string = Txt.removeLeadingCommandDust(string); - string = string.toLowerCase(); + if (straw == null) continue; + straw = Txt.removeLeadingCommandDust(straw); + straw = straw.toLowerCase(); - if (needle.startsWith(string)) return true; + if (needle.startsWith(straw)) return true; } return false;