Refactoring to make my life easier

This commit is contained in:
nossr50
2018-12-29 05:24:55 -08:00
parent 35368db05d
commit 0d260a74c9
126 changed files with 1471 additions and 1408 deletions

View File

@@ -4,6 +4,7 @@ import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.AnimalTamer;
@@ -11,12 +12,10 @@ import org.bukkit.entity.Animals;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Guardian;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wolf;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@@ -29,7 +28,6 @@ import org.bukkit.projectiles.ProjectileSource;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.XPGainReason;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
@@ -66,7 +64,7 @@ public final class CombatUtils {
Map<DamageModifier, Double> modifiers = getModifiers(event);
if (swordsManager.canActivateAbility()) {
mcMMOPlayer.checkAbilityActivation(SkillType.SWORDS);
mcMMOPlayer.checkAbilityActivation(PrimarySkill.SWORDS);
}
if (swordsManager.canUseBleed()) {
@@ -77,7 +75,7 @@ public final class CombatUtils {
swordsManager.serratedStrikes(target, initialDamage, modifiers);
}
startGainXp(mcMMOPlayer, target, SkillType.SWORDS);
startGainXp(mcMMOPlayer, target, PrimarySkill.SWORDS);
}
private static void processAxeCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) {
@@ -93,7 +91,7 @@ public final class CombatUtils {
AxesManager axesManager = mcMMOPlayer.getAxesManager();
if (axesManager.canActivateAbility()) {
mcMMOPlayer.checkAbilityActivation(SkillType.AXES);
mcMMOPlayer.checkAbilityActivation(PrimarySkill.AXES);
}
if (axesManager.canUseAxeMastery()) {
@@ -116,7 +114,7 @@ public final class CombatUtils {
}
applyScaledModifiers(initialDamage, finalDamage, event);
startGainXp(mcMMOPlayer, target, SkillType.AXES);
startGainXp(mcMMOPlayer, target, PrimarySkill.AXES);
}
private static void processUnarmedCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) {
@@ -131,7 +129,7 @@ public final class CombatUtils {
UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager();
if (unarmedManager.canActivateAbility()) {
mcMMOPlayer.checkAbilityActivation(SkillType.UNARMED);
mcMMOPlayer.checkAbilityActivation(PrimarySkill.UNARMED);
}
if (unarmedManager.canUseIronArm()) {
@@ -147,7 +145,7 @@ public final class CombatUtils {
}
applyScaledModifiers(initialDamage, finalDamage, event);
startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
startGainXp(mcMMOPlayer, target, PrimarySkill.UNARMED);
}
private static void processTamingCombat(LivingEntity target, Player master, Wolf wolf, EntityDamageByEntityEvent event) {
@@ -172,7 +170,7 @@ public final class CombatUtils {
}
applyScaledModifiers(initialDamage, finalDamage, event);
startGainXp(mcMMOPlayer, target, SkillType.TAMING);
startGainXp(mcMMOPlayer, target, PrimarySkill.TAMING);
}
private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Arrow arrow) {
@@ -182,7 +180,7 @@ public final class CombatUtils {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager();
if (target instanceof Player && SkillType.UNARMED.getPVPEnabled()) {
if (target instanceof Player && PrimarySkill.UNARMED.getPVPEnabled()) {
UnarmedManager unarmedManager = UserManager.getPlayer((Player) target).getUnarmedManager();
if (unarmedManager.canDeflect()) {
@@ -209,7 +207,7 @@ public final class CombatUtils {
archeryManager.distanceXpBonus(target, arrow);
applyScaledModifiers(initialDamage, finalDamage, event);
startGainXp(mcMMOPlayer, target, SkillType.ARCHERY, arrow.getMetadata(mcMMO.bowForceKey).get(0).asDouble());
startGainXp(mcMMOPlayer, target, PrimarySkill.ARCHERY, arrow.getMetadata(mcMMO.bowForceKey).get(0).asDouble());
}
/**
@@ -247,29 +245,29 @@ public final class CombatUtils {
}
if (ItemUtils.isSword(heldItem)) {
if (!SkillType.SWORDS.shouldProcess(target)) {
if (!PrimarySkill.SWORDS.shouldProcess(target)) {
return;
}
if (SkillType.SWORDS.getPermissions(player)) {
if (PrimarySkill.SWORDS.getPermissions(player)) {
processSwordCombat(target, player, event);
}
}
else if (ItemUtils.isAxe(heldItem)) {
if (!SkillType.AXES.shouldProcess(target)) {
if (!PrimarySkill.AXES.shouldProcess(target)) {
return;
}
if (SkillType.AXES.getPermissions(player)) {
if (PrimarySkill.AXES.getPermissions(player)) {
processAxeCombat(target, player, event);
}
}
else if (ItemUtils.isUnarmed(heldItem)) {
if (!SkillType.UNARMED.shouldProcess(target)) {
if (!PrimarySkill.UNARMED.shouldProcess(target)) {
return;
}
if (SkillType.UNARMED.getPermissions(player)) {
if (PrimarySkill.UNARMED.getPermissions(player)) {
processUnarmedCombat(target, player, event);
}
}
@@ -279,10 +277,10 @@ public final class CombatUtils {
Wolf wolf = (Wolf) damager;
AnimalTamer tamer = wolf.getOwner();
if (tamer != null && tamer instanceof Player && SkillType.TAMING.shouldProcess(target)) {
if (tamer != null && tamer instanceof Player && PrimarySkill.TAMING.shouldProcess(target)) {
Player master = (Player) tamer;
if (!Misc.isNPCEntity(master) && SkillType.TAMING.getPermissions(master)) {
if (!Misc.isNPCEntity(master) && PrimarySkill.TAMING.getPermissions(master)) {
processTamingCombat(target, master, wolf, event);
}
}
@@ -291,14 +289,14 @@ public final class CombatUtils {
Arrow arrow = (Arrow) damager;
ProjectileSource projectileSource = arrow.getShooter();
if (projectileSource != null && projectileSource instanceof Player && SkillType.ARCHERY.shouldProcess(target)) {
if (projectileSource != null && projectileSource instanceof Player && PrimarySkill.ARCHERY.shouldProcess(target)) {
Player player = (Player) projectileSource;
if (!Misc.isNPCEntity(player) && SkillType.ARCHERY.getPermissions(player)) {
if (!Misc.isNPCEntity(player) && PrimarySkill.ARCHERY.getPermissions(player)) {
processArcheryCombat(target, player, event, arrow);
}
if (target.getType() != EntityType.CREEPER && !Misc.isNPCEntity(player) && SkillType.TAMING.getPermissions(player)) {
if (target.getType() != EntityType.CREEPER && !Misc.isNPCEntity(player) && PrimarySkill.TAMING.getPermissions(player)) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
TamingManager tamingManager = mcMMOPlayer.getTamingManager();
tamingManager.attackTarget(target);
@@ -323,7 +321,7 @@ public final class CombatUtils {
}
if (ItemUtils.isSword(player.getInventory().getItemInMainHand())) {
if (!SkillType.SWORDS.shouldProcess(target)) {
if (!PrimarySkill.SWORDS.shouldProcess(target)) {
return;
}
@@ -399,7 +397,7 @@ public final class CombatUtils {
* @param damage The initial damage amount
* @param type The type of skill being used
*/
public static void applyAbilityAoE(Player attacker, LivingEntity target, double damage, Map<DamageModifier, Double> modifiers, SkillType type) {
public static void applyAbilityAoE(Player attacker, LivingEntity target, double damage, Map<DamageModifier, Double> modifiers, PrimarySkill type) {
int numberOfTargets = getTier(attacker.getInventory().getItemInMainHand()); // The higher the weapon tier, the more targets you hit
double damageAmount = Math.max(damage, 1);
@@ -440,8 +438,8 @@ public final class CombatUtils {
}
}
public static void startGainXp(McMMOPlayer mcMMOPlayer, LivingEntity target, SkillType skillType) {
startGainXp(mcMMOPlayer, target, skillType, 1.0);
public static void startGainXp(McMMOPlayer mcMMOPlayer, LivingEntity target, PrimarySkill primarySkill) {
startGainXp(mcMMOPlayer, target, primarySkill, 1.0);
}
/**
@@ -449,9 +447,9 @@ public final class CombatUtils {
*
* @param mcMMOPlayer The attacking player
* @param target The defending entity
* @param skillType The skill being used
* @param primarySkill The skill being used
*/
private static void startGainXp(McMMOPlayer mcMMOPlayer, LivingEntity target, SkillType skillType, double multiplier) {
private static void startGainXp(McMMOPlayer mcMMOPlayer, LivingEntity target, PrimarySkill primarySkill, double multiplier) {
double baseXP = 0;
XPGainReason xpGainReason;
@@ -518,7 +516,7 @@ public final class CombatUtils {
baseXP *= multiplier;
if (baseXP != 0) {
new AwardCombatXpTask(mcMMOPlayer, skillType, baseXP, target, xpGainReason).runTaskLater(mcMMO.p, 0);
new AwardCombatXpTask(mcMMOPlayer, primarySkill, baseXP, target, xpGainReason).runTaskLater(mcMMO.p, 0);
}
}

View File

@@ -1,9 +1,9 @@
package com.gmail.nossr50.util.skills;
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.Permissions;
public final class PerksUtils {
@@ -44,7 +44,7 @@ public final class PerksUtils {
return ticks;
}
public static float handleXpPerks(Player player, float xp, SkillType skill) {
public static float handleXpPerks(Player player, float xp, PrimarySkill skill) {
if (Permissions.customXpBoost(player, skill)) {
xp *= ExperienceConfig.getInstance().getCustomXpPerkBoost();
}
@@ -74,10 +74,10 @@ public final class PerksUtils {
* Calculate activation chance for a skill.
*
* @param player Player to check the activation chance for
* @param skill SkillType to check the activation chance of
* @param skill PrimarySkill to check the activation chance of
* @return the activation chance with "lucky perk" accounted for
*/
public static int handleLuckyPerks(Player player, SkillType skill) {
public static int handleLuckyPerks(Player player, PrimarySkill skill) {
if (Permissions.lucky(player, skill)) {
return LUCKY_SKILL_ACTIVATION_CHANCE;
}

View File

@@ -1,7 +1,7 @@
package com.gmail.nossr50.util.skills;
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.SubSkill;
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
import java.util.HashMap;
@@ -19,13 +19,13 @@ import java.util.HashMap;
//TODO: Propagate events when milestones are achieved
//TODO: Update existing parts of the codebase to use this where appropriate
public class SkillMilestoneManager {
public static final HashMap<SkillType, SecondaryAbility> subskillMilestones;
public static final HashMap<PrimarySkill, SubSkill> subskillMilestones;
static {
//Init our maps
subskillMilestones = new HashMap<>();
for(SkillType skillType : SkillType.values())
for(PrimarySkill primarySkill : PrimarySkill.values())
{
//TODO: Setup these values
}

View File

@@ -4,11 +4,11 @@ import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.secondaryabilities.SecondaryAbilityEvent;
import com.gmail.nossr50.events.skills.secondaryabilities.SecondaryAbilityWeightedActivationCheckEvent;
import com.gmail.nossr50.datatypes.skills.SuperAbility;
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
import com.gmail.nossr50.datatypes.skills.SubSkill;
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillEvent;
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillWeightedActivationCheckEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.EventUtils;
@@ -32,7 +32,7 @@ import java.util.ArrayList;
import java.util.List;
public class SkillUtils {
public static int handleFoodSkills(Player player, SkillType skill, int eventFoodLevel, int baseLevel, int maxLevel, int rankChange) {
public static int handleFoodSkills(Player player, PrimarySkill skill, int eventFoodLevel, int baseLevel, int maxLevel, int rankChange) {
int skillLevel = UserManager.getPlayer(player).getSkillLevel(skill);
int currentFoodLevel = player.getFoodLevel();
@@ -80,7 +80,7 @@ public class SkillUtils {
* @return true if this is a valid skill, false otherwise
*/
public static boolean isSkill(String skillName) {
return Config.getInstance().getLocale().equalsIgnoreCase("en_US") ? SkillType.getSkill(skillName) != null : isLocalizedSkill(skillName);
return Config.getInstance().getLocale().equalsIgnoreCase("en_US") ? PrimarySkill.getSkill(skillName) != null : isLocalizedSkill(skillName);
}
public static void sendSkillMessage(Player player, String message) {
@@ -130,7 +130,7 @@ public class SkillUtils {
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
SkillType skill = mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER) ? SkillType.MINING : SkillType.EXCAVATION;
PrimarySkill skill = mcMMOPlayer.getAbilityMode(SuperAbility.SUPER_BREAKER) ? PrimarySkill.MINING : PrimarySkill.EXCAVATION;
int ticks = PerksUtils.handleActivationPerks(player, 2 + (mcMMOPlayer.getSkillLevel(skill) / AdvancedConfig.getInstance().getAbilityLength()), skill.getAbility().getMaxLength()) * Misc.TICK_CONVERSION_FACTOR;
PotionEffect abilityBuff = new PotionEffect(PotionEffectType.FAST_DIGGING, duration + ticks, amplifier + 10);
@@ -199,7 +199,7 @@ public class SkillUtils {
/**
* Checks whether or not the given skill succeeds
* @param skillAbility The ability corresponding to this check
* @param subSkill The ability corresponding to this check
* @param player The player whose skill levels we are checking against
* @param skillLevel The skill level of the corresponding skill
* @param activationChance used to determine activation chance
@@ -207,9 +207,9 @@ public class SkillUtils {
* @param maxLevel maximum skill level bonus
* @return true if random chance succeeds and the event isn't cancelled
*/
private static boolean performRandomSkillCheck(SecondaryAbility skillAbility, Player player, int skillLevel, int activationChance, double maxChance, int maxLevel) {
private static boolean performRandomSkillCheck(SubSkill subSkill, Player player, int skillLevel, int activationChance, double maxChance, int maxLevel) {
double chance = (maxChance / maxLevel) * Math.min(skillLevel, maxLevel) / activationChance;
return performRandomSkillCheckStatic(skillAbility, player, activationChance, chance);
return performRandomSkillCheckStatic(subSkill, player, activationChance, chance);
}
/**
@@ -224,34 +224,34 @@ public class SkillUtils {
* Random skills check for success based on numbers and then fire a cancellable event, if that event is not cancelled they succeed
* All other skills just fire the cancellable event and succeed if it is not cancelled
*
* @param skillAbility The identifier for this specific sub-skill
* @param subSkill The identifier for this specific sub-skill
* @param player The owner of this sub-skill
* @param skill The identifier for the parent of our sub-skill
* @param activationChance This is the value that we roll against, 100 is normal, and 75 is for lucky perk
* @param secondarySkillActivationType this value represents what kind of activation procedures this sub-skill uses
* @param subskillActivationType this value represents what kind of activation procedures this sub-skill uses
* @return returns true if all conditions are met and they event is not cancelled
*/
public static boolean isActivationSuccessful(SecondarySkillActivationType secondarySkillActivationType, SecondaryAbility skillAbility, Player player,
SkillType skill, int skillLevel, int activationChance)
public static boolean isActivationSuccessful(SubSkillActivationType subskillActivationType, SubSkill subSkill, Player player,
PrimarySkill skill, int skillLevel, int activationChance)
{
//Maximum chance to succeed
double maxChance = AdvancedConfig.getInstance().getMaxChance(skillAbility);
double maxChance = AdvancedConfig.getInstance().getMaxChance(subSkill);
//Maximum roll we can make
int maxBonusLevel = AdvancedConfig.getInstance().getMaxBonusLevel(skillAbility);
int maxBonusLevel = AdvancedConfig.getInstance().getMaxBonusLevel(subSkill);
switch(secondarySkillActivationType)
switch(subskillActivationType)
{
//100 Skill = Guaranteed
case RANDOM_LINEAR_100_SCALE_NO_CAP:
return performRandomSkillCheck(skillAbility, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), 100.0D, 100);
return performRandomSkillCheck(subSkill, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), 100.0D, 100);
case RANDOM_LINEAR_100_SCALE_WITH_CAP:
return performRandomSkillCheck(skillAbility, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), AdvancedConfig.getInstance().getMaxChance(skillAbility), AdvancedConfig.getInstance().getMaxBonusLevel(skillAbility));
return performRandomSkillCheck(subSkill, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), AdvancedConfig.getInstance().getMaxChance(subSkill), AdvancedConfig.getInstance().getMaxBonusLevel(subSkill));
case RANDOM_STATIC_CHANCE:
//Grab the static activation chance of this skill
double staticRoll = getSecondaryAbilityStaticChance(skillAbility) / activationChance;
return performRandomSkillCheckStatic(skillAbility, player, activationChance, staticRoll);
double staticRoll = getSecondaryAbilityStaticChance(subSkill) / activationChance;
return performRandomSkillCheckStatic(subSkill, player, activationChance, staticRoll);
case ALWAYS_FIRES:
SecondaryAbilityEvent event = EventUtils.callSecondaryAbilityEvent(player, skillAbility);
SubSkillEvent event = EventUtils.callSubSkillEvent(player, subSkill);
return !event.isCancelled();
default:
return false;
@@ -260,18 +260,18 @@ public class SkillUtils {
/**
* Grabs static activation rolls for Secondary Abilities
* @param secondaryAbility The secondary ability to grab properties of
* @param subSkill The secondary ability to grab properties of
* @return The static activation roll involved in the RNG calculation
*/
public static double getSecondaryAbilityStaticChance(SecondaryAbility secondaryAbility)
public static double getSecondaryAbilityStaticChance(SubSkill subSkill)
{
switch(secondaryAbility)
switch(subSkill)
{
case ARMOR_IMPACT:
case AXES_ARMOR_IMPACT:
return AdvancedConfig.getInstance().getImpactChance();
case GREATER_IMPACT:
case AXES_GREATER_IMPACT:
return AdvancedConfig.getInstance().getGreaterImpactChance();
case FAST_FOOD:
case TAMING_FAST_FOOD:
return AdvancedConfig.getInstance().getFastFoodChance();
default:
return 100.0D;
@@ -280,26 +280,26 @@ public class SkillUtils {
/**
* Used to determine whether or not a sub-skill activates from random chance (using static values)
* @param skillAbility The identifier for this specific sub-skill
* @param subSkill The identifier for this specific sub-skill
* @param player The owner of this sub-skill
* @param activationChance This is the value that we roll against, 100 is normal, and 75 is for lucky perk
* @param chance This is the static modifier for our random calculations
* @return true if random chance was successful and the event wasn't cancelled
*/
private static boolean performRandomSkillCheckStatic(SecondaryAbility skillAbility, Player player, int activationChance, double chance) {
SecondaryAbilityWeightedActivationCheckEvent event = new SecondaryAbilityWeightedActivationCheckEvent(player, skillAbility, chance);
private static boolean performRandomSkillCheckStatic(SubSkill subSkill, Player player, int activationChance, double chance) {
SubSkillWeightedActivationCheckEvent event = new SubSkillWeightedActivationCheckEvent(player, subSkill, chance);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return (event.getChance() * activationChance) > Misc.getRandom().nextInt(activationChance) && !event.isCancelled();
}
public static boolean treasureDropSuccessful(Player player, double dropChance, int activationChance) {
SecondaryAbilityWeightedActivationCheckEvent event = new SecondaryAbilityWeightedActivationCheckEvent(player, SecondaryAbility.EXCAVATION_TREASURE_HUNTER, dropChance / activationChance);
SubSkillWeightedActivationCheckEvent event = new SubSkillWeightedActivationCheckEvent(player, SubSkill.EXCAVATION_TREASURE_HUNTER, dropChance / activationChance);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return (event.getChance() * activationChance) > (Misc.getRandom().nextDouble() * activationChance) && !event.isCancelled();
}
private static boolean isLocalizedSkill(String skillName) {
for (SkillType skill : SkillType.values()) {
for (PrimarySkill skill : PrimarySkill.values()) {
if (skillName.equalsIgnoreCase(LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".SkillName"))) {
return true;
}

View File

@@ -3,7 +3,7 @@ package com.gmail.nossr50.util.skills;
/**
* Defines the type of random calculations to use with a given skill
*/
public enum SecondarySkillActivationType {
public enum SubSkillActivationType {
RANDOM_LINEAR_100_SCALE_NO_CAP, //A skill level of 100 would guarantee the proc with this
RANDOM_LINEAR_100_SCALE_WITH_CAP, //This one is based on a scale of 1-100 but with a specified cap for max bonus
RANDOM_STATIC_CHANCE, //The skill always has a SPECIFIC chance to succeed