diff --git a/src/main/java/com/gmail/nossr50/core/DynamicSettingsManager.java b/src/main/java/com/gmail/nossr50/core/DynamicSettingsManager.java index 842252751..c5e4f69e2 100644 --- a/src/main/java/com/gmail/nossr50/core/DynamicSettingsManager.java +++ b/src/main/java/com/gmail/nossr50/core/DynamicSettingsManager.java @@ -170,4 +170,7 @@ public class DynamicSettingsManager { return skillPropertiesManager; } + public SkillBehaviourManager getSkillBehaviourManager() { + return skillBehaviourManager; + } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/behaviours/AcrobaticsBehaviour.java b/src/main/java/com/gmail/nossr50/datatypes/skills/behaviours/AcrobaticsBehaviour.java index b94fece06..927bc9292 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/behaviours/AcrobaticsBehaviour.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/behaviours/AcrobaticsBehaviour.java @@ -12,7 +12,25 @@ import com.gmail.nossr50.mcMMO; public class AcrobaticsBehaviour { private final mcMMO pluginRef; + private double dodgeDamageModifier; + private int dodgeXpModifier; + public AcrobaticsBehaviour(mcMMO pluginRef) { this.pluginRef = pluginRef; + + dodgeDamageModifier = pluginRef.getConfigManager().getConfigAcrobatics().getDamageReductionDivisor(); + dodgeXpModifier = pluginRef.getConfigManager().getConfigExperience().getDodgeXP(); + } + + public double calculateModifiedDodgeDamage(double damage, double damageModifier) { + return Math.max(damage / damageModifier, 1.0); + } + + public double getDodgeDamageModifier() { + return dodgeDamageModifier; + } + + public int getDodgeXpModifier() { + return dodgeXpModifier; } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/behaviours/ArcheryBehaviour.java b/src/main/java/com/gmail/nossr50/datatypes/skills/behaviours/ArcheryBehaviour.java index f9da4c787..576ad8db4 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/behaviours/ArcheryBehaviour.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/behaviours/ArcheryBehaviour.java @@ -1,6 +1,16 @@ package com.gmail.nossr50.datatypes.skills.behaviours; +import com.gmail.nossr50.core.MetadataConstants; +import com.gmail.nossr50.datatypes.meta.TrackedArrowMeta; +import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.util.skills.RankUtils; +import org.bukkit.Material; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; /** * These behaviour classes are a band-aid fix for a larger problem @@ -16,4 +26,46 @@ public class ArcheryBehaviour { public ArcheryBehaviour(mcMMO pluginRef) { this.pluginRef = pluginRef; } + + /** + * Check for arrow retrieval. + * + * @param livingEntity The entity hit by the arrows + */ + public void arrowRetrievalCheck(LivingEntity livingEntity) { + if(livingEntity.hasMetadata(MetadataConstants.ARROW_TRACKER_METAKEY)) { + Misc.dropItems(livingEntity.getLocation(), new ItemStack(Material.ARROW), livingEntity.getMetadata(MetadataConstants.ARROW_TRACKER_METAKEY).get(0).asInt()); + } + } + + public void incrementArrowCount(LivingEntity livingEntity) { + if(livingEntity.hasMetadata(MetadataConstants.ARROW_TRACKER_METAKEY)) { + int arrowCount = livingEntity.getMetadata(MetadataConstants.ARROW_TRACKER_METAKEY).get(0).asInt(); + livingEntity.getMetadata(MetadataConstants.ARROW_TRACKER_METAKEY).set(0, new FixedMetadataValue(pluginRef, arrowCount + 1)); + } else { + livingEntity.setMetadata(MetadataConstants.ARROW_TRACKER_METAKEY, new TrackedArrowMeta(pluginRef, 1)); + } + } + + public double getSkillShotBonusDamage(Player player, double oldDamage) { + double damageBonusPercent = getDamageBonusPercent(player); + double newDamage = oldDamage + (oldDamage * damageBonusPercent); + return Math.min(newDamage, getSkillShotDamageCap()); + } + + public double getDamageBonusPercent(Player player) { + return ((RankUtils.getRank(player, SubSkillType.ARCHERY_SKILL_SHOT)) * pluginRef.getConfigManager().getConfigArchery().getSkillShotDamageMultiplier()) / 100.0D; + } + + public double getSkillShotDamageCap() { + return pluginRef.getConfigManager().getConfigArchery().getSkillShotDamageCeiling(); + } + + public double getDazeBonusDamage() { + return pluginRef.getConfigManager().getConfigArchery().getDaze().getDazeBonusDamage(); + } + + public double getDistanceXpMultiplier() { + return pluginRef.getConfigManager().getConfigExperience().getExperienceArchery().getDistanceMultiplier(); + } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/behaviours/AxesBehaviour.java b/src/main/java/com/gmail/nossr50/datatypes/skills/behaviours/AxesBehaviour.java index a4e9e61d6..4e5f5c845 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/behaviours/AxesBehaviour.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/behaviours/AxesBehaviour.java @@ -1,6 +1,12 @@ package com.gmail.nossr50.datatypes.skills.behaviours; +import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.util.ItemUtils; +import com.gmail.nossr50.util.skills.RankUtils; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; /** * These behaviour classes are a band-aid fix for a larger problem @@ -16,4 +22,24 @@ public class AxesBehaviour { public AxesBehaviour(mcMMO pluginRef) { this.pluginRef = pluginRef; } + + public boolean hasArmor(LivingEntity target) { + for (ItemStack itemStack : target.getEquipment().getArmorContents()) { + if (itemStack != null && ItemUtils.isArmor(itemStack)) { + return true; + } + } + + return false; + } + + /** + * For every rank in Axe Mastery we add RankDamageMultiplier to get the total bonus damage from Axe Mastery + * + * @param player The target player + * @return The axe mastery bonus damage which will be added to their attack + */ + public double getAxeMasteryBonusDamage(Player player) { + return RankUtils.getRank(player, SubSkillType.AXES_AXE_MASTERY) * pluginRef.getConfigManager().getConfigAxes().getAxeMasteryMultiplier(); + } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java index 671144100..43de2e092 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java @@ -28,9 +28,11 @@ import org.bukkit.inventory.ItemStack; public class Roll extends AcrobaticsSubSkill { + private final mcMMO pluginRef; - public Roll() { + public Roll(mcMMO pluginRef) { super("Roll", EventPriority.HIGHEST, SubSkillType.ACROBATICS_ROLL); + this.pluginRef = pluginRef; } protected static double calculateModifiedRollDamage(double damage, double damageThreshold) { diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java deleted file mode 100644 index 899167a35..000000000 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.gmail.nossr50.skills.acrobatics; - -public final class Acrobatics { - public static double dodgeDamageModifier; - public static int dodgeXpModifier; -// public static boolean dodgeLightningDisabled; - - private Acrobatics() { - dodgeDamageModifier = pluginRef.getConfigManager().getConfigAcrobatics().getDamageReductionDivisor(); - dodgeXpModifier = pluginRef.getConfigManager().getConfigExperience().getDodgeXP(); -// dodgeLightningDisabled = MainConfig.getInstance().getDodgeLightningDisabled(); - } - - protected static double calculateModifiedDodgeDamage(double damage, double damageModifier) { - return Math.max(damage / damageModifier, 1.0); - } -} 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 995422745..ca271fa83 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java @@ -6,6 +6,7 @@ import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType; +import com.gmail.nossr50.datatypes.skills.behaviours.AcrobaticsBehaviour; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.util.Misc; @@ -25,9 +26,13 @@ public class AcrobaticsManager extends SkillManager { private long rollXPInterval; private long rollXPIntervalLengthen = (1000 * 10); //10 Seconds private LimitedSizeList fallLocationMap; + private AcrobaticsBehaviour acrobaticsBehaviour; public AcrobaticsManager(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) { super(pluginRef, mcMMOPlayer, PrimarySkillType.ACROBATICS); + //Init Behaviour + acrobaticsBehaviour = pluginRef.getDynamicSettingsManager().getSkillBehaviourManager().getAcrobaticsBehaviour(); + rollXPInterval = (1000 * pluginRef.getConfigManager().getConfigExploitPrevention().getConfigSectionExploitAcrobatics().getRollXPGainCooldownSeconds()); //Save some memory if exploit prevention is off @@ -80,7 +85,7 @@ public class AcrobaticsManager extends SkillManager { * @return the modified event damage if the ability was successful, the original event damage otherwise */ public double dodgeCheck(double damage) { - double modifiedDamage = Acrobatics.calculateModifiedDodgeDamage(damage, Acrobatics.dodgeDamageModifier); + double modifiedDamage = acrobaticsBehaviour.calculateModifiedDodgeDamage(damage, acrobaticsBehaviour.getDodgeDamageModifier()); Player player = getPlayer(); if (!isFatal(modifiedDamage) && RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.ACROBATICS_DODGE, player)) { @@ -92,10 +97,10 @@ public class AcrobaticsManager extends SkillManager { //Check respawn to prevent abuse if (!pluginRef.getConfigManager().getConfigExploitPrevention().getConfigSectionExploitAcrobatics().isPreventAcrobaticsAbuse()) - applyXpGain((float) (damage * Acrobatics.dodgeXpModifier), XPGainReason.PVP); + applyXpGain((float) (damage * acrobaticsBehaviour.getDodgeXpModifier()), XPGainReason.PVP); else if (SkillUtils.cooldownExpired(mcMMOPlayer.getRespawnATS(), Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS) && mcMMOPlayer.getTeleportATS() < System.currentTimeMillis()) { - applyXpGain((float) (damage * Acrobatics.dodgeXpModifier), XPGainReason.PVP); + applyXpGain((float) (damage * acrobaticsBehaviour.getDodgeXpModifier()), XPGainReason.PVP); } return modifiedDamage; diff --git a/src/main/java/com/gmail/nossr50/skills/archery/Archery.java b/src/main/java/com/gmail/nossr50/skills/archery/Archery.java deleted file mode 100644 index b8853a497..000000000 --- a/src/main/java/com/gmail/nossr50/skills/archery/Archery.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.gmail.nossr50.skills.archery; - -import com.gmail.nossr50.core.MetadataConstants; -import com.gmail.nossr50.datatypes.meta.TrackedArrowMeta; -import com.gmail.nossr50.datatypes.skills.SubSkillType; -import com.gmail.nossr50.util.Misc; -import com.gmail.nossr50.util.skills.RankUtils; -import org.bukkit.Material; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.FixedMetadataValue; - -public class Archery { - /** - * Check for arrow retrieval. - * - * @param livingEntity The entity hit by the arrows - */ - public static void arrowRetrievalCheck(LivingEntity livingEntity) { - if(livingEntity.hasMetadata(MetadataConstants.ARROW_TRACKER_METAKEY)) { - Misc.dropItems(livingEntity.getLocation(), new ItemStack(Material.ARROW), livingEntity.getMetadata(MetadataConstants.ARROW_TRACKER_METAKEY).get(0).asInt()); - } - } - - public static void incrementArrowCount(LivingEntity livingEntity) { - if(livingEntity.hasMetadata(MetadataConstants.ARROW_TRACKER_METAKEY)) { - int arrowCount = livingEntity.getMetadata(MetadataConstants.ARROW_TRACKER_METAKEY).get(0).asInt(); - livingEntity.getMetadata(MetadataConstants.ARROW_TRACKER_METAKEY).set(0, new FixedMetadataValue(pluginRef, arrowCount + 1)); - } else { - livingEntity.setMetadata(MetadataConstants.ARROW_TRACKER_METAKEY, new TrackedArrowMeta(pluginRef, 1)); - } - } - - public static double getSkillShotBonusDamage(Player player, double oldDamage) { - double damageBonusPercent = getDamageBonusPercent(player); - double newDamage = oldDamage + (oldDamage * damageBonusPercent); - return Math.min(newDamage, getSkillShotDamageCap()); - } - - public static double getDamageBonusPercent(Player player) { - return ((RankUtils.getRank(player, SubSkillType.ARCHERY_SKILL_SHOT)) * pluginRef.getConfigManager().getConfigArchery().getSkillShotDamageMultiplier()) / 100.0D; - } - - public static double getSkillShotDamageCap() { - return pluginRef.getConfigManager().getConfigArchery().getSkillShotDamageCeiling(); - } - - public static double getDazeBonusDamage() { - return pluginRef.getConfigManager().getConfigArchery().getDaze().getDazeBonusDamage(); - } - - public static double getDistanceXpMultiplier() { - return pluginRef.getConfigManager().getConfigExperience().getExperienceArchery().getDistanceMultiplier(); - } -} diff --git a/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java b/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java index a3bca77de..25b7b4e3b 100644 --- a/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java +++ b/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java @@ -5,6 +5,7 @@ import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType; +import com.gmail.nossr50.datatypes.skills.behaviours.ArcheryBehaviour; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.util.Misc; @@ -21,8 +22,14 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; public class ArcheryManager extends SkillManager { + + private final ArcheryBehaviour archeryBehaviour; + public ArcheryManager(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) { super(pluginRef, mcMMOPlayer, PrimarySkillType.ARCHERY); + + //Init Behaviour + this.archeryBehaviour = pluginRef.getDynamicSettingsManager().getSkillBehaviourManager().getArcheryBehaviour(); } public boolean canDaze(LivingEntity target) { @@ -64,7 +71,7 @@ public class ArcheryManager extends SkillManager { return 1; } - return 1 + Math.min(firedLocation.distance(targetLocation), 50) * Archery.getDistanceXpMultiplier(); + return 1 + Math.min(firedLocation.distance(targetLocation), 50) * archeryBehaviour.getDistanceXpMultiplier(); } /** @@ -74,7 +81,7 @@ public class ArcheryManager extends SkillManager { */ public void processArrowRetrievalActivation(LivingEntity target, Projectile projectile) { if(projectile.hasMetadata(MetadataConstants.ARROW_TRACKER_METAKEY)) { - Archery.incrementArrowCount(target); + archeryBehaviour.incrementArrowCount(target); projectile.removeMetadata(MetadataConstants.ARROW_TRACKER_METAKEY, pluginRef); //Only 1 entity per projectile } } @@ -104,7 +111,7 @@ public class ArcheryManager extends SkillManager { pluginRef.getNotificationManager().sendPlayerInformation(getPlayer(), NotificationType.SUBSKILL_MESSAGE, "Combat.TargetDazed"); } - return Archery.getDazeBonusDamage(); + return archeryBehaviour.getDazeBonusDamage(); } /** @@ -117,6 +124,6 @@ public class ArcheryManager extends SkillManager { return oldDamage; } - return Archery.getSkillShotBonusDamage(getPlayer(), oldDamage); + return archeryBehaviour.getSkillShotBonusDamage(getPlayer(), oldDamage); } } diff --git a/src/main/java/com/gmail/nossr50/skills/axes/Axes.java b/src/main/java/com/gmail/nossr50/skills/axes/Axes.java deleted file mode 100644 index 861ec389b..000000000 --- a/src/main/java/com/gmail/nossr50/skills/axes/Axes.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.gmail.nossr50.skills.axes; - -import com.gmail.nossr50.datatypes.skills.SubSkillType; -import com.gmail.nossr50.util.ItemUtils; -import com.gmail.nossr50.util.skills.RankUtils; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class Axes { - - protected static boolean hasArmor(LivingEntity target) { - for (ItemStack itemStack : target.getEquipment().getArmorContents()) { - if (itemStack != null && ItemUtils.isArmor(itemStack)) { - return true; - } - } - - return false; - } - - /** - * For every rank in Axe Mastery we add RankDamageMultiplier to get the total bonus damage from Axe Mastery - * - * @param player The target player - * @return The axe mastery bonus damage which will be added to their attack - */ - public static double getAxeMasteryBonusDamage(Player player) { - return RankUtils.getRank(player, SubSkillType.AXES_AXE_MASTERY) * pluginRef.getConfigManager().getConfigAxes().getAxeMasteryMultiplier(); - } -} diff --git a/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java b/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java index 95b6dd29f..2316db8cd 100644 --- a/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java +++ b/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java @@ -6,6 +6,7 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.datatypes.skills.ToolType; +import com.gmail.nossr50.datatypes.skills.behaviours.AxesBehaviour; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.util.ItemUtils; @@ -20,8 +21,12 @@ import org.bukkit.inventory.ItemStack; import java.util.Map; public class AxesManager extends SkillManager { + + private final AxesBehaviour axesBehaviour; + public AxesManager(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) { super(pluginRef, mcMMOPlayer, PrimarySkillType.AXES); + this.axesBehaviour = pluginRef.getDynamicSettingsManager().getSkillBehaviourManager().getAxesBehaviour(); } public boolean canUseAxeMastery() { @@ -42,14 +47,14 @@ public class AxesManager extends SkillManager { if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.AXES_ARMOR_IMPACT)) return false; - return target.isValid() && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.AXES_ARMOR_IMPACT) && Axes.hasArmor(target); + return target.isValid() && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.AXES_ARMOR_IMPACT) && axesBehaviour.hasArmor(target); } public boolean canGreaterImpact(LivingEntity target) { if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.AXES_GREATER_IMPACT)) return false; - return target.isValid() && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.AXES_GREATER_IMPACT) && !Axes.hasArmor(target); + return target.isValid() && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.AXES_GREATER_IMPACT) && !axesBehaviour.hasArmor(target); } public boolean canUseSkullSplitter(LivingEntity target) { @@ -71,7 +76,7 @@ public class AxesManager extends SkillManager { return 0; } - return Axes.getAxeMasteryBonusDamage(getPlayer()); + return axesBehaviour.getAxeMasteryBonusDamage(getPlayer()); } /**