From 716e6296e5a0f90863026b2e0c5a7bc08f2627b2 Mon Sep 17 00:00:00 2001 From: GJ Date: Thu, 9 Feb 2012 00:58:05 -0500 Subject: [PATCH] Updates to Swords & Axes skills, optimizations. --- src/main/java/com/gmail/nossr50/Combat.java | 8 +- .../nossr50/listeners/mcEntityListener.java | 7 +- .../java/com/gmail/nossr50/skills/Axes.java | 110 +++++++++--------- .../java/com/gmail/nossr50/skills/Swords.java | 93 +++++++-------- 4 files changed, 109 insertions(+), 109 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/Combat.java b/src/main/java/com/gmail/nossr50/Combat.java index 6c7a5829d..4e5388c92 100644 --- a/src/main/java/com/gmail/nossr50/Combat.java +++ b/src/main/java/com/gmail/nossr50/Combat.java @@ -60,7 +60,10 @@ public class Combat if(mcPermissions.getInstance().unarmed(attacker) && attacker.getItemInHand().getTypeId() == 0) //Unarmed Unarmed.unarmedBonus(attacker, eventb); if(m.isAxes(attacker.getItemInHand()) && mcPermissions.getInstance().axes(attacker) && Users.getProfile(attacker).getSkillLevel(SkillType.AXES) >= 500) - event.setDamage(event.getDamage()+4); + { + int damage = event.getDamage()+4; + event.setDamage(damage); + } //If there are any abilities to activate combatAbilityChecks(attacker, PPa, pluginx); @@ -69,7 +72,7 @@ public class Combat if(!(((EntityDamageByEntityEvent) event).getDamager() instanceof Arrow)) { if(mcPermissions.getInstance().axes(attacker)) - Axes.axeCriticalCheck(attacker, eventb, pluginx); //Axe Criticals + Axes.axeCriticalCheck(attacker, eventb, pluginx); //Axe Critical Checks if(!pluginx.misc.bleedTracker.contains((LivingEntity) event.getEntity())) //Swords Bleed Swords.bleedCheck(attacker, (LivingEntity)event.getEntity(), pluginx); @@ -389,6 +392,7 @@ public class Combat public static void dealDamage(LivingEntity target, int dmg, Player attacker) { EntityDamageEvent ede = new EntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, dmg); Bukkit.getPluginManager().callEvent(ede); + if(ede.isCancelled()) return; target.damage(ede.getDamage()); } diff --git a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java index f5908c933..9648e2ca6 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java @@ -225,8 +225,7 @@ public class mcEntityListener implements Listener int skillLevel = plugin.misc.tntTracker.get(block); BlastMining.biggerBombs(skillLevel, event); } - } - + } } @EventHandler (priority = EventPriority.LOW) @@ -234,8 +233,8 @@ public class mcEntityListener implements Listener { if(event.getEntity() instanceof TNTPrimed) { - Block block = event.getLocation().getBlock();; - + Block block = event.getLocation().getBlock(); + if(plugin.misc.tntTracker.get(block) != null) { int skillLevel = plugin.misc.tntTracker.get(block); diff --git a/src/main/java/com/gmail/nossr50/skills/Axes.java b/src/main/java/com/gmail/nossr50/skills/Axes.java index 4c0e0e601..3fe4c4e9d 100644 --- a/src/main/java/com/gmail/nossr50/skills/Axes.java +++ b/src/main/java/com/gmail/nossr50/skills/Axes.java @@ -72,6 +72,7 @@ public class Axes { public static void axeCriticalCheck(Player attacker, EntityDamageByEntityEvent event, Plugin pluginx) { Entity x = event.getEntity(); + if(x instanceof Wolf){ Wolf wolf = (Wolf)x; if(Taming.getOwner(wolf, pluginx) != null) @@ -85,27 +86,29 @@ public class Axes { PlayerProfile PPa = Users.getProfile(attacker); if(m.isAxes(attacker.getItemInHand()) && mcPermissions.getInstance().axes(attacker)){ if(PPa.getSkillLevel(SkillType.AXES) >= 750){ - if(Math.random() * 1000 <= 750){ + if(Math.random() * 1000 <= 750 && !x.isDead()){ if(x instanceof Player){ + int damage = (event.getDamage() * 2) - (event.getDamage() / 2); + event.setDamage(damage); Player player = (Player)x; player.sendMessage(ChatColor.DARK_RED + "You were CRITICALLY hit!"); } - if(x instanceof Player){ - event.setDamage(event.getDamage() * 2 - event.getDamage() / 2); - } else { - event.setDamage(event.getDamage() * 2); + else { + int damage = event.getDamage() * 2; + event.setDamage(damage); } attacker.sendMessage(ChatColor.RED+"CRITICAL HIT!"); } - } else if(Math.random() * 1000 <= PPa.getSkillLevel(SkillType.AXES)){ + } else if(Math.random() * 1000 <= PPa.getSkillLevel(SkillType.AXES) && !x.isDead()){ if(x instanceof Player){ + int damage = (event.getDamage() * 2) - (event.getDamage() / 2); + event.setDamage(damage); Player player = (Player)x; player.sendMessage(ChatColor.DARK_RED + "You were CRITICALLY hit!"); } - if(x instanceof Player){ - event.setDamage(event.getDamage() * 2 - event.getDamage() / 2); - } else { - event.setDamage(event.getDamage() * 2); + else { + int damage = event.getDamage() * 2; + event.setDamage(damage); } attacker.sendMessage(ChatColor.RED+"CRITICAL HIT!"); } @@ -121,53 +124,52 @@ public class Axes { LivingEntity x = (LivingEntity) event.getEntity(); targets = m.getTier(attacker); - for(Entity derp : x.getWorld().getEntities()) - { - if(m.getDistance(x.getLocation(), derp.getLocation()) < 5) - { - - - //Make sure the Wolf is not friendly - if(derp instanceof Wolf) + for(Entity derp : x.getNearbyEntities(2.5, 2.5, 2.5)) + { + //Make sure the Wolf is not friendly + if(derp instanceof Wolf) + { + Wolf hurrDurr = (Wolf)derp; + if(Taming.getOwner(hurrDurr, pluginx) == attacker) + continue; + if(Party.getInstance().inSameParty(attacker, Taming.getOwner(hurrDurr, pluginx))) + continue; + } + //Damage nearby LivingEntities + if(derp instanceof LivingEntity && targets >= 1) + { + if(derp instanceof Player) { - Wolf hurrDurr = (Wolf)derp; - if(Taming.getOwner(hurrDurr, pluginx) == attacker) - continue; - if(Party.getInstance().inSameParty(attacker, Taming.getOwner(hurrDurr, pluginx))) - continue; - } - //Damage nearby LivingEntities - if(derp instanceof LivingEntity && targets >= 1) - { - if(derp instanceof Player) - { - Player target = (Player)derp; - - if(Users.getProfile(target).getGodMode()) - continue; + Player target = (Player)derp; + + if(Users.getProfile(target).getGodMode()) + continue; - if(target.getName().equals(attacker.getName())) - continue; - - if(Party.getInstance().inSameParty(attacker, target)) - continue; - if(targets >= 1 && derp.getWorld().getPVP()) - { - Combat.dealDamage(target, event.getDamage() / 2, attacker); - target.sendMessage(ChatColor.DARK_RED+"Struck by CLEAVE!"); - targets--; - continue; - } - } - else - { - LivingEntity target = (LivingEntity)derp; + if(target.getName().equals(attacker.getName())) + continue; + + if(Party.getInstance().inSameParty(attacker, target)) + continue; + + if(target.isDead()) + continue; + + if(targets >= 1 && derp.getWorld().getPVP() && !target.isDead()) + { Combat.dealDamage(target, event.getDamage() / 2, attacker); - targets--; - } + target.sendMessage(ChatColor.DARK_RED+"Struck by CLEAVE!"); + targets--; + continue; + } + } + else + { + LivingEntity target = (LivingEntity)derp; + Combat.dealDamage(target, event.getDamage() / 2, attacker); + targets--; } - } - } + } + } } - } + } } diff --git a/src/main/java/com/gmail/nossr50/skills/Swords.java b/src/main/java/com/gmail/nossr50/skills/Swords.java index d944650b4..e1009709c 100644 --- a/src/main/java/com/gmail/nossr50/skills/Swords.java +++ b/src/main/java/com/gmail/nossr50/skills/Swords.java @@ -84,7 +84,7 @@ public class Swords if(mcPermissions.getInstance().swords(attacker) && m.isSwords(attacker.getItemInHand())){ if(PPa.getSkillLevel(SkillType.SWORDS) >= 750) { - if(Math.random() * 1000 >= 750) + if(Math.random() * 1000 <= 750) { if(!(x instanceof Player)) pluginx.misc.addToBleedQue(x); @@ -118,59 +118,54 @@ public class Swords LivingEntity x = (LivingEntity) event.getEntity(); targets = m.getTier(attacker); - for(Entity derp : x.getWorld().getEntities()) + for(Entity derp : x.getNearbyEntities(2.5, 2.5, 2.5)) { - if(m.getDistance(x.getLocation(), derp.getLocation()) < 5) - { - - - //Make sure the Wolf is not friendly - if(derp instanceof Wolf) + //Make sure the Wolf is not friendly + if(derp instanceof Wolf) + { + Wolf hurrDurr = (Wolf)derp; + if(Taming.getOwner(hurrDurr, pluginx) == attacker) + continue; + if(Party.getInstance().inSameParty(attacker, Taming.getOwner(hurrDurr, pluginx))) + continue; + } + //Damage nearby LivingEntities + if(derp instanceof LivingEntity && targets >= 1) + { + if(derp instanceof Player) { - Wolf hurrDurr = (Wolf)derp; - if(Taming.getOwner(hurrDurr, pluginx) == attacker) - continue; - if(Party.getInstance().inSameParty(attacker, Taming.getOwner(hurrDurr, pluginx))) - continue; - } - //Damage nearby LivingEntities - if(derp instanceof LivingEntity && targets >= 1) - { - if(derp instanceof Player) - { - Player target = (Player)derp; - - if(target.getName().equals(attacker.getName())) - continue; - - if(Users.getProfile(target).getGodMode()) - continue; - - if(Party.getInstance().inSameParty(attacker, target)) - continue; - if(targets >= 1 && derp.getWorld().getPVP()) - { - Combat.dealDamage(target, event.getDamage() / 4, attacker); - target.sendMessage(ChatColor.DARK_RED+"Struck by Serrated Strikes!"); - Users.getProfile(target).addBleedTicks(5); - targets--; - continue; - } - } - else - { - if(!pluginx.misc.bleedTracker.contains(derp)) - pluginx.misc.addToBleedQue((LivingEntity)derp); - - LivingEntity target = (LivingEntity)derp; + Player target = (Player)derp; + + if(target.getName().equals(attacker.getName())) + continue; + + if(Users.getProfile(target).getGodMode()) + continue; + + if(Party.getInstance().inSameParty(attacker, target)) + continue; + if(targets >= 1 && derp.getWorld().getPVP()) + { Combat.dealDamage(target, event.getDamage() / 4, attacker); - targets--; - } + target.sendMessage(ChatColor.DARK_RED+"Struck by Serrated Strikes!"); + Users.getProfile(target).addBleedTicks(5); + targets--; + continue; + } + } + else + { + if(!pluginx.misc.bleedTracker.contains(derp)) + pluginx.misc.addToBleedQue((LivingEntity)derp); + + LivingEntity target = (LivingEntity)derp; + Combat.dealDamage(target, event.getDamage() / 4, attacker); + targets--; } - } - } + } + } } - } + } public static void counterAttackChecks(EntityDamageByEntityEvent event) {