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

@ -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));
}
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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)

View File

@ -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<String> LOCALIZED_SKILL_NAMES;
public final ImmutableList<String> FORMATTED_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> COMBAT_SKILLS;
public final ImmutableList<PrimarySkillType> GATHERING_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 EnumMap<SuperAbilityType, PrimarySkillType> superAbilityParentRelationshipMap; //TODO: This disgusts me, but it will have to do until the new skill system is in place
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<SubSkillType, PrimarySkillType> subSkillParentRelationshipMap;
private ImmutableMap<SuperAbilityType, PrimarySkillType> superAbilityParentRelationshipMap;
private ImmutableMap<PrimarySkillType, Set<SubSkillType>> primarySkillChildrenMap;
// 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 EnumMap<PrimarySkillType, ToolType> primarySkillToolMap; //TODO: Christ..
private ImmutableMap<PrimarySkillType, SuperAbilityType> mainActivatedAbilityChildMap;
private ImmutableMap<PrimarySkillType, ToolType> 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, ToolType>(PrimarySkillType.class);
EnumMap<PrimarySkillType, ToolType> tempToolMap = new EnumMap<PrimarySkillType, ToolType>(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, PrimarySkillType>(SuperAbilityType.class);
mainActivatedAbilityChildMap = new EnumMap<PrimarySkillType, SuperAbilityType>(PrimarySkillType.class);
EnumMap<SuperAbilityType, PrimarySkillType> tempAbilityParentRelationshipMap = new EnumMap<SuperAbilityType, PrimarySkillType>(SuperAbilityType.class);
EnumMap<PrimarySkillType, SuperAbilityType> tempMainActivatedAbilityChildMap = new EnumMap<PrimarySkillType, SuperAbilityType>(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<String> buildLocalizedPrimarySkillNames() {
private @NotNull ArrayList<String> buildLocalizedPrimarySkillNames() {
ArrayList<String> 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, HashSet<SubSkillType>>(PrimarySkillType.class);
EnumMap<PrimarySkillType, Set<SubSkillType>> tempPrimaryChildMap = new EnumMap<PrimarySkillType, Set<SubSkillType>>(PrimarySkillType.class);
//Init the empty Hash Sets
for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
primarySkillChildrenMap.put(primarySkillType, new HashSet<SubSkillType>());
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<String> buildFormattedSubSkillNameList() {
private @NotNull ArrayList<String> buildFormattedSubSkillNameList() {
ArrayList<String> subSkillNameList = new ArrayList<>();
for(SubSkillType subSkillType : SubSkillType.values()) {
@ -178,7 +185,7 @@ public class SkillTools {
return subSkillNameList;
}
private HashSet<String> buildExactSubSkillNameList() {
private @NotNull HashSet<String> buildExactSubSkillNameList() {
HashSet<String> 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, PrimarySkillType>(SubSkillType.class);
EnumMap<SubSkillType, PrimarySkillType> tempSubParentMap = new EnumMap<SubSkillType, PrimarySkillType>(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<SubSkillType> getSubSkills(PrimarySkillType primarySkillType) {
public Set<SubSkillType> 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);
}
/**

View File

@ -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