diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 4d361aa02..46435265c 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -4,7 +4,6 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingBlock; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -28,18 +27,16 @@ import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.config.AdvancedConfig; -import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageEvent; import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.runnables.BleedTimer; import com.gmail.nossr50.skills.Combat; -import com.gmail.nossr50.skills.SkillType; -import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.acrobatics.Acrobatics; import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager; import com.gmail.nossr50.skills.archery.Archery; +import com.gmail.nossr50.skills.fishing.Fishing; import com.gmail.nossr50.skills.herbalism.Herbalism; import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.taming.TamingManager; @@ -78,22 +75,22 @@ public class EntityListener implements Listener { } /** - * Monitor EntityDamageByEntity events. + * Handle EntityDamageByEntity events that involve modifying the event. * * @param event The event to watch */ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { - if (event instanceof FakeEntityDamageByEntityEvent) + if (event instanceof FakeEntityDamageByEntityEvent || event.getDamage() <= 0) return; - if (event.getDamage() <= 0) - return; - - Entity attacker = event.getDamager(); Entity defender = event.getEntity(); - if (attacker.hasMetadata("NPC") || defender.hasMetadata("NPC")) return; // Check if either players is are Citizens NPCs + if (Misc.isNPCEntity(defender) || defender.isDead()) { + return; + } + + Entity attacker = event.getDamager(); if (attacker instanceof Projectile) { attacker = ((Projectile) attacker).getShooter(); @@ -101,7 +98,7 @@ public class EntityListener implements Listener { else if (attacker instanceof Tameable) { AnimalTamer animalTamer = ((Tameable) attacker).getOwner(); - if (animalTamer instanceof Entity) { + if (animalTamer != null) { attacker = (Entity) animalTamer; } } @@ -113,11 +110,9 @@ public class EntityListener implements Listener { return; } - if (attacker instanceof Player) { - if (PartyManager.getInstance().inSameParty(defendingPlayer, (Player) attacker)) { - event.setCancelled(true); - return; - } + if (attacker instanceof Player && PartyManager.getInstance().inSameParty(defendingPlayer, (Player) attacker)) { + event.setCancelled(true); + return; } } @@ -126,35 +121,32 @@ public class EntityListener implements Listener { LivingEntity livingDefender = (LivingEntity) defender; if (!Misc.isInvincible(livingDefender, event)) { - Combat.combatChecks(event); + Combat.combatChecks(event, attacker, livingDefender); } } } /** - * Monitor EntityDamage events. + * Handle EntityDamage events that involve modifying the event. * - * @param event The event to watch + * @param event The event to modify */ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEntityDamage(EntityDamageEvent event) { - if (event instanceof FakeEntityDamageEvent) { + if (event instanceof FakeEntityDamageEvent || event.getDamage() <= 0) { return; } Entity entity = event.getEntity(); - DamageCause cause = event.getCause(); - - if (entity.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC if (!(entity instanceof LivingEntity)) { return; } - LivingEntity lEntity = (LivingEntity) entity; + DamageCause cause = event.getCause(); + LivingEntity livingEntity = (LivingEntity) entity; - if (lEntity instanceof Player) { - /* Check for invincibility */ + if (livingEntity instanceof Player) { Player player = (Player) entity; if (!player.isOnline()) { @@ -163,17 +155,18 @@ public class EntityListener implements Listener { PlayerProfile profile = Users.getProfile(player); - if (profile == null) { + if (Misc.isNPCPlayer(player, profile)) { return; } + /* Check for invincibility */ if (profile.getGodMode()) { event.setCancelled(true); return; } if (!Misc.isInvincible(player, event)) { - if (cause == DamageCause.FALL && !player.isInsideVehicle() && !(player.getItemInHand().getType() == Material.ENDER_PEARL)) { + if (cause == DamageCause.FALL && player.getItemInHand().getType() != Material.ENDER_PEARL && !(Acrobatics.afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player)) { AcrobaticsManager acroManager = new AcrobaticsManager(player); acroManager.rollCheck(event); } @@ -186,11 +179,12 @@ public class EntityListener implements Listener { profile.actualizeRecentlyHurt(); } } - } else if (lEntity instanceof Tameable) { - Tameable pet = (Tameable) lEntity; + } + else if (livingEntity instanceof Tameable) { + Tameable pet = (Tameable) livingEntity; AnimalTamer owner = pet.getOwner(); - if ((!Misc.isInvincible(lEntity, event)) && pet.isTamed() && (owner instanceof Player) && pet instanceof Wolf) { + if ((!Misc.isInvincible(livingEntity, event)) && pet.isTamed() && owner instanceof Player && pet instanceof Wolf) { TamingManager tamingManager = new TamingManager((Player) owner); tamingManager.preventDamage(event); } @@ -277,11 +271,11 @@ public class EntityListener implements Listener { } /** - * Monitor FoodLevelChange events. + * Handle FoodLevelChange events that involve modifying the event. * - * @param event The event to watch + * @param event The event to modify */ - @EventHandler (priority = EventPriority.LOW) + @EventHandler (priority = EventPriority.LOW, ignoreCancelled = true) public void onFoodLevelChange(FoodLevelChangeEvent event) { Entity entity = event.getEntity(); @@ -295,6 +289,7 @@ public class EntityListener implements Listener { int currentFoodLevel = player.getFoodLevel(); int newFoodLevel = event.getFoodLevel(); + int foodChange = newFoodLevel - currentFoodLevel; /* * Some foods have 3 ranks @@ -302,127 +297,35 @@ public class EntityListener implements Listener { * The number of ranks is based on how 'common' the item is * We can adjust this quite easily if we find something is giving too much of a bonus */ - - if (newFoodLevel > currentFoodLevel) { - Material food = player.getItemInHand().getType(); - int herbLevel = profile.getSkillLevel(SkillType.HERBALISM); - int fishLevel = profile.getSkillLevel(SkillType.FISHING); - int foodChange = newFoodLevel - currentFoodLevel; - int rankChange = 0; - boolean fish = false; - boolean herb = false; - int fishFoodRank1 = AdvancedConfig.getInstance().getFishermanDietRankChange(); - int fishFoodRank2 = AdvancedConfig.getInstance().getFishermanDietRankChange() * 2; - int fishFoodRankMax = AdvancedConfig.getInstance().getFishermanDietRankChange() * 5; - - switch (food) { - case BREAD: - /* BREAD RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */ - herb = true; - rankChange = Herbalism.farmersDietRankLevel1; + if (foodChange > 0) { + switch (player.getItemInHand().getType()) { + case BAKED_POTATO: /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */ + case BREAD: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */ + case CARROT_ITEM: /* RESTORES 2 HUNGER - RESTORES 4 1/2 HUNGER @ 1000 */ + case GOLDEN_CARROT: /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */ + case MUSHROOM_SOUP: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */ + case PUMPKIN_PIE: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */ + Herbalism.farmersDiet(player, Herbalism.farmersDietRankLevel1, event); break; - case COOKIE: - /* COOKIE RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */ - herb = true; - rankChange = Herbalism.farmersDietRankLevel2; + case COOKIE: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */ + case MELON: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */ + case POISONOUS_POTATO: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */ + case POTATO_ITEM: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */ + Herbalism.farmersDiet(player, Herbalism.farmersDietRankLevel2, event); break; - case MELON: - /* MELON RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */ - herb = true; - rankChange = Herbalism.farmersDietRankLevel2; + case COOKED_FISH: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */ + Fishing.fishermansDiet(player, Fishing.fishermansDietRankLevel1, event); break; - case MUSHROOM_SOUP: - /* MUSHROOM SOUP RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */ - herb = true; - rankChange = Herbalism.farmersDietRankLevel1; - break; - - case CARROT_ITEM: - /* CARROT RESTORES 2 HUNGER - RESTORES 4 1/2 HUNGER @ 1000 */ - herb = true; - rankChange = Herbalism.farmersDietRankLevel1; - break; - - case POTATO_ITEM: - /* POTATO RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */ - herb = true; - rankChange = Herbalism.farmersDietRankLevel2; - break; - - case BAKED_POTATO: - /* BAKED POTATO RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */ - herb = true; - rankChange = Herbalism.farmersDietRankLevel1; - break; - - case POISONOUS_POTATO: - /* POISONOUS POTATO RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */ - herb = true; - rankChange = Herbalism.farmersDietRankLevel2; - break; - - case GOLDEN_CARROT: - /* GOLDEN CARROT RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */ - herb = true; - rankChange = Herbalism.farmersDietRankLevel1; - break; - - case PUMPKIN_PIE: - /* PUMPKIN PIE RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */ - herb = true; - rankChange = Herbalism.farmersDietRankLevel1; - break; - - case RAW_FISH: - /* RAW FISH RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */ - rankChange = fishFoodRank2; - fish = true; - break; - - case COOKED_FISH: - /* COOKED FISH RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */ - rankChange = fishFoodRank1; - fish = true; + case RAW_FISH: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */ + Fishing.fishermansDiet(player, Fishing.fishermansDietRankLevel2, event); break; default: return; } - - if (herb) { - if (!Permissions.farmersDiet(player)) { - return; - } - - for (int i = Herbalism.farmersDietRankLevel1; i <= Herbalism.farmersDietMaxLevel; i += rankChange) { - if (herbLevel >= i) { - foodChange++; - } - } - } - else if (fish) { - if (!Permissions.fishermansDiet(player)) { - return; - } - - for (int i = fishFoodRank1; i <= fishFoodRankMax; i += rankChange) { - if (fish && fishLevel >= i) { - foodChange++; - } - } - } - - /* Make sure we don't go over the max value */ - newFoodLevel = currentFoodLevel + foodChange; - if (newFoodLevel > 20) { - event.setFoodLevel(20); - } - else { - event.setFoodLevel(newFoodLevel); - } } } } @@ -432,31 +335,15 @@ public class EntityListener implements Listener { * * @param event The event to watch */ - @EventHandler (priority = EventPriority.MONITOR) + @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityTame(EntityTameEvent event) { Player player = (Player) event.getOwner(); - if (player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC - - if (Permissions.taming(player) && !mcMMO.placeStore.isSpawnedPet(event.getEntity())) { - PlayerProfile profile = Users.getProfile(player); - EntityType type = event.getEntityType(); - int xp = 0; - - switch (type) { - case WOLF: - xp = Config.getInstance().getTamingXPWolf(); - break; - - case OCELOT: - xp = Config.getInstance().getTamingXPOcelot(); - break; - - default: - break; - } - - Skills.xpProcessing(player, profile, SkillType.TAMING, xp); + if (Misc.isNPCPlayer(player)) { + return; } + + TamingManager tamingManager = new TamingManager(player); + tamingManager.awardTamingXP(event); } } diff --git a/src/main/java/com/gmail/nossr50/skills/Combat.java b/src/main/java/com/gmail/nossr50/skills/Combat.java index 00bc9d2d7..a1f783504 100644 --- a/src/main/java/com/gmail/nossr50/skills/Combat.java +++ b/src/main/java/com/gmail/nossr50/skills/Combat.java @@ -28,11 +28,15 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.runnables.BleedTimer; import com.gmail.nossr50.runnables.GainXp; +import com.gmail.nossr50.skills.acrobatics.Acrobatics; import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager; +import com.gmail.nossr50.skills.archery.Archery; import com.gmail.nossr50.skills.archery.ArcheryManager; import com.gmail.nossr50.skills.axes.AxeManager; +import com.gmail.nossr50.skills.axes.Axes; import com.gmail.nossr50.skills.swords.Swords; import com.gmail.nossr50.skills.swords.SwordsManager; +import com.gmail.nossr50.skills.taming.Taming; import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.unarmed.UnarmedManager; import com.gmail.nossr50.util.ItemChecks; @@ -48,29 +52,28 @@ public class Combat { * * @param event The event to run the combat checks on. */ - public static void combatChecks(EntityDamageByEntityEvent event) { - if (event.getDamage() == 0 || event.getEntity().isDead()) { - return; - } - - Entity damager = event.getDamager(); - LivingEntity target = (LivingEntity) event.getEntity(); - + public static void combatChecks(EntityDamageByEntityEvent event, Entity damager, LivingEntity target) { boolean targetIsPlayer = (target.getType() == EntityType.PLAYER); boolean targetIsTamedPet = (target instanceof Tameable) ? ((Tameable) target).isTamed() : false; switch (damager.getType()) { case PLAYER: Player attacker = (Player) event.getDamager(); - ItemStack itemInHand = attacker.getItemInHand(); - if (ItemChecks.isSword(itemInHand)) { + if (Misc.isNPCPlayer(attacker)) { + return; + } + + ItemStack heldItem = attacker.getItemInHand(); + Material heldItemType = heldItem.getType(); + + if (ItemChecks.isSword(heldItem)) { if (targetIsPlayer || targetIsTamedPet) { - if (!configInstance.getSwordsPVP()) { + if (!Swords.pvpEnabled) { return; } } - else if (!configInstance.getSwordsPVE()) { + else if (!Swords.pveEnabled) { return; } @@ -82,13 +85,13 @@ public class Combat { startGainXp(attacker, swordsManager.getProfile(), target, SkillType.SWORDS); } - else if (ItemChecks.isAxe(itemInHand) && Permissions.axes(attacker)) { + else if (ItemChecks.isAxe(heldItem)) { if (targetIsPlayer || targetIsTamedPet) { - if (!configInstance.getAxesPVP()) { + if (!Axes.pvpEnabled) { return; } } - else if (!configInstance.getAxesPVE()) { + else if (!Axes.pveEnabled) { return; } @@ -96,13 +99,13 @@ public class Combat { AxeManager axeManager = new AxeManager(attacker); axeManager.bonusDamage(event); - axeManager.criticalHitCheck(event); - axeManager.impact(event); - axeManager.skullSplitter(event); + axeManager.criticalHitCheck(event, target); + axeManager.impact(event, target); + axeManager.skullSplitter(target, event.getDamage()); startGainXp(attacker, axeManager.getProfile(), target, SkillType.AXES); } - else if (itemInHand.getType() == Material.AIR && Permissions.unarmed(attacker)) { + else if (heldItemType == Material.AIR) { if (targetIsPlayer || targetIsTamedPet) { if (!configInstance.getUnarmedPVP()) { return; @@ -115,20 +118,13 @@ public class Combat { Skills.abilityCheck(attacker, SkillType.UNARMED); UnarmedManager unarmedManager = new UnarmedManager(attacker); - unarmedManager.bonusDamage(event); - - if (unarmedManager.getProfile().getAbilityMode(AbilityType.BERSERK) && Permissions.berserk(attacker)) { - event.setDamage((int) (event.getDamage() * 1.5)); - } - - if (targetIsPlayer) { - unarmedManager.disarmCheck((Player) target); - } + unarmedManager.berserkDamage(event); + unarmedManager.disarmCheck(target); startGainXp(attacker, unarmedManager.getProfile(), target, SkillType.UNARMED); } - else if (itemInHand.getType() == Material.BONE && target instanceof Tameable) { + else if (heldItemType == Material.BONE && target instanceof Tameable) { TamingManager tamingManager = new TamingManager(attacker); tamingManager.beastLore(target); event.setCancelled(true); @@ -143,21 +139,20 @@ public class Combat { Player master = (Player) wolf.getOwner(); if (targetIsPlayer || targetIsTamedPet) { - if (!configInstance.getTamingPVP()) { + if (!Taming.pvpEnabled) { return; } } - else if (!configInstance.getTamingPVE()) { + else if (!Taming.pveEnabled) { return; } TamingManager tamingManager = new TamingManager(master); - tamingManager.fastFoodService(wolf, event.getDamage()); tamingManager.sharpenedClaws(event); tamingManager.gore(event); - startGainXp(master, Users.getProfile(master), target, SkillType.TAMING); + startGainXp(master, tamingManager.getProfile(), target, SkillType.TAMING); } break; @@ -165,16 +160,17 @@ public class Combat { case ARROW: LivingEntity shooter = ((Arrow) damager).getShooter(); + //TODO: Is there a reason we're breaking here instead of returning? if (shooter == null || shooter.getType() != EntityType.PLAYER) { break; } if (targetIsPlayer || targetIsTamedPet) { - if (!configInstance.getArcheryPVP()) { + if (!Archery.pvpEnabled) { return; } } - else if (!configInstance.getArcheryPVE()) { + else if (!Archery.pveEnabled) { return; } @@ -188,29 +184,29 @@ public class Combat { if (targetIsPlayer) { Player player = (Player) target; - AcrobaticsManager acroManager = new AcrobaticsManager(player); + AcrobaticsManager acrobaticsManager = new AcrobaticsManager(player); SwordsManager swordsManager = new SwordsManager(player); - if (damager.getType() == EntityType.PLAYER) { - if (configInstance.getSwordsPVP()) { + if (damager instanceof Player) { + if (Swords.pvpEnabled) { swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage()); } - if (configInstance.getAcrobaticsPVP()) { - acroManager.dodgeCheck(event); + if (Acrobatics.pvpEnabled) { + acrobaticsManager.dodgeCheck(event); } } else { - if (configInstance.getSwordsPVE() && damager instanceof LivingEntity) { + if (Swords.pveEnabled && damager instanceof LivingEntity) { swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage()); } - if (configInstance.getAcrobaticsPVE()) { - if (damager instanceof LightningStrike && configInstance.getDodgeLightningDisabled()) { + if (Acrobatics.pveEnabled) { + if (damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled) { return; } - acroManager.dodgeCheck(event); + acrobaticsManager.dodgeCheck(event); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/Skills.java b/src/main/java/com/gmail/nossr50/skills/Skills.java index 15c0f71be..79ff7053c 100644 --- a/src/main/java/com/gmail/nossr50/skills/Skills.java +++ b/src/main/java/com/gmail/nossr50/skills/Skills.java @@ -532,9 +532,6 @@ public class Skills { * @param xp the amount of XP to gain */ public static void xpProcessing(Player player, PlayerProfile profile, SkillType type, int xp) { - if (player == null) - return; - if (type.getPermissions(player)) { if (Users.getPlayer(player) == null) return; diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java index c61485b79..da5551ab8 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.skills.acrobatics; import com.gmail.nossr50.config.AdvancedConfig; +import com.gmail.nossr50.config.Config; public class Acrobatics { public static double dodgeMaxChance = AdvancedConfig.getInstance().getDodgeChanceMax(); @@ -9,9 +10,16 @@ public class Acrobatics { public static double rollMaxChance = AdvancedConfig.getInstance().getRollChanceMax(); public static int rollMaxBonusLevel = AdvancedConfig.getInstance().getRollMaxBonusLevel(); + public static double gracefulRollMaxChance = AdvancedConfig.getInstance().getGracefulRollChanceMax(); public static int gracefulRollMaxBonusLevel = AdvancedConfig.getInstance().getGracefulRollMaxBonusLevel(); public static int rollXpModifier = AdvancedConfig.getInstance().getRollXPModifier(); public static int fallXpModifier = AdvancedConfig.getInstance().getFallXPModifier(); + + public static boolean pvpEnabled = Config.getInstance().getAcrobaticsPVP(); + public static boolean pveEnabled = Config.getInstance().getAcrobaticsPVE(); + + public static boolean afkLevelingDisabled = Config.getInstance().getAcrobaticsAFKDisabled(); + public static boolean dodgeLightningDisabled = Config.getInstance().getDodgeLightningDisabled(); } diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java index 588ac8f24..b98b1005c 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java @@ -3,7 +3,6 @@ package com.gmail.nossr50.skills.acrobatics; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; -import com.gmail.nossr50.config.Config; import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillType; import com.gmail.nossr50.util.Misc; @@ -20,14 +19,6 @@ public class AcrobaticsManager extends SkillManager { * @param event The event to check */ public void rollCheck(EntityDamageEvent event) { - if (Misc.isNPCPlayer(player) || !Permissions.roll(player)) { - return; - } - - if (Config.getInstance().getAcrobaticsAFKDisabled() && player.isInsideVehicle()) { - return; - } - RollEventHandler eventHandler = new RollEventHandler(this, event); double chance; diff --git a/src/main/java/com/gmail/nossr50/skills/archery/Archery.java b/src/main/java/com/gmail/nossr50/skills/archery/Archery.java index ddd59f3ae..9aa3eb15f 100644 --- a/src/main/java/com/gmail/nossr50/skills/archery/Archery.java +++ b/src/main/java/com/gmail/nossr50/skills/archery/Archery.java @@ -9,6 +9,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.config.AdvancedConfig; +import com.gmail.nossr50.config.Config; import com.gmail.nossr50.util.Misc; public class Archery { @@ -25,6 +26,9 @@ public class Archery { public static double dazeMaxBonus = AdvancedConfig.getInstance().getDazeBonusMax(); public static int dazeModifier = AdvancedConfig.getInstance().getDazeModifier(); + public static boolean pvpEnabled = Config.getInstance().getArcheryPVP(); + public static boolean pveEnabled = Config.getInstance().getArcheryPVE(); + protected static void incrementTrackerValue(LivingEntity livingEntity) { for (TrackedEntity trackedEntity : trackedEntities) { if (trackedEntity.getLivingEntity().getEntityId() == livingEntity.getEntityId()) { diff --git a/src/main/java/com/gmail/nossr50/skills/axes/AxeManager.java b/src/main/java/com/gmail/nossr50/skills/axes/AxeManager.java index 3bcbf0dc5..32c509096 100644 --- a/src/main/java/com/gmail/nossr50/skills/axes/AxeManager.java +++ b/src/main/java/com/gmail/nossr50/skills/axes/AxeManager.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.skills.axes; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -21,7 +22,7 @@ public class AxeManager extends SkillManager { * @param event The event to modify */ public void bonusDamage(EntityDamageByEntityEvent event) { - if (Misc.isNPCPlayer(player) || !Permissions.axeBonus(player)) { + if (!Permissions.axeBonus(player)) { return; } @@ -36,20 +37,16 @@ public class AxeManager extends SkillManager { * * @param event The event to modify */ - public void criticalHitCheck(EntityDamageByEntityEvent event) { - if (Misc.isNPCPlayer(player) || !Permissions.criticalHit(player)) { + public void criticalHitCheck(EntityDamageByEntityEvent event, LivingEntity target) { + if (target.isDead() || (target instanceof Tameable && Misc.isFriendlyPet(player, (Tameable) target)) || !Permissions.criticalHit(player)) { return; } - CriticalHitEventHandler eventHandler = new CriticalHitEventHandler(this, event); - - if (eventHandler.defender instanceof Tameable && Misc.isFriendlyPet(player, (Tameable) eventHandler.defender)) { - return; - } + CriticalHitEventHandler eventHandler = new CriticalHitEventHandler(this, event, target); double chance = (Axes.criticalHitMaxChance / Axes.criticalHitMaxBonusLevel) * eventHandler.skillModifier; - if (chance > Misc.getRandom().nextInt(activationChance) && !eventHandler.defender.isDead()) { + if (chance > Misc.getRandom().nextInt(activationChance)) { eventHandler.modifyEventDamage(); eventHandler.sendAbilityMessages(); } @@ -60,18 +57,14 @@ public class AxeManager extends SkillManager { * * @param event The event to modify */ - public void impact(EntityDamageByEntityEvent event) { - if (Misc.isNPCPlayer(player) || !Permissions.impact(player)) { + public void impact(EntityDamageByEntityEvent event, LivingEntity target) { + if (target.isDead() || !Permissions.impact(player)) { return; } - ImpactEventHandler eventHandler = new ImpactEventHandler(this, event); + ImpactEventHandler eventHandler = new ImpactEventHandler(this, event, target); - if (eventHandler.livingDefender == null) { - return; - } - - if (Misc.hasArmor(eventHandler.livingDefender)) { + if (Misc.hasArmor(target)) { eventHandler.damageArmor(); } else { @@ -84,12 +77,12 @@ public class AxeManager extends SkillManager { * * @param event The event to process */ - public void skullSplitter(EntityDamageByEntityEvent event) { - if (Misc.isNPCPlayer(player) || !Permissions.skullSplitter(player) || !profile.getAbilityMode(AbilityType.SKULL_SPLIITER)) { + public void skullSplitter(LivingEntity target, int damage) { + if (target.isDead() || !profile.getAbilityMode(AbilityType.SKULL_SPLIITER) || !Permissions.skullSplitter(player)) { return; } - SkullSplitterEventHandler eventHandler = new SkullSplitterEventHandler(this, event); + SkullSplitterEventHandler eventHandler = new SkullSplitterEventHandler(player, damage, target); eventHandler.applyAbilityEffects(); } } diff --git a/src/main/java/com/gmail/nossr50/skills/axes/Axes.java b/src/main/java/com/gmail/nossr50/skills/axes/Axes.java index 0fd7d60a5..122727cb6 100644 --- a/src/main/java/com/gmail/nossr50/skills/axes/Axes.java +++ b/src/main/java/com/gmail/nossr50/skills/axes/Axes.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.skills.axes; import com.gmail.nossr50.config.AdvancedConfig; +import com.gmail.nossr50.config.Config; public class Axes { public static int bonusDamageMaxBonus = AdvancedConfig.getInstance().getBonusDamageAxesBonusMax(); @@ -19,4 +20,7 @@ public class Axes { public static int greaterImpactBonusDamage = AdvancedConfig.getInstance().getGreaterImpactBonusDamage(); public static int skullSplitterModifier = AdvancedConfig.getInstance().getSkullSplitterModifier(); + + public static boolean pvpEnabled = Config.getInstance().getAxesPVP(); + public static boolean pveEnabled = Config.getInstance().getAxesPVE(); } diff --git a/src/main/java/com/gmail/nossr50/skills/axes/CriticalHitEventHandler.java b/src/main/java/com/gmail/nossr50/skills/axes/CriticalHitEventHandler.java index fe60d5ff3..9dd61ead6 100644 --- a/src/main/java/com/gmail/nossr50/skills/axes/CriticalHitEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/axes/CriticalHitEventHandler.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.skills.axes; -import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -12,13 +12,13 @@ public class CriticalHitEventHandler { private EntityDamageByEntityEvent event; private int damage; - protected Entity defender; + protected LivingEntity defender; protected int skillModifier; - public CriticalHitEventHandler(AxeManager manager, EntityDamageByEntityEvent event) { + public CriticalHitEventHandler(AxeManager manager, EntityDamageByEntityEvent event, LivingEntity defender) { this.manager = manager; this.event = event; - this.defender = event.getEntity(); + this.defender = defender; this.damage = event.getDamage(); calculateSkillModifier(); diff --git a/src/main/java/com/gmail/nossr50/skills/axes/ImpactEventHandler.java b/src/main/java/com/gmail/nossr50/skills/axes/ImpactEventHandler.java index 8572be315..74614361e 100644 --- a/src/main/java/com/gmail/nossr50/skills/axes/ImpactEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/axes/ImpactEventHandler.java @@ -1,7 +1,6 @@ package com.gmail.nossr50.skills.axes; import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -20,20 +19,15 @@ public class ImpactEventHandler { private EntityEquipment equipment; private ItemStack[] armorContents; - protected Entity defender; - protected LivingEntity livingDefender; + protected LivingEntity defender; - public ImpactEventHandler(AxeManager manager, EntityDamageByEntityEvent event) { + public ImpactEventHandler(AxeManager manager, EntityDamageByEntityEvent event, LivingEntity defender) { this.manager = manager; this.player = manager.getPlayer(); this.event = event; - this.defender = event.getEntity(); - - if (defender instanceof LivingEntity) { - this.livingDefender = (LivingEntity) defender; - this.equipment = livingDefender.getEquipment(); - this.armorContents = equipment.getArmorContents(); - } + this.defender = defender; + this.equipment = defender.getEquipment(); + this.armorContents = equipment.getArmorContents(); } protected void damageArmor() { @@ -70,14 +64,14 @@ public class ImpactEventHandler { private void handleGreaterImpactEffect() { event.setDamage(event.getDamage() + Axes.greaterImpactBonusDamage); - livingDefender.setVelocity(player.getLocation().getDirection().normalize().multiply(Axes.greaterImpactKnockbackMultiplier)); + defender.setVelocity(player.getLocation().getDirection().normalize().multiply(Axes.greaterImpactKnockbackMultiplier)); } private void sendAbilityMessge() { player.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc")); - if (livingDefender instanceof Player) { - ((Player) livingDefender).sendMessage(LocaleLoader.getString("Axes.Combat.GI.Struck")); + if (defender instanceof Player) { + ((Player) defender).sendMessage(LocaleLoader.getString("Axes.Combat.GI.Struck")); } } diff --git a/src/main/java/com/gmail/nossr50/skills/axes/SkullSplitterEventHandler.java b/src/main/java/com/gmail/nossr50/skills/axes/SkullSplitterEventHandler.java index 8d70cd079..fb5589be5 100644 --- a/src/main/java/com/gmail/nossr50/skills/axes/SkullSplitterEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/axes/SkullSplitterEventHandler.java @@ -2,7 +2,6 @@ package com.gmail.nossr50.skills.axes; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageByEntityEvent; import com.gmail.nossr50.skills.Combat; import com.gmail.nossr50.skills.SkillType; @@ -12,10 +11,10 @@ public class SkullSplitterEventHandler { private LivingEntity target; private int damage; - protected SkullSplitterEventHandler(AxeManager manager, EntityDamageByEntityEvent event) { - this.player = manager.getPlayer(); - this.target = (LivingEntity) event.getEntity(); - this.damage = event.getDamage(); + protected SkullSplitterEventHandler(Player player, int damage, LivingEntity target) { + this.player = player; + this.target = target; + this.damage = damage; } protected void applyAbilityEffects() { diff --git a/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java b/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java index 565649865..4be0c3942 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java @@ -15,6 +15,7 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Sheep; import org.bukkit.entity.Skeleton; import org.bukkit.entity.Skeleton.SkeletonType; +import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; @@ -50,11 +51,20 @@ public class Fishing { public static int shakeChanceLevel5 = AdvancedConfig.getInstance().getShakeChanceRank5(); public static int shakeUnlockLevel = AdvancedConfig.getInstance().getShakeUnlockLevel(); - public static int fishermanDietRankChangeLevel = AdvancedConfig.getInstance().getFishermanDietRankChange(); - public static int fishermanDietMaxLevel = fishermanDietRankChangeLevel * 5; + public static int fishermansDietRankLevel1 = AdvancedConfig.getInstance().getFishermanDietRankChange(); + public static int fishermansDietRankLevel2 = fishermansDietRankLevel1 * 2; + public static int fishermansDietMaxLevel = fishermansDietRankLevel1 * 5; public static int magicHunterMultiplier = AdvancedConfig.getInstance().getFishingMagicMultiplier(); + public static void fishermansDiet(Player player, int rankChange, FoodLevelChangeEvent event) { + if (!Permissions.fishermansDiet(player)) { + return; + } + + Skills.handleFoodSkills(player, SkillType.FISHING, event, fishermansDietRankLevel1, fishermansDietMaxLevel, rankChange); + } + /** * Get the player's current fishing loot tier. * diff --git a/src/main/java/com/gmail/nossr50/skills/fishing/FishingCommand.java b/src/main/java/com/gmail/nossr50/skills/fishing/FishingCommand.java index d23c1c319..149a3a03c 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/FishingCommand.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/FishingCommand.java @@ -49,7 +49,7 @@ public class FishingCommand extends SkillCommand { shakeChanceLucky = shakeStrings[1]; //FISHERMAN'S DIET - fishermansDietRank = calculateRank(Fishing.fishermanDietMaxLevel, Fishing.fishermanDietRankChangeLevel); + fishermansDietRank = calculateRank(Fishing.fishermansDietMaxLevel, Fishing.fishermansDietRankLevel1); } @Override diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index ddd01a8a8..f34b573d3 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -83,10 +83,6 @@ public class MiningManager extends SkillManager{ * @param event Event whose explosion damage is being reduced */ public void demolitionsExpertise(EntityDamageEvent event) { - if (Misc.isNPCPlayer(player)) { - return; - } - DemoltionsExpertiseEventHandler eventHandler = new DemoltionsExpertiseEventHandler(this, event); eventHandler.calculateDamageModifier(); diff --git a/src/main/java/com/gmail/nossr50/skills/swords/Swords.java b/src/main/java/com/gmail/nossr50/skills/swords/Swords.java index f4cfcb518..8c28bb1c5 100644 --- a/src/main/java/com/gmail/nossr50/skills/swords/Swords.java +++ b/src/main/java/com/gmail/nossr50/skills/swords/Swords.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.skills.swords; import com.gmail.nossr50.config.AdvancedConfig; +import com.gmail.nossr50.config.Config; public class Swords { public static double bleedMaxChance = AdvancedConfig.getInstance().getBleedChanceMax(); @@ -14,4 +15,8 @@ public class Swords { public static int serratedStrikesModifier = AdvancedConfig.getInstance().getSerratedStrikesModifier(); public static int serratedStrikesBleedTicks = AdvancedConfig.getInstance().getSerratedStrikesTicks(); + + public static boolean pvpEnabled = Config.getInstance().getSwordsPVP(); + public static boolean pveEnabled = Config.getInstance().getSwordsPVE(); } + diff --git a/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java b/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java index a069b773e..840209878 100644 --- a/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java @@ -21,9 +21,6 @@ public class SwordsManager extends SkillManager { * @param defender The defending entity */ public void bleedCheck(LivingEntity defender) { - if (player == null) - return; - if (!Permissions.swordsBleed(player)) { return; } @@ -42,9 +39,6 @@ public class SwordsManager extends SkillManager { } public void counterAttackChecks(LivingEntity attacker, int damage) { - if (player == null) - return; - if (!Permissions.counterAttack(player)) { return; } @@ -65,7 +59,7 @@ public class SwordsManager extends SkillManager { } public void serratedStrikes(LivingEntity target, int damage) { - if (Misc.isNPCPlayer(player) || !Permissions.serratedStrikes(player) || !profile.getAbilityMode(AbilityType.SERRATED_STRIKES)) { + if (!profile.getAbilityMode(AbilityType.SERRATED_STRIKES) || !Permissions.serratedStrikes(player)) { return; } diff --git a/src/main/java/com/gmail/nossr50/skills/taming/EnvironmentallyAwareEventHandler.java b/src/main/java/com/gmail/nossr50/skills/taming/EnvironmentallyAwareEventHandler.java index 096e65962..01a0eba27 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/EnvironmentallyAwareEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/EnvironmentallyAwareEventHandler.java @@ -18,9 +18,6 @@ public class EnvironmentallyAwareEventHandler { } protected void teleportWolf() { - if (player == null) - return; - if (event.getDamage() > wolf.getHealth()) { return; } @@ -29,9 +26,6 @@ public class EnvironmentallyAwareEventHandler { } protected void sendAbilityMessage() { - if (player == null) - return; - player.sendMessage(LocaleLoader.getString("Taming.Listener.Wolf")); } diff --git a/src/main/java/com/gmail/nossr50/skills/taming/Taming.java b/src/main/java/com/gmail/nossr50/skills/taming/Taming.java index 8285e7448..96d324799 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/Taming.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/Taming.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.skills.taming; import com.gmail.nossr50.config.AdvancedConfig; +import com.gmail.nossr50.config.Config; public class Taming { public static int environmentallyAwareUnlockLevel = AdvancedConfig.getInstance().getEnviromentallyAwareUnlock(); @@ -21,4 +22,10 @@ public class Taming { public static int thickFurUnlockLevel = AdvancedConfig.getInstance().getThickFurUnlock(); public static int thickFurModifier = AdvancedConfig.getInstance().getThickFurModifier(); + + public static int wolfXP = Config.getInstance().getTamingXPWolf(); + public static int ocelotXP = Config.getInstance().getTamingXPOcelot(); + + public static boolean pvpEnabled = Config.getInstance().getTamingPVP(); + public static boolean pveEnabled = Config.getInstance().getTamingPVE(); } diff --git a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java index d35dbb148..06a4c7530 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java @@ -6,11 +6,14 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Wolf; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityTameEvent; import org.bukkit.inventory.ItemStack; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillType; +import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -22,6 +25,30 @@ public class TamingManager extends SkillManager { this.configInstance = Config.getInstance(); } + /** + * Award XP for taming. + * + * @param event The event to award XP for + */ + public void awardTamingXP(EntityTameEvent event) { + if (mcMMO.placeStore.isSpawnedMob(event.getEntity())) { + return; + } + + switch (event.getEntityType()) { + case WOLF: + Skills.xpProcessing(player, profile, SkillType.TAMING, Taming.wolfXP); + break; + + case OCELOT: + Skills.xpProcessing(player, profile, SkillType.TAMING, Taming.ocelotXP); + break; + + default: + break; + } + } + /** * Apply the Fast Food Service ability. * @@ -29,14 +56,7 @@ public class TamingManager extends SkillManager { * @param damage The damage being absorbed by the wolf */ public void fastFoodService(Wolf wolf, int damage) { - if (player == null) - return; - - if (!Permissions.fastFoodService(player)) { - return; - } - - if (skillLevel >= Taming.fastFoodServiceUnlockLevel) { + if (skillLevel >= Taming.fastFoodServiceUnlockLevel && Permissions.fastFoodService(player)) { if (Misc.getRandom().nextInt(activationChance) < Taming.fastFoodServiceActivationChance) { FastFoodServiceEventHandler eventHandler = new FastFoodServiceEventHandler(wolf); @@ -51,14 +71,7 @@ public class TamingManager extends SkillManager { * @param event The event to modify */ public void sharpenedClaws(EntityDamageEvent event) { - if (player == null) - return; - - if (!Permissions.sharpenedClaws(player)) { - return; - } - - if (skillLevel >= Taming.sharpenedClawsUnlockLevel) { + if (skillLevel >= Taming.sharpenedClawsUnlockLevel && Permissions.sharpenedClaws(player)) { SharpenedClawsEventHandler eventHandler = new SharpenedClawsEventHandler(event); eventHandler.modifyEventDamage(); @@ -71,9 +84,6 @@ public class TamingManager extends SkillManager { * @param event The event to modify */ public void gore(EntityDamageEvent event) { - if (player == null) - return; - if (!Permissions.gore(player)) { return; } @@ -143,15 +153,11 @@ public class TamingManager extends SkillManager { * @param livingEntity The entity to examine */ public void beastLore(LivingEntity livingEntity) { - if (player == null) - return; - if (!Permissions.beastLore(player)) { return; } BeastLoreEventHandler eventHandler = new BeastLoreEventHandler(player, livingEntity); - eventHandler.sendInspectMessage(); } @@ -193,14 +199,7 @@ public class TamingManager extends SkillManager { * @param cause The damage cause of the event */ private void environmentallyAware(EntityDamageEvent event, DamageCause cause) { - if (player == null) - return; - - if (!Permissions.environmentallyAware(player)) { - return; - } - - if (skillLevel >= Taming.environmentallyAwareUnlockLevel) { + if (skillLevel >= Taming.environmentallyAwareUnlockLevel && Permissions.environmentallyAware(player)) { EnvironmentallyAwareEventHandler eventHandler = new EnvironmentallyAwareEventHandler(this, event); switch (cause) { @@ -228,16 +227,8 @@ public class TamingManager extends SkillManager { * @param cause The damage cause of the event */ private void thickFur(EntityDamageEvent event, DamageCause cause) { - if (player == null) - return; - - if (!Permissions.thickFur(player)) { - return; - } - - if (skillLevel >= Taming.thickFurUnlockLevel) { + if (skillLevel >= Taming.thickFurUnlockLevel && Permissions.thickFur(player)) { ThickFurEventHandler eventHandler = new ThickFurEventHandler(event, cause); - eventHandler.modifyEventDamage(); } } @@ -248,16 +239,8 @@ public class TamingManager extends SkillManager { * @param event The event to modify */ private void shockProof(EntityDamageEvent event) { - if (player == null) - return; - - if (!Permissions.shockProof(player)) { - return; - } - - if (skillLevel >= Taming.shockProofUnlockLevel) { + if (skillLevel >= Taming.shockProofUnlockLevel && Permissions.shockProof(player)) { ShockProofEventHandler eventHandler = new ShockProofEventHandler(event); - eventHandler.modifyEventDamage(); } } diff --git a/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java b/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java index 68a72113b..fd13e4f6f 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java @@ -14,4 +14,6 @@ public class Unarmed { public static double ironGripMaxChance = AdvancedConfig.getInstance().getIronGripChanceMax(); public static int ironGripMaxBonusLevel = AdvancedConfig.getInstance().getIronGripMaxBonusLevel(); + + public static double berserkDamageModifier = 1.5; } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java index 5f533685b..8ab66618a 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java @@ -1,8 +1,10 @@ package com.gmail.nossr50.skills.unarmed; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; +import com.gmail.nossr50.skills.AbilityType; import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillType; import com.gmail.nossr50.util.Misc; @@ -18,12 +20,13 @@ public class UnarmedManager extends SkillManager { * * @param defender The defending player */ - public void disarmCheck(Player defender) { - if (Misc.isNPCPlayer(player) || !Permissions.disarm(player)) { + public void disarmCheck(LivingEntity defender) { + if (!(defender instanceof Player) || !Permissions.disarm(player)) { return; } - DisarmEventHandler eventHandler = new DisarmEventHandler(this, defender); + Player defendingPlayer = (Player) defender; + DisarmEventHandler eventHandler = new DisarmEventHandler(this, defendingPlayer); if (eventHandler.isHoldingItem()) { eventHandler.calculateSkillModifier(); @@ -32,7 +35,7 @@ public class UnarmedManager extends SkillManager { if (chance > Unarmed.disarmMaxChance) chance = (float) Unarmed.disarmMaxChance; if (chance > Misc.getRandom().nextInt(activationChance)) { - if (!hasIronGrip(defender)) { + if (!hasIronGrip(defendingPlayer)) { eventHandler.handleDisarm(); } } @@ -64,15 +67,18 @@ public class UnarmedManager extends SkillManager { } } + public void berserkDamage(EntityDamageEvent event) { + if (!profile.getAbilityMode(AbilityType.BERSERK) || !Permissions.berserk(player)) { + event.setDamage((int) (event.getDamage() * Unarmed.berserkDamageModifier)); + } + } + /** * Handle Unarmed bonus damage. * * @param event The event to modify. */ public void bonusDamage(EntityDamageEvent event) { - if (player == null) - return; - if (!Permissions.unarmedBonus(player)) { return; } @@ -90,10 +96,7 @@ public class UnarmedManager extends SkillManager { * @return true if the defender was not disarmed, false otherwise */ private boolean hasIronGrip(Player defender) { - if (defender == null) - return false; - - if (!Permissions.ironGrip(defender)) { + if (Misc.isNPCEntity(defender) || !Permissions.ironGrip(defender)) { return false; } diff --git a/src/main/resources/advanced.yml b/src/main/resources/advanced.yml index e08270fb1..16a50a214 100644 --- a/src/main/resources/advanced.yml +++ b/src/main/resources/advanced.yml @@ -173,7 +173,7 @@ Skills: # SuperRepair_MaxBonusLevel: On this level, Super Repair chance will be SuperRepair_ChanceMax SuperRepair_ChanceMax: 100.0 SuperRepair_MaxBonusLevel: 1000 - + Arcane_Forging: May_Lose_Enchants: true Rank_Levels: