More Type Security

This commit is contained in:
Olof Larsson 2015-05-16 14:30:49 +02:00
parent a9b80dacfe
commit b244ff63c7
11 changed files with 49 additions and 31 deletions

View File

@ -36,7 +36,8 @@ public class FactionEqualsPredictate implements Predictate<CommandSender>, Seria
@Override @Override
public boolean apply(CommandSender sender) public boolean apply(CommandSender sender)
{ {
if (MUtil.isNpc(sender)) return false; if (MUtil.isntSender(sender)) return false;
MPlayer mplayer = MPlayer.get(sender); MPlayer mplayer = MPlayer.get(sender);
return this.factionId.equals(mplayer.getFactionId()); return this.factionId.equals(mplayer.getFactionId());
} }

View File

@ -120,7 +120,7 @@ public class CmdFactionsHome extends FactionsCommandHome
for (Player p : me.getServer().getOnlinePlayers()) 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) if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w)
continue; continue;

View File

@ -26,7 +26,8 @@ public class ReqHasFaction extends ReqAbstract
@Override @Override
public boolean apply(CommandSender sender, MassiveCommand command) public boolean apply(CommandSender sender, MassiveCommand command)
{ {
if (MUtil.isNpc(sender)) return false; if (MUtil.isntSender(sender)) return false;
MPlayer mplayer = MPlayer.get(sender); MPlayer mplayer = MPlayer.get(sender);
return mplayer.hasFaction(); return mplayer.hasFaction();
} }

View File

@ -26,7 +26,8 @@ public class ReqHasntFaction extends ReqAbstract
@Override @Override
public boolean apply(CommandSender sender, MassiveCommand command) public boolean apply(CommandSender sender, MassiveCommand command)
{ {
if (MUtil.isNpc(sender)) return true; if (MUtil.isntSender(sender)) return true;
MPlayer mplayer = MPlayer.get(sender); MPlayer mplayer = MPlayer.get(sender);
return !mplayer.hasFaction(); return !mplayer.hasFaction();
} }

View File

@ -34,7 +34,8 @@ public class ReqRoleIsAtLeast extends ReqAbstract
@Override @Override
public boolean apply(CommandSender sender, MassiveCommand command) public boolean apply(CommandSender sender, MassiveCommand command)
{ {
if (MUtil.isNpc(sender)) return false; if (MUtil.isntSender(sender)) return false;
MPlayer mplayer = MPlayer.get(sender); MPlayer mplayer = MPlayer.get(sender);
return mplayer.getRole().isAtLeast(this.rel); return mplayer.getRole().isAtLeast(this.rel);
} }

View File

