Update SkillTools

This commit is contained in:
nossr50 2021-04-09 11:13:27 -07:00
parent cfdcc9dee5
commit be44c0e417
16 changed files with 81 additions and 74 deletions

View File

@ -802,7 +802,7 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid * @throws InvalidSkillException if the given skill is not valid
*/ */
public static int getLevelCap(String skillType) { public static int getLevelCap(String skillType) {
return mcMMO.p.getGeneralConfig().getLevelCap(getSkillType(skillType)); return mcMMO.p.getSkillTools().getLevelCap(getSkillType(skillType));
} }
/** /**

View File

@ -936,7 +936,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
if (mcMMO.p.getGeneralConfig().getTruncateSkills()) { if (mcMMO.p.getGeneralConfig().getTruncateSkills()) {
for (PrimarySkillType skill : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) { 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) { 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 = connection.prepareStatement("UPDATE `" + tablePrefix + "skills` SET `" + skill.name().toLowerCase(Locale.ENGLISH) + "` = " + cap + " WHERE `" + skill.name().toLowerCase(Locale.ENGLISH) + "` > " + cap);
statement.executeUpdate(); statement.executeUpdate();

View File

@ -252,7 +252,7 @@ public class McMMOPlayer implements Identified {
NotificationManager.sendPlayerInformationChatOnly(player, "LevelCap.PowerLevel", String.valueOf(mcMMO.p.getGeneralConfig().getPowerLevelCap())); NotificationManager.sendPlayerInformationChatOnly(player, "LevelCap.PowerLevel", String.valueOf(mcMMO.p.getGeneralConfig().getPowerLevelCap()));
} else if(hasReachedLevelCap(primarySkillType)) { } else if(hasReachedLevelCap(primarySkillType)) {
NotificationManager.sendPlayerInformationChatOnly(player, "LevelCap.Skill", NotificationManager.sendPlayerInformationChatOnly(player, "LevelCap.Skill",
String.valueOf(mcMMO.p.getGeneralConfig().getLevelCap(primarySkillType)), String.valueOf(mcMMO.p.getSkillTools().getLevelCap(primarySkillType)),
mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType)); mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType));
} }
@ -570,7 +570,7 @@ public class McMMOPlayer implements Identified {
int powerLevel = 0; int powerLevel = 0;
for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) { for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
if (Permissions.skillEnabled(player, primarySkillType)) { if (mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, primarySkillType)) {
powerLevel += getSkillLevel(primarySkillType); powerLevel += getSkillLevel(primarySkillType);
} }
} }
@ -588,7 +588,7 @@ public class McMMOPlayer implements Identified {
if(hasReachedPowerLevelCap()) if(hasReachedPowerLevelCap())
return true; 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(); float splitXp = xp / parentSkills.size();
for (PrimarySkillType parentSkill : parentSkills) { for (PrimarySkillType parentSkill : parentSkills) {
if (Permissions.skillEnabled(player, parentSkill)) { if (mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, parentSkill)) {
beginXpGain(parentSkill, splitXp, xpGainReason, xpGainSource); beginXpGain(parentSkill, splitXp, xpGainReason, xpGainSource);
} }
} }
@ -660,7 +660,7 @@ public class McMMOPlayer implements Identified {
* @param xp Experience amount to add * @param xp Experience amount to add
*/ */
public void applyXpGain(PrimarySkillType primarySkillType, float xp, XPGainReason xpGainReason, XPGainSource xpGainSource) { public void applyXpGain(PrimarySkillType primarySkillType, float xp, XPGainReason xpGainReason, XPGainSource xpGainSource) {
if (!Permissions.skillEnabled(player, primarySkillType)) { if (!mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, primarySkillType)) {
return; return;
} }
@ -837,7 +837,7 @@ public class McMMOPlayer implements Identified {
*/ */
private float modifyXpGain(PrimarySkillType primarySkillType, float xp) { 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 //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())) { || (mcMMO.p.getGeneralConfig().getPowerLevelCap() <= getPowerLevel())) {
return 0; return 0;
} }
@ -953,7 +953,7 @@ public class McMMOPlayer implements Identified {
} }
public void processAbilityActivation(@NotNull PrimarySkillType primarySkillType) { public void processAbilityActivation(@NotNull PrimarySkillType primarySkillType) {
if (!Permissions.skillEnabled(getPlayer(), primarySkillType)) { if (!mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(getPlayer(), primarySkillType)) {
return; return;
} }

View File

@ -432,7 +432,7 @@ public class PlayerProfile {
int sum = 0; int sum = 0;
for (PrimarySkillType parent : parents) { 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(); return sum / parents.size();

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public enum PrimarySkillType { public enum PrimarySkillType {
@ -140,7 +141,7 @@ public enum PrimarySkillType {
*/ */
@Deprecated @Deprecated
public List<SubSkillType> getSkillAbilities() { public List<SubSkillType> getSkillAbilities() {
return mcMMO.p.getSkillTools().getSubSkills(this); return new ArrayList<>(mcMMO.p.getSkillTools().getSubSkills(this));
} }
/** /**
@ -217,7 +218,7 @@ public enum PrimarySkillType {
*/ */
@Deprecated @Deprecated
public boolean getPermissions(Player player) { public boolean getPermissions(Player player) {
return Permissions.skillEnabled(player, this); return mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, this);
} }
/** /**

View File

@ -111,7 +111,7 @@ public enum SuperAbilityType {
} }
public int getCooldown() { public int getCooldown() {
return mcMMO.p.getGeneralConfig().getCooldown(this); return mcMMO.p.getSkillTools().getSuperAbilityCooldown(this);
} }
public int getMaxLength() { public int getMaxLength() {

View File

@ -83,7 +83,7 @@ public class Roll extends AcrobaticsSubSkill {
entityDamageEvent.setCancelled(true); entityDamageEvent.setCancelled(true);
return true; return true;
} }
} else if(Permissions.skillEnabled(player, PrimarySkillType.ACROBATICS)) { } else if(mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.ACROBATICS)) {
//Give XP Anyways //Give XP Anyways
SkillUtils.applyXpGain(mcMMOPlayer, getPrimarySkill(), calculateRollXP(player, ((EntityDamageEvent) event).getFinalDamage(), false), XPGainReason.PVE); SkillUtils.applyXpGain(mcMMOPlayer, getPrimarySkill(), calculateRollXP(player, ((EntityDamageEvent) event).getFinalDamage(), false), XPGainReason.PVE);
} }

View File

@ -228,10 +228,10 @@ public class BlockListener implements Listener {
if(mcMMOPlayer == null) if(mcMMOPlayer == null)
return; 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(); 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(); 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. * We don't check the block store here because herbalism has too many unusual edge cases.
* Instead, we check it inside the drops handler. * 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); herbalismManager.processHerbalismBlockBreakEvent(event);
} }
/* /*
@ -344,14 +344,14 @@ public class BlockListener implements Listener {
} }
/* MINING */ /* 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 miningManager = mcMMOPlayer.getMiningManager();
miningManager.miningBlockCheck(blockState); miningManager.miningBlockCheck(blockState);
} }
/* WOOD CUTTING */ /* WOOD CUTTING */
else if (BlockUtils.hasWoodcuttingXP(blockState) && ItemUtils.isAxe(heldItem) 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(); WoodcuttingManager woodcuttingManager = mcMMOPlayer.getWoodcuttingManager();
if (woodcuttingManager.canUseTreeFeller(heldItem)) { if (woodcuttingManager.canUseTreeFeller(heldItem)) {
woodcuttingManager.processTreeFeller(blockState); woodcuttingManager.processTreeFeller(blockState);
@ -366,7 +366,7 @@ public class BlockListener implements Listener {
} }
/* EXCAVATION */ /* 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 excavationManager = mcMMOPlayer.getExcavationManager();
excavationManager.excavationBlockCheck(blockState); excavationManager.excavationBlockCheck(blockState);

View File

@ -296,7 +296,7 @@ public class PlayerListener implements Listener {
return; return;
} }
if (!UserManager.hasPlayerDataKey(player) || !Permissions.skillEnabled(player, PrimarySkillType.FISHING)) { if (!UserManager.hasPlayerDataKey(player) || !mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.FISHING)) {
return; return;
} }
@ -382,7 +382,7 @@ public class PlayerListener implements Listener {
return; return;
} }
if (!UserManager.hasPlayerDataKey(player) || !Permissions.skillEnabled(player, PrimarySkillType.FISHING)) { if (!UserManager.hasPlayerDataKey(player) || !mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.FISHING)) {
return; return;
} }
@ -677,7 +677,7 @@ public class PlayerListener implements Listener {
if (!mcMMO.p.getGeneralConfig().getAbilitiesOnlyActivateWhenSneaking() || player.isSneaking()) { if (!mcMMO.p.getGeneralConfig().getAbilitiesOnlyActivateWhenSneaking() || player.isSneaking()) {
/* REPAIR CHECKS */ /* REPAIR CHECKS */
if (type == Repair.anvilMaterial if (type == Repair.anvilMaterial
&& Permissions.skillEnabled(player, PrimarySkillType.REPAIR) && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.REPAIR)
&& mcMMO.getRepairableManager().isRepairable(heldItem) && mcMMO.getRepairableManager().isRepairable(heldItem)
&& heldItem.getAmount() <= 1) { && heldItem.getAmount() <= 1) {
RepairManager repairManager = mcMMOPlayer.getRepairManager(); RepairManager repairManager = mcMMOPlayer.getRepairManager();
@ -691,7 +691,7 @@ public class PlayerListener implements Listener {
} }
/* SALVAGE CHECKS */ /* SALVAGE CHECKS */
else if (type == Salvage.anvilMaterial else if (type == Salvage.anvilMaterial
&& Permissions.skillEnabled(player, PrimarySkillType.SALVAGE) && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.SALVAGE)
&& RankUtils.hasUnlockedSubskill(player, SubSkillType.SALVAGE_SCRAP_COLLECTOR) && RankUtils.hasUnlockedSubskill(player, SubSkillType.SALVAGE_SCRAP_COLLECTOR)
&& mcMMO.getSalvageableManager().isSalvageable(heldItem) && mcMMO.getSalvageableManager().isSalvageable(heldItem)
&& heldItem.getAmount() <= 1) { && heldItem.getAmount() <= 1) {
@ -724,7 +724,7 @@ public class PlayerListener implements Listener {
if (!mcMMO.p.getGeneralConfig().getAbilitiesOnlyActivateWhenSneaking() || player.isSneaking()) { if (!mcMMO.p.getGeneralConfig().getAbilitiesOnlyActivateWhenSneaking() || player.isSneaking()) {
/* REPAIR CHECKS */ /* 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(); RepairManager repairManager = mcMMOPlayer.getRepairManager();
// Cancel repairing an enchanted item // Cancel repairing an enchanted item
@ -734,7 +734,7 @@ public class PlayerListener implements Listener {
} }
} }
/* SALVAGE CHECKS */ /* 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(); SalvageManager salvageManager = mcMMOPlayer.getSalvageManager();
// Cancel salvaging an enchanted item // Cancel salvaging an enchanted item

View File

@ -47,7 +47,7 @@ public class McrankCommandDisplayTask extends BukkitRunnable {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName)); sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName));
for (PrimarySkillType skill : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) { for (PrimarySkillType skill : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
// if (!Permissions.skillEnabled(player, skill)) { // if (!mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, skill)) {
// continue; // continue;
// } // }

View File

@ -6,7 +6,6 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
import com.gmail.nossr50.util.text.StringUtils; import com.gmail.nossr50.util.text.StringUtils;
@ -209,7 +208,7 @@ public final class CommandUtils {
if (mcMMO.p.getSkillTools().isChildSkill(skill)) { if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
return LocaleLoader.getString("Skills.ChildStats", LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".Listener") + " ", profile.getSkillLevel(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), 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)); 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); displayData.add(header);
for (PrimarySkillType primarySkillType : skillGroup) { for (PrimarySkillType primarySkillType : skillGroup) {
if (Permissions.skillEnabled(inspectTarget, primarySkillType)) { if (mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(inspectTarget, primarySkillType)) {
displayData.add(displaySkill(profile, primarySkillType)); displayData.add(displaySkill(profile, primarySkillType));
} }
} }

View File

@ -88,7 +88,7 @@ public class FormulaManager {
public int[] calculateNewLevel(PrimarySkillType primarySkillType, int experience, FormulaType formulaType) { public int[] calculateNewLevel(PrimarySkillType primarySkillType, int experience, FormulaType formulaType) {
int newLevel = 0; int newLevel = 0;
int remainder = 0; int remainder = 0;
int maxLevel = mcMMO.p.getGeneralConfig().getLevelCap(primarySkillType); int maxLevel = mcMMO.p.getSkillTools().getLevelCap(primarySkillType);
while (experience > 0 && newLevel < maxLevel) { while (experience > 0 && newLevel < maxLevel) {
int experienceToNextLevel = getXPtoNextLevel(newLevel, formulaType); int experienceToNextLevel = getXPtoNextLevel(newLevel, formulaType);

View File

@ -13,7 +13,6 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.child.FamilyTree; import com.gmail.nossr50.skills.child.FamilyTree;
import com.gmail.nossr50.util.Misc; 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.NotificationManager;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager.SidebarType; import com.gmail.nossr50.util.scoreboards.ScoreboardManager.SidebarType;
@ -580,7 +579,7 @@ public class ScoreboardWrapper {
powerLevel += level; powerLevel += level;
// TODO: Verify that this is what we want - calculated in power level but not displayed // 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; continue;
} }
@ -608,7 +607,7 @@ public class ScoreboardWrapper {
Player player = mcMMO.p.getServer().getPlayerExact(playerName); Player player = mcMMO.p.getServer().getPlayerExact(playerName);
for (PrimarySkillType skill : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) { for (PrimarySkillType skill : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
if (!Permissions.skillEnabled(player, skill)) { if (!mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, skill)) {
continue; continue;
} }

View File

@ -384,7 +384,7 @@ public final class CombatUtils {
return; return;
} }
if (Permissions.skillEnabled(player, PrimarySkillType.SWORDS)) { if (mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.SWORDS)) {
processSwordCombat(target, player, event); processSwordCombat(target, player, event);
} }
@ -394,7 +394,7 @@ public final class CombatUtils {
return; return;
} }
if (Permissions.skillEnabled(player, PrimarySkillType.AXES)) { if (mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.AXES)) {
processAxeCombat(target, player, event); processAxeCombat(target, player, event);
} }
} }
@ -403,7 +403,7 @@ public final class CombatUtils {
return; return;
} }
if (Permissions.skillEnabled(player, PrimarySkillType.UNARMED)) { if (mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.UNARMED)) {
processUnarmedCombat(target, player, event); processUnarmedCombat(target, player, event);
} }
} }
@ -416,7 +416,7 @@ public final class CombatUtils {
if (tamer instanceof Player && mcMMO.p.getSkillTools().canCombatSkillsTrigger(PrimarySkillType.TAMING, target)) { if (tamer instanceof Player && mcMMO.p.getSkillTools().canCombatSkillsTrigger(PrimarySkillType.TAMING, target)) {
Player master = (Player) tamer; 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); processTamingCombat(target, master, wolf, event);
} }
} }
@ -428,14 +428,14 @@ public final class CombatUtils {
if (projectileSource instanceof Player && mcMMO.p.getSkillTools().canCombatSkillsTrigger(PrimarySkillType.ARCHERY, target)) { if (projectileSource instanceof Player && mcMMO.p.getSkillTools().canCombatSkillsTrigger(PrimarySkillType.ARCHERY, target)) {
Player player = (Player) projectileSource; 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); processArcheryCombat(target, player, event, arrow);
} else { } else {
//Cleanup Arrow //Cleanup Arrow
cleanupArrowMetadata(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); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if(mcMMOPlayer == null) if(mcMMOPlayer == null)

View File

@ -11,6 +11,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.text.StringUtils; import com.gmail.nossr50.util.text.StringUtils;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -27,19 +28,19 @@ public class SkillTools {
public final ImmutableList<String> LOCALIZED_SKILL_NAMES; public final ImmutableList<String> LOCALIZED_SKILL_NAMES;
public final ImmutableList<String> FORMATTED_SUBSKILL_NAMES; public final ImmutableList<String> FORMATTED_SUBSKILL_NAMES;
public final ImmutableSet<String> EXACT_SUBSKILL_NAMES; public final ImmutableSet<String> EXACT_SUBSKILL_NAMES;
public final List<PrimarySkillType> CHILD_SKILLS; public final ImmutableList<PrimarySkillType> CHILD_SKILLS;
public final ImmutableList<PrimarySkillType> NON_CHILD_SKILLS; public final ImmutableList<PrimarySkillType> NON_CHILD_SKILLS;
public final ImmutableList<PrimarySkillType> COMBAT_SKILLS; public final ImmutableList<PrimarySkillType> COMBAT_SKILLS;
public final ImmutableList<PrimarySkillType> GATHERING_SKILLS; public final ImmutableList<PrimarySkillType> GATHERING_SKILLS;
public final ImmutableList<PrimarySkillType> MISC_SKILLS; public final ImmutableList<PrimarySkillType> MISC_SKILLS;
private EnumMap<SubSkillType, PrimarySkillType> subSkillParentRelationshipMap; //TODO: This disgusts me, but it will have to do until the new skill system is in place private ImmutableMap<SubSkillType, PrimarySkillType> subSkillParentRelationshipMap;
private EnumMap<SuperAbilityType, PrimarySkillType> superAbilityParentRelationshipMap; //TODO: This disgusts me, but it will have to do until the new skill system is in place private ImmutableMap<SuperAbilityType, PrimarySkillType> superAbilityParentRelationshipMap;
private EnumMap<PrimarySkillType, HashSet<SubSkillType>> primarySkillChildrenMap; //TODO: This disgusts me, but it will have to do until the new skill system is in place private ImmutableMap<PrimarySkillType, Set<SubSkillType>> primarySkillChildrenMap;
// The map below is for the super abilities which require readying a tool, its everything except blast mining // The map below is for the super abilities which require readying a tool, its everything except blast mining
private EnumMap<PrimarySkillType, SuperAbilityType> mainActivatedAbilityChildMap; //TODO: This disgusts me, but it will have to do until the new skill system is in place private ImmutableMap<PrimarySkillType, SuperAbilityType> mainActivatedAbilityChildMap;
private EnumMap<PrimarySkillType, ToolType> primarySkillToolMap; //TODO: Christ.. private ImmutableMap<PrimarySkillType, ToolType> primarySkillToolMap;
public SkillTools(@NotNull mcMMO pluginRef) { public SkillTools(@NotNull mcMMO pluginRef) {
this.pluginRef = pluginRef; this.pluginRef = pluginRef;
@ -72,39 +73,43 @@ public class SkillTools {
NON_CHILD_SKILLS = ImmutableList.copyOf(nonChildSkills); NON_CHILD_SKILLS = ImmutableList.copyOf(nonChildSkills);
} }
//TODO: What is with this design?
private void initPrimaryToolMap() { private void initPrimaryToolMap() {
primarySkillToolMap = new EnumMap<PrimarySkillType, ToolType>(PrimarySkillType.class); EnumMap<PrimarySkillType, ToolType> tempToolMap = new EnumMap<PrimarySkillType, ToolType>(PrimarySkillType.class);
primarySkillToolMap.put(PrimarySkillType.AXES, ToolType.AXE); tempToolMap.put(PrimarySkillType.AXES, ToolType.AXE);
primarySkillToolMap.put(PrimarySkillType.WOODCUTTING, ToolType.AXE); tempToolMap.put(PrimarySkillType.WOODCUTTING, ToolType.AXE);
primarySkillToolMap.put(PrimarySkillType.UNARMED, ToolType.FISTS); tempToolMap.put(PrimarySkillType.UNARMED, ToolType.FISTS);
primarySkillToolMap.put(PrimarySkillType.SWORDS, ToolType.SWORD); tempToolMap.put(PrimarySkillType.SWORDS, ToolType.SWORD);
primarySkillToolMap.put(PrimarySkillType.EXCAVATION, ToolType.SHOVEL); tempToolMap.put(PrimarySkillType.EXCAVATION, ToolType.SHOVEL);
primarySkillToolMap.put(PrimarySkillType.HERBALISM, ToolType.HOE); tempToolMap.put(PrimarySkillType.HERBALISM, ToolType.HOE);
primarySkillToolMap.put(PrimarySkillType.MINING, ToolType.PICKAXE); tempToolMap.put(PrimarySkillType.MINING, ToolType.PICKAXE);
primarySkillToolMap = ImmutableMap.copyOf(tempToolMap);
} }
private void initSuperAbilityParentRelationships() { private void initSuperAbilityParentRelationships() {
superAbilityParentRelationshipMap = new EnumMap<SuperAbilityType, PrimarySkillType>(SuperAbilityType.class); EnumMap<SuperAbilityType, PrimarySkillType> tempAbilityParentRelationshipMap = new EnumMap<SuperAbilityType, PrimarySkillType>(SuperAbilityType.class);
mainActivatedAbilityChildMap = new EnumMap<PrimarySkillType, SuperAbilityType>(PrimarySkillType.class); EnumMap<PrimarySkillType, SuperAbilityType> tempMainActivatedAbilityChildMap = new EnumMap<PrimarySkillType, SuperAbilityType>(PrimarySkillType.class);
for(SuperAbilityType superAbilityType : SuperAbilityType.values()) { for(SuperAbilityType superAbilityType : SuperAbilityType.values()) {
try { try {
PrimarySkillType parent = getSuperAbilityParent(superAbilityType); PrimarySkillType parent = getSuperAbilityParent(superAbilityType);
superAbilityParentRelationshipMap.put(superAbilityType, parent); tempAbilityParentRelationshipMap.put(superAbilityType, parent);
if(superAbilityType != SuperAbilityType.BLAST_MINING) { if(superAbilityType != SuperAbilityType.BLAST_MINING) {
//This map is used only for abilities that have a tool readying phase, so blast mining is ignored //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) { } catch (InvalidSkillException e) {
e.printStackTrace(); 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) { switch(superAbilityType) {
case BERSERK: case BERSERK:
return PrimarySkillType.UNARMED; return PrimarySkillType.UNARMED;
@ -130,7 +135,7 @@ public class SkillTools {
* Builds a list of localized {@link PrimarySkillType} names * Builds a list of localized {@link PrimarySkillType} names
* @return list of localized {@link PrimarySkillType} names * @return list of localized {@link PrimarySkillType} names
*/ */
private ArrayList<String> buildLocalizedPrimarySkillNames() { private @NotNull ArrayList<String> buildLocalizedPrimarySkillNames() {
ArrayList<String> localizedSkillNameList = new ArrayList<>(); ArrayList<String> localizedSkillNameList = new ArrayList<>();
for(PrimarySkillType primarySkillType : PrimarySkillType.values()) { for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
@ -147,11 +152,11 @@ public class SkillTools {
* Disgusting Hacky Fix until the new skill system is in place * Disgusting Hacky Fix until the new skill system is in place
*/ */
private void initPrimaryChildMap() { private void initPrimaryChildMap() {
primarySkillChildrenMap = new EnumMap<PrimarySkillType, HashSet<SubSkillType>>(PrimarySkillType.class); EnumMap<PrimarySkillType, Set<SubSkillType>> tempPrimaryChildMap = new EnumMap<PrimarySkillType, Set<SubSkillType>>(PrimarySkillType.class);
//Init the empty Hash Sets //Init the empty Hash Sets
for(PrimarySkillType primarySkillType : PrimarySkillType.values()) { for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
primarySkillChildrenMap.put(primarySkillType, new HashSet<SubSkillType>()); tempPrimaryChildMap.put(primarySkillType, new HashSet<>());
} }
//Fill in the hash sets //Fill in the hash sets
@ -159,8 +164,10 @@ public class SkillTools {
PrimarySkillType parentSkill = subSkillParentRelationshipMap.get(subSkillType); PrimarySkillType parentSkill = subSkillParentRelationshipMap.get(subSkillType);
//Add this subskill as a child //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 * Used in tab completion mostly
* @return a list of formatted sub skill names * @return a list of formatted sub skill names
*/ */
private ArrayList<String> buildFormattedSubSkillNameList() { private @NotNull ArrayList<String> buildFormattedSubSkillNameList() {
ArrayList<String> subSkillNameList = new ArrayList<>(); ArrayList<String> subSkillNameList = new ArrayList<>();
for(SubSkillType subSkillType : SubSkillType.values()) { for(SubSkillType subSkillType : SubSkillType.values()) {
@ -178,7 +185,7 @@ public class SkillTools {
return subSkillNameList; return subSkillNameList;
} }
private HashSet<String> buildExactSubSkillNameList() { private @NotNull HashSet<String> buildExactSubSkillNameList() {
HashSet<String> subSkillNameExactSet = new HashSet<>(); HashSet<String> subSkillNameExactSet = new HashSet<>();
for(SubSkillType subSkillType : SubSkillType.values()) { for(SubSkillType subSkillType : SubSkillType.values()) {
@ -193,7 +200,7 @@ public class SkillTools {
* Disgusting Hacky Fix until the new skill system is in place * Disgusting Hacky Fix until the new skill system is in place
*/ */
private void initSubSkillRelationshipMap() { private void initSubSkillRelationshipMap() {
subSkillParentRelationshipMap = new EnumMap<SubSkillType, PrimarySkillType>(SubSkillType.class); EnumMap<SubSkillType, PrimarySkillType> tempSubParentMap = new EnumMap<SubSkillType, PrimarySkillType>(SubSkillType.class);
//Super hacky and disgusting //Super hacky and disgusting
for(PrimarySkillType primarySkillType : PrimarySkillType.values()) { for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
@ -202,10 +209,12 @@ public class SkillTools {
if(primarySkillType.toString().equalsIgnoreCase(splitSubSkillName[0])) { if(primarySkillType.toString().equalsIgnoreCase(splitSubSkillName[0])) {
//Parent Skill Found //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); return primarySkillToolMap.get(primarySkillType);
} }
public List<SubSkillType> getSubSkills(PrimarySkillType primarySkillType) { public Set<SubSkillType> getSubSkills(PrimarySkillType primarySkillType) {
//TODO: Cache this! //TODO: Cache this!
return new ArrayList<>(primarySkillChildrenMap.get(primarySkillType)); return primarySkillChildrenMap.get(primarySkillType);
} }
public double getXpModifier(PrimarySkillType primarySkillType) { public double getXpModifier(PrimarySkillType primarySkillType) {
@ -323,7 +332,7 @@ public class SkillTools {
return StringUtils.getCapitalized(LocaleLoader.getString(StringUtils.getCapitalized(primarySkillType.toString()) + ".SkillName")); 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); return Permissions.skillEnabled(player, primarySkillType);
} }
@ -364,7 +373,7 @@ public class SkillTools {
} }
public int getLevelCap(@NotNull PrimarySkillType primarySkillType) { public int getLevelCap(@NotNull PrimarySkillType primarySkillType) {
return mcMMO.p.getGeneralConfig().getLevelCap(primarySkillType); return mcMMO.p.getSkillTools().getLevelCap(primarySkillType);
} }
/** /**

View File

@ -3,7 +3,6 @@ package com.gmail.nossr50.util.skills;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -89,7 +88,7 @@ public class SmeltingTracker {
} }
public void processFurnaceOwnership(Furnace furnace, Player player) { public void processFurnaceOwnership(Furnace furnace, Player player) {
if(!Permissions.skillEnabled(player, PrimarySkillType.SMELTING)) if(!mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.SMELTING))
return; return;
//Don't swap ownership if its the same player //Don't swap ownership if its the same player