mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-04 11:03:43 +01:00 
			
		
		
		
	Add some tests for com.gmail.nossr50.util.random classes
This commit is contained in:
		@@ -37,7 +37,7 @@ public final class CommandRegistrationManager {
 | 
			
		||||
    private static void registerSkillCommands() {
 | 
			
		||||
        for (PrimarySkillType skill : PrimarySkillType.values()) {
 | 
			
		||||
            String commandName = skill.toString().toLowerCase(Locale.ENGLISH);
 | 
			
		||||
            String localizedName = skill.getName().toLowerCase(Locale.ENGLISH);
 | 
			
		||||
            String localizedName = skill.getLocalizedName().toLowerCase(Locale.ENGLISH);
 | 
			
		||||
 | 
			
		||||
            PluginCommand command;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -149,7 +149,7 @@ public class ExperienceBarManager {
 | 
			
		||||
    private void informPlayer(@NotNull ExperienceBarManager.@NotNull XPBarSettingTarget settingTarget, @Nullable PrimarySkillType skillType) {
 | 
			
		||||
        //Inform player of setting change
 | 
			
		||||
        if(settingTarget != XPBarSettingTarget.RESET) {
 | 
			
		||||
            NotificationManager.sendPlayerInformationChatOnlyPrefixed(mcMMOPlayer.getPlayer(), "Commands.XPBar.SettingChanged", skillType.getName(), settingTarget.toString());
 | 
			
		||||
            NotificationManager.sendPlayerInformationChatOnlyPrefixed(mcMMOPlayer.getPlayer(), "Commands.XPBar.SettingChanged", skillType.getLocalizedName(), settingTarget.toString());
 | 
			
		||||
        } else {
 | 
			
		||||
            NotificationManager.sendPlayerInformationChatOnlyPrefixed(mcMMOPlayer.getPlayer(), "Commands.XPBar.Reset");
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,6 @@
 | 
			
		||||
package com.gmail.nossr50.util.random;
 | 
			
		||||
 | 
			
		||||
import com.gmail.nossr50.config.AdvancedConfig;
 | 
			
		||||
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.util.Permissions;
 | 
			
		||||
import com.gmail.nossr50.util.player.UserManager;
 | 
			
		||||
@@ -11,109 +9,92 @@ import org.jetbrains.annotations.NotNull;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
 | 
			
		||||
public class RandomChanceSkill implements RandomChanceExecution {
 | 
			
		||||
 | 
			
		||||
    protected final @NotNull PrimarySkillType primarySkillType;
 | 
			
		||||
    protected final @NotNull SubSkillType subSkillType;
 | 
			
		||||
    protected final double probabilityCap;
 | 
			
		||||
    protected final boolean isLucky;
 | 
			
		||||
    protected int skillLevel;
 | 
			
		||||
    protected double resultModifier;
 | 
			
		||||
    protected final double resultModifier;
 | 
			
		||||
    protected final double maximumBonusLevelCap;
 | 
			
		||||
 | 
			
		||||
    public RandomChanceSkill(@Nullable Player player, @NotNull SubSkillType subSkillType, double resultModifier) {
 | 
			
		||||
        this.primarySkillType = subSkillType.getParentSkill();
 | 
			
		||||
        this.subSkillType = subSkillType;
 | 
			
		||||
        this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR;
 | 
			
		||||
 | 
			
		||||
        final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
 | 
			
		||||
        if (player != null && mcMMOPlayer != null) {
 | 
			
		||||
            this.skillLevel = mcMMOPlayer.getSkillLevel(primarySkillType);
 | 
			
		||||
            this.skillLevel = mcMMOPlayer.getSkillLevel(subSkillType.getParentSkill());
 | 
			
		||||
        } else {
 | 
			
		||||
            this.skillLevel = 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (player != null)
 | 
			
		||||
            isLucky = Permissions.lucky(player, primarySkillType);
 | 
			
		||||
            isLucky = Permissions.lucky(player, subSkillType.getParentSkill());
 | 
			
		||||
        else
 | 
			
		||||
            isLucky = false;
 | 
			
		||||
 | 
			
		||||
        this.resultModifier = resultModifier;
 | 
			
		||||
        this.maximumBonusLevelCap = RandomChanceUtil.getMaxBonusLevelCap(subSkillType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RandomChanceSkill(@Nullable Player player, @NotNull SubSkillType subSkillType) {
 | 
			
		||||
        this.primarySkillType = subSkillType.getParentSkill();
 | 
			
		||||
        this.subSkillType = subSkillType;
 | 
			
		||||
        this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR;
 | 
			
		||||
 | 
			
		||||
        final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
 | 
			
		||||
        if (player != null && mcMMOPlayer != null) {
 | 
			
		||||
            this.skillLevel = mcMMOPlayer.getSkillLevel(primarySkillType);
 | 
			
		||||
            this.skillLevel = mcMMOPlayer.getSkillLevel(subSkillType.getParentSkill());
 | 
			
		||||
        } else {
 | 
			
		||||
            this.skillLevel = 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (player != null)
 | 
			
		||||
            isLucky = Permissions.lucky(player, primarySkillType);
 | 
			
		||||
            isLucky = Permissions.lucky(player, subSkillType.getParentSkill());
 | 
			
		||||
        else
 | 
			
		||||
            isLucky = false;
 | 
			
		||||
 | 
			
		||||
        this.resultModifier = 1.0D;
 | 
			
		||||
        this.maximumBonusLevelCap = RandomChanceUtil.getMaxBonusLevelCap(subSkillType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RandomChanceSkill(@Nullable Player player, @NotNull SubSkillType subSkillType, boolean hasCap) {
 | 
			
		||||
        if (hasCap)
 | 
			
		||||
            this.probabilityCap = AdvancedConfig.getInstance().getMaximumProbability(subSkillType);
 | 
			
		||||
            this.probabilityCap = RandomChanceUtil.getMaximumProbability(subSkillType);
 | 
			
		||||
        else
 | 
			
		||||
            this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR;
 | 
			
		||||
 | 
			
		||||
        this.primarySkillType = subSkillType.getParentSkill();
 | 
			
		||||
        this.subSkillType = subSkillType;
 | 
			
		||||
 | 
			
		||||
        final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
 | 
			
		||||
        if (player != null && mcMMOPlayer != null) {
 | 
			
		||||
            this.skillLevel = mcMMOPlayer.getSkillLevel(primarySkillType);
 | 
			
		||||
            this.skillLevel = mcMMOPlayer.getSkillLevel(subSkillType.getParentSkill());
 | 
			
		||||
        } else {
 | 
			
		||||
            this.skillLevel = 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (player != null)
 | 
			
		||||
            isLucky = Permissions.lucky(player, primarySkillType);
 | 
			
		||||
            isLucky = Permissions.lucky(player, subSkillType.getParentSkill());
 | 
			
		||||
        else
 | 
			
		||||
            isLucky = false;
 | 
			
		||||
 | 
			
		||||
        this.resultModifier = 1.0D;
 | 
			
		||||
        this.maximumBonusLevelCap = RandomChanceUtil.getMaxBonusLevelCap(subSkillType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RandomChanceSkill(@Nullable Player player, @NotNull SubSkillType subSkillType, boolean hasCap, double resultModifier) {
 | 
			
		||||
        if (hasCap)
 | 
			
		||||
            this.probabilityCap = AdvancedConfig.getInstance().getMaximumProbability(subSkillType);
 | 
			
		||||
            this.probabilityCap = RandomChanceUtil.getMaximumProbability(subSkillType);
 | 
			
		||||
        else
 | 
			
		||||
            this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR;
 | 
			
		||||
 | 
			
		||||
        this.primarySkillType = subSkillType.getParentSkill();
 | 
			
		||||
        this.subSkillType = subSkillType;
 | 
			
		||||
 | 
			
		||||
        final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
 | 
			
		||||
        if (player != null && mcMMOPlayer != null) {
 | 
			
		||||
            this.skillLevel = mcMMOPlayer.getSkillLevel(primarySkillType);
 | 
			
		||||
            this.skillLevel = mcMMOPlayer.getSkillLevel(subSkillType.getParentSkill());
 | 
			
		||||
        } else {
 | 
			
		||||
            this.skillLevel = 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (player != null)
 | 
			
		||||
            isLucky = Permissions.lucky(player, primarySkillType);
 | 
			
		||||
            isLucky = Permissions.lucky(player, subSkillType.getParentSkill());
 | 
			
		||||
        else
 | 
			
		||||
            isLucky = false;
 | 
			
		||||
 | 
			
		||||
        this.resultModifier = resultModifier;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The subskill corresponding to this RandomChanceSkill
 | 
			
		||||
     *
 | 
			
		||||
     * @return this subskill
 | 
			
		||||
     */
 | 
			
		||||
    public @NotNull SubSkillType getSubSkill() {
 | 
			
		||||
        return subSkillType;
 | 
			
		||||
        this.maximumBonusLevelCap = RandomChanceUtil.getMaxBonusLevelCap(subSkillType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -142,7 +123,7 @@ public class RandomChanceSkill implements RandomChanceExecution {
 | 
			
		||||
     * @return the maximum bonus from skill level for this skill
 | 
			
		||||
     */
 | 
			
		||||
    public double getMaximumBonusLevelCap() {
 | 
			
		||||
        return AdvancedConfig.getInstance().getMaxBonusLevel(subSkillType);
 | 
			
		||||
        return maximumBonusLevelCap;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -173,8 +154,4 @@ public class RandomChanceSkill implements RandomChanceExecution {
 | 
			
		||||
    public double getResultModifier() {
 | 
			
		||||
        return resultModifier;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setResultModifier(double resultModifier) {
 | 
			
		||||
        this.resultModifier = resultModifier;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,6 @@ package com.gmail.nossr50.util.random;
 | 
			
		||||
import com.gmail.nossr50.config.AdvancedConfig;
 | 
			
		||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
 | 
			
		||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
 | 
			
		||||
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
 | 
			
		||||
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillEvent;
 | 
			
		||||
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillRandomCheckEvent;
 | 
			
		||||
import com.gmail.nossr50.util.EventUtils;
 | 
			
		||||
@@ -20,6 +19,7 @@ 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;
 | 
			
		||||
    public static final double LUCKY_MODIFIER = 1.333D;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is the final step in determining if a Sub-Skill / Secondary Skill in mcMMO successfully activates either from chance or otherwise
 | 
			
		||||
@@ -142,7 +142,7 @@ public class RandomChanceUtil {
 | 
			
		||||
        return chanceOfSuccess;
 | 
			
		||||
    }*/
 | 
			
		||||
 | 
			
		||||
    private static double calculateChanceOfSuccess(@NotNull RandomChanceSkill randomChance) {
 | 
			
		||||
    public static double calculateChanceOfSuccess(@NotNull RandomChanceSkill randomChance) {
 | 
			
		||||
        double skillLevel = randomChance.getSkillLevel();
 | 
			
		||||
        double maximumProbability = randomChance.getProbabilityCap();
 | 
			
		||||
        double maximumBonusLevel = randomChance.getMaximumBonusLevelCap();
 | 
			
		||||
@@ -163,7 +163,7 @@ public class RandomChanceUtil {
 | 
			
		||||
        return chanceOfSuccess;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static double calculateChanceOfSuccess(@NotNull RandomChanceSkillStatic randomChance) {
 | 
			
		||||
    public static double calculateChanceOfSuccess(@NotNull RandomChanceSkillStatic randomChance) {
 | 
			
		||||
        double chanceOfSuccess = getChanceOfSuccess(randomChance.getXPos(), 100, 100);
 | 
			
		||||
 | 
			
		||||
        //Add Luck
 | 
			
		||||
@@ -304,15 +304,23 @@ public class RandomChanceUtil {
 | 
			
		||||
 | 
			
		||||
    public static double addLuck(@NotNull Player player, @NotNull PrimarySkillType primarySkillType, double chance) {
 | 
			
		||||
        if (Permissions.lucky(player, primarySkillType))
 | 
			
		||||
            return chance * 1.333D;
 | 
			
		||||
            return chance * LUCKY_MODIFIER;
 | 
			
		||||
        else
 | 
			
		||||
            return chance;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static double addLuck(boolean isLucky, double chance) {
 | 
			
		||||
        if (isLucky)
 | 
			
		||||
            return chance * 1.333D;
 | 
			
		||||
            return chance * LUCKY_MODIFIER;
 | 
			
		||||
        else
 | 
			
		||||
            return chance;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static double getMaximumProbability(@NotNull SubSkillType subSkillType) {
 | 
			
		||||
        return AdvancedConfig.getInstance().getMaximumProbability(subSkillType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static double getMaxBonusLevelCap(@NotNull SubSkillType subSkillType) {
 | 
			
		||||
        return AdvancedConfig.getInstance().getMaxBonusLevel(subSkillType);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -93,7 +93,7 @@ public class ScoreboardManager {
 | 
			
		||||
            int i = 0;
 | 
			
		||||
            for (PrimarySkillType type : PrimarySkillType.values()) {
 | 
			
		||||
                // Include child skills
 | 
			
		||||
                skillLabelBuilder.put(type, getShortenedName(colors.get(i) + type.getName(), false));
 | 
			
		||||
                skillLabelBuilder.put(type, getShortenedName(colors.get(i) + type.getLocalizedName(), false));
 | 
			
		||||
 | 
			
		||||
                if (type.getAbility() != null) {
 | 
			
		||||
                    abilityLabelBuilder.put(type.getAbility(), getShortenedName(colors.get(i) + type.getAbility().getLocalizedName()));
 | 
			
		||||
@@ -115,7 +115,7 @@ public class ScoreboardManager {
 | 
			
		||||
        else {
 | 
			
		||||
            for (PrimarySkillType type : PrimarySkillType.values()) {
 | 
			
		||||
                // Include child skills
 | 
			
		||||
                skillLabelBuilder.put(type, getShortenedName(ChatColor.GREEN + type.getName()));
 | 
			
		||||
                skillLabelBuilder.put(type, getShortenedName(ChatColor.GREEN + type.getLocalizedName()));
 | 
			
		||||
 | 
			
		||||
                if (type.getAbility() != null) {
 | 
			
		||||
                    abilityLabelBuilder.put(type.getAbility(), formatAbility(type.getAbility().getLocalizedName()));
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,6 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
 | 
			
		||||
import com.gmail.nossr50.events.skills.SkillActivationPerkEvent;
 | 
			
		||||
import com.gmail.nossr50.util.Permissions;
 | 
			
		||||
import com.gmail.nossr50.util.player.UserManager;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user