From b244ff63c76c43c7cfe171cc3bcda456cd6ff3d0 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Sat, 16 May 2015 14:30:49 +0200 Subject: [PATCH] More Type Security --- .../factions/FactionEqualsPredictate.java | 3 +- .../factions/cmd/CmdFactionsHome.java | 2 +- .../factions/cmd/req/ReqHasFaction.java | 3 +- .../factions/cmd/req/ReqHasntFaction.java | 3 +- .../factions/cmd/req/ReqRoleIsAtLeast.java | 3 +- .../factions/engine/EngineChat.java | 2 +- .../factions/engine/EngineMain.java | 34 +++++++++---------- .../factions/engine/EngineSeeChunk.java | 2 ++ .../massivecraft/factions/entity/Faction.java | 24 ++++++++++--- .../factions/spigot/EngineSpigot.java | 2 +- .../factions/task/TaskPlayerPowerUpdate.java | 2 +- 11 files changed, 49 insertions(+), 31 deletions(-) diff --git a/src/com/massivecraft/factions/FactionEqualsPredictate.java b/src/com/massivecraft/factions/FactionEqualsPredictate.java index 4bc24a1e..1c667581 100644 --- a/src/com/massivecraft/factions/FactionEqualsPredictate.java +++ b/src/com/massivecraft/factions/FactionEqualsPredictate.java @@ -36,7 +36,8 @@ public class FactionEqualsPredictate implements Predictate, Seria @Override public boolean apply(CommandSender sender) { - if (MUtil.isNpc(sender)) return false; + if (MUtil.isntSender(sender)) return false; + MPlayer mplayer = MPlayer.get(sender); return this.factionId.equals(mplayer.getFactionId()); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java index ef407252..4e4fb16a 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java @@ -120,7 +120,7 @@ public class CmdFactionsHome extends FactionsCommandHome for (Player p : me.getServer().getOnlinePlayers()) { - if (MUtil.isNpc(p)) continue; + if (MUtil.isntPlayer(p)) continue; if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w) continue; diff --git a/src/com/massivecraft/factions/cmd/req/ReqHasFaction.java b/src/com/massivecraft/factions/cmd/req/ReqHasFaction.java index d7c285ff..d34e6271 100644 --- a/src/com/massivecraft/factions/cmd/req/ReqHasFaction.java +++ b/src/com/massivecraft/factions/cmd/req/ReqHasFaction.java @@ -26,7 +26,8 @@ public class ReqHasFaction extends ReqAbstract @Override public boolean apply(CommandSender sender, MassiveCommand command) { - if (MUtil.isNpc(sender)) return false; + if (MUtil.isntSender(sender)) return false; + MPlayer mplayer = MPlayer.get(sender); return mplayer.hasFaction(); } diff --git a/src/com/massivecraft/factions/cmd/req/ReqHasntFaction.java b/src/com/massivecraft/factions/cmd/req/ReqHasntFaction.java index 1924cd67..158f474d 100644 --- a/src/com/massivecraft/factions/cmd/req/ReqHasntFaction.java +++ b/src/com/massivecraft/factions/cmd/req/ReqHasntFaction.java @@ -26,7 +26,8 @@ public class ReqHasntFaction extends ReqAbstract @Override public boolean apply(CommandSender sender, MassiveCommand command) { - if (MUtil.isNpc(sender)) return true; + if (MUtil.isntSender(sender)) return true; + MPlayer mplayer = MPlayer.get(sender); return !mplayer.hasFaction(); } diff --git a/src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java b/src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java index c04979b9..afbc654d 100644 --- a/src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java +++ b/src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java @@ -34,7 +34,8 @@ public class ReqRoleIsAtLeast extends ReqAbstract @Override public boolean apply(CommandSender sender, MassiveCommand command) { - if (MUtil.isNpc(sender)) return false; + if (MUtil.isntSender(sender)) return false; + MPlayer mplayer = MPlayer.get(sender); return mplayer.getRole().isAtLeast(this.rel); } diff --git a/src/com/massivecraft/factions/engine/EngineChat.java b/src/com/massivecraft/factions/engine/EngineChat.java index bff28e12..5620edb2 100644 --- a/src/com/massivecraft/factions/engine/EngineChat.java +++ b/src/com/massivecraft/factions/engine/EngineChat.java @@ -107,7 +107,7 @@ public class EngineChat extends EngineAbstract public static void parseTags(AsyncPlayerChatEvent event) { Player player = event.getPlayer(); - if (MUtil.isNpc(player)) return; + if (MUtil.isntPlayer(player)) return; String format = event.getFormat(); format = ChatFormatter.format(format, player, null); diff --git a/src/com/massivecraft/factions/engine/EngineMain.java b/src/com/massivecraft/factions/engine/EngineMain.java index f2f379eb..80594a26 100644 --- a/src/com/massivecraft/factions/engine/EngineMain.java +++ b/src/com/massivecraft/factions/engine/EngineMain.java @@ -345,7 +345,8 @@ public class EngineMain extends EngineAbstract public static void updateLastActivity(CommandSender sender) { if (sender == null) throw new RuntimeException("sender"); - if (MUtil.isNpc(sender)) return; + if (MUtil.isntSender(sender)) return; + MPlayer mplayer = MPlayer.get(sender); mplayer.setLastActivityMillis(); } @@ -390,7 +391,7 @@ public class EngineMain extends EngineAbstract { // Gather info ... final Player player = event.getPlayer(); - if (MUtil.isNpc(player)) return; + if (MUtil.isntPlayer(player)) return; final MPlayer mplayer = MPlayer.get(player); final Faction faction = mplayer.getFaction(); @@ -664,7 +665,7 @@ public class EngineMain extends EngineAbstract // If the player is moving from one chunk to another ... if (MUtil.isSameChunk(event)) return; Player player = event.getPlayer(); - if (MUtil.isNpc(player)) return; + if (MUtil.isntPlayer(player)) return; // ... gather info on the player and the move ... MPlayer mplayer = MPlayer.get(player); @@ -772,7 +773,7 @@ public class EngineMain extends EngineAbstract { // If a player dies ... Player player = event.getEntity(); - if (MUtil.isNpc(player)) return; + if (MUtil.isntPlayer(player)) return; // ... and this is the first death event this tick ... // (yeah other plugins can case death event to fire twice the same tick) @@ -872,9 +873,8 @@ public class EngineMain extends EngineAbstract // If the defender is a player ... Entity edefender = event.getEntity(); - if (!(edefender instanceof Player)) return true; + if (MUtil.isntPlayer(edefender)) return true; Player defender = (Player)edefender; - if (MUtil.isNpc(defender)) return true; MPlayer mdefender = MPlayer.get(edefender); // ... and the attacker is someone else ... @@ -897,7 +897,7 @@ public class EngineMain extends EngineAbstract // Let's behave as if it were a player return falseUnlessDisallowedPvpEventCancelled(null, defender, event); } - if (eattacker instanceof Player) + if (MUtil.isPlayer(eattacker)) { ret = falseUnlessDisallowedPvpEventCancelled((Player)eattacker, defender, event); if (!ret && notify) @@ -911,7 +911,7 @@ public class EngineMain extends EngineAbstract } // ... and if the attacker is a player ... - if (!(eattacker instanceof Player)) return true; + if (MUtil.isntPlayer(eattacker)) return true; Player attacker = (Player)eattacker; MPlayer uattacker = MPlayer.get(attacker); @@ -995,9 +995,8 @@ public class EngineMain extends EngineAbstract { // If the entity is a player ... Entity entity = event.getEntity(); - if (!(entity instanceof Player)) return; + if (MUtil.isntPlayer(entity)) return; Player player = (Player)entity; - if (MUtil.isNpc(player)) return; MPlayer mplayer = MPlayer.get(player); // ... and that player has a faction ... @@ -1069,7 +1068,7 @@ public class EngineMain extends EngineAbstract { // If a player is trying to run a command ... Player player = event.getPlayer(); - if (MUtil.isNpc(player)) return; + if (MUtil.isntPlayer(player)) return; MPlayer mplayer = MPlayer.get(player); // ... and the player does not have adminmode ... @@ -1434,7 +1433,7 @@ public class EngineMain extends EngineAbstract HangingBreakByEntityEvent entityEvent = (HangingBreakByEntityEvent)event; Entity breaker = entityEvent.getRemover(); - if (! (breaker instanceof Player)) return; + if (MUtil.isntPlayer(breaker)) return; if ( ! canPlayerBuildAt(breaker, PS.valueOf(event.getEntity().getLocation()), true)) { @@ -1451,7 +1450,7 @@ public class EngineMain extends EngineAbstract { // If a player ... Entity edamager = MUtil.getLiableDamager(event); - if (!(edamager instanceof Player)) return; + if (MUtil.isntPlayer(edamager)) return; Player player = (Player)edamager; // ... damages an entity which is edited on damage ... @@ -1494,7 +1493,7 @@ public class EngineMain extends EngineAbstract public static boolean playerCanUseItemHere(Player player, PS ps, Material material, boolean verboose) { - if (MUtil.isNpc(player)) return true; + if (MUtil.isntPlayer(player)) return true; if ( ! MConf.get().materialsEditTools.contains(material) && ! MConf.get().materialsEditToolsDupeBug.contains(material)) return true; @@ -1509,7 +1508,7 @@ public class EngineMain extends EngineAbstract public static boolean canPlayerUseBlock(Player player, Block block, boolean verboose) { - if (MUtil.isNpc(player)) return true; + if (MUtil.isntPlayer(player)) return true; String name = player.getName(); if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true; @@ -1548,8 +1547,7 @@ public class EngineMain extends EngineAbstract public static boolean canPlayerUseEntity(Player player, Entity entity, boolean verboose) { // If a player ... - if (player == null) return true; - if (MUtil.isNpc(player)) return true; + if (MUtil.isntPlayer(player)) return true; // ... interacts with an entity ... if (entity == null) return true; @@ -1606,7 +1604,7 @@ public class EngineMain extends EngineAbstract { // If a player is respawning ... final Player player = event.getPlayer(); - if (MUtil.isNpc(player)) return; + if (MUtil.isntPlayer(player)) return; final MPlayer mplayer = MPlayer.get(player); // ... homes are enabled, active and at this priority ... diff --git a/src/com/massivecraft/factions/engine/EngineSeeChunk.java b/src/com/massivecraft/factions/engine/EngineSeeChunk.java index 86b61598..459a35f3 100644 --- a/src/com/massivecraft/factions/engine/EngineSeeChunk.java +++ b/src/com/massivecraft/factions/engine/EngineSeeChunk.java @@ -54,6 +54,8 @@ public class EngineSeeChunk extends EngineAbstract public static void leaveAndWorldChangeRemoval(Player player) { + if (MUtil.isntPlayer(player)) return; + final MPlayer mplayer = MPlayer.get(player); mplayer.setSeeingChunk(false); } diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 1d09947c..953488a1 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -1074,27 +1074,41 @@ public class Faction extends Entity implements EconomyParticipator public List getOnlineCommandSenders() { + // Create Ret List ret = new ArrayList(); - for (CommandSender player : IdUtil.getOnlineSenders()) + + // Fill Ret + for (CommandSender sender : IdUtil.getOnlineSenders()) { - if (MUtil.isNpc(player)) continue; - MPlayer mplayer = MPlayer.get(player); + if (MUtil.isntSender(sender)) continue; + + MPlayer mplayer = MPlayer.get(sender); if (mplayer.getFaction() != this) continue; - ret.add(player); + + ret.add(sender); } + + // Return Ret return ret; } public List getOnlinePlayers() { + // Create Ret List ret = new ArrayList(); + + // Fill Ret for (Player player : MUtil.getOnlinePlayers()) { - if (MUtil.isNpc(player)) continue; + if (MUtil.isntPlayer(player)) continue; + MPlayer mplayer = MPlayer.get(player); if (mplayer.getFaction() != this) continue; + ret.add(player); } + + // Return Ret return ret; } diff --git a/src/com/massivecraft/factions/spigot/EngineSpigot.java b/src/com/massivecraft/factions/spigot/EngineSpigot.java index fb925cda..aef0b094 100644 --- a/src/com/massivecraft/factions/spigot/EngineSpigot.java +++ b/src/com/massivecraft/factions/spigot/EngineSpigot.java @@ -71,7 +71,7 @@ public class EngineSpigot extends EngineAbstract { // Gather Info final Player player = event.getPlayer(); - if (MUtil.isNpc(player)) return; + if (MUtil.isntPlayer(player)) return; final Entity entity = event.getRightClicked(); final boolean verboose = true; diff --git a/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java b/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java index 5d628f3a..79def210 100644 --- a/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java +++ b/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java @@ -50,7 +50,7 @@ public class TaskPlayerPowerUpdate extends ModuloRepeatTask for (Player player : MUtil.getOnlinePlayers()) { - if (MUtil.isNpc(player)) continue; + if (MUtil.isntPlayer(player)) continue; if (player.isDead()) continue; MPlayer mplayer = MPlayer.get(player);