From 7626aed06aabf4cdd1de7f6ca0ac51b81b5493d9 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 26 Apr 2013 10:32:02 +0200 Subject: [PATCH] Fixing a few bugs, and adding in some debug output for unsolved ones. --- plugin.yml | 1 + .../factions/cmd/CmdFactionsMap.java | 2 +- .../cmd/CmdFactionsRelationAbstract.java | 2 + .../massivecraft/factions/entity/Board.java | 11 +++-- .../massivecraft/factions/entity/Faction.java | 9 ++++- .../factions/entity/FactionColl.java | 40 ++++++++----------- .../factions/entity/UPlayerColls.java | 12 ++++++ .../listeners/FactionsListenerExploit.java | 10 ++--- .../listeners/FactionsListenerMain.java | 19 +++++++-- 9 files changed, 66 insertions(+), 40 deletions(-) diff --git a/plugin.yml b/plugin.yml index 9be9ac73..5c9ce313 100644 --- a/plugin.yml +++ b/plugin.yml @@ -165,6 +165,7 @@ permissions: factions.list: true factions.map: true factions.money.*: true + factions.officer: true factions.open: true factions.perm: true factions.power: true diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java index 94141c0c..7e149aee 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java @@ -49,7 +49,7 @@ public class CmdFactionsMap extends FCommand public void showMap() { - sendMessage(BoardColls.get().getMap(usenderFaction, PS.valueOf(me), usender.getPlayer().getLocation().getYaw())); + sendMessage(BoardColls.get().getMap(usenderFaction, PS.valueOf(me), me.getLocation().getYaw())); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java index 3767e874..28a76ba6 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java @@ -18,6 +18,8 @@ public abstract class CmdFactionsRelationAbstract extends FCommand public CmdFactionsRelationAbstract() { + this.addRequiredArg("faction"); + this.addRequirements(ReqFactionsEnabled.get()); this.addRequirements(ReqHasPerm.get(Perm.RELATION.node)); this.addRequirements(ReqHasFaction.get()); diff --git a/src/com/massivecraft/factions/entity/Board.java b/src/com/massivecraft/factions/entity/Board.java index 5354f6c8..ea0e033f 100644 --- a/src/com/massivecraft/factions/entity/Board.java +++ b/src/com/massivecraft/factions/entity/Board.java @@ -98,7 +98,8 @@ public class Board extends Entity implements BoardInterface public Faction getFactionAt(PS ps) { if (ps == null) return null; - return FactionColls.get().get(this).get(this.getTerritoryAccessAt(ps).getHostFactionId()); + String factionId = this.getTerritoryAccessAt(ps).getHostFactionId(); + return FactionColls.get().get(this).get(factionId); } // SET @@ -158,16 +159,18 @@ public class Board extends Entity implements BoardInterface @Override public void clean() { + FactionColl factionColl = FactionColls.get().get(this); + for (Entry entry : this.map.entrySet()) { TerritoryAccess territoryAccess = entry.getValue(); - - if (FactionColls.get().get(this).containsId(territoryAccess.getHostFactionId())) continue; + String factionId = territoryAccess.getHostFactionId(); + if (factionColl.containsId(factionId)) continue; PS ps = entry.getKey(); this.removeAt(ps); - Factions.get().log("Board cleaner removed "+territoryAccess.getHostFactionId()+" from "+entry.getKey()); + Factions.get().log("Board cleaner removed "+factionId+" from "+ps); } } diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 72fb88b0..7180d1e3 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -642,7 +642,14 @@ public class Faction extends Entity implements EconomyParticipator while (iter.hasNext()) { Entry> entry = iter.next(); - if (entry.getKey().getDefault(this).equals(entry.getValue())) + FPerm key = entry.getKey(); + Set keyDefault = key.getDefault(this); + Set value = entry.getValue(); + + if (keyDefault == null) System.out.println("keyDefault was null"); + if (value == null) System.out.println("value was null"); + + if (keyDefault.equals(value)) { iter.remove(); } diff --git a/src/com/massivecraft/factions/entity/FactionColl.java b/src/com/massivecraft/factions/entity/FactionColl.java index 9ebfff29..048544b8 100644 --- a/src/com/massivecraft/factions/entity/FactionColl.java +++ b/src/com/massivecraft/factions/entity/FactionColl.java @@ -40,29 +40,6 @@ public class FactionColl extends Coll this.createSpecialFactions(); } - /* - @Override - protected synchronized String attach(Faction faction, Object oid, boolean noteChange) - { - String ret = super.attach(faction, oid, noteChange); - - // Factions start with 0 money. - // TODO: Can this be done here? - // TODO: Or will it be a to heavy operation to do this often? - - //System.out.println("faction "+faction); - //System.out.println("faction.getId() "+faction.getId()); - // TODO: Why does this happen for Wilderness? - if (faction.getId() == null) return ret; - - if (!Money.exists(faction)) - { - Money.set(faction, 0); - } - - return ret; - }*/ - // TODO: I hope this one is not crucial anymore. // If it turns out to be I will just have to recreate the feature in the proper place. /* @@ -80,6 +57,23 @@ public class FactionColl extends Coll } */ + @Override + public Faction get(Object oid) + { + Faction ret = super.get(oid); + + if (ret == null) + { + String message = Txt.parse("Non existing factionId %s requested. Cleaning all boards and uplayers.", this.fixId(oid)); + Factions.get().log(message); + + BoardColls.get().clean(); + UPlayerColls.get().clean(); + } + + return ret; + } + @Override public Faction detachId(Object oid) { diff --git a/src/com/massivecraft/factions/entity/UPlayerColls.java b/src/com/massivecraft/factions/entity/UPlayerColls.java index a731a070..d502fb8b 100644 --- a/src/com/massivecraft/factions/entity/UPlayerColls.java +++ b/src/com/massivecraft/factions/entity/UPlayerColls.java @@ -80,4 +80,16 @@ public class UPlayerColls extends XColls oldFile.renameTo(newFile); } + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public void clean() + { + for (UPlayerColl coll : this.getColls()) + { + coll.clean(); + } + } + } diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerExploit.java b/src/com/massivecraft/factions/listeners/FactionsListenerExploit.java index fd64f6bf..aab2d8dd 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerExploit.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerExploit.java @@ -1,29 +1,22 @@ package com.massivecraft.factions.listeners; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.bukkit.block.Block; -import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.util.NumberConversions; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import com.massivecraft.factions.Factions; import com.massivecraft.factions.entity.MConf; -import com.massivecraft.mcore.util.SenderUtil; -import com.massivecraft.mcore.util.Txt; public class FactionsListenerExploit implements Listener @@ -48,7 +41,9 @@ public class FactionsListenerExploit implements Listener // INTERACT SPAM // -------------------------------------------- // // TODO: Now that I decoupled this one it may be to sensitive. + // TODO: Yeah it's faaaaaaaaaar to sensitive. Let's just comment it out for now. + /* @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void interactSpam(PlayerInteractEvent event) { @@ -91,6 +86,7 @@ public class FactionsListenerExploit implements Listener return attempts; } } + */ // -------------------------------------------- // // OBSIDIAN GENERATORS diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index 39571c36..2183c801 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.List; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Enderman; @@ -560,14 +561,14 @@ public class FactionsListenerMain implements Listener @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void blockExplosion(EntityExplodeEvent event) { - // If an entity is exploding ... - Entity entity = event.getEntity(); + // If an explosion occurs at a location ... + Location location = event.getLocation(); // Check Disabled - if (UConf.isDisabled(entity)) return; + if (UConf.isDisabled(location)) return; // Check the entity. Are explosions disabled there? - if (BoardColls.get().getFactionAt(PS.valueOf(event.getEntity())).getFlag(FFlag.EXPLOSIONS) == false) + if (BoardColls.get().getFactionAt(PS.valueOf(location)).getFlag(FFlag.EXPLOSIONS) == false) { event.setCancelled(true); return; @@ -637,6 +638,16 @@ public class FactionsListenerMain implements Listener // If the faction at the block has firespread disabled ... PS ps = PS.valueOf(block); Faction faction = BoardColls.get().getFactionAt(ps); + + // TODO: Remove this debug output soon. + if (faction == null) + { + System.out.println("faction was null"); + System.out.println("block was "+block); + System.out.println("ps was "+ps); + return; + } + if (faction.getFlag(FFlag.FIRESPREAD)) return; // then cancel the event.