From be44c0e417768c847b6460bea03587cd958847f4 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 9 Apr 2021 11:13:27 -0700 Subject: [PATCH] Update SkillTools --- .../com/gmail/nossr50/api/ExperienceAPI.java | 2 +- .../nossr50/database/SQLDatabaseManager.java | 2 +- .../nossr50/datatypes/player/McMMOPlayer.java | 14 ++-- .../datatypes/player/PlayerProfile.java | 2 +- .../datatypes/skills/PrimarySkillType.java | 5 +- .../datatypes/skills/SuperAbilityType.java | 2 +- .../skills/subskills/acrobatics/Roll.java | 2 +- .../nossr50/listeners/BlockListener.java | 12 +-- .../nossr50/listeners/PlayerListener.java | 12 +-- .../commands/McrankCommandDisplayTask.java | 2 +- .../nossr50/util/commands/CommandUtils.java | 5 +- .../util/experience/FormulaManager.java | 2 +- .../util/scoreboards/ScoreboardWrapper.java | 5 +- .../nossr50/util/skills/CombatUtils.java | 12 +-- .../gmail/nossr50/util/skills/SkillTools.java | 73 +++++++++++-------- .../nossr50/util/skills/SmeltingTracker.java | 3 +- 16 files changed, 81 insertions(+), 74 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java index 81873a699..bc15b7043 100644 --- a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java +++ b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java @@ -802,7 +802,7 @@ public final class ExperienceAPI { * @throws InvalidSkillException if the given skill is not valid */ public static int getLevelCap(String skillType) { - return mcMMO.p.getGeneralConfig().getLevelCap(getSkillType(skillType)); + return mcMMO.p.getSkillTools().getLevelCap(getSkillType(skillType)); } /** diff --git a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java index c218401a2..462fd6d66 100644 --- a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java @@ -936,7 +936,7 @@ public final class SQLDatabaseManager implements DatabaseManager { if (mcMMO.p.getGeneralConfig().getTruncateSkills()) { for (PrimarySkillType skill : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) { - int cap = mcMMO.p.getGeneralConfig().getLevelCap(skill); + int cap = mcMMO.p.getSkillTools().getLevelCap(skill); if (cap != Integer.MAX_VALUE) { statement = connection.prepareStatement("UPDATE `" + tablePrefix + "skills` SET `" + skill.name().toLowerCase(Locale.ENGLISH) + "` = " + cap + " WHERE `" + skill.name().toLowerCase(Locale.ENGLISH) + "` > " + cap); statement.executeUpdate(); diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index 64f482fea..e851fb110 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -252,7 +252,7 @@ public class McMMOPlayer implements Identified { NotificationManager.sendPlayerInformationChatOnly(player, "LevelCap.PowerLevel", String.valueOf(mcMMO.p.getGeneralConfig().getPowerLevelCap())); } else if(hasReachedLevelCap(primarySkillType)) { NotificationManager.sendPlayerInformationChatOnly(player, "LevelCap.Skill", - String.valueOf(mcMMO.p.getGeneralConfig().getLevelCap(primarySkillType)), + String.valueOf(mcMMO.p.getSkillTools().getLevelCap(primarySkillType)), mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType)); } @@ -570,7 +570,7 @@ public class McMMOPlayer implements Identified { int powerLevel = 0; for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) { - if (Permissions.skillEnabled(player, primarySkillType)) { + if (mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, primarySkillType)) { powerLevel += getSkillLevel(primarySkillType); } } @@ -588,7 +588,7 @@ public class McMMOPlayer implements Identified { if(hasReachedPowerLevelCap()) return true; - return getSkillLevel(primarySkillType) >= mcMMO.p.getGeneralConfig().getLevelCap(primarySkillType); + return getSkillLevel(primarySkillType) >= mcMMO.p.getSkillTools().getLevelCap(primarySkillType); } /** @@ -616,7 +616,7 @@ public class McMMOPlayer implements Identified { float splitXp = xp / parentSkills.size(); for (PrimarySkillType parentSkill : parentSkills) { - if (Permissions.skillEnabled(player, parentSkill)) { + if (mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, parentSkill)) { beginXpGain(parentSkill, splitXp, xpGainReason, xpGainSource); } } @@ -660,7 +660,7 @@ public class McMMOPlayer implements Identified { * @param xp Experience amount to add */ public void applyXpGain(PrimarySkillType primarySkillType, float xp, XPGainReason xpGainReason, XPGainSource xpGainSource) { - if (!Permissions.skillEnabled(player, primarySkillType)) { + if (!mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, primarySkillType)) { return; } @@ -837,7 +837,7 @@ public class McMMOPlayer implements Identified { */ private float modifyXpGain(PrimarySkillType primarySkillType, float xp) { //TODO: A rare situation can occur where the default Power Level cap can prevent a player with one skill edited to something silly like Integer.MAX_VALUE from gaining XP in any skill, we may need to represent power level with another data type - if ((mcMMO.p.getGeneralConfig().getLevelCap(primarySkillType) <= getSkillLevel(primarySkillType)) + if ((mcMMO.p.getSkillTools().getLevelCap(primarySkillType) <= getSkillLevel(primarySkillType)) || (mcMMO.p.getGeneralConfig().getPowerLevelCap() <= getPowerLevel())) { return 0; } @@ -953,7 +953,7 @@ public class McMMOPlayer implements Identified { } public void processAbilityActivation(@NotNull PrimarySkillType primarySkillType) { - if (!Permissions.skillEnabled(getPlayer(), primarySkillType)) { + if (!mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(getPlayer(), primarySkillType)) { return; } diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java index 0b2b3cbb9..3fc0d6d70 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java @@ -432,7 +432,7 @@ public class PlayerProfile { int sum = 0; for (PrimarySkillType parent : parents) { - sum += Math.min(getSkillLevel(parent), mcMMO.p.getGeneralConfig().getLevelCap(parent)); + sum += Math.min(getSkillLevel(parent), mcMMO.p.getSkillTools().getLevelCap(parent)); } return sum / parents.size(); diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/PrimarySkillType.java b/src/main/java/com/gmail/nossr50/datatypes/skills/PrimarySkillType.java index 24f215191..cad2245c1 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/PrimarySkillType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/PrimarySkillType.java @@ -8,6 +8,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; import java.util.List; public enum PrimarySkillType { @@ -140,7 +141,7 @@ public enum PrimarySkillType { */ @Deprecated public List getSkillAbilities() { - return mcMMO.p.getSkillTools().getSubSkills(this); + return new ArrayList<>(mcMMO.p.getSkillTools().getSubSkills(this)); } /** @@ -217,7 +218,7 @@ public enum PrimarySkillType { */ @Deprecated public boolean getPermissions(Player player) { - return Permissions.skillEnabled(player, this); + return mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, this); } /** diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/SuperAbilityType.java b/src/main/java/com/gmail/nossr50/datatypes/skills/SuperAbilityType.java index 72c9fee69..6e4de8d78 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/SuperAbilityType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/SuperAbilityType.java @@ -111,7 +111,7 @@ public enum SuperAbilityType { } public int getCooldown() { - return mcMMO.p.getGeneralConfig().getCooldown(this); + return mcMMO.p.getSkillTools().getSuperAbilityCooldown(this); } public int getMaxLength() { 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 1a1c99fc9..64a3a14fb 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 @@ -83,7 +83,7 @@ public class Roll extends AcrobaticsSubSkill { entityDamageEvent.setCancelled(true); return true; } - } else if(Permissions.skillEnabled(player, PrimarySkillType.ACROBATICS)) { + } else if(mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.ACROBATICS)) { //Give XP Anyways SkillUtils.applyXpGain(mcMMOPlayer, getPrimarySkill(), calculateRollXP(player, ((EntityDamageEvent) event).getFinalDamage(), false), XPGainReason.PVE); } diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index bdcb2833f..4ac4cec47 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -228,10 +228,10 @@ public class BlockListener implements Listener { if(mcMMOPlayer == null) return; - if (blockState.getType() == Repair.anvilMaterial && Permissions.skillEnabled(player, PrimarySkillType.REPAIR)) { + if (blockState.getType() == Repair.anvilMaterial && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.REPAIR)) { mcMMOPlayer.getRepairManager().placedAnvilCheck(); } - else if (blockState.getType() == Salvage.anvilMaterial && Permissions.skillEnabled(player, PrimarySkillType.SALVAGE)) { + else if (blockState.getType() == Salvage.anvilMaterial && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.SALVAGE)) { mcMMOPlayer.getSalvageManager().placedAnvilCheck(); } } @@ -333,7 +333,7 @@ public class BlockListener implements Listener { * We don't check the block store here because herbalism has too many unusual edge cases. * Instead, we check it inside the drops handler. */ - if (Permissions.skillEnabled(player, PrimarySkillType.HERBALISM)) { + if (mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.HERBALISM)) { herbalismManager.processHerbalismBlockBreakEvent(event); } /* @@ -344,14 +344,14 @@ public class BlockListener implements Listener { } /* MINING */ - else if (BlockUtils.affectedBySuperBreaker(blockState) && ItemUtils.isPickaxe(heldItem) && Permissions.skillEnabled(player, PrimarySkillType.MINING) && !mcMMO.getPlaceStore().isTrue(blockState)) { + else if (BlockUtils.affectedBySuperBreaker(blockState) && ItemUtils.isPickaxe(heldItem) && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.MINING) && !mcMMO.getPlaceStore().isTrue(blockState)) { MiningManager miningManager = mcMMOPlayer.getMiningManager(); miningManager.miningBlockCheck(blockState); } /* WOOD CUTTING */ else if (BlockUtils.hasWoodcuttingXP(blockState) && ItemUtils.isAxe(heldItem) - && Permissions.skillEnabled(player, PrimarySkillType.WOODCUTTING) && !mcMMO.getPlaceStore().isTrue(blockState)) { + && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.WOODCUTTING) && !mcMMO.getPlaceStore().isTrue(blockState)) { WoodcuttingManager woodcuttingManager = mcMMOPlayer.getWoodcuttingManager(); if (woodcuttingManager.canUseTreeFeller(heldItem)) { woodcuttingManager.processTreeFeller(blockState); @@ -366,7 +366,7 @@ public class BlockListener implements Listener { } /* EXCAVATION */ - else if (BlockUtils.affectedByGigaDrillBreaker(blockState) && ItemUtils.isShovel(heldItem) && Permissions.skillEnabled(player, PrimarySkillType.EXCAVATION) && !mcMMO.getPlaceStore().isTrue(blockState)) { + else if (BlockUtils.affectedByGigaDrillBreaker(blockState) && ItemUtils.isShovel(heldItem) && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.EXCAVATION) && !mcMMO.getPlaceStore().isTrue(blockState)) { ExcavationManager excavationManager = mcMMOPlayer.getExcavationManager(); excavationManager.excavationBlockCheck(blockState); diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index f487a09ef..40c57adf7 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -296,7 +296,7 @@ public class PlayerListener implements Listener { return; } - if (!UserManager.hasPlayerDataKey(player) || !Permissions.skillEnabled(player, PrimarySkillType.FISHING)) { + if (!UserManager.hasPlayerDataKey(player) || !mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.FISHING)) { return; } @@ -382,7 +382,7 @@ public class PlayerListener implements Listener { return; } - if (!UserManager.hasPlayerDataKey(player) || !Permissions.skillEnabled(player, PrimarySkillType.FISHING)) { + if (!UserManager.hasPlayerDataKey(player) || !mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.FISHING)) { return; } @@ -677,7 +677,7 @@ public class PlayerListener implements Listener { if (!mcMMO.p.getGeneralConfig().getAbilitiesOnlyActivateWhenSneaking() || player.isSneaking()) { /* REPAIR CHECKS */ if (type == Repair.anvilMaterial - && Permissions.skillEnabled(player, PrimarySkillType.REPAIR) + && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem) && heldItem.getAmount() <= 1) { RepairManager repairManager = mcMMOPlayer.getRepairManager(); @@ -691,7 +691,7 @@ public class PlayerListener implements Listener { } /* SALVAGE CHECKS */ else if (type == Salvage.anvilMaterial - && Permissions.skillEnabled(player, PrimarySkillType.SALVAGE) + && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.SALVAGE) && RankUtils.hasUnlockedSubskill(player, SubSkillType.SALVAGE_SCRAP_COLLECTOR) && mcMMO.getSalvageableManager().isSalvageable(heldItem) && heldItem.getAmount() <= 1) { @@ -724,7 +724,7 @@ public class PlayerListener implements Listener { if (!mcMMO.p.getGeneralConfig().getAbilitiesOnlyActivateWhenSneaking() || player.isSneaking()) { /* REPAIR CHECKS */ - if (type == Repair.anvilMaterial && Permissions.skillEnabled(player, PrimarySkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) { + if (type == Repair.anvilMaterial && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) { RepairManager repairManager = mcMMOPlayer.getRepairManager(); // Cancel repairing an enchanted item @@ -734,7 +734,7 @@ public class PlayerListener implements Listener { } } /* SALVAGE CHECKS */ - else if (type == Salvage.anvilMaterial && Permissions.skillEnabled(player, PrimarySkillType.SALVAGE) && mcMMO.getSalvageableManager().isSalvageable(heldItem)) { + else if (type == Salvage.anvilMaterial && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.SALVAGE) && mcMMO.getSalvageableManager().isSalvageable(heldItem)) { SalvageManager salvageManager = mcMMOPlayer.getSalvageManager(); // Cancel salvaging an enchanted item diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java index 28d09f8aa..b589357c0 100644 --- a/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java @@ -47,7 +47,7 @@ public class McrankCommandDisplayTask extends BukkitRunnable { sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName)); for (PrimarySkillType skill : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) { -// if (!Permissions.skillEnabled(player, skill)) { +// if (!mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, skill)) { // continue; // } diff --git a/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java b/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java index 0ccee19be..adb2d4851 100644 --- a/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java +++ b/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java @@ -6,7 +6,6 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.Misc; -import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.text.StringUtils; @@ -209,7 +208,7 @@ public final class CommandUtils { if (mcMMO.p.getSkillTools().isChildSkill(skill)) { return LocaleLoader.getString("Skills.ChildStats", LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".Listener") + " ", profile.getSkillLevel(skill)); } - if (profile.getSkillLevel(skill) == mcMMO.p.getGeneralConfig().getLevelCap(skill)){ + if (profile.getSkillLevel(skill) == mcMMO.p.getSkillTools().getLevelCap(skill)){ return LocaleLoader.getString("Skills.Stats", LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".Listener") + " ", profile.getSkillLevel(skill), profile.getSkillXpLevel(skill), LocaleLoader.getString("Skills.MaxXP")); } return LocaleLoader.getString("Skills.Stats", LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".Listener") + " ", profile.getSkillLevel(skill), profile.getSkillXpLevel(skill), profile.getXpToLevel(skill)); @@ -225,7 +224,7 @@ public final class CommandUtils { displayData.add(header); for (PrimarySkillType primarySkillType : skillGroup) { - if (Permissions.skillEnabled(inspectTarget, primarySkillType)) { + if (mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(inspectTarget, primarySkillType)) { displayData.add(displaySkill(profile, primarySkillType)); } } diff --git a/src/main/java/com/gmail/nossr50/util/experience/FormulaManager.java b/src/main/java/com/gmail/nossr50/util/experience/FormulaManager.java index c82a6e00e..f7478e24c 100644 --- a/src/main/java/com/gmail/nossr50/util/experience/FormulaManager.java +++ b/src/main/java/com/gmail/nossr50/util/experience/FormulaManager.java @@ -88,7 +88,7 @@ public class FormulaManager { public int[] calculateNewLevel(PrimarySkillType primarySkillType, int experience, FormulaType formulaType) { int newLevel = 0; int remainder = 0; - int maxLevel = mcMMO.p.getGeneralConfig().getLevelCap(primarySkillType); + int maxLevel = mcMMO.p.getSkillTools().getLevelCap(primarySkillType); while (experience > 0 && newLevel < maxLevel) { int experienceToNextLevel = getXPtoNextLevel(newLevel, formulaType); diff --git a/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java b/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java index cee2d135a..9c23627da 100644 --- a/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java +++ b/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java @@ -13,7 +13,6 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.skills.child.FamilyTree; import com.gmail.nossr50.util.Misc; -import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.player.NotificationManager; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.scoreboards.ScoreboardManager.SidebarType; @@ -580,7 +579,7 @@ public class ScoreboardWrapper { powerLevel += level; // TODO: Verify that this is what we want - calculated in power level but not displayed - if (!Permissions.skillEnabled(player, skill)) { + if (!mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, skill)) { continue; } @@ -608,7 +607,7 @@ public class ScoreboardWrapper { Player player = mcMMO.p.getServer().getPlayerExact(playerName); for (PrimarySkillType skill : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) { - if (!Permissions.skillEnabled(player, skill)) { + if (!mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, skill)) { continue; } diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index 2c9820a2c..934a3e07b 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -384,7 +384,7 @@ public final class CombatUtils { return; } - if (Permissions.skillEnabled(player, PrimarySkillType.SWORDS)) { + if (mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.SWORDS)) { processSwordCombat(target, player, event); } @@ -394,7 +394,7 @@ public final class CombatUtils { return; } - if (Permissions.skillEnabled(player, PrimarySkillType.AXES)) { + if (mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.AXES)) { processAxeCombat(target, player, event); } } @@ -403,7 +403,7 @@ public final class CombatUtils { return; } - if (Permissions.skillEnabled(player, PrimarySkillType.UNARMED)) { + if (mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.UNARMED)) { processUnarmedCombat(target, player, event); } } @@ -416,7 +416,7 @@ public final class CombatUtils { if (tamer instanceof Player && mcMMO.p.getSkillTools().canCombatSkillsTrigger(PrimarySkillType.TAMING, target)) { Player master = (Player) tamer; - if (!Misc.isNPCEntityExcludingVillagers(master) && Permissions.skillEnabled(master, PrimarySkillType.TAMING)) { + if (!Misc.isNPCEntityExcludingVillagers(master) && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(master, PrimarySkillType.TAMING)) { processTamingCombat(target, master, wolf, event); } } @@ -428,14 +428,14 @@ public final class CombatUtils { if (projectileSource instanceof Player && mcMMO.p.getSkillTools().canCombatSkillsTrigger(PrimarySkillType.ARCHERY, target)) { Player player = (Player) projectileSource; - if (!Misc.isNPCEntityExcludingVillagers(player) && Permissions.skillEnabled(player, PrimarySkillType.ARCHERY)) { + if (!Misc.isNPCEntityExcludingVillagers(player) && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.ARCHERY)) { processArcheryCombat(target, player, event, arrow); } else { //Cleanup Arrow cleanupArrowMetadata(arrow); } - if (target.getType() != EntityType.CREEPER && !Misc.isNPCEntityExcludingVillagers(player) && Permissions.skillEnabled(player, PrimarySkillType.TAMING)) { + if (target.getType() != EntityType.CREEPER && !Misc.isNPCEntityExcludingVillagers(player) && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.TAMING)) { McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); if(mcMMOPlayer == null) diff --git a/src/main/java/com/gmail/nossr50/util/skills/SkillTools.java b/src/main/java/com/gmail/nossr50/util/skills/SkillTools.java index 846c7c413..cf61f7b96 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/SkillTools.java +++ b/src/main/java/com/gmail/nossr50/util/skills/SkillTools.java @@ -11,6 +11,7 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.text.StringUtils; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -27,19 +28,19 @@ public class SkillTools { public final ImmutableList LOCALIZED_SKILL_NAMES; public final ImmutableList FORMATTED_SUBSKILL_NAMES; public final ImmutableSet EXACT_SUBSKILL_NAMES; - public final List CHILD_SKILLS; + public final ImmutableList CHILD_SKILLS; public final ImmutableList NON_CHILD_SKILLS; public final ImmutableList COMBAT_SKILLS; public final ImmutableList GATHERING_SKILLS; public final ImmutableList MISC_SKILLS; - private EnumMap subSkillParentRelationshipMap; //TODO: This disgusts me, but it will have to do until the new skill system is in place - private EnumMap superAbilityParentRelationshipMap; //TODO: This disgusts me, but it will have to do until the new skill system is in place - private EnumMap> primarySkillChildrenMap; //TODO: This disgusts me, but it will have to do until the new skill system is in place + private ImmutableMap subSkillParentRelationshipMap; + private ImmutableMap superAbilityParentRelationshipMap; + private ImmutableMap> primarySkillChildrenMap; // The map below is for the super abilities which require readying a tool, its everything except blast mining - private EnumMap mainActivatedAbilityChildMap; //TODO: This disgusts me, but it will have to do until the new skill system is in place - private EnumMap primarySkillToolMap; //TODO: Christ.. + private ImmutableMap mainActivatedAbilityChildMap; + private ImmutableMap primarySkillToolMap; public SkillTools(@NotNull mcMMO pluginRef) { this.pluginRef = pluginRef; @@ -72,39 +73,43 @@ public class SkillTools { NON_CHILD_SKILLS = ImmutableList.copyOf(nonChildSkills); } - //TODO: What is with this design? private void initPrimaryToolMap() { - primarySkillToolMap = new EnumMap(PrimarySkillType.class); + EnumMap tempToolMap = new EnumMap(PrimarySkillType.class); - primarySkillToolMap.put(PrimarySkillType.AXES, ToolType.AXE); - primarySkillToolMap.put(PrimarySkillType.WOODCUTTING, ToolType.AXE); - primarySkillToolMap.put(PrimarySkillType.UNARMED, ToolType.FISTS); - primarySkillToolMap.put(PrimarySkillType.SWORDS, ToolType.SWORD); - primarySkillToolMap.put(PrimarySkillType.EXCAVATION, ToolType.SHOVEL); - primarySkillToolMap.put(PrimarySkillType.HERBALISM, ToolType.HOE); - primarySkillToolMap.put(PrimarySkillType.MINING, ToolType.PICKAXE); + tempToolMap.put(PrimarySkillType.AXES, ToolType.AXE); + tempToolMap.put(PrimarySkillType.WOODCUTTING, ToolType.AXE); + tempToolMap.put(PrimarySkillType.UNARMED, ToolType.FISTS); + tempToolMap.put(PrimarySkillType.SWORDS, ToolType.SWORD); + tempToolMap.put(PrimarySkillType.EXCAVATION, ToolType.SHOVEL); + tempToolMap.put(PrimarySkillType.HERBALISM, ToolType.HOE); + tempToolMap.put(PrimarySkillType.MINING, ToolType.PICKAXE); + + primarySkillToolMap = ImmutableMap.copyOf(tempToolMap); } private void initSuperAbilityParentRelationships() { - superAbilityParentRelationshipMap = new EnumMap(SuperAbilityType.class); - mainActivatedAbilityChildMap = new EnumMap(PrimarySkillType.class); + EnumMap tempAbilityParentRelationshipMap = new EnumMap(SuperAbilityType.class); + EnumMap tempMainActivatedAbilityChildMap = new EnumMap(PrimarySkillType.class); for(SuperAbilityType superAbilityType : SuperAbilityType.values()) { try { PrimarySkillType parent = getSuperAbilityParent(superAbilityType); - superAbilityParentRelationshipMap.put(superAbilityType, parent); + tempAbilityParentRelationshipMap.put(superAbilityType, parent); if(superAbilityType != SuperAbilityType.BLAST_MINING) { //This map is used only for abilities that have a tool readying phase, so blast mining is ignored - mainActivatedAbilityChildMap.put(parent, superAbilityType); + tempMainActivatedAbilityChildMap.put(parent, superAbilityType); } } catch (InvalidSkillException e) { e.printStackTrace(); } } + + superAbilityParentRelationshipMap = ImmutableMap.copyOf(tempAbilityParentRelationshipMap); + mainActivatedAbilityChildMap = ImmutableMap.copyOf(tempMainActivatedAbilityChildMap); } - private PrimarySkillType getSuperAbilityParent(SuperAbilityType superAbilityType) throws InvalidSkillException { + private @NotNull PrimarySkillType getSuperAbilityParent(SuperAbilityType superAbilityType) throws InvalidSkillException { switch(superAbilityType) { case BERSERK: return PrimarySkillType.UNARMED; @@ -130,7 +135,7 @@ public class SkillTools { * Builds a list of localized {@link PrimarySkillType} names * @return list of localized {@link PrimarySkillType} names */ - private ArrayList buildLocalizedPrimarySkillNames() { + private @NotNull ArrayList buildLocalizedPrimarySkillNames() { ArrayList localizedSkillNameList = new ArrayList<>(); for(PrimarySkillType primarySkillType : PrimarySkillType.values()) { @@ -147,11 +152,11 @@ public class SkillTools { * Disgusting Hacky Fix until the new skill system is in place */ private void initPrimaryChildMap() { - primarySkillChildrenMap = new EnumMap>(PrimarySkillType.class); + EnumMap> tempPrimaryChildMap = new EnumMap>(PrimarySkillType.class); //Init the empty Hash Sets for(PrimarySkillType primarySkillType : PrimarySkillType.values()) { - primarySkillChildrenMap.put(primarySkillType, new HashSet()); + tempPrimaryChildMap.put(primarySkillType, new HashSet<>()); } //Fill in the hash sets @@ -159,8 +164,10 @@ public class SkillTools { PrimarySkillType parentSkill = subSkillParentRelationshipMap.get(subSkillType); //Add this subskill as a child - primarySkillChildrenMap.get(parentSkill).add(subSkillType); + tempPrimaryChildMap.get(parentSkill).add(subSkillType); } + + primarySkillChildrenMap = ImmutableMap.copyOf(tempPrimaryChildMap); } /** @@ -168,7 +175,7 @@ public class SkillTools { * Used in tab completion mostly * @return a list of formatted sub skill names */ - private ArrayList buildFormattedSubSkillNameList() { + private @NotNull ArrayList buildFormattedSubSkillNameList() { ArrayList subSkillNameList = new ArrayList<>(); for(SubSkillType subSkillType : SubSkillType.values()) { @@ -178,7 +185,7 @@ public class SkillTools { return subSkillNameList; } - private HashSet buildExactSubSkillNameList() { + private @NotNull HashSet buildExactSubSkillNameList() { HashSet subSkillNameExactSet = new HashSet<>(); for(SubSkillType subSkillType : SubSkillType.values()) { @@ -193,7 +200,7 @@ public class SkillTools { * Disgusting Hacky Fix until the new skill system is in place */ private void initSubSkillRelationshipMap() { - subSkillParentRelationshipMap = new EnumMap(SubSkillType.class); + EnumMap tempSubParentMap = new EnumMap(SubSkillType.class); //Super hacky and disgusting for(PrimarySkillType primarySkillType : PrimarySkillType.values()) { @@ -202,10 +209,12 @@ public class SkillTools { if(primarySkillType.toString().equalsIgnoreCase(splitSubSkillName[0])) { //Parent Skill Found - subSkillParentRelationshipMap.put(subSkillType, primarySkillType); + tempSubParentMap.put(subSkillType, primarySkillType); } } } + + subSkillParentRelationshipMap = ImmutableMap.copyOf(tempSubParentMap); } /** @@ -292,9 +301,9 @@ public class SkillTools { return primarySkillToolMap.get(primarySkillType); } - public List getSubSkills(PrimarySkillType primarySkillType) { + public Set getSubSkills(PrimarySkillType primarySkillType) { //TODO: Cache this! - return new ArrayList<>(primarySkillChildrenMap.get(primarySkillType)); + return primarySkillChildrenMap.get(primarySkillType); } public double getXpModifier(PrimarySkillType primarySkillType) { @@ -323,7 +332,7 @@ public class SkillTools { return StringUtils.getCapitalized(LocaleLoader.getString(StringUtils.getCapitalized(primarySkillType.toString()) + ".SkillName")); } - public boolean doesPlayerHaveSkillPermission(PrimarySkillType primarySkillType, Player player) { + public boolean doesPlayerHaveSkillPermission(Player player, PrimarySkillType primarySkillType) { return Permissions.skillEnabled(player, primarySkillType); } @@ -364,7 +373,7 @@ public class SkillTools { } public int getLevelCap(@NotNull PrimarySkillType primarySkillType) { - return mcMMO.p.getGeneralConfig().getLevelCap(primarySkillType); + return mcMMO.p.getSkillTools().getLevelCap(primarySkillType); } /** diff --git a/src/main/java/com/gmail/nossr50/util/skills/SmeltingTracker.java b/src/main/java/com/gmail/nossr50/util/skills/SmeltingTracker.java index 630991341..dfa313181 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/SmeltingTracker.java +++ b/src/main/java/com/gmail/nossr50/util/skills/SmeltingTracker.java @@ -3,7 +3,6 @@ package com.gmail.nossr50.util.skills; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.player.UserManager; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -89,7 +88,7 @@ public class SmeltingTracker { } public void processFurnaceOwnership(Furnace furnace, Player player) { - if(!Permissions.skillEnabled(player, PrimarySkillType.SMELTING)) + if(!mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.SMELTING)) return; //Don't swap ownership if its the same player