From 4b26732f51fe62b4876856f9cab38491ea30f730 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sun, 26 Feb 2012 04:15:50 -0800 Subject: [PATCH 1/3] Removed redundancy --- src/main/java/com/gmail/nossr50/Combat.java | 244 +++++++++--------- .../nossr50/listeners/mcEntityListener.java | 2 +- 2 files changed, 121 insertions(+), 125 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/Combat.java b/src/main/java/com/gmail/nossr50/Combat.java index 002d099d0..8c7facc3c 100644 --- a/src/main/java/com/gmail/nossr50/Combat.java +++ b/src/main/java/com/gmail/nossr50/Combat.java @@ -40,147 +40,143 @@ import com.gmail.nossr50.skills.Unarmed; public class Combat { - public static void combatChecks(EntityDamageEvent event, mcMMO pluginx) + public static void combatChecks(EntityDamageByEntityEvent event, mcMMO pluginx) { if(event.isCancelled() || event.getDamage() == 0 || event.getEntity().isDead()) return; - if(event instanceof EntityDamageByEntityEvent) - { - //Declare Things - EntityDamageByEntityEvent eEvent = (EntityDamageByEntityEvent) event; - Entity damager = eEvent.getDamager(); - LivingEntity target = (LivingEntity) eEvent.getEntity(); - int damage = eEvent.getDamage(); + //Declare Things + Entity damager = event.getDamager(); + LivingEntity target = (LivingEntity) event.getEntity(); + int damage = event.getDamage(); + + /* + * PLAYER VERSUS ENTITIES + */ + if(damager instanceof Player) + { + Player attacker = (Player) event.getDamager(); + ItemStack itemInHand = attacker.getItemInHand(); + PlayerProfile PPa = Users.getProfile(attacker); - /* - * PLAYER VERSUS ENTITIES - */ - if(damager instanceof Player) + //If there are any abilities to activate + combatAbilityChecks(attacker, PPa, pluginx); + + //Damage modifiers and proc checks + if(m.isSwords(itemInHand) && mcPermissions.getInstance().swords(attacker)) { - Player attacker = (Player) eEvent.getDamager(); - ItemStack itemInHand = attacker.getItemInHand(); - PlayerProfile PPa = Users.getProfile(attacker); + if(!pluginx.misc.bleedTracker.contains(target)) //Bleed + Swords.bleedCheck(attacker, target, pluginx); + + if (!(event instanceof FakeEntityDamageByEntityEvent) && PPa.getSerratedStrikesMode()) + Swords.applySerratedStrikes(attacker, event, pluginx); + + if(target instanceof Player) + PvPExperienceGain(attacker, PPa, (Player) target, damage, SkillType.SWORDS); + else if(!pluginx.misc.mobSpawnerList.contains(target.getEntityId())) + PvEExperienceGain(attacker, PPa, target, damage, SkillType.SWORDS); + } + else if(m.isAxes(itemInHand) && mcPermissions.getInstance().axes(attacker)) + { + if(Users.getProfile(attacker).getSkillLevel(SkillType.AXES) >= 500) + event.setDamage(damage + 4); - //If there are any abilities to activate - combatAbilityChecks(attacker, PPa, pluginx); + Axes.axeCriticalCheck(attacker, event, pluginx); //Critical hit - //Damage modifiers and proc checks - if(m.isSwords(itemInHand) && mcPermissions.getInstance().swords(attacker)) - { - if(!pluginx.misc.bleedTracker.contains(target)) //Bleed - Swords.bleedCheck(attacker, target, pluginx); - - if (!(event instanceof FakeEntityDamageByEntityEvent) && PPa.getSerratedStrikesMode()) - Swords.applySerratedStrikes(attacker, eEvent, pluginx); - - if(target instanceof Player) - PvPExperienceGain(attacker, PPa, (Player) target, damage, SkillType.SWORDS); - else if(!pluginx.misc.mobSpawnerList.contains(target.getEntityId())) - PvEExperienceGain(attacker, PPa, target, damage, SkillType.SWORDS); - } - else if(m.isAxes(itemInHand) && mcPermissions.getInstance().axes(attacker)) - { - if(Users.getProfile(attacker).getSkillLevel(SkillType.AXES) >= 500) - event.setDamage(damage + 4); - - Axes.axeCriticalCheck(attacker, eEvent, pluginx); //Critical hit - - if (!(event instanceof FakeEntityDamageByEntityEvent) && PPa.getSkullSplitterMode()) - Axes.applyAoeDamage(attacker, eEvent, pluginx); - - if(target instanceof Player) - PvPExperienceGain(attacker, PPa, (Player) target, eEvent.getDamage(), SkillType.AXES); - else if(!pluginx.misc.mobSpawnerList.contains(target.getEntityId())) - PvEExperienceGain(attacker, PPa, target, eEvent.getDamage(), SkillType.AXES); - } - else if(itemInHand.getTypeId() == 0 && mcPermissions.getInstance().unarmed(attacker)) //Unarmed - { - Unarmed.unarmedBonus(attacker, eEvent); - if(PPa.getBerserkMode()) - event.setDamage(eEvent.getDamage() + (eEvent.getDamage() / 2)); - if(target instanceof Player) - Unarmed.disarmProcCheck(attacker, (Player) target); //Disarm - - if(target instanceof Player) - PvPExperienceGain(attacker, PPa, (Player) target, eEvent.getDamage(), SkillType.UNARMED); - else if(!pluginx.misc.mobSpawnerList.contains(target.getEntityId())) - PvEExperienceGain(attacker, PPa, target, eEvent.getDamage(), SkillType.UNARMED); - } + if (!(event instanceof FakeEntityDamageByEntityEvent) && PPa.getSkullSplitterMode()) + Axes.applyAoeDamage(attacker, event, pluginx); - //Player use bone on wolf. - else if(target instanceof Wolf) - { - Wolf wolf = (Wolf) target; + if(target instanceof Player) + PvPExperienceGain(attacker, PPa, (Player) target, event.getDamage(), SkillType.AXES); + else if(!pluginx.misc.mobSpawnerList.contains(target.getEntityId())) + PvEExperienceGain(attacker, PPa, target, event.getDamage(), SkillType.AXES); + } + else if(itemInHand.getTypeId() == 0 && mcPermissions.getInstance().unarmed(attacker)) //Unarmed + { + Unarmed.unarmedBonus(attacker, event); + if(PPa.getBerserkMode()) + event.setDamage(event.getDamage() + (event.getDamage() / 2)); + if(target instanceof Player) + Unarmed.disarmProcCheck(attacker, (Player) target); //Disarm - if(itemInHand.getTypeId() == 352 && mcPermissions.getInstance().taming(attacker)) - { - event.setCancelled(true); - if(wolf.isTamed()) - attacker.sendMessage(mcLocale.getString("Combat.BeastLore")+" "+ - mcLocale.getString("Combat.BeastLoreOwner", new Object[] {Taming.getOwnerName(wolf)})+" "+ - mcLocale.getString("Combat.BeastLoreHealthWolfTamed", new Object[] {wolf.getHealth()})); - else - attacker.sendMessage(mcLocale.getString("Combat.BeastLore")+" "+ - mcLocale.getString("Combat.BeastLoreHealthWolf", new Object[] {wolf.getHealth()})); - } - } + if(target instanceof Player) + PvPExperienceGain(attacker, PPa, (Player) target, event.getDamage(), SkillType.UNARMED); + else if(!pluginx.misc.mobSpawnerList.contains(target.getEntityId())) + PvEExperienceGain(attacker, PPa, target, event.getDamage(), SkillType.UNARMED); } - /* - * TAMING (WOLVES VERSUS ENTITIES) - */ - else if(damager instanceof Wolf) - { - Wolf wolf = (Wolf) damager; - - if (wolf.isTamed() && Taming.ownerOnline(wolf, pluginx)) - { - Player master = Taming.getOwner(wolf, pluginx); - if (master == null) //Can it really happen? - return; - - PlayerProfile PPo = Users.getProfile(master); - if(mcPermissions.getInstance().taming(master)) - { - //Fast Food Service - Taming.fastFoodService(PPo, wolf, event); - - //Sharpened Claws - Taming.sharpenedClaws(PPo, event); - - //Gore - Taming.gore(PPo, event, master, pluginx); - - //Reward XP - Taming.rewardXp(event, pluginx, master); - } - } - } - - //Another offensive check for Archery - else if(damager instanceof Arrow) - archeryCheck((EntityDamageByEntityEvent)event, pluginx); - - /* - * DEFENSIVE CHECKS - */ - if(target instanceof Player) - { - Swords.counterAttackChecks(eEvent); - Acrobatics.dodgeChecks(eEvent); - } - - /* - * DEFENSIVE CHECKS FOR WOLVES - */ + //Player use bone on wolf. else if(target instanceof Wolf) { Wolf wolf = (Wolf) target; - if(wolf.isTamed() && Taming.ownerOnline(wolf, pluginx)) - Taming.preventDamage(eEvent, pluginx); + + if(itemInHand.getTypeId() == 352 && mcPermissions.getInstance().taming(attacker)) + { + event.setCancelled(true); + if(wolf.isTamed()) + attacker.sendMessage(mcLocale.getString("Combat.BeastLore")+" "+ + mcLocale.getString("Combat.BeastLoreOwner", new Object[] {Taming.getOwnerName(wolf)})+" "+ + mcLocale.getString("Combat.BeastLoreHealthWolfTamed", new Object[] {wolf.getHealth()})); + else + attacker.sendMessage(mcLocale.getString("Combat.BeastLore")+" "+ + mcLocale.getString("Combat.BeastLoreHealthWolf", new Object[] {wolf.getHealth()})); + } } } + + /* + * TAMING (WOLVES VERSUS ENTITIES) + */ + else if(damager instanceof Wolf) + { + Wolf wolf = (Wolf) damager; + + if (wolf.isTamed() && Taming.ownerOnline(wolf, pluginx)) + { + Player master = Taming.getOwner(wolf, pluginx); + if (master == null) //Can it really happen? + return; + + PlayerProfile PPo = Users.getProfile(master); + if(mcPermissions.getInstance().taming(master)) + { + //Fast Food Service + Taming.fastFoodService(PPo, wolf, event); + + //Sharpened Claws + Taming.sharpenedClaws(PPo, event); + + //Gore + Taming.gore(PPo, event, master, pluginx); + + //Reward XP + Taming.rewardXp(event, pluginx, master); + } + } + } + + //Another offensive check for Archery + else if(damager instanceof Arrow) + archeryCheck((EntityDamageByEntityEvent)event, pluginx); + + /* + * DEFENSIVE CHECKS + */ + if(target instanceof Player) + { + Swords.counterAttackChecks(event); + Acrobatics.dodgeChecks(event); + } + + /* + * DEFENSIVE CHECKS FOR WOLVES + */ + else if(target instanceof Wolf) + { + Wolf wolf = (Wolf) target; + if(wolf.isTamed() && Taming.ownerOnline(wolf, pluginx)) + Taming.preventDamage(event, pluginx); + } } public static void combatAbilityChecks(Player attacker, PlayerProfile PPa, Plugin pluginx) diff --git a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java index d7ad894e4..f0c4a322d 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java @@ -125,7 +125,7 @@ public class mcEntityListener implements Listener if(Party.getInstance().inSameParty(defender, attacker)) event.setCancelled(true); } - Combat.combatChecks(event, plugin); + Combat.combatChecks(eventb, plugin); } /* * Check to see if the defender took damage so we can apply recently hurt From dd445dbac593e7b03f2e09b3921f217cd962c118 Mon Sep 17 00:00:00 2001 From: GJ Date: Sun, 26 Feb 2012 14:38:03 -0500 Subject: [PATCH 2/3] Updates to Combat - Breaks R4 Compatability. --- src/main/java/com/gmail/nossr50/Combat.java | 82 ++++++++++++--------- 1 file changed, 49 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/Combat.java b/src/main/java/com/gmail/nossr50/Combat.java index 8c7facc3c..d05db8e6e 100644 --- a/src/main/java/com/gmail/nossr50/Combat.java +++ b/src/main/java/com/gmail/nossr50/Combat.java @@ -381,38 +381,54 @@ public class Combat else xpinc = damage; - if(entity instanceof Animals) - xp = (int) (xpinc * LoadProperties.animalXP); - else - { - if(entity instanceof Enderman) - xp = (int) (xpinc * LoadProperties.endermanXP); - else if(entity instanceof Creeper) - xp = (int) (xpinc * LoadProperties.creeperXP); - else if(entity instanceof Silverfish) - xp = (int) (xpinc * LoadProperties.silverfishXP); - else if(entity instanceof CaveSpider) - xp = (int) (xpinc * LoadProperties.cavespiderXP); - else if(entity instanceof Spider) - xp = (int) (xpinc * LoadProperties.spiderXP); - else if(entity instanceof Skeleton) - xp = (int) (xpinc * LoadProperties.skeletonXP); - else if(entity instanceof Zombie) - xp = (int) (xpinc * LoadProperties.zombieXP); - else if(entity instanceof PigZombie) - xp = (int) (xpinc * LoadProperties.pigzombieXP); - else if(entity instanceof Slime) - xp = (int) (xpinc * LoadProperties.slimeXP); - else if(entity instanceof Ghast) - xp = (int) (xpinc * LoadProperties.ghastXP); - else if(entity instanceof Blaze) - xp = (int) (xpinc * LoadProperties.blazeXP); - else if(entity instanceof EnderDragon) - xp = (int) (xpinc * LoadProperties.enderdragonXP); - else if(entity instanceof MagmaCube) - xp = (int) (xpinc * LoadProperties.magmacubeXP); - } - } - return xp; + if(entity instanceof Animals) + xp = (int) (xpinc * LoadProperties.animalXP); + else + { + EntityType type = entity.getType(); + switch(type){ + case BLAZE: + xp = (int) (xpinc * LoadProperties.blazeXP); + break; + case CAVE_SPIDER: + xp = (int) (xpinc * LoadProperties.cavespiderXP); + break; + case CREEPER: + xp = (int) (xpinc * LoadProperties.creeperXP); + break; + case ENDER_DRAGON: + xp = (int) (xpinc * LoadProperties.enderdragonXP); + break; + case ENDERMAN: + xp = (int) (xpinc * LoadProperties.endermanXP); + break; + case GHAST: + xp = (int) (xpinc * LoadProperties.ghastXP); + break; + case MAGMA_CUBE: + xp = (int) (xpinc * LoadProperties.magmacubeXP); + break; + case PIG_ZOMBIE: + xp = (int) (xpinc * LoadProperties.pigzombieXP); + break; + case SILVERFISH: + xp = (int) (xpinc * LoadProperties.silverfishXP); + break; + case SKELETON: + xp = (int) (xpinc * LoadProperties.skeletonXP); + break; + case SLIME: + xp = (int) (xpinc * LoadProperties.slimeXP); + break; + case SPIDER: + xp = (int) (xpinc * LoadProperties.spiderXP); + break; + case ZOMBIE: + xp = (int) (xpinc * LoadProperties.zombieXP); + break; + } + } + } + return xp; } } From cae4b4753811a231ee0ff4a12b2efd1f06650972 Mon Sep 17 00:00:00 2001 From: GJ Date: Sun, 26 Feb 2012 14:38:55 -0500 Subject: [PATCH 3/3] Updates to Unarmed --- .../com/gmail/nossr50/skills/Unarmed.java | 66 ++++++++----------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/Unarmed.java b/src/main/java/com/gmail/nossr50/skills/Unarmed.java index 507aa1cc5..d68ec9020 100644 --- a/src/main/java/com/gmail/nossr50/skills/Unarmed.java +++ b/src/main/java/com/gmail/nossr50/skills/Unarmed.java @@ -16,7 +16,6 @@ */ package com.gmail.nossr50.skills; -import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.inventory.ItemStack; @@ -32,12 +31,11 @@ public class Unarmed { public static void berserkActivationCheck(Player player) { PlayerProfile PP = Users.getProfile(player); - if(player.getItemInHand().getTypeId() == 0) + AbilityType ability = AbilityType.BERSERK; + if(player.getItemInHand() == null) { if(PP.getFistsPreparationMode()) - { PP.setFistsPreparationMode(false); - } int ticks = 2; int x = PP.getSkillLevel(SkillType.UNARMED); @@ -48,16 +46,16 @@ public class Unarmed { ticks++; } - if(!PP.getBerserkMode() && Skills.cooldownOver(player, PP.getSkillDATS(AbilityType.BERSERK), LoadProperties.berserkCooldown)) + if(!PP.getBerserkMode() && Skills.cooldownOver(player, PP.getSkillDATS(ability), LoadProperties.berserkCooldown)) { + player.sendMessage(mcLocale.getString("Skills.BerserkOn")); for(Player y : player.getWorld().getPlayers()) { if(y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10) y.sendMessage(mcLocale.getString("Skills.BerserkPlayer", new Object[] {player.getName()})); } - PP.setSkillDATS(AbilityType.BERSERK, System.currentTimeMillis()+(ticks*1000)); - System.out.println("getSkillDATS(): "+PP.getSkillDATS(AbilityType.BERSERK)); + PP.setSkillDATS(ability, System.currentTimeMillis()+(ticks*1000)); PP.setBerserkMode(true); } } @@ -65,56 +63,48 @@ public class Unarmed { public static void unarmedBonus(Player attacker, EntityDamageByEntityEvent event) { - PlayerProfile PPa = Users.getProfile(attacker); int bonus = 3; //Add 1 DMG for every 50 skill levels - bonus += PPa.getSkillLevel(SkillType.UNARMED)/50; + bonus += Users.getProfile(attacker).getSkillLevel(SkillType.UNARMED)/50; if(bonus > 8) bonus = 8; - event.setDamage(event.getDamage()+bonus); + event.setDamage(event.getDamage() + bonus); } public static void disarmProcCheck(Player attacker, Player defender) { - PlayerProfile PP = Users.getProfile(attacker); - if(attacker.getItemInHand().getTypeId() == 0) + int skillLevel = Users.getProfile(attacker).getSkillLevel(SkillType.UNARMED); + if(attacker.getItemInHand() == null) { - if(PP.getSkillLevel(SkillType.UNARMED) >= 1000) + if(skillLevel >= 1000) { - if(Math.random() * 4000 <= 1000) - { - Location loc = defender.getLocation(); - if(defender.getItemInHand() != null && defender.getItemInHand().getTypeId() != 0) + if(Math.random() * 4000 <= 1000) + { + ItemStack item = defender.getItemInHand(); + if(item != null) { defender.sendMessage(mcLocale.getString("Skills.Disarmed")); - ItemStack item = defender.getItemInHand(); - if(item != null) - { - m.mcDropItem(loc, item); - ItemStack itemx = null; - defender.setItemInHand(itemx); - } + m.mcDropItem(defender.getLocation(), item); + defender.setItemInHand(null); } - } - } else { - if(Math.random() * 4000 <= PP.getSkillLevel(SkillType.UNARMED)){ - Location loc = defender.getLocation(); - if(defender.getItemInHand() != null && defender.getItemInHand().getTypeId() != 0) + } + } + else + { + if(Math.random() * 4000 <= skillLevel) + { + ItemStack item = defender.getItemInHand(); + if(item != null) { defender.sendMessage(mcLocale.getString("Skills.Disarmed")); - ItemStack item = defender.getItemInHand(); - if(item != null) - { - m.mcDropItem(loc, item); - ItemStack itemx = null; - defender.setItemInHand(itemx); - } + m.mcDropItem(defender.getLocation(), item); + defender.setItemInHand(null); } - } - } + } + } } } }