From 7ce0100e739010cd8bf79a7950fe0cfee47e2bb3 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 26 Apr 2013 11:06:07 +0200 Subject: [PATCH] Minor changes to npe detection and denied commands --- src/com/massivecraft/factions/entity/BoardColls.java | 8 -------- src/com/massivecraft/factions/entity/UPlayer.java | 6 ------ .../factions/listeners/FactionsListenerMain.java | 9 ++++++--- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/com/massivecraft/factions/entity/BoardColls.java b/src/com/massivecraft/factions/entity/BoardColls.java index d7b0c876..8ce013b6 100644 --- a/src/com/massivecraft/factions/entity/BoardColls.java +++ b/src/com/massivecraft/factions/entity/BoardColls.java @@ -101,7 +101,6 @@ public class BoardColls extends XColls implements BoardInterfa @Override public TerritoryAccess getTerritoryAccessAt(PS ps) { - if (ps == null) return null; BoardColl coll = this.getForWorld(ps.getWorld()); if (coll == null) return null; return coll.getTerritoryAccessAt(ps); @@ -110,7 +109,6 @@ public class BoardColls extends XColls implements BoardInterfa @Override public Faction getFactionAt(PS ps) { - if (ps == null) return null; BoardColl coll = this.getForWorld(ps.getWorld()); if (coll == null) return null; return coll.getFactionAt(ps); @@ -121,7 +119,6 @@ public class BoardColls extends XColls implements BoardInterfa @Override public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess) { - if (ps == null) return; BoardColl coll = this.getForWorld(ps.getWorld()); if (coll == null) return; coll.setTerritoryAccessAt(ps, territoryAccess); @@ -130,7 +127,6 @@ public class BoardColls extends XColls implements BoardInterfa @Override public void setFactionAt(PS ps, Faction faction) { - if (ps == null) return; BoardColl coll = this.getForWorld(ps.getWorld()); if (coll == null) return; coll.setFactionAt(ps, faction); @@ -141,7 +137,6 @@ public class BoardColls extends XColls implements BoardInterfa @Override public void removeAt(PS ps) { - if (ps == null) return; BoardColl coll = this.getForWorld(ps.getWorld()); if (coll == null) return; coll.removeAt(ps); @@ -194,7 +189,6 @@ public class BoardColls extends XColls implements BoardInterfa @Override public boolean isBorderPs(PS ps) { - if (ps == null) return false; BoardColl coll = this.getForWorld(ps.getWorld()); if (coll == null) return false; return coll.isBorderPs(ps); @@ -203,7 +197,6 @@ public class BoardColls extends XColls implements BoardInterfa @Override public boolean isConnectedPs(PS ps, Faction faction) { - if (ps == null) return false; BoardColl coll = this.getForWorld(ps.getWorld()); if (coll == null) return false; return coll.isConnectedPs(ps, faction); @@ -214,7 +207,6 @@ public class BoardColls extends XColls implements BoardInterfa @Override public ArrayList getMap(RelationParticipator observer, PS centerPs, double inDegrees) { - if (centerPs == null) return null; BoardColl coll = this.getForWorld(centerPs.getWorld()); if (coll == null) return null; return coll.getMap(observer, centerPs, inDegrees); diff --git a/src/com/massivecraft/factions/entity/UPlayer.java b/src/com/massivecraft/factions/entity/UPlayer.java index a6099678..d2e33ecd 100644 --- a/src/com/massivecraft/factions/entity/UPlayer.java +++ b/src/com/massivecraft/factions/entity/UPlayer.java @@ -515,12 +515,6 @@ public class UPlayer extends SenderEntity implements EconomyParticipato return RelationUtil.getRelationOfThatToMe(this, observer, ignorePeaceful); } - public Rel getRelationToLocation() - { - // TODO: Use some built in system to get sender - return BoardColls.get().getFactionAt(PS.valueOf(this.getPlayer())).getRelationTo(this); - } - @Override public ChatColor getColorTo(RelationParticipator observer) { diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index 2183c801..6ffab3be 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -454,10 +454,13 @@ public class FactionsListenerMain implements Listener return; } - // ... the command may be denied in the territory of this relation type ... - Rel rel = uplayer.getRelationToLocation(); + // ... if there is a faction at the players location ... PS ps = PS.valueOf(player).getChunk(true); - if (BoardColls.get().getFactionAt(ps).isNone()) return; + Faction factionAtPs = BoardColls.get().getFactionAt(ps); + if (factionAtPs.isNone()) return; + + // ... the command may be denied in the territory of this relation type ... + Rel rel = factionAtPs.getRelationTo(uplayer); List deniedCommands = UConf.get(player).denyCommandsTerritoryRelation.get(rel); if (deniedCommands == null) return;