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 2a5d648b5..ead48f6d8 100644 --- a/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java +++ b/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java @@ -17,6 +17,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent.DamageModifier; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; import java.util.Map; @@ -32,28 +33,28 @@ public class AxesManager extends SkillManager { return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.AXES_AXE_MASTERY); } - public boolean canCriticalHit(LivingEntity target) { + public boolean canCriticalHit(@NotNull LivingEntity target) { if(!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.AXES_CRITICAL_STRIKES)) return false; return target.isValid() && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.AXES_CRITICAL_STRIKES); } - public boolean canImpact(LivingEntity target) { + public boolean canImpact(@NotNull LivingEntity target) { if(!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.AXES_ARMOR_IMPACT)) return false; return target.isValid() && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.AXES_ARMOR_IMPACT) && Axes.hasArmor(target); } - public boolean canGreaterImpact(LivingEntity target) { + public boolean canGreaterImpact(@NotNull 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); } - public boolean canUseSkullSplitter(LivingEntity target) { + public boolean canUseSkullSplitter(@NotNull LivingEntity target) { if(!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.AXES_SKULL_SPLITTER)) return false; @@ -68,7 +69,7 @@ public class AxesManager extends SkillManager { * Handle the effects of the Axe Mastery ability */ public double axeMastery() { - if (!RandomChanceUtil.isActivationSuccessful(SkillActivationType.ALWAYS_FIRES, SubSkillType.AXES_AXE_MASTERY, getPlayer(), mmoPlayer.getAttackStrength())) { + if (!RandomChanceUtil.isActivationSuccessful(SkillActivationType.ALWAYS_FIRES, SubSkillType.AXES_AXE_MASTERY, getPlayer())) { return 0; } @@ -82,7 +83,7 @@ public class AxesManager extends SkillManager { * @param damage The amount of damage initially dealt by the event */ public double criticalHit(LivingEntity target, double damage) { - if (!RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.AXES_CRITICAL_STRIKES, getPlayer(), mmoPlayer.getAttackStrength())) { + if (!RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.AXES_CRITICAL_STRIKES, getPlayer())) { return 0; } @@ -113,12 +114,12 @@ public class AxesManager extends SkillManager { * * @param target The {@link LivingEntity} being affected by Impact */ - public void impactCheck(LivingEntity target) { + public void impactCheck(@NotNull LivingEntity target) { double durabilityDamage = getImpactDurabilityDamage(); for (ItemStack armor : target.getEquipment().getArmorContents()) { if (armor != null && ItemUtils.isArmor(armor)) { - if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_STATIC_CHANCE, SubSkillType.AXES_ARMOR_IMPACT, getPlayer(), mmoPlayer.getAttackStrength())) { + if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_STATIC_CHANCE, SubSkillType.AXES_ARMOR_IMPACT, getPlayer())) { SkillUtils.handleDurabilityChange(armor, durabilityDamage, 1); } } @@ -134,9 +135,9 @@ public class AxesManager extends SkillManager { * * @param target The {@link LivingEntity} being affected by the ability */ - public double greaterImpact(LivingEntity target) { + public double greaterImpact(@NotNull LivingEntity target) { //static chance (3rd param) - if (!RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_STATIC_CHANCE, SubSkillType.AXES_GREATER_IMPACT, getPlayer(), mmoPlayer.getAttackStrength())) { + if (!RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_STATIC_CHANCE, SubSkillType.AXES_GREATER_IMPACT, getPlayer())) { return 0; } @@ -166,7 +167,7 @@ public class AxesManager extends SkillManager { * @param target The {@link LivingEntity} being affected by the ability * @param damage The amount of damage initially dealt by the event */ - public void skullSplitterCheck(LivingEntity target, double damage, Map modifiers) { + public void skullSplitterCheck(@NotNull LivingEntity target, double damage, Map modifiers) { CombatUtils.applyAbilityAoE(getPlayer(), target, damage / Axes.skullSplitterModifier, modifiers, skill); } } 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 ebcc93993..1c3fa3766 100644 --- a/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java @@ -62,7 +62,7 @@ public class SwordsManager extends SkillManager { */ public void ruptureCheck(@NotNull LivingEntity target) throws IllegalStateException { if(BleedTimerTask.isBleedOperationAllowed()) { - if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.SWORDS_RUPTURE, getPlayer(), this.mmoPlayer.getAttackStrength())) { + if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.SWORDS_RUPTURE, getPlayer())) { if (target instanceof Player) { Player defender = (Player) target; @@ -98,7 +98,7 @@ public class SwordsManager extends SkillManager { return 0; } - public int getToolTier(ItemStack itemStack) + public int getToolTier(@NotNull ItemStack itemStack) { if(ItemUtils.isNetheriteTool(itemStack)) return 5; @@ -128,7 +128,7 @@ public class SwordsManager extends SkillManager { * @param attacker The {@link LivingEntity} being affected by the ability * @param damage The amount of damage initially dealt by the event */ - public void counterAttackChecks(LivingEntity attacker, double damage) { + public void counterAttackChecks(@NotNull LivingEntity attacker, double damage) { if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.SWORDS_COUNTER_ATTACK, getPlayer())) { CombatUtils.dealDamage(attacker, damage / Swords.counterAttackModifier, getPlayer()); @@ -146,7 +146,7 @@ public class SwordsManager extends SkillManager { * @param target The {@link LivingEntity} being affected by the ability * @param damage The amount of damage initially dealt by the event */ - public void serratedStrikes(LivingEntity target, double damage, Map modifiers) { + public void serratedStrikes(@NotNull LivingEntity target, double damage, Map modifiers) { CombatUtils.applyAbilityAoE(getPlayer(), target, damage / Swords.serratedStrikesModifier, modifiers, skill); } } 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 c20620cf8..73bf3dce9 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java @@ -25,6 +25,7 @@ import org.bukkit.entity.Item; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; public class UnarmedManager extends SkillManager { @@ -70,7 +71,7 @@ public class UnarmedManager extends SkillManager { return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.UNARMED_BLOCK_CRACKER); } - public boolean blockCrackerCheck(BlockState blockState) { + public boolean blockCrackerCheck(@NotNull BlockState blockState) { if (!RandomChanceUtil.isActivationSuccessful(SkillActivationType.ALWAYS_FIRES, SubSkillType.UNARMED_BLOCK_CRACKER, getPlayer())) { return false; } @@ -101,8 +102,8 @@ public class UnarmedManager extends SkillManager { * * @param defender The defending player */ - public void disarmCheck(Player defender) { - if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.UNARMED_DISARM, getPlayer(), mmoPlayer.getAttackStrength()) && !hasIronGrip(defender)) { + public void disarmCheck(@NotNull Player defender) { + if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.UNARMED_DISARM, getPlayer()) && !hasIronGrip(defender)) { if (EventUtils.callDisarmEvent(defender).isCancelled()) { return; } @@ -179,7 +180,7 @@ public class UnarmedManager extends SkillManager { * @param defender The defending player * @return true if the defender was not disarmed, false otherwise */ - private boolean hasIronGrip(Player defender) { + private boolean hasIronGrip(@NotNull Player defender) { if (!Misc.isNPCEntityExcludingVillagers(defender) && Permissions.isSubSkillEnabled(defender, SubSkillType.UNARMED_IRON_GRIP) && RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.UNARMED_IRON_GRIP, defender)) { diff --git a/src/main/java/com/gmail/nossr50/util/random/RandomChanceExecution.java b/src/main/java/com/gmail/nossr50/util/random/RandomChanceExecution.java index 8d0da9285..e5d51d740 100644 --- a/src/main/java/com/gmail/nossr50/util/random/RandomChanceExecution.java +++ b/src/main/java/com/gmail/nossr50/util/random/RandomChanceExecution.java @@ -3,6 +3,7 @@ package com.gmail.nossr50.util.random; public interface RandomChanceExecution { /** * Gets the XPos used in the formula for success + * * @return value of x for our success probability graph */ double getXPos(); @@ -10,6 +11,7 @@ public interface RandomChanceExecution { /** * The maximum odds for this RandomChanceExecution * For example, if this value is 10, then 10% odds would be the maximum and would be achieved only when xPos equaled the LinearCurvePeak + * * @return maximum probability odds from 0.00 (no chance of ever happened) to 100.0 (probability can be guaranteed) */ double getProbabilityCap(); diff --git a/src/main/java/com/gmail/nossr50/util/random/RandomChanceSkill.java b/src/main/java/com/gmail/nossr50/util/random/RandomChanceSkill.java index 5d47b44bd..67221a433 100644 --- a/src/main/java/com/gmail/nossr50/util/random/RandomChanceSkill.java +++ b/src/main/java/com/gmail/nossr50/util/random/RandomChanceSkill.java @@ -7,18 +7,19 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.player.UserManager; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class RandomChanceSkill implements RandomChanceExecution { - protected final PrimarySkillType primarySkillType; - protected final SubSkillType subSkillType; + protected final @NotNull PrimarySkillType primarySkillType; + protected final @NotNull SubSkillType subSkillType; protected final double probabilityCap; protected final boolean isLucky; protected int skillLevel; protected double resultModifier; - public RandomChanceSkill(Player player, SubSkillType subSkillType, double resultModifier) - { + public RandomChanceSkill(@Nullable Player player, @NotNull SubSkillType subSkillType, double resultModifier) { this.primarySkillType = subSkillType.getParentSkill(); this.subSkillType = subSkillType; this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR; @@ -30,7 +31,7 @@ public class RandomChanceSkill implements RandomChanceExecution { this.skillLevel = 0; } - if(player != null) + if (player != null) isLucky = Permissions.lucky(player, primarySkillType); else isLucky = false; @@ -38,8 +39,7 @@ public class RandomChanceSkill implements RandomChanceExecution { this.resultModifier = resultModifier; } - public RandomChanceSkill(Player player, SubSkillType subSkillType) - { + public RandomChanceSkill(@Nullable Player player, @NotNull SubSkillType subSkillType) { this.primarySkillType = subSkillType.getParentSkill(); this.subSkillType = subSkillType; this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR; @@ -51,7 +51,7 @@ public class RandomChanceSkill implements RandomChanceExecution { this.skillLevel = 0; } - if(player != null) + if (player != null) isLucky = Permissions.lucky(player, primarySkillType); else isLucky = false; @@ -59,9 +59,8 @@ public class RandomChanceSkill implements RandomChanceExecution { this.resultModifier = 1.0D; } - public RandomChanceSkill(Player player, SubSkillType subSkillType, boolean hasCap) - { - if(hasCap) + public RandomChanceSkill(@Nullable Player player, @NotNull SubSkillType subSkillType, boolean hasCap) { + if (hasCap) this.probabilityCap = AdvancedConfig.getInstance().getMaximumProbability(subSkillType); else this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR; @@ -76,7 +75,7 @@ public class RandomChanceSkill implements RandomChanceExecution { this.skillLevel = 0; } - if(player != null) + if (player != null) isLucky = Permissions.lucky(player, primarySkillType); else isLucky = false; @@ -84,9 +83,8 @@ public class RandomChanceSkill implements RandomChanceExecution { this.resultModifier = 1.0D; } - public RandomChanceSkill(Player player, SubSkillType subSkillType, boolean hasCap, double resultModifier) - { - if(hasCap) + public RandomChanceSkill(@Nullable Player player, @NotNull SubSkillType subSkillType, boolean hasCap, double resultModifier) { + if (hasCap) this.probabilityCap = AdvancedConfig.getInstance().getMaximumProbability(subSkillType); else this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR; @@ -101,7 +99,7 @@ public class RandomChanceSkill implements RandomChanceExecution { this.skillLevel = 0; } - if(player != null) + if (player != null) isLucky = Permissions.lucky(player, primarySkillType); else isLucky = false; @@ -111,23 +109,25 @@ public class RandomChanceSkill implements RandomChanceExecution { /** * The subskill corresponding to this RandomChanceSkill + * * @return this subskill */ - public SubSkillType getSubSkill() { + public @NotNull SubSkillType getSubSkill() { return subSkillType; } /** * Gets the skill level of the player who owns this RandomChanceSkill + * * @return the current skill level relating to this RandomChanceSkill */ - public int getSkillLevel() - { + public int getSkillLevel() { return skillLevel; } /** * Modify the skill level used for this skill's RNG calculations + * * @param newSkillLevel new skill level */ public void setSkillLevel(int newSkillLevel) { diff --git a/src/main/java/com/gmail/nossr50/util/random/RandomChanceSkillStatic.java b/src/main/java/com/gmail/nossr50/util/random/RandomChanceSkillStatic.java index 6223dcda8..ab5f33ecd 100644 --- a/src/main/java/com/gmail/nossr50/util/random/RandomChanceSkillStatic.java +++ b/src/main/java/com/gmail/nossr50/util/random/RandomChanceSkillStatic.java @@ -2,19 +2,19 @@ package com.gmail.nossr50.util.random; import com.gmail.nossr50.datatypes.skills.SubSkillType; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class RandomChanceSkillStatic extends RandomChanceSkill { private final double xPos; - public RandomChanceSkillStatic(double xPos, Player player, SubSkillType subSkillType) - { + public RandomChanceSkillStatic(double xPos, @Nullable Player player, @NotNull SubSkillType subSkillType) { super(player, subSkillType); this.xPos = xPos; } - public RandomChanceSkillStatic(double xPos, Player player, SubSkillType subSkillType, double resultModifier) - { + public RandomChanceSkillStatic(double xPos, @Nullable Player player, @NotNull SubSkillType subSkillType, double resultModifier) { super(player, subSkillType, resultModifier); this.xPos = xPos; diff --git a/src/main/java/com/gmail/nossr50/util/random/RandomChanceStatic.java b/src/main/java/com/gmail/nossr50/util/random/RandomChanceStatic.java index 30f84cfbf..3204a348d 100644 --- a/src/main/java/com/gmail/nossr50/util/random/RandomChanceStatic.java +++ b/src/main/java/com/gmail/nossr50/util/random/RandomChanceStatic.java @@ -5,8 +5,7 @@ public class RandomChanceStatic implements RandomChanceExecution { private final double probabilityCap; private final boolean isLucky; - public RandomChanceStatic(double xPos, boolean isLucky) - { + public RandomChanceStatic(double xPos, boolean isLucky) { this.xPos = xPos; this.probabilityCap = xPos; this.isLucky = isLucky; diff --git a/src/main/java/com/gmail/nossr50/util/random/RandomChanceUtil.java b/src/main/java/com/gmail/nossr50/util/random/RandomChanceUtil.java index 29866144d..885ff3a90 100644 --- a/src/main/java/com/gmail/nossr50/util/random/RandomChanceUtil.java +++ b/src/main/java/com/gmail/nossr50/util/random/RandomChanceUtil.java @@ -10,13 +10,14 @@ import com.gmail.nossr50.util.EventUtils; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.skills.SkillActivationType; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.text.DecimalFormat; import java.util.concurrent.ThreadLocalRandom; -public class RandomChanceUtil -{ - public static final DecimalFormat percent = new DecimalFormat("##0.00%"); +public class RandomChanceUtil { + public static final @NotNull DecimalFormat percent = new DecimalFormat("##0.00%"); //public static final DecimalFormat decimal = new DecimalFormat("##0.00"); public static final double LINEAR_CURVE_VAR = 100.0D; @@ -26,14 +27,12 @@ public class RandomChanceUtil * non-RNG skills just fire the cancellable event and succeed if they go uncancelled * * @param skillActivationType this value represents what kind of activation procedures this sub-skill uses - * @param subSkillType The identifier for this specific sub-skill - * @param player The owner of this sub-skill + * @param subSkillType The identifier for this specific sub-skill + * @param player The owner of this sub-skill * @return returns true if all conditions are met and the event is not cancelled */ - public static boolean isActivationSuccessful(SkillActivationType skillActivationType, SubSkillType subSkillType, Player player) - { - switch(skillActivationType) - { + public static boolean isActivationSuccessful(@NotNull SkillActivationType skillActivationType, @NotNull SubSkillType subSkillType, @Nullable Player player) { + switch (skillActivationType) { case RANDOM_LINEAR_100_SCALE_WITH_CAP: return checkRandomChanceExecutionSuccess(player, subSkillType, true); case RANDOM_STATIC_CHANCE: @@ -46,36 +45,8 @@ public class RandomChanceUtil } } - /** - * This method is the final step in determining if a Sub-Skill / Secondary Skill in mcMMO successfully activates either from chance or otherwise - * Random skills check for success based on numbers and then fire a cancellable event, if that event is not cancelled they succeed - * non-RNG skills just fire the cancellable event and succeed if they go uncancelled - * - * @param skillActivationType this value represents what kind of activation procedures this sub-skill uses - * @param subSkillType The identifier for this specific sub-skill - * @param player The owner of this sub-skill - * @return returns true if all conditions are met and the event is not cancelled - */ - public static boolean isActivationSuccessful(SkillActivationType skillActivationType, SubSkillType subSkillType, Player player, double resultModifier) - { - switch(skillActivationType) - { - case RANDOM_LINEAR_100_SCALE_WITH_CAP: - return checkRandomChanceExecutionSuccess(player, subSkillType, true); - case RANDOM_STATIC_CHANCE: - return checkRandomStaticChanceExecutionSuccess(player, subSkillType, resultModifier); - case ALWAYS_FIRES: - SubSkillEvent event = EventUtils.callSubSkillEvent(player, subSkillType); - return !event.isCancelled(); - default: - return false; - } - } - - public static double getActivationChance(SkillActivationType skillActivationType, SubSkillType subSkillType, Player player) - { - switch(skillActivationType) - { + public static double getActivationChance(@NotNull SkillActivationType skillActivationType, @NotNull SubSkillType subSkillType, @Nullable Player player) { + switch (skillActivationType) { case RANDOM_LINEAR_100_SCALE_WITH_CAP: return getRandomChanceExecutionSuccess(player, subSkillType, true); case RANDOM_STATIC_CHANCE: @@ -87,10 +58,10 @@ public class RandomChanceUtil /** * Checks whether or not the random chance succeeds + * * @return true if the random chance succeeds */ - public static boolean checkRandomChanceExecutionSuccess(Player player, PrimarySkillType primarySkillType, double chance) - { + public static boolean checkRandomChanceExecutionSuccess(@NotNull Player player, @NotNull PrimarySkillType primarySkillType, double chance) { //Check the odds chance *= 100; @@ -113,11 +84,11 @@ public class RandomChanceUtil /** * Used for stuff like Excavation, Fishing, etc... + * * @param randomChance * @return */ - public static boolean checkRandomChanceExecutionSuccess(RandomChanceSkillStatic randomChance, double resultModifier) - { + public static boolean checkRandomChanceExecutionSuccess(@NotNull RandomChanceSkillStatic randomChance, double resultModifier) { double chanceOfSuccess = calculateChanceOfSuccess(randomChance); //Check the odds @@ -126,16 +97,15 @@ public class RandomChanceUtil /** * Used for stuff like Excavation, Fishing, etc... + * * @param randomChance * @return */ - public static boolean checkRandomChanceExecutionSuccess(RandomChanceSkillStatic randomChance) - { + public static boolean checkRandomChanceExecutionSuccess(@NotNull RandomChanceSkillStatic randomChance) { return checkRandomChanceExecutionSuccess(randomChance, 1.0F); } - public static boolean checkRandomChanceExecutionSuccess(RandomChanceSkill randomChance) - { + public static boolean checkRandomChanceExecutionSuccess(@NotNull RandomChanceSkill randomChance) { double chanceOfSuccess = calculateChanceOfSuccess(randomChance); //Check the odds @@ -151,14 +121,15 @@ public class RandomChanceUtil /** * Gets the Static Chance for something to activate + * * @param randomChance * @return */ - public static double getRandomChanceExecutionChance(RandomChanceExecution randomChance) { + public static double getRandomChanceExecutionChance(@NotNull RandomChanceExecution randomChance) { return getChanceOfSuccess(randomChance.getXPos(), randomChance.getProbabilityCap(), LINEAR_CURVE_VAR); } - public static double getRandomChanceExecutionChance(RandomChanceStatic randomChance) { + public static double getRandomChanceExecutionChance(@NotNull RandomChanceStatic randomChance) { double chanceOfSuccess = getChanceOfSuccess(randomChance.getXPos(), randomChance.getProbabilityCap(), LINEAR_CURVE_VAR); chanceOfSuccess = addLuck(randomChance.isLucky(), chanceOfSuccess); @@ -171,7 +142,7 @@ public class RandomChanceUtil return chanceOfSuccess; }*/ - private static double calculateChanceOfSuccess(RandomChanceSkill randomChance) { + private static double calculateChanceOfSuccess(@NotNull RandomChanceSkill randomChance) { double skillLevel = randomChance.getSkillLevel(); double maximumProbability = randomChance.getProbabilityCap(); double maximumBonusLevel = randomChance.getMaximumBonusLevelCap(); @@ -192,7 +163,7 @@ public class RandomChanceUtil return chanceOfSuccess; } - private static double calculateChanceOfSuccess(RandomChanceSkillStatic randomChance) { + private static double calculateChanceOfSuccess(@NotNull RandomChanceSkillStatic randomChance) { double chanceOfSuccess = getChanceOfSuccess(randomChance.getXPos(), 100, 100); //Add Luck @@ -207,27 +178,23 @@ public class RandomChanceUtil * * @return the chance of success from 0-100 (100 = guaranteed) */ - private static int getChanceOfSuccess(double skillLevel, double maxProbability, double maxLevel) - { + private static int getChanceOfSuccess(double skillLevel, double maxProbability, double maxLevel) { //return (int) (x / (y / LINEAR_CURVE_VAR)); - return (int) (maxProbability * (skillLevel/maxLevel)); + return (int) (maxProbability * (skillLevel / maxLevel)); // max probability * (weight/maxlevel) = chance of success } - private static int getChanceOfSuccess(double x, double y) - { + private static int getChanceOfSuccess(double x, double y) { return (int) (x / (y / LINEAR_CURVE_VAR)); // max probability * (weight/maxlevel) = chance of success } - public static double getRandomChanceExecutionSuccess(Player player, SubSkillType subSkillType, boolean hasCap) - { + public static double getRandomChanceExecutionSuccess(@Nullable Player player, @NotNull SubSkillType subSkillType, boolean hasCap) { RandomChanceSkill rcs = new RandomChanceSkill(player, subSkillType, hasCap); return calculateChanceOfSuccess(rcs); } - public static double getRandomStaticChanceExecutionSuccess(Player player, SubSkillType subSkillType) - { + public static double getRandomStaticChanceExecutionSuccess(@Nullable Player player, @NotNull SubSkillType subSkillType) { try { return getRandomChanceExecutionChance(new RandomChanceSkillStatic(getStaticRandomChance(subSkillType), player, subSkillType)); } catch (InvalidStaticChance invalidStaticChance) { @@ -238,29 +205,24 @@ public class RandomChanceUtil return 0.1337; //Puts on shades } - public static boolean checkRandomChanceExecutionSuccess(Player player, SubSkillType subSkillType, boolean hasCap) - { + public static boolean checkRandomChanceExecutionSuccess(@Nullable Player player, @NotNull SubSkillType subSkillType, boolean hasCap) { return checkRandomChanceExecutionSuccess(new RandomChanceSkill(player, subSkillType, hasCap)); } - public static boolean checkRandomChanceExecutionSuccess(Player player, SubSkillType subSkillType) - { + public static boolean checkRandomChanceExecutionSuccess(@Nullable Player player, @NotNull SubSkillType subSkillType) { return checkRandomChanceExecutionSuccess(new RandomChanceSkill(player, subSkillType)); } - public static boolean checkRandomChanceExecutionSuccess(Player player, SubSkillType subSkillType, boolean hasCap, double resultModifier) - { + public static boolean checkRandomChanceExecutionSuccess(@Nullable Player player, @NotNull SubSkillType subSkillType, boolean hasCap, double resultModifier) { return checkRandomChanceExecutionSuccess(new RandomChanceSkill(player, subSkillType, hasCap, resultModifier)); } - public static boolean checkRandomChanceExecutionSuccess(Player player, SubSkillType subSkillType, double resultModifier) - { + public static boolean checkRandomChanceExecutionSuccess(@Nullable Player player, @NotNull SubSkillType subSkillType, double resultModifier) { return checkRandomChanceExecutionSuccess(new RandomChanceSkill(player, subSkillType, resultModifier)); } - public static boolean checkRandomStaticChanceExecutionSuccess(Player player, SubSkillType subSkillType, double resultModifier) - { + public static boolean checkRandomStaticChanceExecutionSuccess(@Nullable Player player, @NotNull SubSkillType subSkillType) { try { return checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(getStaticRandomChance(subSkillType), player, subSkillType)); } catch (InvalidStaticChance invalidStaticChance) { @@ -271,21 +233,15 @@ public class RandomChanceUtil return false; } - public static boolean checkRandomStaticChanceExecutionSuccess(Player player, SubSkillType subSkillType) - { - return checkRandomStaticChanceExecutionSuccess(player, subSkillType, 1.0F); - } - /** * Grabs static activation rolls for Secondary Abilities + * * @param subSkillType The secondary ability to grab properties of - * @throws InvalidStaticChance if the skill has no defined static chance this exception will be thrown and you should know you're a naughty boy * @return The static activation roll involved in the RNG calculation + * @throws InvalidStaticChance if the skill has no defined static chance this exception will be thrown and you should know you're a naughty boy */ - public static double getStaticRandomChance(SubSkillType subSkillType) throws InvalidStaticChance - { - switch(subSkillType) - { + public static double getStaticRandomChance(@NotNull SubSkillType subSkillType) throws InvalidStaticChance { + switch (subSkillType) { case AXES_ARMOR_IMPACT: return AdvancedConfig.getInstance().getImpactChance(); case AXES_GREATER_IMPACT: @@ -297,24 +253,12 @@ public class RandomChanceUtil } } - public static boolean sendSkillEvent(Player player, SubSkillType subSkillType, double activationChance) - { + public static boolean sendSkillEvent(Player player, SubSkillType subSkillType, double activationChance) { SubSkillRandomCheckEvent event = new SubSkillRandomCheckEvent(player, subSkillType, activationChance); return !event.isCancelled(); } - /*public static boolean treasureDropSuccessful(Player player, double dropChance, int activationChance) { - SubSkillRandomCheckEvent event = new SubSkillRandomCheckEvent(player, SubSkillType.EXCAVATION_ARCHAEOLOGY, dropChance / activationChance); - mcMMO.p.getServer().getPluginManager().callEvent(event); - return (event.getChance() * activationChance) > (Misc.getRandom().nextDouble() * activationChance) && !event.isCancelled(); - }*/ - - public static boolean isActivationSuccessful(SkillActivationType skillActivationType, AbstractSubSkill abstractSubSkill, Player player) - { - return isActivationSuccessful(skillActivationType, abstractSubSkill.getSubSkillType(), player); - } - - public static String[] calculateAbilityDisplayValues(SkillActivationType skillActivationType, Player player, SubSkillType subSkillType) { + public static String @NotNull [] calculateAbilityDisplayValues(@NotNull SkillActivationType skillActivationType, @NotNull Player player, @NotNull SubSkillType subSkillType) { double successChance = getActivationChance(skillActivationType, subSkillType, player); String[] displayValues = new String[2]; @@ -326,7 +270,7 @@ public class RandomChanceUtil return displayValues; } - public static String[] calculateAbilityDisplayValuesStatic(Player player, PrimarySkillType primarySkillType, double chance) { + public static String @NotNull [] calculateAbilityDisplayValuesStatic(@NotNull Player player, @NotNull PrimarySkillType primarySkillType, double chance) { RandomChanceStatic rcs = new RandomChanceStatic(chance, false); double successChance = getRandomChanceExecutionChance(rcs); @@ -343,7 +287,7 @@ public class RandomChanceUtil return displayValues; } - public static String[] calculateAbilityDisplayValuesCustom(SkillActivationType skillActivationType, Player player, SubSkillType subSkillType, double multiplier) { + public static String @NotNull [] calculateAbilityDisplayValuesCustom(@NotNull SkillActivationType skillActivationType, @NotNull Player player, @NotNull SubSkillType subSkillType, double multiplier) { double successChance = getActivationChance(skillActivationType, subSkillType, player); successChance *= multiplier; //Currently only used for graceful roll String[] displayValues = new String[2]; @@ -358,17 +302,15 @@ public class RandomChanceUtil return displayValues; } - public static double addLuck(Player player, PrimarySkillType primarySkillType, double chance) - { - if(Permissions.lucky(player, primarySkillType)) + public static double addLuck(@NotNull Player player, @NotNull PrimarySkillType primarySkillType, double chance) { + if (Permissions.lucky(player, primarySkillType)) return chance * 1.333D; else return chance; } - public static double addLuck(boolean isLucky, double chance) - { - if(isLucky) + public static double addLuck(boolean isLucky, double chance) { + if (isLucky) return chance * 1.333D; else return chance;