From 10fa9e5465e96c3cb7ddc522fb44e1b4a64e8877 Mon Sep 17 00:00:00 2001 From: GJ Date: Thu, 23 Feb 2012 21:44:44 -0500 Subject: [PATCH] Optimize more things. --- .../nossr50/listeners/mcEntityListener.java | 76 ++++++++----------- .../com/gmail/nossr50/skills/Acrobatics.java | 73 +++++++++--------- 2 files changed, 67 insertions(+), 82 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java index a63e23597..96991fe64 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java @@ -63,18 +63,21 @@ public class mcEntityListener implements Listener @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEntityDamage(EntityDamageEvent event) { + Entity entity = event.getEntity(); + DamageCause cause = event.getCause(); + //Check for world pvp flag if(event instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent eventb = (EntityDamageByEntityEvent)event; - if(eventb.getEntity() instanceof Player && eventb.getDamager() instanceof Player && !event.getEntity().getWorld().getPVP()) + if(eventb.getEntity() instanceof Player && eventb.getDamager() instanceof Player && !entity.getWorld().getPVP()) return; } /* * CHECK FOR INVULNERABILITY */ - if(event.getEntity() instanceof Player) + if(entity instanceof Player) { Player defender = (Player)event.getEntity(); PlayerProfile PPd = Users.getProfile(defender); @@ -84,66 +87,52 @@ public class mcEntityListener implements Listener Users.addUser(defender); } - /* - * Demolitions Expert - */ - - if(event.getCause() == DamageCause.BLOCK_EXPLOSION) - { - if(event.getEntity() instanceof Player) - { - Player player = (Player)event.getEntity(); - if(mcPermissions.getInstance().blastmining(player)) - BlastMining.demolitionsExpertise(player, event); - } - } - - - if(event.getEntity() instanceof LivingEntity) + if(entity instanceof LivingEntity) { { - LivingEntity entityliving = (LivingEntity)event.getEntity(); + LivingEntity entityliving = (LivingEntity)entity; if(entityliving.getNoDamageTicks() < entityliving.getMaximumNoDamageTicks()/2.0F) { - Entity x = event.getEntity(); - DamageCause type = event.getCause(); - if(event.getEntity() instanceof Wolf && ((Wolf)event.getEntity()).isTamed() && Taming.getOwner(((Wolf)event.getEntity()), plugin) != null) + if(entity instanceof Wolf && ((Wolf)entity).isTamed() && Taming.getOwner(((Wolf)entity), plugin) != null) { Wolf theWolf = (Wolf) event.getEntity(); Player master = Taming.getOwner(theWolf, plugin); PlayerProfile PPo = Users.getProfile(master); + int skillLevel = PPo.getSkillLevel(SkillType.TAMING); + if(master == null || PPo == null) return; //Environmentally Aware - if((event.getCause() == DamageCause.CONTACT || event.getCause() == DamageCause.LAVA || event.getCause() == DamageCause.FIRE) && PPo.getSkillLevel(SkillType.TAMING) >= 100) + if((cause == DamageCause.CONTACT || cause == DamageCause.LAVA || cause == DamageCause.FIRE) && skillLevel >= 100) { - if(event.getDamage() < ((Wolf) event.getEntity()).getHealth()) + if(event.getDamage() < theWolf.getHealth()) { - event.getEntity().teleport(Taming.getOwner(theWolf, plugin).getLocation()); + entity.teleport(Taming.getOwner(theWolf, plugin).getLocation()); master.sendMessage(mcLocale.getString("mcEntityListener.WolfComesBack")); //$NON-NLS-1$ - event.getEntity().setFireTicks(0); + entity.setFireTicks(0); } } - if(event.getCause() == DamageCause.FALL && PPo.getSkillLevel(SkillType.TAMING) >= 100) - { + if(cause == DamageCause.FALL && skillLevel >= 100) event.setCancelled(true); - } //Thick Fur - if(event.getCause() == DamageCause.FIRE_TICK) - { + if(cause == DamageCause.FIRE_TICK) event.getEntity().setFireTicks(0); - } } - /* - * ACROBATICS - */ - if(x instanceof Player){ - Player player = (Player)x; - if(type == DamageCause.FALL){ + + if(entity instanceof Player){ + Player player = (Player)entity; + /* + * ACROBATICS + */ + if(cause == DamageCause.FALL && mcPermissions.getInstance().acrobatics(player)) Acrobatics.acrobaticsCheck(player, event); - } + /* + * Demolitions Expert + */ + if(cause == DamageCause.BLOCK_EXPLOSION && mcPermissions.getInstance().blastmining(player)) + BlastMining.demolitionsExpertise(player, event); } /* @@ -153,13 +142,12 @@ public class mcEntityListener implements Listener { EntityDamageByEntityEvent eventb = (EntityDamageByEntityEvent) event; Entity f = eventb.getDamager(); - Entity e = event.getEntity(); /* * PARTY CHECKS */ - if(e instanceof Player && f instanceof Player) + if(entity instanceof Player && f instanceof Player) { - Player defender = (Player)e; + Player defender = (Player)entity; Player attacker = (Player)f; if(Party.getInstance().inSameParty(defender, attacker)) event.setCancelled(true); @@ -169,9 +157,9 @@ public class mcEntityListener implements Listener /* * Check to see if the defender took damage so we can apply recently hurt */ - if(event.getEntity() instanceof Player) + if(entity instanceof Player) { - Player herpderp = (Player)event.getEntity(); + Player herpderp = (Player)entity; if(!event.isCancelled() && event.getDamage() >= 1) { Users.getProfile(herpderp).setRecentlyHurt(System.currentTimeMillis()); diff --git a/src/main/java/com/gmail/nossr50/skills/Acrobatics.java b/src/main/java/com/gmail/nossr50/skills/Acrobatics.java index 3a871c9c4..5a5d61e27 100644 --- a/src/main/java/com/gmail/nossr50/skills/Acrobatics.java +++ b/src/main/java/com/gmail/nossr50/skills/Acrobatics.java @@ -30,46 +30,43 @@ import com.gmail.nossr50.datatypes.SkillType; public class Acrobatics { public static void acrobaticsCheck(Player player, EntityDamageEvent event) { - if(player != null && mcPermissions.getInstance().acrobatics(player)) - { - PlayerProfile PP = Users.getProfile(player); - int acrovar = PP.getSkillLevel(SkillType.ACROBATICS); - - if(player.isSneaking()) - acrovar = acrovar * 2; - - if(Math.random() * 1000 <= acrovar && !event.isCancelled()) - { - int threshold = 7; - if(player.isSneaking()) - threshold = 14; - - int newDamage = event.getDamage() - threshold; - if(newDamage < 0) - newDamage = 0; - /* - * Check for death - */ - if(player.getHealth() - newDamage >= 1){ - if(!event.isCancelled()) - PP.addXP(SkillType.ACROBATICS, (event.getDamage() * 8)*10, player); - Skills.XpCheckSkill(SkillType.ACROBATICS, player); - event.setDamage(newDamage); - if(event.getDamage() <= 0) - event.setCancelled(true); - if(player.isSneaking()){ - player.sendMessage(ChatColor.GREEN+"**GRACEFUL ROLL**"); - } else { - player.sendMessage("**ROLL**"); - } - } - } else if (!event.isCancelled()){ - if(player.getHealth() - event.getDamage() >= 1){ - PP.addXP(SkillType.ACROBATICS, (event.getDamage() * 12)*10, player); - Skills.XpCheckSkill(SkillType.ACROBATICS, player); + PlayerProfile PP = Users.getProfile(player); + int acrovar = PP.getSkillLevel(SkillType.ACROBATICS); + + if(player.isSneaking()) + acrovar = acrovar * 2; + + if(Math.random() * 1000 <= acrovar && !event.isCancelled()) + { + int threshold = 7; + if(player.isSneaking()) + threshold = 14; + + int newDamage = event.getDamage() - threshold; + if(newDamage < 0) + newDamage = 0; + /* + * Check for death + */ + if(player.getHealth() - newDamage >= 1){ + if(!event.isCancelled()) + PP.addXP(SkillType.ACROBATICS, (event.getDamage() * 8)*10, player); + Skills.XpCheckSkill(SkillType.ACROBATICS, player); + event.setDamage(newDamage); + if(event.getDamage() <= 0) + event.setCancelled(true); + if(player.isSneaking()){ + player.sendMessage(ChatColor.GREEN+"**GRACEFUL ROLL**"); + } else { + player.sendMessage("**ROLL**"); } } - } + } else if (!event.isCancelled()){ + if(player.getHealth() - event.getDamage() >= 1){ + PP.addXP(SkillType.ACROBATICS, (event.getDamage() * 12)*10, player); + Skills.XpCheckSkill(SkillType.ACROBATICS, player); + } + } } public static void dodgeChecks(EntityDamageByEntityEvent event){ Player defender = (Player) event.getEntity();