From d0a213397602b8385df262dc18bbd417e84e0e91 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 3 Oct 2014 11:48:25 +0200 Subject: [PATCH] Some NPE evasion and checking --- .../massivecraft/factions/entity/MPerm.java | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/entity/MPerm.java b/src/main/java/com/massivecraft/factions/entity/MPerm.java index cabbdda8..1f156ec9 100644 --- a/src/main/java/com/massivecraft/factions/entity/MPerm.java +++ b/src/main/java/com/massivecraft/factions/entity/MPerm.java @@ -4,6 +4,8 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import org.bukkit.entity.Player; + import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; @@ -245,26 +247,44 @@ public class MPerm extends Entity implements Prioritized, Registerable public String createDeniedMessage(MPlayer mplayer, Faction hostFaction) { + // Null Check + if (mplayer == null) throw new NullPointerException("mplayer"); + if (hostFaction == null) throw new NullPointerException("hostFaction"); + String ret = Txt.parse("%s does not allow you to %s.", hostFaction.describeTo(mplayer, true), this.getDesc()); - if (Perm.ADMIN.has(mplayer.getPlayer())) + + Player player = mplayer.getPlayer(); + if (player != null && Perm.ADMIN.has(player)) { ret += Txt.parse("\nYou can bypass by using " + Factions.get().getOuterCmdFactions().cmdFactionsAdmin.getUseageTemplate(false)); } + return ret; } public boolean has(Faction faction, Faction hostFaction) { + // Null Check + if (faction == null) throw new NullPointerException("faction"); + if (hostFaction == null) throw new NullPointerException("hostFaction"); + Rel rel = faction.getRelationTo(hostFaction); - return hostFaction.getPermittedRelations(this).contains(rel); + + Set permittedRelations = hostFaction.getPermittedRelations(this); + return permittedRelations.contains(rel); } public boolean has(MPlayer mplayer, Faction hostFaction, boolean verboose) { + // Null Check + if (mplayer == null) throw new NullPointerException("mplayer"); + if (hostFaction == null) throw new NullPointerException("hostFaction"); + if (mplayer.isUsingAdminMode()) return true; Rel rel = mplayer.getRelationTo(hostFaction); - if (hostFaction.getPermittedRelations(this).contains(rel)) return true; + Set permittedRelations = hostFaction.getPermittedRelations(this); + if (permittedRelations.contains(rel)) return true; if (verboose) mplayer.sendMessage(this.createDeniedMessage(mplayer, hostFaction)); @@ -273,6 +293,10 @@ public class MPerm extends Entity implements Prioritized, Registerable public boolean has(MPlayer mplayer, PS ps, boolean verboose) { + // Null Check + if (mplayer == null) throw new NullPointerException("mplayer"); + if (ps == null) throw new NullPointerException("ps"); + if (mplayer.isUsingAdminMode()) return true; TerritoryAccess ta = BoardColl.get().getTerritoryAccessAt(ps);