@ -107,7 +107,7 @@ public class EngineChat extends EngineAbstract
public static void parseTags(AsyncPlayerChatEvent event) public static void parseTags(AsyncPlayerChatEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (MUtil.isNpc(player)) return; if (MUtil.isntPlayer(player)) return;
String format = event.getFormat(); String format = event.getFormat();
format = ChatFormatter.format(format, player, null); format = ChatFormatter.format(format, player, null);

View File

@ -345,7 +345,8 @@ public class EngineMain extends EngineAbstract
public static void updateLastActivity(CommandSender sender) public static void updateLastActivity(CommandSender sender)
{ {
if (sender == null) throw new RuntimeException("sender"); if (sender == null) throw new RuntimeException("sender");
if (MUtil.isNpc(sender)) return; if (MUtil.isntSender(sender)) return;
MPlayer mplayer = MPlayer.get(sender); MPlayer mplayer = MPlayer.get(sender);
mplayer.setLastActivityMillis(); mplayer.setLastActivityMillis();
} }
@ -390,7 +391,7 @@ public class EngineMain extends EngineAbstract
{ {
// Gather info ... // Gather info ...
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (MUtil.isNpc(player)) return; if (MUtil.isntPlayer(player)) return;
final MPlayer mplayer = MPlayer.get(player); final MPlayer mplayer = MPlayer.get(player);
final Faction faction = mplayer.getFaction(); 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 the player is moving from one chunk to another ...
if (MUtil.isSameChunk(event)) return; if (MUtil.isSameChunk(event)) return;
Player player = event.getPlayer(); Player player = event.getPlayer();
if (MUtil.isNpc(player)) return; if (MUtil.isntPlayer(player)) return;
// ... gather info on the player and the move ... // ... gather info on the player and the move ...
MPlayer mplayer = MPlayer.get(player); MPlayer mplayer = MPlayer.get(player);
@ -772,7 +773,7 @@ public class EngineMain extends EngineAbstract
{ {
// If a player dies ... // If a player dies ...
Player player = event.getEntity(); Player player = event.getEntity();
if (MUtil.isNpc(player)) return; if (MUtil.isntPlayer(player)) return;
// ... and this is the first death event this tick ... // ... and this is the first death event this tick ...
// (yeah other plugins can case death event to fire twice the same 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 ... // If the defender is a player ...
Entity edefender = event.getEntity(); Entity edefender = event.getEntity();
if (!(edefender instanceof Player)) return true; if (MUtil.isntPlayer(edefender)) return true;
Player defender = (Player)edefender; Player defender = (Player)edefender;
if (MUtil.isNpc(defender)) return true;
MPlayer mdefender = MPlayer.get(edefender); MPlayer mdefender = MPlayer.get(edefender);
// ... and the attacker is someone else ... // ... and the attacker is someone else ...
@ -897,7 +897,7 @@ public class EngineMain extends EngineAbstract
// Let's behave as if it were a player // Let's behave as if it were a player
return falseUnlessDisallowedPvpEventCancelled(null, defender, event); return falseUnlessDisallowedPvpEventCancelled(null, defender, event);
} }
if (eattacker instanceof Player) if (MUtil.isPlayer(eattacker))
{ {
ret = falseUnlessDisallowedPvpEventCancelled((Player)eattacker, defender, event); ret = falseUnlessDisallowedPvpEventCancelled((Player)eattacker, defender, event);
if (!ret && notify) if (!ret && notify)
@ -911,7 +911,7 @@ public class EngineMain extends EngineAbstract
} }
// ... and if the attacker is a player ... // ... and if the attacker is a player ...
if (!(eattacker instanceof Player)) return true; if (MUtil.isntPlayer(eattacker)) return true;
Player attacker = (Player)eattacker; Player attacker = (Player)eattacker;
MPlayer uattacker = MPlayer.get(attacker); MPlayer uattacker = MPlayer.get(attacker);
@ -995,9 +995,8 @@ public class EngineMain extends EngineAbstract
{ {
// If the entity is a player ... // If the entity is a player ...
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (!(entity instanceof Player)) return; if (MUtil.isntPlayer(entity)) return;
Player player = (Player)entity; Player player = (Player)entity;
if (MUtil.isNpc(player)) return;
MPlayer mplayer = MPlayer.get(player); MPlayer mplayer = MPlayer.get(player);
// ... and that player has a faction ... // ... and that player has a faction ...
@ -1069,7 +1068,7 @@ public class EngineMain extends EngineAbstract
{ {
// If a player is trying to run a command ... // If a player is trying to run a command ...
Player player = event.getPlayer(); Player player = event.getPlayer();
if (MUtil.isNpc(player)) return; if (MUtil.isntPlayer(player)) return;
MPlayer mplayer = MPlayer.get(player); MPlayer mplayer = MPlayer.get(player);
// ... and the player does not have adminmode ... // ... and the player does not have adminmode ...
@ -1434,7 +1433,7 @@ public class EngineMain extends EngineAbstract
HangingBreakByEntityEvent entityEvent = (HangingBreakByEntityEvent)event; HangingBreakByEntityEvent entityEvent = (HangingBreakByEntityEvent)event;
Entity breaker = entityEvent.getRemover(); Entity breaker = entityEvent.getRemover();
if (! (breaker instanceof Player)) return; if (MUtil.isntPlayer(breaker)) return;
if ( ! canPlayerBuildAt(breaker, PS.valueOf(event.getEntity().getLocation()), true)) if ( ! canPlayerBuildAt(breaker, PS.valueOf(event.getEntity().getLocation()), true))
{ {
@ -1451,7 +1450,7 @@ public class EngineMain extends EngineAbstract
{ {
// If a player ... // If a player ...
Entity edamager = MUtil.getLiableDamager(event); Entity edamager = MUtil.getLiableDamager(event);
if (!(edamager instanceof Player)) return; if (MUtil.isntPlayer(edamager)) return;
Player player = (Player)edamager; Player player = (Player)edamager;
// ... damages an entity which is edited on damage ... // ... 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) 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; 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) 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(); String name = player.getName();
if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true; 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) public static boolean canPlayerUseEntity(Player player, Entity entity, boolean verboose)
{ {
// If a player ... // If a player ...
if (player == null) return true; if (MUtil.isntPlayer(player)) return true;
if (MUtil.isNpc(player)) return true;
// ... interacts with an entity ... // ... interacts with an entity ...
if (entity == null) return true; if (entity == null) return true;
@ -1606,7 +1604,7 @@ public class EngineMain extends EngineAbstract
{ {
// If a player is respawning ... // If a player is respawning ...
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (MUtil.isNpc(player)) return; if (MUtil.isntPlayer(player)) return;
final MPlayer mplayer = MPlayer.get(player); final MPlayer mplayer = MPlayer.get(player);
// ... homes are enabled, active and at this priority ... // ... homes are enabled, active and at this priority ...

View File

@ -54,6 +54,8 @@ public class EngineSeeChunk extends EngineAbstract
public static void leaveAndWorldChangeRemoval(Player player) public static void leaveAndWorldChangeRemoval(Player player)
{ {
if (MUtil.isntPlayer(player)) return;
final MPlayer mplayer = MPlayer.get(player); final MPlayer mplayer = MPlayer.get(player);
mplayer.setSeeingChunk(false); mplayer.setSeeingChunk(false);
} }

View File

@ -1074,27 +1074,41 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
public List<CommandSender> getOnlineCommandSenders() public List<CommandSender> getOnlineCommandSenders()
{ {
// Create Ret
List<CommandSender> ret = new ArrayList<CommandSender>(); List<CommandSender> ret = new ArrayList<CommandSender>();
for (CommandSender player : IdUtil.getOnlineSenders())
// Fill Ret
for (CommandSender sender : IdUtil.getOnlineSenders())
{ {
if (MUtil.isNpc(player)) continue; if (MUtil.isntSender(sender)) continue;
MPlayer mplayer = MPlayer.get(player);
MPlayer mplayer = MPlayer.get(sender);
if (mplayer.getFaction() != this) continue; if (mplayer.getFaction() != this) continue;
ret.add(player);
ret.add(sender);
} }
// Return Ret
return ret; return ret;
} }
public List<Player> getOnlinePlayers() public List<Player> getOnlinePlayers()
{ {
// Create Ret
List<Player> ret = new ArrayList<Player>(); List<Player> ret = new ArrayList<Player>();
// Fill Ret
for (Player player : MUtil.getOnlinePlayers()) for (Player player : MUtil.getOnlinePlayers())
{ {
if (MUtil.isNpc(player)) continue; if (MUtil.isntPlayer(player)) continue;
MPlayer mplayer = MPlayer.get(player); MPlayer mplayer = MPlayer.get(player);
if (mplayer.getFaction() != this) continue; if (mplayer.getFaction() != this) continue;
ret.add(player); ret.add(player);
} }
// Return Ret
return ret; return ret;
} }

View File

@ -71,7 +71,7 @@ public class EngineSpigot extends EngineAbstract
{ {
// Gather Info // Gather Info
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (MUtil.isNpc(player)) return; if (MUtil.isntPlayer(player)) return;
final Entity entity = event.getRightClicked(); final Entity entity = event.getRightClicked();
final boolean verboose = true; final boolean verboose = true;

View File

@ -50,7 +50,7 @@ public class TaskPlayerPowerUpdate extends ModuloRepeatTask
for (Player player : MUtil.getOnlinePlayers()) for (Player player : MUtil.getOnlinePlayers())
{ {
if (MUtil.isNpc(player)) continue; if (MUtil.isntPlayer(player)) continue;
if (player.isDead()) continue; if (player.isDead()) continue;
MPlayer mplayer = MPlayer.get(player); MPlayer mplayer = MPlayer.get(player);