PrimarySkillType refactor and other refactors

This commit is contained in:
nossr50 2021-04-08 13:21:34 -07:00
parent 5080d86e44
commit eec5feb2bf
59 changed files with 1204 additions and 796 deletions

View File

@ -2,6 +2,9 @@ Version 2.1.189
Removed MHD command (it didn't do anything for a while now)
Removed UP warning
Updated pl locale (Thanks Mich3l3k)
Fixed an IllegalPluginAccessException error that could happen during server shutdown
Minor performance optimizations to FlatFile database
Refactored a lot of code
NOTES:
Ultra Permissions is SAFE to use with mcMMO

View File

@ -35,7 +35,7 @@ public final class ExperienceAPI {
* @return true if this is a valid mcMMO skill
*/
public static boolean isValidSkillType(String skillType) {
return PrimarySkillType.getSkill(skillType) != null;
return mcMMO.p.getSkillTools().matchSkill(skillType) != null;
}
/**
@ -78,9 +78,9 @@ public final class ExperienceAPI {
* @return true if this is a valid, non-child mcMMO skill
*/
public static boolean isNonChildSkill(String skillType) {
PrimarySkillType skill = PrimarySkillType.getSkill(skillType);
PrimarySkillType skill = mcMMO.p.getSkillTools().matchSkill(skillType);
return skill != null && !skill.isChildSkill();
return skill != null && !mcMMO.p.getSkillTools().isChildSkill(skill);
}
@Deprecated
@ -294,11 +294,12 @@ public final class ExperienceAPI {
PrimarySkillType skill = getSkillType(skillType);
if (isUnshared) {
getPlayer(player).beginUnsharedXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
getPlayer(player).beginUnsharedXpGain(skill,
(int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(skill) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
return;
}
getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
getPlayer(player).applyXpGain(skill, (int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(skill) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
}
/**
@ -317,7 +318,7 @@ public final class ExperienceAPI {
public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
PrimarySkillType skill = getSkillType(skillType);
addOfflineXP(playerName, skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()));
addOfflineXP(playerName, skill, (int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(skill) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()));
}
/**
@ -625,7 +626,7 @@ public final class ExperienceAPI {
PlayerProfile profile = getOfflineProfile(playerName);
PrimarySkillType skill = getSkillType(skillType);
if (skill.isChildSkill()) {
if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
Set<PrimarySkillType> parentSkills = FamilyTree.getParents(skill);
for (PrimarySkillType parentSkill : parentSkills) {
@ -656,7 +657,7 @@ public final class ExperienceAPI {
PlayerProfile profile = getOfflineProfile(uuid);
PrimarySkillType skill = getSkillType(skillType);
if (skill.isChildSkill()) {
if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
Set<PrimarySkillType> parentSkills = FamilyTree.getParents(skill);
for (PrimarySkillType parentSkill : parentSkills) {
@ -762,7 +763,7 @@ public final class ExperienceAPI {
int powerLevel = 0;
PlayerProfile profile = getOfflineProfile(playerName);
for (PrimarySkillType type : PrimarySkillType.NON_CHILD_SKILLS) {
for (PrimarySkillType type : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
powerLevel += profile.getSkillLevel(type);
}
@ -783,7 +784,7 @@ public final class ExperienceAPI {
int powerLevel = 0;
PlayerProfile profile = getOfflineProfile(uuid);
for (PrimarySkillType type : PrimarySkillType.NON_CHILD_SKILLS) {
for (PrimarySkillType type : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
powerLevel += profile.getSkillLevel(type);
}
@ -1168,7 +1169,7 @@ public final class ExperienceAPI {
}
private static PrimarySkillType getSkillType(String skillType) throws InvalidSkillException {
PrimarySkillType skill = PrimarySkillType.getSkill(skillType);
PrimarySkillType skill = mcMMO.p.getSkillTools().matchSkill(skillType);
if (skill == null) {
throw new InvalidSkillException();
@ -1180,7 +1181,7 @@ public final class ExperienceAPI {
private static PrimarySkillType getNonChildSkillType(String skillType) throws InvalidSkillException, UnsupportedOperationException {
PrimarySkillType skill = getSkillType(skillType);
if (skill.isChildSkill()) {
if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
throw new UnsupportedOperationException("Child skills do not have XP");
}

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.api;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import java.util.ArrayList;
import java.util.Arrays;
@ -30,7 +31,7 @@ public final class SkillAPI {
* @return a list of strings with valid skill names
*/
public static List<String> getNonChildSkills() {
return getListFromEnum(PrimarySkillType.NON_CHILD_SKILLS);
return getListFromEnum(mcMMO.p.getSkillTools().NON_CHILD_SKILLS);
}
/**
@ -42,7 +43,7 @@ public final class SkillAPI {
* @return a list of strings with valid skill names
*/
public static List<String> getChildSkills() {
return getListFromEnum(PrimarySkillType.CHILD_SKILLS);
return getListFromEnum(mcMMO.p.getSkillTools().CHILD_SKILLS);
}
/**
@ -54,7 +55,7 @@ public final class SkillAPI {
* @return a list of strings with valid skill names
*/
public static List<String> getCombatSkills() {
return getListFromEnum(PrimarySkillType.COMBAT_SKILLS);
return getListFromEnum(mcMMO.p.getSkillTools().COMBAT_SKILLS);
}
/**
@ -66,7 +67,7 @@ public final class SkillAPI {
* @return a list of strings with valid skill names
*/
public static List<String> getGatheringSkills() {
return getListFromEnum(PrimarySkillType.GATHERING_SKILLS);
return getListFromEnum(mcMMO.p.getSkillTools().GATHERING_SKILLS);
}
/**
@ -78,7 +79,7 @@ public final class SkillAPI {
* @return a list of strings with valid skill names
*/
public static List<String> getMiscSkills() {
return getListFromEnum(PrimarySkillType.MISC_SKILLS);
return getListFromEnum(mcMMO.p.getSkillTools().MISC_SKILLS);
}
private static List<String> getListFromEnum(List<PrimarySkillType> skillsTypes) {

View File

@ -5,6 +5,7 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
@ -55,6 +56,6 @@ public class AddlevelsCommand extends ExperienceCommand {
if(isSilent)
return;
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", value, skill.getName()));
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", value, mcMMO.p.getSkillTools().getLocalizedSkillName(skill)));
}
}

View File

@ -5,6 +5,7 @@ import com.gmail.nossr50.datatypes.experience.XPGainSource;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import org.bukkit.command.CommandSender;
@ -49,6 +50,6 @@ public class AddxpCommand extends ExperienceCommand {
if(isSilent)
return;
player.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", value, skill.getName()));
player.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", value, mcMMO.p.getSkillTools().getLocalizedSkillName(skill)));
}
}

View File

@ -44,13 +44,13 @@ public abstract class ExperienceCommand implements TabExecutor {
return true;
}
skill = PrimarySkillType.getSkill(args[0]);
skill = mcMMO.p.getSkillTools().matchSkill(args[0]);
if (args[1].equalsIgnoreCase("all")) {
skill = null;
}
if (skill != null && skill.isChildSkill())
if (skill != null && mcMMO.p.getSkillTools().isChildSkill(skill))
{
sender.sendMessage(LocaleLoader.getString("Commands.Skill.ChildSkill"));
return true;
@ -77,13 +77,13 @@ public abstract class ExperienceCommand implements TabExecutor {
return true;
}
skill = PrimarySkillType.getSkill(args[1]);
skill = mcMMO.p.getSkillTools().matchSkill(args[1]);
if (args[1].equalsIgnoreCase("all")) {
skill = null;
}
if (skill != null && skill.isChildSkill())
if (skill != null && mcMMO.p.getSkillTools().isChildSkill(skill))
{
sender.sendMessage(LocaleLoader.getString("Commands.Skill.ChildSkill"));
return true;
@ -144,7 +144,7 @@ public abstract class ExperienceCommand implements TabExecutor {
List<String> playerNames = CommandUtils.getOnlinePlayerNames(sender);
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size()));
case 2:
return StringUtil.copyPartialMatches(args[1], PrimarySkillType.SKILL_NAMES, new ArrayList<>(PrimarySkillType.SKILL_NAMES.size()));
return StringUtil.copyPartialMatches(args[1], mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES, new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size()));
default:
return ImmutableList.of();
}
@ -165,13 +165,13 @@ public abstract class ExperienceCommand implements TabExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", playerName));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", skill.getName(), playerName));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", mcMMO.p.getSkillTools().getLocalizedSkillName(skill), playerName));
}
}
protected void editValues(Player player, PlayerProfile profile, PrimarySkillType skill, int value, boolean isSilent) {
if (skill == null) {
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
handleCommand(player, profile, primarySkillType, value);
}

View File

@ -5,6 +5,7 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
@ -61,6 +62,6 @@ public class MmoeditCommand extends ExperienceCommand {
if(isSilent)
return;
player.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", skill.getName(), value));
player.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", mcMMO.p.getSkillTools().getLocalizedSkillName(skill), value));
}
}

View File

@ -50,7 +50,7 @@ public class SkillresetCommand implements TabExecutor {
skill = null;
}
else {
skill = PrimarySkillType.getSkill(args[0]);
skill = mcMMO.p.getSkillTools().matchSkill(args[0]);
}
editValues((Player) sender, UserManager.getPlayer(sender.getName()).getProfile(), skill);
@ -70,7 +70,7 @@ public class SkillresetCommand implements TabExecutor {
skill = null;
}
else {
skill = PrimarySkillType.getSkill(args[1]);
skill = mcMMO.p.getSkillTools().matchSkill(args[1]);
}
String playerName = CommandUtils.getMatchedPlayerName(args[0]);
@ -116,7 +116,7 @@ public class SkillresetCommand implements TabExecutor {
List<String> playerNames = CommandUtils.getOnlinePlayerNames(sender);
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size()));
case 2:
return StringUtil.copyPartialMatches(args[1], PrimarySkillType.SKILL_NAMES, new ArrayList<>(PrimarySkillType.SKILL_NAMES.size()));
return StringUtil.copyPartialMatches(args[1], mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES, new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size()));
default:
return ImmutableList.of();
}
@ -149,7 +149,7 @@ public class SkillresetCommand implements TabExecutor {
}
protected void handlePlayerMessageSkill(Player player, PrimarySkillType skill) {
player.sendMessage(LocaleLoader.getString("Commands.Reset.Single", skill.getName()));
player.sendMessage(LocaleLoader.getString("Commands.Reset.Single", mcMMO.p.getSkillTools().getLocalizedSkillName(skill)));
}
private boolean validateArguments(CommandSender sender, String skillName) {
@ -161,13 +161,13 @@ public class SkillresetCommand implements TabExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", playerName));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", skill.getName(), playerName));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", mcMMO.p.getSkillTools().getLocalizedSkillName(skill), playerName));
}
}
protected void editValues(Player player, PlayerProfile profile, PrimarySkillType skill) {
if (skill == null) {
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
handleCommand(player, profile, primarySkillType);
}

View File

@ -51,7 +51,7 @@
//
// private void toggle(boolean enable, PrimarySkillType skill) {
// if (skill == null) {
// for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
// for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
// primarySkillType.setHardcoreStatLossEnabled(enable);
// }
// }
@ -59,6 +59,6 @@
// skill.setHardcoreStatLossEnabled(enable);
// }
//
// mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Mode." + (enable ? "Enabled" : "Disabled"), LocaleLoader.getString("Hardcore.DeathStatLoss.Name"), (skill == null ? "all skills" : skill.getName())));
// mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Mode." + (enable ? "Enabled" : "Disabled"), LocaleLoader.getString("Hardcore.DeathStatLoss.Name"), (skill == null ? "all skills" : mcMMO.p.getSkillTools().getLocalizedSkillName(skill))));
// }
//}

View File

@ -1,129 +1,129 @@
package com.gmail.nossr50.commands.hardcore;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.text.StringUtils;
import com.google.common.collect.ImmutableList;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
public abstract class HardcoreModeCommand implements TabExecutor {
protected final DecimalFormat percent = new DecimalFormat("##0.00%");
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
switch (args.length) {
case 0:
if (!checkTogglePermissions(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (checkEnabled(null)) {
disable(null);
}
else {
enable(null);
}
return true;
case 1:
if (CommandUtils.shouldEnableToggle(args[0])) {
if (!Permissions.hardcoreToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
enable(null);
return true;
}
if (CommandUtils.shouldDisableToggle(args[0])) {
if (!Permissions.hardcoreToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
disable(null);
return true;
}
if (CommandUtils.isInvalidDouble(sender, args[0])) {
return true;
}
if (!Permissions.hardcoreModify(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
modify(sender, Double.parseDouble(args[0]));
return true;
case 2:
if (CommandUtils.isInvalidSkill(sender, args[0])) {
return true;
}
PrimarySkillType skill = PrimarySkillType.getSkill(args[0]);
if (!CommandUtils.isChildSkill(sender, skill)) {
return true;
}
if (CommandUtils.shouldEnableToggle(args[1])) {
if (!Permissions.hardcoreToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
enable(skill);
return true;
}
if (CommandUtils.shouldDisableToggle(args[1])) {
if (!Permissions.hardcoreToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
enable(skill);
return true;
}
return true;
default:
return false;
}
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
if (args.length == 1) {
if (StringUtils.isDouble(args[0])) {
return ImmutableList.of();
}
return StringUtil.copyPartialMatches(args[0], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList<>(CommandUtils.TRUE_FALSE_OPTIONS.size()));
}
return ImmutableList.of();
}
protected abstract boolean checkTogglePermissions(CommandSender sender);
protected abstract boolean checkModifyPermissions(CommandSender sender);
protected abstract boolean checkEnabled(PrimarySkillType skill);
protected abstract void enable(PrimarySkillType skill);
protected abstract void disable(PrimarySkillType skill);
protected abstract void modify(CommandSender sender, double newPercentage);
}
//package com.gmail.nossr50.commands.hardcore;
//
//import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
//import com.gmail.nossr50.util.Permissions;
//import com.gmail.nossr50.util.commands.CommandUtils;
//import com.gmail.nossr50.util.text.StringUtils;
//import com.google.common.collect.ImmutableList;
//import org.bukkit.command.Command;
//import org.bukkit.command.CommandSender;
//import org.bukkit.command.TabExecutor;
//import org.bukkit.util.StringUtil;
//import org.jetbrains.annotations.NotNull;
//
//import java.text.DecimalFormat;
//import java.util.ArrayList;
//import java.util.List;
//
//public abstract class HardcoreModeCommand implements TabExecutor {
// protected final DecimalFormat percent = new DecimalFormat("##0.00%");
//
// @Override
// public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
// switch (args.length) {
// case 0:
// if (!checkTogglePermissions(sender)) {
// sender.sendMessage(command.getPermissionMessage());
// return true;
// }
//
// if (checkEnabled(null)) {
// disable(null);
// }
// else {
// enable(null);
// }
//
// return true;
//
// case 1:
// if (CommandUtils.shouldEnableToggle(args[0])) {
// if (!Permissions.hardcoreToggle(sender)) {
// sender.sendMessage(command.getPermissionMessage());
// return true;
// }
//
// enable(null);
// return true;
// }
//
// if (CommandUtils.shouldDisableToggle(args[0])) {
// if (!Permissions.hardcoreToggle(sender)) {
// sender.sendMessage(command.getPermissionMessage());
// return true;
// }
//
// disable(null);
// return true;
// }
//
// if (CommandUtils.isInvalidDouble(sender, args[0])) {
// return true;
// }
//
// if (!Permissions.hardcoreModify(sender)) {
// sender.sendMessage(command.getPermissionMessage());
// return true;
// }
//
// modify(sender, Double.parseDouble(args[0]));
// return true;
//
//
// case 2:
// if (CommandUtils.isInvalidSkill(sender, args[0])) {
// return true;
// }
//
// PrimarySkillType skill = PrimarySkillType.getSkill(args[0]);
//
// if (!CommandUtils.isChildSkill(sender, skill)) {
// return true;
// }
//
// if (CommandUtils.shouldEnableToggle(args[1])) {
// if (!Permissions.hardcoreToggle(sender)) {
// sender.sendMessage(command.getPermissionMessage());
// return true;
// }
//
// enable(skill);
// return true;
// }
//
// if (CommandUtils.shouldDisableToggle(args[1])) {
// if (!Permissions.hardcoreToggle(sender)) {
// sender.sendMessage(command.getPermissionMessage());
// return true;
// }
//
// enable(skill);
// return true;
// }
//
// return true;
//
// default:
// return false;
// }
// }
//
// @Override
// public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
// if (args.length == 1) {
// if (StringUtils.isDouble(args[0])) {
// return ImmutableList.of();
// }
//
// return StringUtil.copyPartialMatches(args[0], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList<>(CommandUtils.TRUE_FALSE_OPTIONS.size()));
// }
// return ImmutableList.of();
// }
//
// protected abstract boolean checkTogglePermissions(CommandSender sender);
// protected abstract boolean checkModifyPermissions(CommandSender sender);
// protected abstract boolean checkEnabled(PrimarySkillType skill);
// protected abstract void enable(PrimarySkillType skill);
// protected abstract void disable(PrimarySkillType skill);
// protected abstract void modify(CommandSender sender, double newPercentage);
//}

View File

@ -51,7 +51,7 @@
//
// private void toggle(boolean enable, PrimarySkillType skill) {
// if (skill == null) {
// for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
// for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
// primarySkillType.setHardcoreVampirismEnabled(enable);
// }
// }

View File

@ -48,17 +48,17 @@ public class InspectCommand implements TabExecutor {
sender.sendMessage(LocaleLoader.getString("Inspect.OfflineStats", playerName));
sender.sendMessage(LocaleLoader.getString("Stats.Header.Gathering"));
for (PrimarySkillType skill : PrimarySkillType.GATHERING_SKILLS) {
for (PrimarySkillType skill : mcMMO.p.getSkillTools().GATHERING_SKILLS) {
sender.sendMessage(CommandUtils.displaySkill(profile, skill));
}
sender.sendMessage(LocaleLoader.getString("Stats.Header.Combat"));
for (PrimarySkillType skill : PrimarySkillType.COMBAT_SKILLS) {
for (PrimarySkillType skill : mcMMO.p.getSkillTools().COMBAT_SKILLS) {
sender.sendMessage(CommandUtils.displaySkill(profile, skill));
}
sender.sendMessage(LocaleLoader.getString("Stats.Header.Misc"));
for (PrimarySkillType skill : PrimarySkillType.MISC_SKILLS) {
for (PrimarySkillType skill : mcMMO.p.getSkillTools().MISC_SKILLS) {
sender.sendMessage(CommandUtils.displaySkill(profile, skill));
}

View File

@ -68,7 +68,7 @@ public class MctopCommand implements TabExecutor {
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], PrimarySkillType.SKILL_NAMES, new ArrayList<>(PrimarySkillType.SKILL_NAMES.size()));
return StringUtil.copyPartialMatches(args[0], mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES, new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size()));
}
return ImmutableList.of();
}
@ -122,7 +122,7 @@ public class MctopCommand implements TabExecutor {
return null;
}
PrimarySkillType skill = PrimarySkillType.getSkill(skillName);
PrimarySkillType skill = mcMMO.p.getSkillTools().matchSkill(skillName);
if (CommandUtils.isChildSkill(sender, skill)) {
return null;

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.commands.player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.experience.ExperienceBarManager;
import com.gmail.nossr50.util.player.NotificationManager;
import com.gmail.nossr50.util.player.UserManager;
@ -51,7 +52,7 @@ public class XPBarCommand implements TabExecutor {
if(SkillUtils.isSkill(skillName)) {
PrimarySkillType targetSkill = PrimarySkillType.getSkill(skillName);
PrimarySkillType targetSkill = mcMMO.p.getSkillTools().matchSkill(skillName);
//Target setting
String option = args[0].toLowerCase();
@ -103,7 +104,7 @@ public class XPBarCommand implements TabExecutor {
return StringUtil.copyPartialMatches(args[0], options, new ArrayList<>(ExperienceBarManager.XPBarSettingTarget.values().length));
case 2:
if(!args[0].equalsIgnoreCase(ExperienceBarManager.XPBarSettingTarget.RESET.toString()))
return StringUtil.copyPartialMatches(args[1], PrimarySkillType.SKILL_NAMES, new ArrayList<>(PrimarySkillType.SKILL_NAMES.size()));
return StringUtil.copyPartialMatches(args[1], mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES, new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size()));
default:
return ImmutableList.of();
}

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType;
@ -93,7 +94,7 @@ public class HerbalismCommand extends SkillCommand {
canGreenThumbPlants = RankUtils.hasUnlockedSubskill(player, SubSkillType.HERBALISM_GREEN_THUMB) && (Permissions.greenThumbPlant(player, Material.WHEAT) || Permissions.greenThumbPlant(player, Material.CARROT) || Permissions.greenThumbPlant(player, Material.POTATO) || Permissions.greenThumbPlant(player, Material.BEETROOT) || Permissions.greenThumbPlant(player, Material.NETHER_WART) || Permissions.greenThumbPlant(player, Material.COCOA));
canGreenThumbBlocks = RankUtils.hasUnlockedSubskill(player, SubSkillType.HERBALISM_GREEN_THUMB) && (Permissions.greenThumbBlock(player, Material.DIRT) || Permissions.greenThumbBlock(player, Material.COBBLESTONE) || Permissions.greenThumbBlock(player, Material.COBBLESTONE_WALL) || Permissions.greenThumbBlock(player, Material.STONE_BRICKS));
canFarmersDiet = canUseSubskill(player, SubSkillType.HERBALISM_FARMERS_DIET);
canDoubleDrop = canUseSubskill(player, SubSkillType.HERBALISM_DOUBLE_DROPS) && !skill.getDoubleDropsDisabled();
canDoubleDrop = canUseSubskill(player, SubSkillType.HERBALISM_DOUBLE_DROPS) && !mcMMO.p.getGeneralConfig().getDoubleDropsDisabled(skill);
canShroomThumb = canUseSubskill(player, SubSkillType.HERBALISM_SHROOM_THUMB);
}

View File

@ -4,6 +4,7 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.listeners.InteractionManager;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.text.TextComponentFactory;
import com.google.common.collect.ImmutableList;
@ -45,7 +46,7 @@ public class MmoInfoCommand implements TabExecutor {
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.DetailsHeader"));
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.Mystery"));
return true;
} else if(InteractionManager.getAbstractByName(args[0]) != null || PrimarySkillType.SUBSKILL_NAMES.contains(args[0]))
} else if(InteractionManager.getAbstractByName(args[0]) != null || mcMMO.p.getSkillTools().EXACT_SUBSKILL_NAMES.contains(args[0]))
{
displayInfo(player, args[0]);
return true;
@ -63,7 +64,7 @@ public class MmoInfoCommand implements TabExecutor {
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], PrimarySkillType.SUBSKILL_NAMES, new ArrayList<>(PrimarySkillType.SUBSKILL_NAMES.size()));
return StringUtil.copyPartialMatches(args[0], mcMMO.p.getSkillTools().EXACT_SUBSKILL_NAMES, new ArrayList<>(mcMMO.p.getSkillTools().EXACT_SUBSKILL_NAMES.size()));
}
return ImmutableList.of();
}

View File

@ -44,7 +44,7 @@ public abstract class SkillCommand implements TabExecutor {
public SkillCommand(PrimarySkillType skill) {
this.skill = skill;
skillName = skill.getName();
skillName = mcMMO.p.getSkillTools().getLocalizedSkillName(skill);
skillGuideCommand = new SkillGuideCommand(skill);
}
@ -142,7 +142,7 @@ public abstract class SkillCommand implements TabExecutor {
player.sendMessage(LocaleLoader.getString("Skills.Overhaul.Header", skillName));
if(!skill.isChildSkill())
if(!mcMMO.p.getSkillTools().isChildSkill(skill))
{
/*
* NON-CHILD SKILLS
@ -172,10 +172,10 @@ public abstract class SkillCommand implements TabExecutor {
{
if(i+1 < parentList.size())
{
parentMessage.append(LocaleLoader.getString("Effects.Child.ParentList", parentList.get(i).getName(), mcMMOPlayer.getSkillLevel(parentList.get(i))));
parentMessage.append(LocaleLoader.getString("Effects.Child.ParentList", mcMMO.p.getSkillTools().getLocalizedSkillName(parentList.get(i)), mcMMOPlayer.getSkillLevel(parentList.get(i))));
parentMessage.append(ChatColor.GRAY).append(", ");
} else {
parentMessage.append(LocaleLoader.getString("Effects.Child.ParentList", parentList.get(i).getName(), mcMMOPlayer.getSkillLevel(parentList.get(i))));
parentMessage.append(LocaleLoader.getString("Effects.Child.ParentList", mcMMO.p.getSkillTools().getLocalizedSkillName(parentList.get(i)), mcMMOPlayer.getSkillLevel(parentList.get(i))));
}
}
@ -188,7 +188,7 @@ public abstract class SkillCommand implements TabExecutor {
}
/*
if (!skill.isChildSkill()) {
if (!mcMMO.p.getSkillTools().isChildSkill(skill)) {
player.sendMessage(LocaleLoader.getString("Skills.Header", skillName));
player.sendMessage(LocaleLoader.getString("Commands.XPGain", LocaleLoader.getString("Commands.XPGain." + StringUtils.getCapitalized(skill.toString()))));
player.sendMessage(LocaleLoader.getString("Effects.Level", skillValue, mcMMOPlayer.getSkillXpLevel(skill), mcMMOPlayer.getXpToLevel(skill)));
@ -224,7 +224,7 @@ public abstract class SkillCommand implements TabExecutor {
}
protected String[] calculateLengthDisplayValues(Player player, float skillValue) {
int maxLength = skill.getAbility().getMaxLength();
int maxLength = mcMMO.p.getSkillTools().getSuperAbilityMaxLength(mcMMO.p.getSkillTools().getSuperAbility(skill));
int abilityLengthVar = mcMMO.p.getAdvancedConfig().getAbilityLength();
int abilityLengthCap = mcMMO.p.getAdvancedConfig().getAbilityLengthCap();

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.text.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -18,7 +19,7 @@ public class SkillGuideCommand implements CommandExecutor {
private final String invalidPage = LocaleLoader.getString("Guides.Page.Invalid");
public SkillGuideCommand(PrimarySkillType skill) {
header = LocaleLoader.getString("Guides.Header", skill.getName());
header = LocaleLoader.getString("Guides.Header", mcMMO.p.getSkillTools().getLocalizedSkillName(skill));
guide = getGuide(skill);
}

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType;
@ -55,7 +56,9 @@ public class WoodcuttingCommand extends SkillCommand {
@Override
protected void permissionsCheck(Player player) {
canTreeFell = RankUtils.hasUnlockedSubskill(player, SubSkillType.WOODCUTTING_TREE_FELLER) && Permissions.treeFeller(player);
canDoubleDrop = canUseSubskill(player, SubSkillType.WOODCUTTING_HARVEST_LUMBER) && !skill.getDoubleDropsDisabled() && RankUtils.getRank(player, SubSkillType.WOODCUTTING_HARVEST_LUMBER) >= 1;
canDoubleDrop = canUseSubskill(player, SubSkillType.WOODCUTTING_HARVEST_LUMBER)
&& !mcMMO.p.getGeneralConfig().getDoubleDropsDisabled(skill)
&& RankUtils.getRank(player, SubSkillType.WOODCUTTING_HARVEST_LUMBER) >= 1;
canLeafBlow = canUseSubskill(player, SubSkillType.WOODCUTTING_LEAF_BLOWER);
canKnockOnWood = canTreeFell && canUseSubskill(player, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD);
/*canSplinter = canUseSubskill(player, SubSkillType.WOODCUTTING_SPLINTER);

View File

@ -164,7 +164,7 @@ public class GeneralConfig extends AutoUpdateConfigLoader {
//Retro mode will default the value to true if the config file doesn't contain the entry (server is from a previous mcMMO install)
public boolean getIsRetroMode() { return config.getBoolean("General.RetroMode.Enabled", true); }
public String getLocale() { return config.getString("General.Locale", "en_us"); }
public String getLocale() { return config.getString("General.Locale", "en_US"); }
public boolean getMOTDEnabled() { return config.getBoolean("General.MOTD_Enabled", true); }
public boolean getShowProfileLoadedMessage() { return config.getBoolean("General.Show_Profile_Loaded", true); }
public boolean getDonateMessageEnabled() { return config.getBoolean("Commands.mcmmo.Donate_Message", true); }

View File

@ -7,7 +7,6 @@ import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.player.UniqueDataType;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.datatypes.skills.interfaces.Skill;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Misc;
import org.bukkit.OfflinePlayer;
@ -21,7 +20,7 @@ import java.util.logging.Logger;
public final class FlatFileDatabaseManager implements DatabaseManager {
public static final String IGNORED = "IGNORED";
private final @NotNull HashMap<PrimarySkillType, List<PlayerStat>> playerStatHash = new HashMap<>();
private final @NotNull EnumMap<PrimarySkillType, List<PlayerStat>> playerStatHash = new EnumMap<PrimarySkillType, List<PlayerStat>>(PrimarySkillType.class);
private final @NotNull List<PlayerStat> powerLevels = new ArrayList<>();
private long lastUpdate = 0;
private final @NotNull String usersFilePath;
@ -106,7 +105,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
while ((line = in.readLine()) != null) {
String[] character = line.split(":");
Map<Skill, Integer> skills = getSkillMapFromLine(character);
Map<PrimarySkillType, Integer> skills = getSkillMapFromLine(character);
boolean powerless = true;
for (int skill : skills.values()) {
@ -433,15 +432,15 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
writer.append("\r\n");
}
public @NotNull List<PlayerStat> readLeaderboard(@Nullable PrimarySkillType skill, int pageNumber, int statsPerPage) throws InvalidSkillException {
public @NotNull List<PlayerStat> readLeaderboard(@Nullable PrimarySkillType primarySkillType, int pageNumber, int statsPerPage) throws InvalidSkillException {
//Fix for a plugin that people are using that is throwing SQL errors
if(skill != null && skill.isChildSkill()) {
if(primarySkillType != null && mcMMO.p.getSkillTools().isChildSkill(primarySkillType)) {
logger.severe("A plugin hooking into mcMMO is being naughty with our database commands, update all plugins that hook into mcMMO and contact their devs!");
throw new InvalidSkillException("A plugin hooking into mcMMO that you are using is attempting to read leaderboard skills for child skills, child skills do not have leaderboards! This is NOT an mcMMO error!");
}
updateLeaderboards();
List<PlayerStat> statsList = skill == null ? powerLevels : playerStatHash.get(skill);
List<PlayerStat> statsList = primarySkillType == null ? powerLevels : playerStatHash.get(primarySkillType);
int fromIndex = (Math.max(pageNumber, 1) - 1) * statsPerPage;
return statsList.subList(Math.min(fromIndex, statsList.size()), Math.min(fromIndex + statsPerPage, statsList.size()));
@ -450,9 +449,9 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
public Map<PrimarySkillType, Integer> readRank(String playerName) {
updateLeaderboards();
Map<PrimarySkillType, Integer> skills = new HashMap<>();
Map<PrimarySkillType, Integer> skills = new EnumMap<PrimarySkillType, Integer>(PrimarySkillType.class);
for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) {
for (PrimarySkillType skill : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
skills.put(skill, getPlayerRank(playerName, playerStatHash.get(skill)));
}
@ -893,7 +892,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
playerName = data[USERNAME_INDEX];
int powerLevel = 0;
Map<Skill, Integer> skills = getSkillMapFromLine(data);
Map<PrimarySkillType, Integer> skills = getSkillMapFromLine(data);
powerLevel += putStat(acrobatics, playerName, skills.get(PrimarySkillType.ACROBATICS));
powerLevel += putStat(alchemy, playerName, skills.get(PrimarySkillType.ALCHEMY));
@ -1117,8 +1116,8 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
}
private PlayerProfile loadFromLine(@NotNull String[] character) {
Map<Skill, Integer> skills = getSkillMapFromLine(character); // Skill levels
Map<Skill, Float> skillsXp = new HashMap<>(); // Skill & XP
Map<PrimarySkillType, Integer> skills = getSkillMapFromLine(character); // Skill levels
Map<PrimarySkillType, Float> skillsXp = new EnumMap<>(PrimarySkillType.class); // Skill & XP
Map<SuperAbilityType, Integer> skillsDATS = new EnumMap<>(SuperAbilityType.class); // Ability & Cooldown
Map<UniqueDataType, Integer> uniquePlayerDataMap = new EnumMap<>(UniqueDataType.class);
int scoreboardTipsShown;
@ -1193,7 +1192,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
}
}
private void tryLoadSkillFloatValuesFromRawData(@NotNull Map<Skill, Float> skillMap, @NotNull String[] character, @NotNull Skill primarySkillType, int index, @NotNull String userName) {
private void tryLoadSkillFloatValuesFromRawData(@NotNull Map<PrimarySkillType, Float> skillMap, @NotNull String[] character, @NotNull PrimarySkillType primarySkillType, int index, @NotNull String userName) {
try {
float valueFromString = Integer.parseInt(character[index]);
skillMap.put(primarySkillType, valueFromString);
@ -1204,19 +1203,19 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
}
}
private void tryLoadSkillIntValuesFromRawData(@NotNull Map<Skill, Integer> skillMap, @NotNull String[] character, @NotNull Skill skill, int index, @NotNull String userName) {
private void tryLoadSkillIntValuesFromRawData(@NotNull Map<PrimarySkillType, Integer> skillMap, @NotNull String[] character, @NotNull PrimarySkillType primarySkillType, int index, @NotNull String userName) {
try {
int valueFromString = Integer.parseInt(character[index]);
skillMap.put(skill, valueFromString);
skillMap.put(primarySkillType, valueFromString);
} catch (NumberFormatException e) {
skillMap.put(skill, 0);
logger.severe("Data corruption when trying to load the value for skill "+skill+" for player named " + userName+ " setting value to zero");
skillMap.put(primarySkillType, 0);
logger.severe("Data corruption when trying to load the value for skill "+primarySkillType+" for player named " + userName+ " setting value to zero");
e.printStackTrace();
}
}
private @NotNull Map<Skill, Integer> getSkillMapFromLine(@NotNull String[] character) {
HashMap<Skill, Integer> skills = new HashMap<>(); // Skill & Level
private @NotNull Map<PrimarySkillType, Integer> getSkillMapFromLine(@NotNull String[] character) {
EnumMap<PrimarySkillType, Integer> skills = new EnumMap<>(PrimarySkillType.class); // Skill & Level
String username = character[USERNAME_INDEX];
tryLoadSkillIntValuesFromRawData(skills, character, PrimarySkillType.ACROBATICS, SKILLS_ACROBATICS, username);

View File

@ -9,7 +9,6 @@ import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.player.UniqueDataType;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.datatypes.skills.interfaces.Skill;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.database.UUIDUpdateAsyncTask;
import com.gmail.nossr50.util.Misc;
@ -29,6 +28,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
public static final String MOBHEALTHBAR_VARCHAR = "VARCHAR(50)";
public static final String UUID_VARCHAR = "VARCHAR(36)";
public static final String USER_VARCHAR = "VARCHAR(40)";
public static final int CHILD_SKILLS_SIZE = 2;
private final String tablePrefix = mcMMO.p.getGeneralConfig().getMySQLTablePrefix();
private final Map<UUID, Integer> cachedUserIDs = new HashMap<>();
@ -274,7 +274,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
statement.setInt(12, profile.getSkillLevel(PrimarySkillType.FISHING));
statement.setInt(13, profile.getSkillLevel(PrimarySkillType.ALCHEMY));
int total = 0;
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS)
for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS)
total += profile.getSkillLevel(primarySkillType);
statement.setInt(14, total);
statement.setInt(15, id);
@ -358,7 +358,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
List<PlayerStat> stats = new ArrayList<>();
//Fix for a plugin that people are using that is throwing SQL errors
if(skill != null && skill.isChildSkill()) {
if(skill != null && mcMMO.p.getSkillTools().isChildSkill(skill)) {
mcMMO.p.getLogger().severe("A plugin hooking into mcMMO is being naughty with our database commands, update all plugins that hook into mcMMO and contact their devs!");
throw new InvalidSkillException("A plugin hooking into mcMMO that you are using is attempting to read leaderboard skills for child skills, child skills do not have leaderboards! This is NOT an mcMMO error!");
}
@ -407,7 +407,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
try {
connection = getConnection(PoolIdentifier.MISC);
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
String skillName = primarySkillType.name().toLowerCase(Locale.ENGLISH);
// Get count of all users with higher skill level than player
String sql = "SELECT COUNT(*) AS 'rank' FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE " + skillName + " > 0 " +
@ -880,7 +880,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
resultSet = statement.executeQuery();
if (!resultSet.next()) {
String startingLevel = "'" + mcMMO.p.getAdvancedConfig().getStartingLevel() + "'";
String totalLevel = "'" + (mcMMO.p.getAdvancedConfig().getStartingLevel() * (PrimarySkillType.values().length - PrimarySkillType.CHILD_SKILLS.size())) + "'";
String totalLevel = "'" + (mcMMO.p.getAdvancedConfig().getStartingLevel() * (PrimarySkillType.values().length - CHILD_SKILLS_SIZE)) + "'";
createStatement = connection.createStatement();
createStatement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "skills` ("
+ "`user_id` int(10) unsigned NOT NULL,"
@ -935,7 +935,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
}
if (mcMMO.p.getGeneralConfig().getTruncateSkills()) {
for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) {
for (PrimarySkillType skill : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
int cap = mcMMO.p.getGeneralConfig().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);
@ -1099,8 +1099,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
}
private PlayerProfile loadFromResult(String playerName, ResultSet result) throws SQLException {
Map<Skill, Integer> skills = new HashMap<>(); // Skill & Level
Map<Skill, Float> skillsXp = new HashMap<>(); // Skill & XP
Map<PrimarySkillType, Integer> skills = new EnumMap<PrimarySkillType, Integer>(PrimarySkillType.class); // Skill & Level
Map<PrimarySkillType, Float> skillsXp = new EnumMap<PrimarySkillType, Float>(PrimarySkillType.class); // Skill & XP
Map<SuperAbilityType, Integer> skillsDATS = new EnumMap<>(SuperAbilityType.class); // Ability & Cooldown
Map<UniqueDataType, Integer> uniqueData = new EnumMap<>(UniqueDataType.class); //Chimaera wing cooldown and other misc info
MobHealthbarType mobHealthbarType;
@ -1294,10 +1294,10 @@ public final class SQLDatabaseManager implements DatabaseManager {
resultSet = statement.executeQuery("SHOW INDEX FROM `" + tablePrefix + "skills` WHERE `Key_name` LIKE 'idx\\_%'");
resultSet.last();
if (resultSet.getRow() != PrimarySkillType.NON_CHILD_SKILLS.size()) {
if (resultSet.getRow() != mcMMO.p.getSkillTools().NON_CHILD_SKILLS.size()) {
mcMMO.p.getLogger().info("Indexing tables, this may take a while on larger databases");
for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) {
for (PrimarySkillType skill : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
String skill_name = skill.name().toLowerCase(Locale.ENGLISH);
try {

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.datatypes.player;
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
import com.gmail.nossr50.chat.author.PlayerAuthor;
import com.gmail.nossr50.config.ChatConfig;
import com.gmail.nossr50.config.WorldBlacklist;
@ -66,7 +67,7 @@ import org.bukkit.plugin.Plugin;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@ -80,7 +81,7 @@ public class McMMOPlayer implements Identified {
private final Player player;
private final PlayerProfile profile;
private final Map<PrimarySkillType, SkillManager> skillManagers = new HashMap<>();
private final Map<PrimarySkillType, SkillManager> skillManagers = new EnumMap<PrimarySkillType, SkillManager>(PrimarySkillType.class);
private final ExperienceBarManager experienceBarManager;
private Party party;
@ -99,10 +100,10 @@ public class McMMOPlayer implements Identified {
private ChatChannel chatChannel;
private final Map<SuperAbilityType, Boolean> abilityMode = new HashMap<>();
private final Map<SuperAbilityType, Boolean> abilityInformed = new HashMap<>();
private final Map<SuperAbilityType, Boolean> abilityMode = new EnumMap<SuperAbilityType, Boolean>(SuperAbilityType.class);
private final Map<SuperAbilityType, Boolean> abilityInformed = new EnumMap<SuperAbilityType, Boolean>(SuperAbilityType.class);
private final Map<ToolType, Boolean> toolMode = new HashMap<>();
private final Map<ToolType, Boolean> toolMode = new EnumMap<ToolType, Boolean>(ToolType.class);
private int recentlyHurt;
private int respawnATS;
@ -131,20 +132,7 @@ public class McMMOPlayer implements Identified {
profile.setUniqueId(uuid);
}
/*
* I'm using this method because it makes code shorter and safer (we don't have to add all SkillTypes manually),
* but I actually have no idea about the performance impact, if there is any.
* If in the future someone wants to remove this, don't forget to also remove what is in the PrimarySkillType enum. - bm01
*/
try {
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
skillManagers.put(primarySkillType, primarySkillType.getManagerClass().getConstructor(McMMOPlayer.class).newInstance(this));
}
}
catch (Exception e) {
e.printStackTrace();
mcMMO.p.getPluginLoader().disablePlugin(mcMMO.p);
}
initSkillManagers();
for (SuperAbilityType superAbilityType : SuperAbilityType.values()) {
abilityMode.put(superAbilityType, false);
@ -169,6 +157,69 @@ public class McMMOPlayer implements Identified {
}
}
private void initSkillManagers() {
for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
try {
initManager(primarySkillType);
} catch (InvalidSkillException e) {
e.printStackTrace();
}
}
}
//TODO: Add test
private void initManager(PrimarySkillType primarySkillType) throws InvalidSkillException {
switch(primarySkillType) {
case ACROBATICS:
skillManagers.put(primarySkillType, new AcrobaticsManager(this));
break;
case ALCHEMY:
skillManagers.put(primarySkillType, new AlchemyManager(this));
break;
case ARCHERY:
skillManagers.put(primarySkillType, new ArcheryManager(this));
break;
case AXES:
skillManagers.put(primarySkillType, new AxesManager(this));
break;
case EXCAVATION:
skillManagers.put(primarySkillType, new ExcavationManager(this));
break;
case FISHING:
skillManagers.put(primarySkillType, new FishingManager(this));
break;
case HERBALISM:
skillManagers.put(primarySkillType, new HerbalismManager(this));
break;
case MINING:
skillManagers.put(primarySkillType, new MiningManager(this));
break;
case REPAIR:
skillManagers.put(primarySkillType, new RepairManager(this));
break;
case SALVAGE:
skillManagers.put(primarySkillType, new SalvageManager(this));
break;
case SMELTING:
skillManagers.put(primarySkillType, new SmeltingManager(this));
break;
case SWORDS:
skillManagers.put(primarySkillType, new SwordsManager(this));
break;
case TAMING:
skillManagers.put(primarySkillType, new TamingManager(this));
break;
case UNARMED:
skillManagers.put(primarySkillType, new UnarmedManager(this));
break;
case WOODCUTTING:
skillManagers.put(primarySkillType, new WoodcuttingManager(this));
break;
default:
throw new InvalidSkillException("The skill named has no manager! Contact the devs!");
}
}
public String getPlayerName() {
return playerName;
}
@ -200,7 +251,9 @@ public class McMMOPlayer implements Identified {
if(hasReachedPowerLevelCap()) {
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)), primarySkillType.getName());
NotificationManager.sendPlayerInformationChatOnly(player, "LevelCap.Skill",
String.valueOf(mcMMO.p.getGeneralConfig().getLevelCap(primarySkillType)),
mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType));
}
//Updates from Party sources
@ -227,7 +280,7 @@ public class McMMOPlayer implements Identified {
public double getProgressInCurrentSkillLevel(PrimarySkillType primarySkillType)
{
if(primarySkillType.isChildSkill()) {
if(mcMMO.p.getSkillTools().isChildSkill(primarySkillType)) {
return 1.0D;
}
@ -516,9 +569,9 @@ public class McMMOPlayer implements Identified {
public int getPowerLevel() {
int powerLevel = 0;
for (PrimarySkillType type : PrimarySkillType.NON_CHILD_SKILLS) {
if (type.getPermissions(player)) {
powerLevel += getSkillLevel(type);
for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
if (Permissions.skillEnabled(player, primarySkillType)) {
powerLevel += getSkillLevel(primarySkillType);
}
}
@ -558,12 +611,12 @@ public class McMMOPlayer implements Identified {
return;
}
if (skill.isChildSkill()) {
if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
Set<PrimarySkillType> parentSkills = FamilyTree.getParents(skill);
float splitXp = xp / parentSkills.size();
for (PrimarySkillType parentSkill : parentSkills) {
if (parentSkill.getPermissions(player)) {
if (Permissions.skillEnabled(player, parentSkill)) {
beginXpGain(parentSkill, splitXp, xpGainReason, xpGainSource);
}
}
@ -607,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 (!primarySkillType.getPermissions(player)) {
if (!Permissions.skillEnabled(player, primarySkillType)) {
return;
}
@ -615,7 +668,7 @@ public class McMMOPlayer implements Identified {
Bukkit.getPluginManager().callEvent(mcMMOPlayerPreXpGainEvent);
xp = mcMMOPlayerPreXpGainEvent.getXpGained();
if (primarySkillType.isChildSkill()) {
if (mcMMO.p.getSkillTools().isChildSkill(primarySkillType)) {
Set<PrimarySkillType> parentSkills = FamilyTree.getParents(primarySkillType);
for (PrimarySkillType parentSkill : parentSkills) {
@ -784,12 +837,12 @@ 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 ((primarySkillType.getMaxLevel() <= getSkillLevel(primarySkillType))
if ((mcMMO.p.getGeneralConfig().getLevelCap(primarySkillType) <= getSkillLevel(primarySkillType))
|| (mcMMO.p.getGeneralConfig().getPowerLevelCap() <= getPowerLevel())) {
return 0;
}
xp = (float) (xp / primarySkillType.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier());
xp = (float) (xp / ExperienceConfig.getInstance().getFormulaSkillModifier(primarySkillType) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier());
if (mcMMO.p.getGeneralConfig().getToolModsEnabled()) {
CustomTool tool = mcMMO.getModManager().getTool(player.getInventory().getItemInMainHand());
@ -820,35 +873,36 @@ public class McMMOPlayer implements Identified {
/**
* Check to see if an ability can be activated.
*
* @param skill The skill the ability is based on
* @param primarySkillType The skill the ability is based on
*/
public void checkAbilityActivation(PrimarySkillType skill) {
ToolType tool = skill.getTool();
SuperAbilityType ability = skill.getAbility();
public void checkAbilityActivation(PrimarySkillType primarySkillType) {
ToolType tool = mcMMO.p.getSkillTools().getPrimarySkillToolType(primarySkillType);
SuperAbilityType superAbilityType = mcMMO.p.getSkillTools().getSuperAbility(primarySkillType);
SubSkillType subSkillType = superAbilityType.getSubSkillTypeDefinition();
if (getAbilityMode(ability) || !ability.getPermissions(player)) {
if (getAbilityMode(superAbilityType) || !superAbilityType.getPermissions(player)) {
return;
}
//TODO: This is hacky and temporary solution until skills are move to the new system
//Potential problems with this include skills with two super abilities (ie mining)
if(!skill.isSuperAbilityUnlocked(getPlayer()))
if(!RankUtils.hasUnlockedSubskill(player, subSkillType))
{
int diff = RankUtils.getSuperAbilityUnlockRequirement(skill.getAbility()) - getSkillLevel(skill);
int diff = RankUtils.getSuperAbilityUnlockRequirement(superAbilityType) - getSkillLevel(primarySkillType);
//Inform the player they are not yet skilled enough
NotificationManager.sendPlayerInformation(player, NotificationType.ABILITY_COOLDOWN, "Skills.AbilityGateRequirementFail", String.valueOf(diff), skill.getName());
NotificationManager.sendPlayerInformation(player, NotificationType.ABILITY_COOLDOWN, "Skills.AbilityGateRequirementFail", String.valueOf(diff), mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType));
return;
}
int timeRemaining = calculateTimeRemaining(ability);
int timeRemaining = calculateTimeRemaining(superAbilityType);
if (timeRemaining > 0) {
/*
* Axes and Woodcutting are odd because they share the same tool.
* We show them the too tired message when they take action.
*/
if (skill == PrimarySkillType.WOODCUTTING || skill == PrimarySkillType.AXES) {
if (primarySkillType == PrimarySkillType.WOODCUTTING || primarySkillType == PrimarySkillType.AXES) {
NotificationManager.sendPlayerInformation(player, NotificationType.ABILITY_COOLDOWN, "Skills.TooTired", String.valueOf(timeRemaining));
//SoundManager.sendSound(player, player.getLocation(), SoundType.TIRED);
}
@ -856,7 +910,7 @@ public class McMMOPlayer implements Identified {
return;
}
if (EventUtils.callPlayerAbilityActivateEvent(player, skill).isCancelled()) {
if (EventUtils.callPlayerAbilityActivateEvent(player, primarySkillType).isCancelled()) {
return;
}
@ -869,37 +923,37 @@ public class McMMOPlayer implements Identified {
//Ability cap of 0 or below means no cap
if(abilityLengthCap > 0)
{
ticks = PerksUtils.handleActivationPerks(player, 2 + (Math.min(abilityLengthCap, getSkillLevel(skill)) / abilityLengthVar), ability.getMaxLength());
ticks = PerksUtils.handleActivationPerks(player, 2 + (Math.min(abilityLengthCap, getSkillLevel(primarySkillType)) / abilityLengthVar), superAbilityType.getMaxLength());
} else {
ticks = PerksUtils.handleActivationPerks(player, 2 + (getSkillLevel(skill) / abilityLengthVar), ability.getMaxLength());
ticks = PerksUtils.handleActivationPerks(player, 2 + (getSkillLevel(primarySkillType) / abilityLengthVar), superAbilityType.getMaxLength());
}
if (useChatNotifications()) {
NotificationManager.sendPlayerInformation(player, NotificationType.SUPER_ABILITY, ability.getAbilityOn());
NotificationManager.sendPlayerInformation(player, NotificationType.SUPER_ABILITY, superAbilityType.getAbilityOn());
//player.sendMessage(ability.getAbilityOn());
}
if (mcMMO.p.getAdvancedConfig().sendAbilityNotificationToOtherPlayers()) {
SkillUtils.sendSkillMessage(player, NotificationType.SUPER_ABILITY_ALERT_OTHERS, ability.getAbilityPlayer());
SkillUtils.sendSkillMessage(player, NotificationType.SUPER_ABILITY_ALERT_OTHERS, superAbilityType.getAbilityPlayer());
}
//Sounds
SoundManager.worldSendSound(player.getWorld(), player.getLocation(), SoundType.ABILITY_ACTIVATED_GENERIC);
// Enable the ability
profile.setAbilityDATS(ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR));
setAbilityMode(ability, true);
profile.setAbilityDATS(superAbilityType, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR));
setAbilityMode(superAbilityType, true);
if (ability == SuperAbilityType.SUPER_BREAKER || ability == SuperAbilityType.GIGA_DRILL_BREAKER) {
if (superAbilityType == SuperAbilityType.SUPER_BREAKER || superAbilityType == SuperAbilityType.GIGA_DRILL_BREAKER) {
SkillUtils.handleAbilitySpeedIncrease(player);
}
setToolPreparationMode(tool, false);
new AbilityDisableTask(this, ability).runTaskLater(mcMMO.p, ticks * Misc.TICK_CONVERSION_FACTOR);
new AbilityDisableTask(this, superAbilityType).runTaskLater(mcMMO.p, ticks * Misc.TICK_CONVERSION_FACTOR);
}
public void processAbilityActivation(PrimarySkillType skill) {
if (!skill.getPermissions(getPlayer())) {
public void processAbilityActivation(@NotNull PrimarySkillType primarySkillType) {
if (!Permissions.skillEnabled(getPlayer(), primarySkillType)) {
return;
}
@ -923,15 +977,15 @@ public class McMMOPlayer implements Identified {
}
}
SuperAbilityType ability = skill.getAbility();
ToolType tool = skill.getTool();
SuperAbilityType ability = mcMMO.p.getSkillTools().getSuperAbility(primarySkillType);
ToolType tool = mcMMO.p.getSkillTools().getPrimarySkillToolType(primarySkillType);
/*
* Woodcutting & Axes need to be treated differently.
* Basically the tool always needs to ready and we check to see if the cooldown is over when the user takes action
*/
if (tool.inHand(inHand) && !getToolPreparationMode(tool)) {
if (skill != PrimarySkillType.WOODCUTTING && skill != PrimarySkillType.AXES) {
if (primarySkillType != PrimarySkillType.WOODCUTTING && primarySkillType != PrimarySkillType.AXES) {
int timeRemaining = calculateTimeRemaining(ability);
if (isAbilityOnCooldown(ability)) {
@ -993,7 +1047,7 @@ public class McMMOPlayer implements Identified {
String allCDStr = aSuperAbilityCD + ", " + bSuperAbilityCD;
NotificationManager.sendPlayerInformation(player, NotificationType.TOOL, "Skills.TooTired.Extra",
primarySkillType.getName(),
mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType),
allCDStr);
}

View File

@ -6,7 +6,6 @@ import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.datatypes.experience.SkillXpGain;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.datatypes.skills.interfaces.Skill;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.player.PlayerProfileSaveTask;
import com.gmail.nossr50.skills.child.FamilyTree;
@ -15,7 +14,7 @@ import com.google.common.collect.ImmutableMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@ -33,14 +32,14 @@ public class PlayerProfile {
private int saveAttempts = 0;
/* Skill Data */
private final Map<Skill, Integer> skills = new HashMap<>(); // Skill & Level
private final Map<Skill, Float> skillsXp = new HashMap<>(); // Skill & XP
private final Map<SuperAbilityType, Integer> abilityDATS = new HashMap<>(); // Ability & Cooldown
private final Map<UniqueDataType, Integer> uniquePlayerData = new HashMap<>(); //Misc data that doesn't fit into other categories (chimaera wing, etc..)
private final Map<PrimarySkillType, Integer> skills = new EnumMap<>(PrimarySkillType.class); // Skill & Level
private final Map<PrimarySkillType, Float> skillsXp = new EnumMap<>(PrimarySkillType.class); // Skill & XP
private final Map<SuperAbilityType, Integer> abilityDATS = new EnumMap<SuperAbilityType, Integer>(SuperAbilityType.class); // Ability & Cooldown
private final Map<UniqueDataType, Integer> uniquePlayerData = new EnumMap<UniqueDataType, Integer>(UniqueDataType.class); //Misc data that doesn't fit into other categories (chimaera wing, etc..)
// Store previous XP gains for diminished returns
private final DelayQueue<SkillXpGain> gainedSkillsXp = new DelayQueue<>();
private final HashMap<Skill, Float> rollingSkillsXp = new HashMap<>();
private final Map<PrimarySkillType, Float> rollingSkillsXp = new EnumMap<PrimarySkillType, Float>(PrimarySkillType.class);
@Deprecated
public PlayerProfile(String playerName) {
@ -58,7 +57,7 @@ public class PlayerProfile {
abilityDATS.put(superAbilityType, 0);
}
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
skills.put(primarySkillType, mcMMO.p.getAdvancedConfig().getStartingLevel());
skillsXp.put(primarySkillType, 0F);
}
@ -78,7 +77,7 @@ public class PlayerProfile {
this.loaded = isLoaded;
}
public PlayerProfile(@NotNull String playerName, UUID uuid, Map<Skill, Integer> levelData, Map<Skill, Float> xpData, Map<SuperAbilityType, Integer> cooldownData, @Nullable MobHealthbarType mobHealthbarType, int scoreboardTipsShown, Map<UniqueDataType, Integer> uniqueProfileData) {
public PlayerProfile(@NotNull String playerName, UUID uuid, Map<PrimarySkillType, Integer> levelData, Map<PrimarySkillType, Float> xpData, Map<SuperAbilityType, Integer> cooldownData, @Nullable MobHealthbarType mobHealthbarType, int scoreboardTipsShown, Map<UniqueDataType, Integer> uniqueProfileData) {
this.playerName = playerName;
this.uuid = uuid;
mobHealthbarType = mcMMO.p.getGeneralConfig().getMobHealthbarDefault();
@ -257,7 +256,7 @@ public class PlayerProfile {
*/
public int getSkillLevel(PrimarySkillType skill) {
return skill.isChildSkill() ? getChildSkillLevel(skill) : skills.get(skill);
return mcMMO.p.getSkillTools().isChildSkill(skill) ? getChildSkillLevel(skill) : skills.get(skill);
}
public float getSkillXpLevelRaw(PrimarySkillType skill) {
@ -265,7 +264,7 @@ public class PlayerProfile {
}
public int getSkillXpLevel(PrimarySkillType skill) {
if(skill.isChildSkill()) {
if(mcMMO.p.getSkillTools().isChildSkill(skill)) {
return 0;
}
@ -273,7 +272,7 @@ public class PlayerProfile {
}
public void setSkillXpLevel(PrimarySkillType skill, float xpLevel) {
if (skill.isChildSkill()) {
if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
return;
}
@ -300,7 +299,7 @@ public class PlayerProfile {
* @param xp Amount of xp to remove
*/
public void removeXp(PrimarySkillType skill, int xp) {
if (skill.isChildSkill()) {
if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
return;
}
@ -310,7 +309,7 @@ public class PlayerProfile {
}
public void removeXp(PrimarySkillType skill, float xp) {
if (skill.isChildSkill()) {
if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
return;
}
@ -326,7 +325,7 @@ public class PlayerProfile {
* @param level New level value for the skill
*/
public void modifySkill(PrimarySkillType skill, int level) {
if (skill.isChildSkill()) {
if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
return;
}
@ -359,7 +358,7 @@ public class PlayerProfile {
public void addXp(PrimarySkillType skill, float xp) {
markProfileDirty();
if (skill.isChildSkill()) {
if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
Set<PrimarySkillType> parentSkills = FamilyTree.getParents(skill);
float dividedXP = (xp / parentSkills.size());
@ -418,7 +417,7 @@ public class PlayerProfile {
* @return the total amount of Xp until next level
*/
public int getXpToLevel(PrimarySkillType primarySkillType) {
if(primarySkillType.isChildSkill()) {
if(mcMMO.p.getSkillTools().isChildSkill(primarySkillType)) {
return 0;
}
@ -433,7 +432,7 @@ public class PlayerProfile {
int sum = 0;
for (PrimarySkillType parent : parents) {
sum += Math.min(getSkillLevel(parent), parent.getMaxLevel());
sum += Math.min(getSkillLevel(parent), mcMMO.p.getGeneralConfig().getLevelCap(parent));
}
return sum / parents.size();

View File

@ -1,239 +1,259 @@
package com.gmail.nossr50.datatypes.skills;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.skills.interfaces.Skill;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.alchemy.AlchemyManager;
import com.gmail.nossr50.skills.archery.ArcheryManager;
import com.gmail.nossr50.skills.axes.AxesManager;
import com.gmail.nossr50.skills.excavation.ExcavationManager;
import com.gmail.nossr50.skills.fishing.FishingManager;
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.repair.RepairManager;
import com.gmail.nossr50.skills.salvage.SalvageManager;
import com.gmail.nossr50.skills.smelting.SmeltingManager;
import com.gmail.nossr50.skills.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.text.StringUtils;
import com.google.common.collect.ImmutableList;
import org.bukkit.Color;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public enum PrimarySkillType implements Skill {
ACROBATICS(AcrobaticsManager.class, Color.WHITE,
ImmutableList.of(SubSkillType.ACROBATICS_DODGE, SubSkillType.ACROBATICS_ROLL)),
ALCHEMY(AlchemyManager.class, Color.FUCHSIA,
ImmutableList.of(SubSkillType.ALCHEMY_CATALYSIS, SubSkillType.ALCHEMY_CONCOCTIONS)),
ARCHERY(ArcheryManager.class, Color.MAROON,
ImmutableList.of(SubSkillType.ARCHERY_DAZE, SubSkillType.ARCHERY_ARCHERY_LIMIT_BREAK, SubSkillType.ARCHERY_ARROW_RETRIEVAL, SubSkillType.ARCHERY_SKILL_SHOT)),
AXES(AxesManager.class, Color.AQUA, SuperAbilityType.SKULL_SPLITTER, ToolType.AXE,
ImmutableList.of(SubSkillType.AXES_SKULL_SPLITTER, SubSkillType.AXES_AXES_LIMIT_BREAK, SubSkillType.AXES_ARMOR_IMPACT, SubSkillType.AXES_AXE_MASTERY, SubSkillType.AXES_CRITICAL_STRIKES, SubSkillType.AXES_GREATER_IMPACT)),
EXCAVATION(ExcavationManager.class, Color.fromRGB(139, 69, 19), SuperAbilityType.GIGA_DRILL_BREAKER, ToolType.SHOVEL,
ImmutableList.of(SubSkillType.EXCAVATION_GIGA_DRILL_BREAKER, SubSkillType.EXCAVATION_ARCHAEOLOGY)),
FISHING(FishingManager.class, Color.NAVY,
ImmutableList.of(SubSkillType.FISHING_FISHERMANS_DIET, SubSkillType.FISHING_TREASURE_HUNTER, SubSkillType.FISHING_ICE_FISHING, SubSkillType.FISHING_MAGIC_HUNTER, SubSkillType.FISHING_MASTER_ANGLER, SubSkillType.FISHING_SHAKE)),
HERBALISM(HerbalismManager.class, Color.GREEN, SuperAbilityType.GREEN_TERRA, ToolType.HOE,
ImmutableList.of(SubSkillType.HERBALISM_GREEN_TERRA, SubSkillType.HERBALISM_FARMERS_DIET, SubSkillType.HERBALISM_GREEN_THUMB, SubSkillType.HERBALISM_DOUBLE_DROPS, SubSkillType.HERBALISM_HYLIAN_LUCK, SubSkillType.HERBALISM_SHROOM_THUMB)),
MINING(MiningManager.class, Color.GRAY, SuperAbilityType.SUPER_BREAKER, ToolType.PICKAXE,
ImmutableList.of(SubSkillType.MINING_SUPER_BREAKER, SubSkillType.MINING_DEMOLITIONS_EXPERTISE, SubSkillType.MINING_BIGGER_BOMBS, SubSkillType.MINING_BLAST_MINING, SubSkillType.MINING_DOUBLE_DROPS)),
REPAIR(RepairManager.class, Color.SILVER,
ImmutableList.of(SubSkillType.REPAIR_ARCANE_FORGING, SubSkillType.REPAIR_REPAIR_MASTERY, SubSkillType.REPAIR_SUPER_REPAIR)),
SALVAGE(SalvageManager.class, Color.ORANGE,
ImmutableList.of(SubSkillType.SALVAGE_SCRAP_COLLECTOR, SubSkillType.SALVAGE_ARCANE_SALVAGE)),
SMELTING(SmeltingManager.class, Color.YELLOW,
ImmutableList.of(SubSkillType.SMELTING_UNDERSTANDING_THE_ART, /*SubSkillType.SMELTING_FLUX_MINING,*/ SubSkillType.SMELTING_FUEL_EFFICIENCY, SubSkillType.SMELTING_SECOND_SMELT)),
SWORDS(SwordsManager.class, Color.fromRGB(178, 34, 34), SuperAbilityType.SERRATED_STRIKES, ToolType.SWORD,
ImmutableList.of(SubSkillType.SWORDS_SERRATED_STRIKES, SubSkillType.SWORDS_SWORDS_LIMIT_BREAK, SubSkillType.SWORDS_STAB, SubSkillType.SWORDS_RUPTURE, SubSkillType.SWORDS_COUNTER_ATTACK)),
TAMING(TamingManager.class, Color.PURPLE,
ImmutableList.of(SubSkillType.TAMING_BEAST_LORE, SubSkillType.TAMING_CALL_OF_THE_WILD, SubSkillType.TAMING_ENVIRONMENTALLY_AWARE, SubSkillType.TAMING_FAST_FOOD_SERVICE, SubSkillType.TAMING_GORE, SubSkillType.TAMING_HOLY_HOUND, SubSkillType.TAMING_SHARPENED_CLAWS, SubSkillType.TAMING_SHOCK_PROOF, SubSkillType.TAMING_THICK_FUR, SubSkillType.TAMING_PUMMEL)),
UNARMED(UnarmedManager.class, Color.BLACK, SuperAbilityType.BERSERK, ToolType.FISTS,
ImmutableList.of(SubSkillType.UNARMED_BERSERK, SubSkillType.UNARMED_UNARMED_LIMIT_BREAK, SubSkillType.UNARMED_BLOCK_CRACKER, SubSkillType.UNARMED_ARROW_DEFLECT, SubSkillType.UNARMED_DISARM, SubSkillType.UNARMED_STEEL_ARM_STYLE, SubSkillType.UNARMED_IRON_GRIP)),
WOODCUTTING(WoodcuttingManager.class, Color.OLIVE, SuperAbilityType.TREE_FELLER, ToolType.AXE,
ImmutableList.of(SubSkillType.WOODCUTTING_LEAF_BLOWER, SubSkillType.WOODCUTTING_TREE_FELLER, SubSkillType.WOODCUTTING_HARVEST_LUMBER, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD));
private final Class<? extends SkillManager> managerClass;
private final Color skillColor;
private final SuperAbilityType ability;
private final ToolType tool;
private final List<SubSkillType> subSkillTypes;
public static final List<String> SKILL_NAMES;
public static final List<String> SUBSKILL_NAMES;
public static final List<PrimarySkillType> CHILD_SKILLS;
public static final List<PrimarySkillType> NON_CHILD_SKILLS;
public static final List<PrimarySkillType> COMBAT_SKILLS = ImmutableList.of(ARCHERY, AXES, SWORDS, TAMING, UNARMED);
public static final List<PrimarySkillType> GATHERING_SKILLS = ImmutableList.of(EXCAVATION, FISHING, HERBALISM, MINING, WOODCUTTING);
public static final List<PrimarySkillType> MISC_SKILLS = ImmutableList.of(ACROBATICS, ALCHEMY, REPAIR, SALVAGE, SMELTING);
static {
List<PrimarySkillType> childSkills = new ArrayList<>();
List<PrimarySkillType> nonChildSkills = new ArrayList<>();
ArrayList<String> names = new ArrayList<>();
ArrayList<String> subSkillNames = new ArrayList<>();
for (PrimarySkillType skill : values()) {
if (skill.isChildSkill()) {
childSkills.add(skill);
}
else {
nonChildSkills.add(skill);
}
for(SubSkillType subSkillType : skill.subSkillTypes) {
subSkillNames.add(subSkillType.getNiceNameNoSpaces(subSkillType));
}
names.add(skill.getName());
}
Collections.sort(names);
SKILL_NAMES = ImmutableList.copyOf(names);
SUBSKILL_NAMES = ImmutableList.copyOf(subSkillNames);
CHILD_SKILLS = ImmutableList.copyOf(childSkills);
NON_CHILD_SKILLS = ImmutableList.copyOf(nonChildSkills);
}
PrimarySkillType(Class<? extends SkillManager> managerClass, Color skillColor, List<SubSkillType> subSkillTypes) {
this(managerClass, skillColor, null, null, subSkillTypes);
}
PrimarySkillType(Class<? extends SkillManager> managerClass, Color skillColor, SuperAbilityType ability, ToolType tool, List<SubSkillType> subSkillTypes) {
this.managerClass = managerClass;
this.skillColor = skillColor;
this.ability = ability;
this.tool = tool;
this.subSkillTypes = subSkillTypes;
}
public PrimarySkillType getPrimarySkill() {
return this;
}
public String getPrimaryKeyName() {
return StringUtils.getCapitalized(this.toString());
}
public Class<? extends SkillManager> getManagerClass() {
return managerClass;
}
public SuperAbilityType getAbility() {
return ability;
}
/**
* Get the max level of this skill.
*
* @return the max level of this skill
*/
public int getMaxLevel() {
return mcMMO.p.getGeneralConfig().getLevelCap(this);
}
public boolean isSuperAbilityUnlocked(Player player) { return RankUtils.getRank(player, getAbility().getSubSkillTypeDefinition()) >= 1; }
public boolean getPVPEnabled() {
return mcMMO.p.getGeneralConfig().getPVPEnabled(this);
}
public boolean getPVEEnabled() {
return mcMMO.p.getGeneralConfig().getPVEEnabled(this);
}
public boolean getDoubleDropsDisabled() {
return mcMMO.p.getGeneralConfig().getDoubleDropsDisabled(this);
}
public boolean getHardcoreStatLossEnabled() {
return mcMMO.p.getGeneralConfig().getHardcoreStatLossEnabled(this);
}
public void setHardcoreStatLossEnabled(boolean enable) {
mcMMO.p.getGeneralConfig().setHardcoreStatLossEnabled(this, enable);
}
public boolean getHardcoreVampirismEnabled() {
return mcMMO.p.getGeneralConfig().getHardcoreVampirismEnabled(this);
}
public void setHardcoreVampirismEnabled(boolean enable) {
mcMMO.p.getGeneralConfig().setHardcoreVampirismEnabled(this, enable);
}
public ToolType getTool() {
return tool;
}
public List<SubSkillType> getSkillAbilities() {
return subSkillTypes;
}
public double getXpModifier() {
return ExperienceConfig.getInstance().getFormulaSkillModifier(this);
}
public static PrimarySkillType getSkill(String skillName) {
if (!mcMMO.p.getGeneralConfig().getLocale().equalsIgnoreCase("en_US")) {
for (PrimarySkillType type : values()) {
if (skillName.equalsIgnoreCase(LocaleLoader.getString(StringUtils.getCapitalized(type.name()) + ".SkillName"))) {
return type;
}
}
}
for (PrimarySkillType type : values()) {
if (type.name().equalsIgnoreCase(skillName)) {
return type;
}
}
if (!skillName.equalsIgnoreCase("all")) {
mcMMO.p.getLogger().warning("Invalid mcMMO skill (" + skillName + ")"); //TODO: Localize
}
return null;
}
// TODO: This is a little "hacky", we probably need to add something to distinguish child skills in the enum, or to use another enum for them
public boolean isChildSkill() {
switch (this) {
case SALVAGE:
case SMELTING:
return true;
default:
return false;
}
}
public String getName() {
return StringUtils.getCapitalized(LocaleLoader.getString(StringUtils.getCapitalized(this.toString()) + ".SkillName"));
}
public boolean getPermissions(Player player) {
return Permissions.skillEnabled(player, this);
}
public boolean shouldProcess(Entity target) {
return (target instanceof Player || (target instanceof Tameable && ((Tameable) target).isTamed())) ? getPVPEnabled() : getPVEEnabled();
}
public enum PrimarySkillType {
ACROBATICS,
ALCHEMY,
ARCHERY,
AXES,
EXCAVATION,
FISHING,
HERBALISM,
MINING,
REPAIR,
SALVAGE,
SMELTING,
SWORDS,
TAMING,
UNARMED,
WOODCUTTING
}
//package com.gmail.nossr50.datatypes.skills;
//
//import com.gmail.nossr50.config.experience.ExperienceConfig;
//import com.gmail.nossr50.datatypes.skills.interfaces.Skill;
//import com.gmail.nossr50.locale.LocaleLoader;
//import com.gmail.nossr50.mcMMO;
//import com.gmail.nossr50.skills.SkillManager;
//import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
//import com.gmail.nossr50.skills.alchemy.AlchemyManager;
//import com.gmail.nossr50.skills.archery.ArcheryManager;
//import com.gmail.nossr50.skills.axes.AxesManager;
//import com.gmail.nossr50.skills.excavation.ExcavationManager;
//import com.gmail.nossr50.skills.fishing.FishingManager;
//import com.gmail.nossr50.skills.herbalism.HerbalismManager;
//import com.gmail.nossr50.skills.mining.MiningManager;
//import com.gmail.nossr50.skills.repair.RepairManager;
//import com.gmail.nossr50.skills.salvage.SalvageManager;
//import com.gmail.nossr50.skills.smelting.SmeltingManager;
//import com.gmail.nossr50.skills.swords.SwordsManager;
//import com.gmail.nossr50.skills.taming.TamingManager;
//import com.gmail.nossr50.skills.unarmed.UnarmedManager;
//import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
//import com.gmail.nossr50.util.Permissions;
//import com.gmail.nossr50.util.skills.RankUtils;
//import com.gmail.nossr50.util.text.StringUtils;
//import com.google.common.collect.ImmutableList;
//import org.bukkit.Color;
//import org.bukkit.entity.Entity;
//import org.bukkit.entity.Player;
//import org.bukkit.entity.Tameable;
//
//import java.util.ArrayList;
//import java.util.Collections;
//import java.util.List;
//
//public enum PrimarySkillType implements Skill {
// ACROBATICS(AcrobaticsManager.class, Color.WHITE,
// ImmutableList.of(SubSkillType.ACROBATICS_DODGE, SubSkillType.ACROBATICS_ROLL)),
// ALCHEMY(AlchemyManager.class, Color.FUCHSIA,
// ImmutableList.of(SubSkillType.ALCHEMY_CATALYSIS, SubSkillType.ALCHEMY_CONCOCTIONS)),
// ARCHERY(ArcheryManager.class, Color.MAROON,
// ImmutableList.of(SubSkillType.ARCHERY_DAZE, SubSkillType.ARCHERY_ARCHERY_LIMIT_BREAK, SubSkillType.ARCHERY_ARROW_RETRIEVAL, SubSkillType.ARCHERY_SKILL_SHOT)),
// AXES(AxesManager.class, Color.AQUA, SuperAbilityType.SKULL_SPLITTER, ToolType.AXE,
// ImmutableList.of(SubSkillType.AXES_SKULL_SPLITTER, SubSkillType.AXES_AXES_LIMIT_BREAK, SubSkillType.AXES_ARMOR_IMPACT, SubSkillType.AXES_AXE_MASTERY, SubSkillType.AXES_CRITICAL_STRIKES, SubSkillType.AXES_GREATER_IMPACT)),
// EXCAVATION(ExcavationManager.class, Color.fromRGB(139, 69, 19), SuperAbilityType.GIGA_DRILL_BREAKER, ToolType.SHOVEL,
// ImmutableList.of(SubSkillType.EXCAVATION_GIGA_DRILL_BREAKER, SubSkillType.EXCAVATION_ARCHAEOLOGY)),
// FISHING(FishingManager.class, Color.NAVY,
// ImmutableList.of(SubSkillType.FISHING_FISHERMANS_DIET, SubSkillType.FISHING_TREASURE_HUNTER, SubSkillType.FISHING_ICE_FISHING, SubSkillType.FISHING_MAGIC_HUNTER, SubSkillType.FISHING_MASTER_ANGLER, SubSkillType.FISHING_SHAKE)),
// HERBALISM(HerbalismManager.class, Color.GREEN, SuperAbilityType.GREEN_TERRA, ToolType.HOE,
// ImmutableList.of(SubSkillType.HERBALISM_GREEN_TERRA, SubSkillType.HERBALISM_FARMERS_DIET, SubSkillType.HERBALISM_GREEN_THUMB, SubSkillType.HERBALISM_DOUBLE_DROPS, SubSkillType.HERBALISM_HYLIAN_LUCK, SubSkillType.HERBALISM_SHROOM_THUMB)),
// MINING(MiningManager.class, Color.GRAY, SuperAbilityType.SUPER_BREAKER, ToolType.PICKAXE,
// ImmutableList.of(SubSkillType.MINING_SUPER_BREAKER, SubSkillType.MINING_DEMOLITIONS_EXPERTISE, SubSkillType.MINING_BIGGER_BOMBS, SubSkillType.MINING_BLAST_MINING, SubSkillType.MINING_DOUBLE_DROPS)),
// REPAIR(RepairManager.class, Color.SILVER,
// ImmutableList.of(SubSkillType.REPAIR_ARCANE_FORGING, SubSkillType.REPAIR_REPAIR_MASTERY, SubSkillType.REPAIR_SUPER_REPAIR)),
// SALVAGE(SalvageManager.class, Color.ORANGE,
// ImmutableList.of(SubSkillType.SALVAGE_SCRAP_COLLECTOR, SubSkillType.SALVAGE_ARCANE_SALVAGE)),
// SMELTING(SmeltingManager.class, Color.YELLOW,
// ImmutableList.of(SubSkillType.SMELTING_UNDERSTANDING_THE_ART, /*SubSkillType.SMELTING_FLUX_MINING,*/ SubSkillType.SMELTING_FUEL_EFFICIENCY, SubSkillType.SMELTING_SECOND_SMELT)),
// SWORDS(SwordsManager.class, Color.fromRGB(178, 34, 34), SuperAbilityType.SERRATED_STRIKES, ToolType.SWORD,
// ImmutableList.of(SubSkillType.SWORDS_SERRATED_STRIKES, SubSkillType.SWORDS_SWORDS_LIMIT_BREAK, SubSkillType.SWORDS_STAB, SubSkillType.SWORDS_RUPTURE, SubSkillType.SWORDS_COUNTER_ATTACK)),
// TAMING(TamingManager.class, Color.PURPLE,
// ImmutableList.of(SubSkillType.TAMING_BEAST_LORE, SubSkillType.TAMING_CALL_OF_THE_WILD, SubSkillType.TAMING_ENVIRONMENTALLY_AWARE, SubSkillType.TAMING_FAST_FOOD_SERVICE, SubSkillType.TAMING_GORE, SubSkillType.TAMING_HOLY_HOUND, SubSkillType.TAMING_SHARPENED_CLAWS, SubSkillType.TAMING_SHOCK_PROOF, SubSkillType.TAMING_THICK_FUR, SubSkillType.TAMING_PUMMEL)),
// UNARMED(UnarmedManager.class, Color.BLACK, SuperAbilityType.BERSERK, ToolType.FISTS,
// ImmutableList.of(SubSkillType.UNARMED_BERSERK, SubSkillType.UNARMED_UNARMED_LIMIT_BREAK, SubSkillType.UNARMED_BLOCK_CRACKER, SubSkillType.UNARMED_ARROW_DEFLECT, SubSkillType.UNARMED_DISARM, SubSkillType.UNARMED_STEEL_ARM_STYLE, SubSkillType.UNARMED_IRON_GRIP)),
// WOODCUTTING(WoodcuttingManager.class, Color.OLIVE, SuperAbilityType.TREE_FELLER, ToolType.AXE,
// ImmutableList.of(SubSkillType.WOODCUTTING_LEAF_BLOWER, SubSkillType.WOODCUTTING_TREE_FELLER, SubSkillType.WOODCUTTING_HARVEST_LUMBER, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD));
//
// private final Class<? extends SkillManager> managerClass;
// private final Color skillColor;
// private final SuperAbilityType ability;
// private final ToolType tool;
// private final List<SubSkillType> subSkillTypes;
//
// public static final List<String> SKILL_NAMES;
// public static final List<String> SUBSKILL_NAMES;
//
// public static final List<PrimarySkillType> CHILD_SKILLS;
// public static final List<PrimarySkillType> NON_CHILD_SKILLS;
//
// public static final List<PrimarySkillType> COMBAT_SKILLS = ImmutableList.of(ARCHERY, AXES, SWORDS, TAMING, UNARMED);
// public static final List<PrimarySkillType> GATHERING_SKILLS = ImmutableList.of(EXCAVATION, FISHING, HERBALISM, MINING, WOODCUTTING);
// public static final List<PrimarySkillType> MISC_SKILLS = ImmutableList.of(ACROBATICS, ALCHEMY, REPAIR, SALVAGE, SMELTING);
//
// static {
// List<PrimarySkillType> childSkills = new ArrayList<>();
// List<PrimarySkillType> nonChildSkills = new ArrayList<>();
// ArrayList<String> names = new ArrayList<>();
// ArrayList<String> subSkillNames = new ArrayList<>();
//
// for (PrimarySkillType skill : values()) {
// if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
// childSkills.add(skill);
// }
// else {
// nonChildSkills.add(skill);
// }
//
// for(SubSkillType subSkillType : skill.subSkillTypes) {
// subSkillNames.add(subSkillType.getNiceNameNoSpaces(subSkillType));
// }
//
// names.add(mcMMO.p.getSkillTools().getLocalizedSkillName(skill));
// }
//
// Collections.sort(names);
// SKILL_NAMES = ImmutableList.copyOf(names);
// SUBSKILL_NAMES = ImmutableList.copyOf(subSkillNames);
//
// CHILD_SKILLS = ImmutableList.copyOf(childSkills);
// NON_CHILD_SKILLS = ImmutableList.copyOf(nonChildSkills);
// }
//
// PrimarySkillType(Class<? extends SkillManager> managerClass, Color skillColor, List<SubSkillType> subSkillTypes) {
// this(managerClass, skillColor, null, null, subSkillTypes);
// }
//
// PrimarySkillType(Class<? extends SkillManager> managerClass, Color skillColor, SuperAbilityType ability, ToolType tool, List<SubSkillType> subSkillTypes) {
// this.managerClass = managerClass;
// this.skillColor = skillColor;
// this.ability = ability;
// this.tool = tool;
// this.subSkillTypes = subSkillTypes;
// }
//
// public PrimarySkillType getPrimarySkill() {
// return this;
// }
//
// public String getPrimaryKeyName() {
// return StringUtils.getCapitalized(this.toString());
// }
//
// public Class<? extends SkillManager> getManagerClass() {
// return managerClass;
// }
//
// public SuperAbilityType getAbility() {
// return ability;
// }
//
// /**
// * Get the max level of this skill.
// *
// * @return the max level of this skill
// */
// public int getMaxLevel() {
// return mcMMO.p.getGeneralConfig().getLevelCap(this);
// }
//
// public boolean isSuperAbilityUnlocked(Player player) { return RankUtils.getRank(player, getAbility().getSubSkillTypeDefinition()) >= 1; }
//
// public boolean getPVPEnabled() {
// return mcMMO.p.getGeneralConfig().getPVPEnabled(this);
// }
//
// public boolean getPVEEnabled() {
// return mcMMO.p.getGeneralConfig().getPVEEnabled(this);
// }
//
// public boolean getDoubleDropsDisabled() {
// return mcMMO.p.getGeneralConfig().getDoubleDropsDisabled(this);
// }
//
// public boolean getHardcoreStatLossEnabled() {
// return mcMMO.p.getGeneralConfig().getHardcoreStatLossEnabled(this);
// }
//
// public void setHardcoreStatLossEnabled(boolean enable) {
// mcMMO.p.getGeneralConfig().setHardcoreStatLossEnabled(this, enable);
// }
//
// public boolean getHardcoreVampirismEnabled() {
// return mcMMO.p.getGeneralConfig().getHardcoreVampirismEnabled(this);
// }
//
// public void setHardcoreVampirismEnabled(boolean enable) {
// mcMMO.p.getGeneralConfig().setHardcoreVampirismEnabled(this, enable);
// }
//
// public ToolType getTool() {
// return tool;
// }
//
// public List<SubSkillType> getSkillAbilities() {
// return subSkillTypes;
// }
//
// public double getXpModifier() {
// return ExperienceConfig.getInstance().getFormulaSkillModifier(this);
// }
//
// public static PrimarySkillType getSkill(String skillName) {
// if (!mcMMO.p.getGeneralConfig().getLocale().equalsIgnoreCase("en_US")) {
// for (PrimarySkillType type : values()) {
// if (skillName.equalsIgnoreCase(LocaleLoader.getString(StringUtils.getCapitalized(type.name()) + ".SkillName"))) {
// return type;
// }
// }
// }
//
// for (PrimarySkillType type : values()) {
// if (type.name().equalsIgnoreCase(skillName)) {
// return type;
// }
// }
//
// if (!skillName.equalsIgnoreCase("all")) {
// mcMMO.p.getLogger().warning("Invalid mcMMO skill (" + skillName + ")"); //TODO: Localize
// }
//
// return null;
// }
//
// // TODO: This is a little "hacky", we probably need to add something to distinguish child skills in the enum, or to use another enum for them
// public boolean isChildSkill() {
// switch (this) {
// case SALVAGE:
// case SMELTING:
// return true;
//
// default:
// return false;
// }
// }
//
// public String getName() {
// return StringUtils.getCapitalized(LocaleLoader.getString(StringUtils.getCapitalized(this.toString()) + ".SkillName"));
// }
//
// public boolean getPermissions(Player player) {
// return Permissions.skillEnabled(player, this);
// }
//
// public boolean shouldProcess(Entity target) {
// return (target instanceof Player || (target instanceof Tameable && ((Tameable) target).isTamed())) ? getPVPEnabled() : getPVEEnabled();
// }
//
//
//}

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.datatypes.skills;
import com.gmail.nossr50.datatypes.skills.interfaces.Skill;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.text.StringUtils;
import java.util.Locale;
@ -136,7 +137,7 @@ public enum SubSkillType {
* If we add skills, those immutable lists need to be updated
* @return
*/
public PrimarySkillType getParentSkill() { return Skill.bySecondaryAbility(this); }
public PrimarySkillType getParentSkill() { return mcMMO.p.getSkillTools().getPrimarySkillBySubSkill(this); }
/**
* Returns the root address for this skill in the advanced.yml file

View File

@ -26,88 +26,4 @@ public interface Skill {
* @return config file key name
*/
String getPrimaryKeyName();
Class<? extends SkillManager> getManagerClass();
SuperAbilityType getAbility();
/**
* Get the max level of this skill.
*
* @return the max level of this skill
*/
int getMaxLevel();
boolean isSuperAbilityUnlocked(Player player);
boolean getPVPEnabled();
boolean getPVEEnabled();
boolean getDoubleDropsDisabled();
boolean getHardcoreStatLossEnabled();
void setHardcoreStatLossEnabled(boolean enable);
boolean getHardcoreVampirismEnabled();
void setHardcoreVampirismEnabled(boolean enable);
ToolType getTool();
List<SubSkillType> getSkillAbilities();
double getXpModifier();
// TODO: This is a little "hacky", we probably need to add something to distinguish child skills in the enum, or to use another enum for them
boolean isChildSkill();
static PrimarySkillType bySecondaryAbility(SubSkillType subSkillType) {
for (PrimarySkillType type : PrimarySkillType.values()) {
if (type.getSkillAbilities().contains(subSkillType)) {
return type;
}
}
return null;
}
static PrimarySkillType byAbility(SuperAbilityType ability) {
for (PrimarySkillType type : PrimarySkillType.values()) {
if (type.getAbility() == ability) {
return type;
}
}
return null;
}
static PrimarySkillType getSkill(@NotNull String skillName) {
if (!mcMMO.p.getGeneralConfig().getLocale().equalsIgnoreCase("en_US")) {
for (PrimarySkillType type : PrimarySkillType.values()) {
if (skillName.equalsIgnoreCase(LocaleLoader.getString(StringUtils.getCapitalized(type.name()) + ".SkillName"))) {
return type;
}
}
}
for (PrimarySkillType type : PrimarySkillType.values()) {
if (type.name().equalsIgnoreCase(skillName)) {
return type;
}
}
if (!skillName.equalsIgnoreCase("all")) {
mcMMO.p.getLogger().warning("Invalid mcMMO skill (" + skillName + ")"); //TODO: Localize
}
return null;
}
String getName();
boolean getPermissions(Player player);
boolean shouldProcess(Entity target);
}

View File

@ -441,97 +441,4 @@ public class Roll extends AcrobaticsSubSkill {
return player.getLocation().getBlock().getLocation();
}
public String getPrimaryKeyName() {
return getPrimarySkill().getPrimaryKeyName();
}
@Override
public Class<? extends SkillManager> getManagerClass() {
return getPrimarySkill().getManagerClass();
}
@Override
public SuperAbilityType getAbility() {
return getPrimarySkill().getAbility();
}
@Override
public int getMaxLevel() {
return getPrimarySkill().getMaxLevel();
}
@Override
public boolean isSuperAbilityUnlocked(Player player) {
return getPrimarySkill().isSuperAbilityUnlocked(player);
}
@Override
public boolean getPVPEnabled() {
return getPrimarySkill().getPVPEnabled();
}
@Override
public boolean getPVEEnabled() {
return getPrimarySkill().getPVEEnabled();
}
@Override
public boolean getDoubleDropsDisabled() {
return getPrimarySkill().getDoubleDropsDisabled();
}
@Override
public boolean getHardcoreStatLossEnabled() {
return getPrimarySkill().getHardcoreStatLossEnabled();
}
@Override
public void setHardcoreStatLossEnabled(boolean enable) {
getPrimarySkill().setHardcoreStatLossEnabled(enable);
}
@Override
public boolean getHardcoreVampirismEnabled() {
return getPrimarySkill().getHardcoreVampirismEnabled();
}
@Override
public void setHardcoreVampirismEnabled(boolean enable) {
getPrimarySkill().setHardcoreVampirismEnabled(enable);
}
@Override
public ToolType getTool() {
return getPrimarySkill().getTool();
}
@Override
public List<SubSkillType> getSkillAbilities() {
return getPrimarySkill().getSkillAbilities();
}
@Override
public double getXpModifier() {
return getPrimarySkill().getXpModifier();
}
@Override
public boolean isChildSkill() {
return getPrimarySkill().isChildSkill();
}
@Override
public String getName() {
return getPrimarySkill().getName();
}
@Override
public boolean getPermissions(Player player) {
return getPrimarySkill().getPermissions(player);
}
@Override
public boolean shouldProcess(Entity target) {
return getPrimarySkill().shouldProcess(target);
}
}

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.events.skills.abilities;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
import com.gmail.nossr50.mcMMO;
import org.bukkit.entity.Player;
public class McMMOPlayerAbilityEvent extends McMMOPlayerSkillEvent {
@ -10,7 +11,7 @@ public class McMMOPlayerAbilityEvent extends McMMOPlayerSkillEvent {
protected McMMOPlayerAbilityEvent(Player player, PrimarySkillType skill) {
super(player, skill);
ability = skill.getAbility();
ability = mcMMO.p.getSkillTools().getSuperAbility(skill);
}
public SuperAbilityType getAbility() {

View File

@ -4,6 +4,7 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.interfaces.Skill;
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
import com.gmail.nossr50.mcMMO;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
@ -20,7 +21,7 @@ public class SubSkillEvent extends McMMOPlayerSkillEvent implements Cancellable
*/
@Deprecated
public SubSkillEvent(Player player, SubSkillType subSkillType) {
super(player, Skill.bySecondaryAbility(subSkillType));
super(player, mcMMO.p.getSkillTools().getPrimarySkillBySubSkill(subSkillType));
this.subSkillType = subSkillType;
}
@ -33,7 +34,7 @@ public class SubSkillEvent extends McMMOPlayerSkillEvent implements Cancellable
*/
@Deprecated
public SubSkillEvent(Player player, SubSkillType subSkillType, double resultModifier) {
super(player, Skill.bySecondaryAbility(subSkillType));
super(player, mcMMO.p.getSkillTools().getPrimarySkillBySubSkill(subSkillType));
this.subSkillType = subSkillType;
this.resultModifier = resultModifier;
}

View File

@ -228,10 +228,10 @@ public class BlockListener implements Listener {
if(mcMMOPlayer == null)
return;
if (blockState.getType() == Repair.anvilMaterial && PrimarySkillType.REPAIR.getPermissions(player)) {
if (blockState.getType() == Repair.anvilMaterial && Permissions.skillEnabled(player, PrimarySkillType.REPAIR)) {
mcMMOPlayer.getRepairManager().placedAnvilCheck();
}
else if (blockState.getType() == Salvage.anvilMaterial && PrimarySkillType.SALVAGE.getPermissions(player)) {
else if (blockState.getType() == Salvage.anvilMaterial && Permissions.skillEnabled(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 (PrimarySkillType.HERBALISM.getPermissions(player)) {
if (Permissions.skillEnabled(player, PrimarySkillType.HERBALISM)) {
herbalismManager.processHerbalismBlockBreakEvent(event);
}
/*
@ -344,13 +344,13 @@ public class BlockListener implements Listener {
}
/* MINING */
else if (BlockUtils.affectedBySuperBreaker(blockState) && ItemUtils.isPickaxe(heldItem) && PrimarySkillType.MINING.getPermissions(player) && !mcMMO.getPlaceStore().isTrue(blockState)) {
else if (BlockUtils.affectedBySuperBreaker(blockState) && ItemUtils.isPickaxe(heldItem) && Permissions.skillEnabled(player, PrimarySkillType.MINING) && !mcMMO.getPlaceStore().isTrue(blockState)) {
MiningManager miningManager = mcMMOPlayer.getMiningManager();
miningManager.miningBlockCheck(blockState);
}
/* WOOD CUTTING */
else if (BlockUtils.hasWoodcuttingXP(blockState) && ItemUtils.isAxe(heldItem) && PrimarySkillType.WOODCUTTING.getPermissions(player) && !mcMMO.getPlaceStore().isTrue(blockState)) {
else if (BlockUtils.hasWoodcuttingXP(blockState) && ItemUtils.isAxe(heldItem) && Permissions.skillEnabled(player, PrimarySkillType.WOODCUTTING) && !mcMMO.getPlaceStore().isTrue(blockState)) {
WoodcuttingManager woodcuttingManager = mcMMOPlayer.getWoodcuttingManager();
if (woodcuttingManager.canUseTreeFeller(heldItem)) {
woodcuttingManager.processTreeFeller(blockState);
@ -365,7 +365,7 @@ public class BlockListener implements Listener {
}
/* EXCAVATION */
else if (BlockUtils.affectedByGigaDrillBreaker(blockState) && ItemUtils.isShovel(heldItem) && PrimarySkillType.EXCAVATION.getPermissions(player) && !mcMMO.getPlaceStore().isTrue(blockState)) {
else if (BlockUtils.affectedByGigaDrillBreaker(blockState) && ItemUtils.isShovel(heldItem) && Permissions.skillEnabled(player, PrimarySkillType.EXCAVATION) && !mcMMO.getPlaceStore().isTrue(blockState)) {
ExcavationManager excavationManager = mcMMOPlayer.getExcavationManager();
excavationManager.excavationBlockCheck(blockState);

View File

@ -273,7 +273,7 @@ public class PlayerListener implements Listener {
return;
}
if (!UserManager.hasPlayerDataKey(player) || !PrimarySkillType.FISHING.getPermissions(player)) {
if (!UserManager.hasPlayerDataKey(player) || !Permissions.skillEnabled(player, PrimarySkillType.FISHING)) {
return;
}
@ -359,7 +359,7 @@ public class PlayerListener implements Listener {
return;
}
if (!UserManager.hasPlayerDataKey(player) || !PrimarySkillType.FISHING.getPermissions(player)) {
if (!UserManager.hasPlayerDataKey(player) || !Permissions.skillEnabled(player, PrimarySkillType.FISHING)) {
return;
}
@ -654,7 +654,7 @@ public class PlayerListener implements Listener {
if (!mcMMO.p.getGeneralConfig().getAbilitiesOnlyActivateWhenSneaking() || player.isSneaking()) {
/* REPAIR CHECKS */
if (type == Repair.anvilMaterial
&& PrimarySkillType.REPAIR.getPermissions(player)
&& Permissions.skillEnabled(player, PrimarySkillType.REPAIR)
&& mcMMO.getRepairableManager().isRepairable(heldItem)
&& heldItem.getAmount() <= 1) {
RepairManager repairManager = mcMMOPlayer.getRepairManager();
@ -668,7 +668,7 @@ public class PlayerListener implements Listener {
}
/* SALVAGE CHECKS */
else if (type == Salvage.anvilMaterial
&& PrimarySkillType.SALVAGE.getPermissions(player)
&& Permissions.skillEnabled(player, PrimarySkillType.SALVAGE)
&& RankUtils.hasUnlockedSubskill(player, SubSkillType.SALVAGE_SCRAP_COLLECTOR)
&& mcMMO.getSalvageableManager().isSalvageable(heldItem)
&& heldItem.getAmount() <= 1) {
@ -701,7 +701,7 @@ public class PlayerListener implements Listener {
if (!mcMMO.p.getGeneralConfig().getAbilitiesOnlyActivateWhenSneaking() || player.isSneaking()) {
/* REPAIR CHECKS */
if (type == Repair.anvilMaterial && PrimarySkillType.REPAIR.getPermissions(player) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
if (type == Repair.anvilMaterial && Permissions.skillEnabled(player, PrimarySkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
RepairManager repairManager = mcMMOPlayer.getRepairManager();
// Cancel repairing an enchanted item
@ -711,7 +711,7 @@ public class PlayerListener implements Listener {
}
}
/* SALVAGE CHECKS */
else if (type == Salvage.anvilMaterial && PrimarySkillType.SALVAGE.getPermissions(player) && mcMMO.getSalvageableManager().isSalvageable(heldItem)) {
else if (type == Salvage.anvilMaterial && Permissions.skillEnabled(player, PrimarySkillType.SALVAGE) && mcMMO.getSalvageableManager().isSalvageable(heldItem)) {
SalvageManager salvageManager = mcMMOPlayer.getSalvageManager();
// Cancel salvaging an enchanted item
@ -958,7 +958,7 @@ public class PlayerListener implements Listener {
// Do these ACTUALLY have to be lower case to work properly?
for (PrimarySkillType skill : PrimarySkillType.values()) {
String skillName = skill.toString().toLowerCase(Locale.ENGLISH);
String localizedName = skill.getName().toLowerCase(Locale.ENGLISH);
String localizedName = mcMMO.p.getSkillTools().getLocalizedSkillName(skill).toLowerCase(Locale.ENGLISH);
if (lowerCaseCommand.equals(localizedName)) {
event.setMessage(message.replace(command, skillName));

View File

@ -132,7 +132,7 @@ public class SelfListener implements Listener {
return;
}
if (primarySkillType.isChildSkill()) {
if (mcMMO.p.getSkillTools().isChildSkill(primarySkillType)) {
return;
}
@ -140,7 +140,7 @@ public class SelfListener implements Listener {
float guaranteedMinimum = ExperienceConfig.getInstance().getDiminishedReturnsCap() * rawXp;
float modifiedThreshold = (float) (threshold / primarySkillType.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier());
float modifiedThreshold = (float) (threshold / ExperienceConfig.getInstance().getFormulaSkillModifier(primarySkillType) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier());
float difference = (mcMMOPlayer.getProfile().getRegisteredXpGain(primarySkillType) - modifiedThreshold) / modifiedThreshold;
if (difference > 0) {

View File

@ -129,6 +129,7 @@ public final class LocaleLoader {
if (bundle == null) {
Locale.setDefault(new Locale("en", "US"));
Locale locale = null;
String[] myLocale = mcMMO.p.getGeneralConfig().getLocale().split("[-_ ]");
if (myLocale.length == 1) {

View File

@ -49,6 +49,7 @@ import com.gmail.nossr50.util.player.PlayerLevelUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillTools;
import com.gmail.nossr50.util.skills.SmeltingTracker;
import com.gmail.nossr50.util.upgrade.UpgradeManager;
import com.gmail.nossr50.worldguard.WorldGuardManager;
@ -90,6 +91,9 @@ public class mcMMO extends JavaPlugin {
private static ChatManager chatManager;
private static CommandManager commandManager; //ACF
private static TransientEntityTracker transientEntityTracker;
private @NotNull SkillTools skillTools;
private static boolean serverShutdownExecuted = false;
/* Adventure */
@ -172,8 +176,10 @@ public class mcMMO extends JavaPlugin {
@Override
public void onEnable() {
try {
generalConfig = new GeneralConfig(getDataFolder()); //Load before skillTools
skillTools = new SkillTools(this); //Load after general config
//Init configs
generalConfig = new GeneralConfig(getDataFolder());
advancedConfig = new AdvancedConfig(getDataFolder());
//Store this value so other plugins can check it
@ -767,6 +773,10 @@ public class mcMMO extends JavaPlugin {
return purgeTime;
}
public @NotNull SkillTools getSkillTools() {
return skillTools;
}
public @NotNull GeneralConfig getGeneralConfig() {
return generalConfig;
}

View File

@ -46,13 +46,13 @@ public class McrankCommandDisplayTask extends BukkitRunnable {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading"));
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName));
for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) {
// if (!skill.getPermissions(player)) {
for (PrimarySkillType skill : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
// if (!Permissions.skillEnabled(player, skill)) {
// continue;
// }
rank = skills.get(skill);
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", skill.getName(), (rank == null ? LocaleLoader.getString("Commands.mcrank.Unranked") : rank)));
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", mcMMO.p.getSkillTools().getLocalizedSkillName(skill), (rank == null ? LocaleLoader.getString("Commands.mcrank.Unranked") : rank)));
}
rank = skills.get(null);

View File

@ -60,10 +60,10 @@ public class MctopCommandDisplayTask extends BukkitRunnable {
}
else {
if(sender instanceof Player) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", skill.getName()));
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", mcMMO.p.getSkillTools().getLocalizedSkillName(skill)));
}
else {
sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.Skill.Leaderboard", skill.getName())));
sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.Skill.Leaderboard", mcMMO.p.getSkillTools().getLocalizedSkillName(skill))));
}
}

View File

@ -58,7 +58,7 @@ public class FormulaConversionTask extends BukkitRunnable {
private void editValues(PlayerProfile profile) {
mcMMO.p.debug("========================================================================");
mcMMO.p.debug("Conversion report for " + profile.getPlayerName() + ":");
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
int oldLevel = profile.getSkillLevel(primarySkillType);
int oldXPLevel = profile.getSkillXpLevel(primarySkillType);
int totalOldXP = mcMMO.getFormulaManager().calculateTotalExperience(oldLevel, oldXPLevel);

View File

@ -63,7 +63,9 @@ public class AbilityDisableTask extends BukkitRunnable {
if (mcMMO.p.getAdvancedConfig().sendAbilityNotificationToOtherPlayers()) {
SkillUtils.sendSkillMessage(player, NotificationType.SUPER_ABILITY_ALERT_OTHERS, ability.getAbilityPlayerOff());
}
new AbilityCooldownTask(mcMMOPlayer, ability).runTaskLater(mcMMO.p, PerksUtils.handleCooldownPerks(player, ability.getCooldown()) * Misc.TICK_CONVERSION_FACTOR);
if(!mcMMO.isServerShutdownExecuted()) {
new AbilityCooldownTask(mcMMOPlayer, ability).runTaskLater(mcMMO.p, PerksUtils.handleCooldownPerks(player, ability.getCooldown()) * Misc.TICK_CONVERSION_FACTOR);
}
}
private void resendChunkRadiusAt(Player player) {

View File

@ -72,7 +72,7 @@ public class AcrobaticsManager extends SkillManager {
return false;
}
return skill.shouldProcess(damager);
return mcMMO.p.getSkillTools().canCombatSkillsTrigger(skill, damager);
}
return false;

View File

@ -48,7 +48,6 @@ public final class Alchemy {
public static final int INGREDIENT_SLOT = 3;
public static int catalysisUnlockLevel = RankUtils.getUnlockLevel(SubSkillType.ALCHEMY_CATALYSIS);
public static int catalysisMaxBonusLevel = mcMMO.p.getAdvancedConfig().getCatalysisMaxBonusLevel();
public static double catalysisMinSpeed = mcMMO.p.getAdvancedConfig().getCatalysisMinSpeed();
public static double catalysisMaxSpeed = mcMMO.p.getAdvancedConfig().getCatalysisMaxSpeed();

View File

@ -45,11 +45,11 @@ public class AlchemyManager extends SkillManager {
public double calculateBrewSpeed(boolean isLucky) {
int skillLevel = getSkillLevel();
if (skillLevel < Alchemy.catalysisUnlockLevel) {
if (skillLevel < RankUtils.getUnlockLevel(SubSkillType.ALCHEMY_CATALYSIS)) {
return Alchemy.catalysisMinSpeed;
}
return Math.min(Alchemy.catalysisMaxSpeed, Alchemy.catalysisMinSpeed + (Alchemy.catalysisMaxSpeed - Alchemy.catalysisMinSpeed) * (skillLevel - Alchemy.catalysisUnlockLevel) / (Alchemy.catalysisMaxBonusLevel - Alchemy.catalysisUnlockLevel)) * (isLucky ? LUCKY_MODIFIER : 1.0);
return Math.min(Alchemy.catalysisMaxSpeed, Alchemy.catalysisMinSpeed + (Alchemy.catalysisMaxSpeed - Alchemy.catalysisMinSpeed) * (skillLevel - RankUtils.getUnlockLevel(SubSkillType.ALCHEMY_CATALYSIS)) / (Alchemy.catalysisMaxBonusLevel - RankUtils.getUnlockLevel(SubSkillType.ALCHEMY_CATALYSIS))) * (isLucky ? LUCKY_MODIFIER : 1.0);
}
public void handlePotionBrewSuccesses(PotionStage potionStage, int amount) {

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.skills.child;
import com.gmail.nossr50.config.AutoUpdateConfigLoader;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.text.StringUtils;
import org.bukkit.configuration.file.YamlConfiguration;
@ -20,7 +21,7 @@ public class ChildConfig extends AutoUpdateConfigLoader {
FamilyTree.clearRegistrations(); // when reloading, need to clear statics
for (PrimarySkillType skill : PrimarySkillType.CHILD_SKILLS) {
for (PrimarySkillType skill : mcMMO.p.getSkillTools().CHILD_SKILLS) {
plugin.debug("Finding parents of " + skill.name());
EnumSet<PrimarySkillType> parentSkills = EnumSet.noneOf(PrimarySkillType.class);

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.skills.child;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import java.util.Collections;
import java.util.EnumSet;
@ -40,13 +41,13 @@ public class FamilyTree {
}
protected static void enforceChildSkill(PrimarySkillType skill) {
if (!skill.isChildSkill()) {
if (!mcMMO.p.getSkillTools().isChildSkill(skill)) {
throw new IllegalArgumentException(skill.name() + " is not a child skill!");
}
}
protected static void enforceNotChildSkill(PrimarySkillType skill) {
if (skill.isChildSkill()) {
if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
throw new IllegalArgumentException(skill.name() + " is a child skill!");
}
}

View File

@ -80,7 +80,7 @@ public class MiningManager extends SkillManager {
return;
}
if (mmoPlayer.getAbilityMode(skill.getAbility())) {
if (mmoPlayer.getAbilityMode(mcMMO.p.getSkillTools().getSuperAbility(skill))) {
SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(), mcMMO.p.getGeneralConfig().getAbilityToolDamage());
}
@ -94,7 +94,7 @@ public class MiningManager extends SkillManager {
//TODO: Make this readable
if (RandomChanceUtil.checkRandomChanceExecutionSuccess(getPlayer(), SubSkillType.MINING_DOUBLE_DROPS, true)) {
boolean useTriple = mmoPlayer.getAbilityMode(skill.getAbility()) && mcMMO.p.getAdvancedConfig().getAllowMiningTripleDrops();
boolean useTriple = mmoPlayer.getAbilityMode(mcMMO.p.getSkillTools().getSuperAbility(skill)) && mcMMO.p.getAdvancedConfig().getAllowMiningTripleDrops();
BlockUtils.markDropsAsBonus(blockState, useTriple);
}
}

View File

@ -406,7 +406,7 @@ public final class EventUtils {
experienceChanged = event.getExperienceChanged();
PlayerProfile playerProfile = UserManager.getPlayer(player).getProfile();
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
String skillName = primarySkillType.toString();
int playerSkillLevel = playerProfile.getSkillLevel(primarySkillType);
int threshold = mcMMO.p.getGeneralConfig().getHardcoreDeathStatPenaltyLevelThreshold();
@ -455,7 +455,7 @@ public final class EventUtils {
PlayerProfile victimProfile = UserManager.getPlayer(victim).getProfile();
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
String skillName = primarySkillType.toString();
int victimSkillLevel = victimProfile.getSkillLevel(primarySkillType);
@ -479,7 +479,7 @@ public final class EventUtils {
}
public static McMMOPlayerAbilityDeactivateEvent callAbilityDeactivateEvent(Player player, SuperAbilityType ability) {
McMMOPlayerAbilityDeactivateEvent event = new McMMOPlayerAbilityDeactivateEvent(player, Skill.byAbility(ability));
McMMOPlayerAbilityDeactivateEvent event = new McMMOPlayerAbilityDeactivateEvent(player, mcMMO.p.getSkillTools().getPrimarySkillBySuperAbility(ability));
mcMMO.p.getServer().getPluginManager().callEvent(event);
return event;

View File

@ -34,8 +34,8 @@ public final class HardcoreManager {
HashMap<String, Integer> levelChanged = new HashMap<>();
HashMap<String, Float> experienceChanged = new HashMap<>();
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
if (!primarySkillType.getHardcoreStatLossEnabled()) {
for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
if (!mcMMO.p.getGeneralConfig().getHardcoreStatLossEnabled(primarySkillType)) {
levelChanged.put(primarySkillType.toString(), 0);
experienceChanged.put(primarySkillType.toString(), 0F);
continue;
@ -86,8 +86,8 @@ public final class HardcoreManager {
HashMap<String, Integer> levelChanged = new HashMap<>();
HashMap<String, Float> experienceChanged = new HashMap<>();
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
if (!primarySkillType.getHardcoreVampirismEnabled()) {
for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
if (!mcMMO.p.getGeneralConfig().getHardcoreVampirismEnabled(primarySkillType)) {
levelChanged.put(primarySkillType.toString(), 0);
experienceChanged.put(primarySkillType.toString(), 0F);
continue;
@ -135,8 +135,8 @@ public final class HardcoreManager {
public static boolean isStatLossEnabled() {
boolean enabled = false;
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
if (primarySkillType.getHardcoreStatLossEnabled()) {
for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
if (mcMMO.p.getGeneralConfig().getHardcoreStatLossEnabled(primarySkillType)) {
enabled = true;
break;
}
@ -153,8 +153,8 @@ public final class HardcoreManager {
public static boolean isVampirismEnabled() {
boolean enabled = false;
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
if (primarySkillType.getHardcoreVampirismEnabled()) {
for (PrimarySkillType primarySkillType : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
if (mcMMO.p.getGeneralConfig().getHardcoreVampirismEnabled(primarySkillType)) {
enabled = true;
break;
}

View File

@ -34,7 +34,7 @@ public final class CommandRegistrationManager {
private static void registerSkillCommands() {
for (PrimarySkillType skill : PrimarySkillType.values()) {
String commandName = skill.toString().toLowerCase(Locale.ENGLISH);
String localizedName = skill.getName().toLowerCase(Locale.ENGLISH);
String localizedName = mcMMO.p.getSkillTools().getLocalizedSkillName(skill).toLowerCase(Locale.ENGLISH);
PluginCommand command;

View File

@ -6,6 +6,7 @@ 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;
@ -25,7 +26,7 @@ public final class CommandUtils {
private CommandUtils() {}
public static boolean isChildSkill(CommandSender sender, PrimarySkillType skill) {
if (skill == null || !skill.isChildSkill()) {
if (skill == null || !mcMMO.p.getSkillTools().isChildSkill(skill)) {
return false;
}
@ -169,7 +170,7 @@ public final class CommandUtils {
* @param display The sender to display stats to
*/
public static void printGatheringSkills(Player inspect, CommandSender display) {
printGroupedSkillData(inspect, display, LocaleLoader.getString("Stats.Header.Gathering"), PrimarySkillType.GATHERING_SKILLS);
printGroupedSkillData(inspect, display, LocaleLoader.getString("Stats.Header.Gathering"), mcMMO.p.getSkillTools().GATHERING_SKILLS);
}
public static void printGatheringSkills(Player player) {
@ -183,7 +184,7 @@ public final class CommandUtils {
* @param display The sender to display stats to
*/
public static void printCombatSkills(Player inspect, CommandSender display) {
printGroupedSkillData(inspect, display, LocaleLoader.getString("Stats.Header.Combat"), PrimarySkillType.COMBAT_SKILLS);
printGroupedSkillData(inspect, display, LocaleLoader.getString("Stats.Header.Combat"), mcMMO.p.getSkillTools().COMBAT_SKILLS);
}
public static void printCombatSkills(Player player) {
@ -197,7 +198,7 @@ public final class CommandUtils {
* @param display The sender to display stats to
*/
public static void printMiscSkills(Player inspect, CommandSender display) {
printGroupedSkillData(inspect, display, LocaleLoader.getString("Stats.Header.Misc"), PrimarySkillType.MISC_SKILLS);
printGroupedSkillData(inspect, display, LocaleLoader.getString("Stats.Header.Misc"), mcMMO.p.getSkillTools().getMiscSkills());
}
public static void printMiscSkills(Player player) {
@ -205,7 +206,7 @@ public final class CommandUtils {
}
public static String displaySkill(PlayerProfile profile, PrimarySkillType skill) {
if (skill.isChildSkill()) {
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)){
@ -214,18 +215,18 @@ public final class CommandUtils {
return LocaleLoader.getString("Skills.Stats", LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".Listener") + " ", profile.getSkillLevel(skill), profile.getSkillXpLevel(skill), profile.getXpToLevel(skill));
}
private static void printGroupedSkillData(Player inspect, CommandSender display, String header, List<PrimarySkillType> skillGroup) {
if(UserManager.getPlayer(inspect) == null)
private static void printGroupedSkillData(Player inspectTarget, CommandSender display, String header, List<PrimarySkillType> skillGroup) {
if(UserManager.getPlayer(inspectTarget) == null)
return;
PlayerProfile profile = UserManager.getPlayer(inspect).getProfile();
PlayerProfile profile = UserManager.getPlayer(inspectTarget).getProfile();
List<String> displayData = new ArrayList<>();
displayData.add(header);
for (PrimarySkillType skill : skillGroup) {
if (skill.getPermissions(inspect)) {
displayData.add(displaySkill(profile, skill));
for (PrimarySkillType primarySkillType : skillGroup) {
if (Permissions.skillEnabled(inspectTarget, primarySkillType)) {
displayData.add(displaySkill(profile, primarySkillType));
}
}

View File

@ -146,10 +146,10 @@ public class ExperienceBarManager {
disabledBars.add(PrimarySkillType.SMELTING);
}
private void informPlayer(@NotNull ExperienceBarManager.@NotNull XPBarSettingTarget settingTarget, @Nullable PrimarySkillType skillType) {
private void informPlayer(@NotNull ExperienceBarManager.@NotNull XPBarSettingTarget settingTarget, @Nullable PrimarySkillType primarySkillType) {
//Inform player of setting change
if(settingTarget != XPBarSettingTarget.RESET) {
NotificationManager.sendPlayerInformationChatOnlyPrefixed(mcMMOPlayer.getPlayer(), "Commands.XPBar.SettingChanged", skillType.getName(), settingTarget.toString());
NotificationManager.sendPlayerInformationChatOnlyPrefixed(mcMMOPlayer.getPlayer(), "Commands.XPBar.SettingChanged", mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType), settingTarget.toString());
} else {
NotificationManager.sendPlayerInformationChatOnlyPrefixed(mcMMOPlayer.getPlayer(), "Commands.XPBar.Reset");
}

View File

@ -289,10 +289,10 @@ public class NotificationManager {
.append(Component.newline())
.append(Component.text(LocalDate.now().toString()))
.append(Component.newline())
.append(Component.text(primarySkillType.getName()+" reached level "+level)).color(TextColor.fromHexString(HEX_BEIGE_COLOR))
.append(Component.text(mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType)+" reached level "+level)).color(TextColor.fromHexString(HEX_BEIGE_COLOR))
.asHoverEvent();
String localeMessage = LocaleLoader.getString("Broadcasts.LevelUpMilestone", mmoPlayer.getPlayer().getDisplayName(), level, primarySkillType.getName());
String localeMessage = LocaleLoader.getString("Broadcasts.LevelUpMilestone", mmoPlayer.getPlayer().getDisplayName(), level, mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType));
Component message = Component.text(localeMessage).hoverEvent(levelMilestoneHover);
Bukkit.getScheduler().runTaskLater(mcMMO.p, () -> audience.sendMessage(Identity.nil(), message), 0);

View File

@ -91,14 +91,14 @@ public class ScoreboardManager {
Collections.shuffle(colors, Misc.getRandom());
int i = 0;
for (PrimarySkillType type : PrimarySkillType.values()) {
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
// Include child skills
skillLabelBuilder.put(type, getShortenedName(colors.get(i) + type.getName(), false));
skillLabelBuilder.put(primarySkillType, getShortenedName(colors.get(i) + mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType), false));
if (type.getAbility() != null) {
abilityLabelBuilder.put(type.getAbility(), getShortenedName(colors.get(i) + type.getAbility().getLocalizedName()));
if (mcMMO.p.getSkillTools().getSuperAbility(primarySkillType) != null) {
abilityLabelBuilder.put(mcMMO.p.getSkillTools().getSuperAbility(primarySkillType), getShortenedName(colors.get(i) + mcMMO.p.getSkillTools().getSuperAbility(primarySkillType).getLocalizedName()));
if (type == PrimarySkillType.MINING) {
if (primarySkillType == PrimarySkillType.MINING) {
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, getShortenedName(colors.get(i) + SuperAbilityType.BLAST_MINING.getLocalizedName()));
}
}
@ -113,14 +113,14 @@ public class ScoreboardManager {
* Stylizes the targetBoard using our normal color scheme
*/
else {
for (PrimarySkillType type : PrimarySkillType.values()) {
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
// Include child skills
skillLabelBuilder.put(type, getShortenedName(ChatColor.GREEN + type.getName()));
skillLabelBuilder.put(primarySkillType, getShortenedName(ChatColor.GREEN + mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType)));
if (type.getAbility() != null) {
abilityLabelBuilder.put(type.getAbility(), formatAbility(type.getAbility().getLocalizedName()));
if (mcMMO.p.getSkillTools().getSuperAbility(primarySkillType) != null) {
abilityLabelBuilder.put(mcMMO.p.getSkillTools().getSuperAbility(primarySkillType), formatAbility(mcMMO.p.getSkillTools().getSuperAbility(primarySkillType).getLocalizedName()));
if (type == PrimarySkillType.MINING) {
if (primarySkillType == PrimarySkillType.MINING) {
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, formatAbility(SuperAbilityType.BLAST_MINING.getLocalizedName()));
}
}

View File

@ -13,6 +13,7 @@ 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;
@ -488,7 +489,7 @@ public class ScoreboardWrapper {
case SKILL_BOARD:
Validate.notNull(targetSkill);
if (!targetSkill.isChildSkill()) {
if (!mcMMO.p.getSkillTools().isChildSkill(targetSkill)) {
int currentXP = mcMMOPlayer.getSkillXpLevel(targetSkill);
sidebarObjective.getScore(ScoreboardManager.LABEL_CURRENT_XP).setScore(currentXP);
@ -502,7 +503,7 @@ public class ScoreboardWrapper {
sidebarObjective.getScore(ScoreboardManager.LABEL_LEVEL).setScore(mcMMOPlayer.getSkillLevel(targetSkill));
if (targetSkill.getAbility() != null) {
if (mcMMO.p.getSkillTools().getSuperAbility(targetSkill) != null) {
boolean stopUpdating;
if (targetSkill == PrimarySkillType.MINING) {
@ -518,7 +519,7 @@ public class ScoreboardWrapper {
stopUpdating = (secondsSB == 0 && secondsBM == 0);
}
else {
SuperAbilityType ability = targetSkill.getAbility();
SuperAbilityType ability = mcMMO.p.getSkillTools().getSuperAbility(targetSkill);
Score cooldown = sidebarObjective.getScore(ScoreboardManager.abilityLabelsSkill.get(ability));
int seconds = Math.max(mcMMOPlayer.calculateTimeRemaining(ability), 0);
@ -573,13 +574,13 @@ public class ScoreboardWrapper {
// Calculate power level here
int powerLevel = 0;
for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) { // Don't include child skills, makes the list too long
for (PrimarySkillType skill : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) { // Don't include child skills, makes the list too long
int level = newProfile.getSkillLevel(skill);
powerLevel += level;
// TODO: Verify that this is what we want - calculated in power level but not displayed
if (!skill.getPermissions(player)) {
if (!Permissions.skillEnabled(player, skill)) {
continue;
}
@ -606,8 +607,8 @@ public class ScoreboardWrapper {
Integer rank;
Player player = mcMMO.p.getServer().getPlayerExact(playerName);
for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) {
if (!skill.getPermissions(player)) {
for (PrimarySkillType skill : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
if (!Permissions.skillEnabled(player, skill)) {
continue;
}

View File

@ -342,7 +342,7 @@ public final class CombatUtils {
}
if (ItemUtils.isSword(player.getInventory().getItemInMainHand())) {
if (!PrimarySkillType.SWORDS.shouldProcess(target)) {
if (!mcMMO.p.getSkillTools().canCombatSkillsTrigger(PrimarySkillType.SWORDS, target)) {
return;
}
@ -380,30 +380,30 @@ public final class CombatUtils {
}
if (ItemUtils.isSword(heldItem)) {
if (!PrimarySkillType.SWORDS.shouldProcess(target)) {
if (!mcMMO.p.getSkillTools().canCombatSkillsTrigger(PrimarySkillType.SWORDS, target)) {
return;
}
if (PrimarySkillType.SWORDS.getPermissions(player)) {
if (Permissions.skillEnabled(player, PrimarySkillType.SWORDS)) {
processSwordCombat(target, player, event);
}
}
else if (ItemUtils.isAxe(heldItem)) {
if (!PrimarySkillType.AXES.shouldProcess(target)) {
if (!mcMMO.p.getSkillTools().canCombatSkillsTrigger(PrimarySkillType.AXES, target)) {
return;
}
if (PrimarySkillType.AXES.getPermissions(player)) {
if (Permissions.skillEnabled(player, PrimarySkillType.AXES)) {
processAxeCombat(target, player, event);
}
}
else if (ItemUtils.isUnarmed(heldItem)) {
if (!PrimarySkillType.UNARMED.shouldProcess(target)) {
if (!mcMMO.p.getSkillTools().canCombatSkillsTrigger(PrimarySkillType.UNARMED, target)) {
return;
}
if (PrimarySkillType.UNARMED.getPermissions(player)) {
if (Permissions.skillEnabled(player, PrimarySkillType.UNARMED)) {
processUnarmedCombat(target, player, event);
}
}
@ -413,10 +413,10 @@ public final class CombatUtils {
Wolf wolf = (Wolf) painSource;
AnimalTamer tamer = wolf.getOwner();
if (tamer instanceof Player && PrimarySkillType.TAMING.shouldProcess(target)) {
if (tamer instanceof Player && mcMMO.p.getSkillTools().canCombatSkillsTrigger(PrimarySkillType.TAMING, target)) {
Player master = (Player) tamer;
if (!Misc.isNPCEntityExcludingVillagers(master) && PrimarySkillType.TAMING.getPermissions(master)) {
if (!Misc.isNPCEntityExcludingVillagers(master) && Permissions.skillEnabled(master, PrimarySkillType.TAMING)) {
processTamingCombat(target, master, wolf, event);
}
}
@ -425,17 +425,17 @@ public final class CombatUtils {
Projectile arrow = (Projectile) painSource;
ProjectileSource projectileSource = arrow.getShooter();
if (projectileSource instanceof Player && PrimarySkillType.ARCHERY.shouldProcess(target)) {
if (projectileSource instanceof Player && mcMMO.p.getSkillTools().canCombatSkillsTrigger(PrimarySkillType.ARCHERY, target)) {
Player player = (Player) projectileSource;
if (!Misc.isNPCEntityExcludingVillagers(player) && PrimarySkillType.ARCHERY.getPermissions(player)) {
if (!Misc.isNPCEntityExcludingVillagers(player) && Permissions.skillEnabled(player, PrimarySkillType.ARCHERY)) {
processArcheryCombat(target, player, event, arrow);
} else {
//Cleanup Arrow
cleanupArrowMetadata(arrow);
}
if (target.getType() != EntityType.CREEPER && !Misc.isNPCEntityExcludingVillagers(player) && PrimarySkillType.TAMING.getPermissions(player)) {
if (target.getType() != EntityType.CREEPER && !Misc.isNPCEntityExcludingVillagers(player) && Permissions.skillEnabled(player, PrimarySkillType.TAMING)) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if(mcMMOPlayer == null)

View File

@ -7,6 +7,7 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
import com.gmail.nossr50.listeners.InteractionManager;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.skills.SkillUnlockNotificationTask;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
@ -28,7 +29,7 @@ public class RankUtils {
*/
public static void executeSkillUnlockNotifications(Plugin plugin, McMMOPlayer mcMMOPlayer, PrimarySkillType primarySkillType, int newLevel)
{
for(SubSkillType subSkillType : primarySkillType.getSkillAbilities())
for(SubSkillType subSkillType : mcMMO.p.getSkillTools().getSubSkills(primarySkillType))
{
int playerRankInSkill = getRank(mcMMOPlayer.getPlayer(), subSkillType);

View File

@ -0,0 +1,450 @@
package com.gmail.nossr50.util.skills;
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.locale.LocaleLoader;
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.ImmutableSet;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.jetbrains.annotations.NotNull;
import java.util.*;
public class SkillTools {
private final mcMMO pluginRef;
//TODO: Should these be hash sets instead of lists?
//TODO: Figure out which ones we don't need, this was copy pasted from a diff branch
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> 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
// 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..
public SkillTools(@NotNull mcMMO pluginRef) {
this.pluginRef = pluginRef;
initSubSkillRelationshipMap();
initPrimaryChildMap();
initPrimaryToolMap();
initSuperAbilityParentRelationships();
List<PrimarySkillType> childSkills = new ArrayList<>();
List<PrimarySkillType> nonChildSkills = new ArrayList<>();
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
if (isChildSkill(primarySkillType)) {
childSkills.add(primarySkillType);
} else {
nonChildSkills.add(primarySkillType);
}
}
COMBAT_SKILLS = ImmutableList.of(PrimarySkillType.ARCHERY, PrimarySkillType.AXES, PrimarySkillType.SWORDS, PrimarySkillType.TAMING, PrimarySkillType.UNARMED);
GATHERING_SKILLS = ImmutableList.of(PrimarySkillType.EXCAVATION, PrimarySkillType.FISHING, PrimarySkillType.HERBALISM, PrimarySkillType.MINING, PrimarySkillType.WOODCUTTING);
MISC_SKILLS = ImmutableList.of(PrimarySkillType.ACROBATICS, PrimarySkillType.ALCHEMY, PrimarySkillType.REPAIR, PrimarySkillType.SALVAGE, PrimarySkillType.SMELTING);
LOCALIZED_SKILL_NAMES = ImmutableList.copyOf(buildLocalizedPrimarySkillNames());
FORMATTED_SUBSKILL_NAMES = ImmutableList.copyOf(buildFormattedSubSkillNameList());
EXACT_SUBSKILL_NAMES = ImmutableSet.copyOf(buildExactSubSkillNameList());
CHILD_SKILLS = ImmutableList.copyOf(childSkills);
NON_CHILD_SKILLS = ImmutableList.copyOf(nonChildSkills);
}
//TODO: What is with this design?
private void initPrimaryToolMap() {
primarySkillToolMap = 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);
}
private void initSuperAbilityParentRelationships() {
superAbilityParentRelationshipMap = new EnumMap<SuperAbilityType, PrimarySkillType>(SuperAbilityType.class);
mainActivatedAbilityChildMap = new EnumMap<PrimarySkillType, SuperAbilityType>(PrimarySkillType.class);
for(SuperAbilityType superAbilityType : SuperAbilityType.values()) {
try {
PrimarySkillType parent = getSuperAbilityParent(superAbilityType);
superAbilityParentRelationshipMap.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);
}
} catch (InvalidSkillException e) {
e.printStackTrace();
}
}
}
private PrimarySkillType getSuperAbilityParent(SuperAbilityType superAbilityType) throws InvalidSkillException {
switch(superAbilityType) {
case BERSERK:
return PrimarySkillType.UNARMED;
case GREEN_TERRA:
return PrimarySkillType.HERBALISM;
case TREE_FELLER:
return PrimarySkillType.WOODCUTTING;
case SUPER_BREAKER:
case BLAST_MINING:
return PrimarySkillType.MINING;
case SKULL_SPLITTER:
return PrimarySkillType.AXES;
case SERRATED_STRIKES:
return PrimarySkillType.SWORDS;
case GIGA_DRILL_BREAKER:
return PrimarySkillType.EXCAVATION;
default:
throw new InvalidSkillException("No parent defined for super ability! "+superAbilityType.toString());
}
}
/**
* Builds a list of localized {@link PrimarySkillType} names
* @return list of localized {@link PrimarySkillType} names
*/
private ArrayList<String> buildLocalizedPrimarySkillNames() {
ArrayList<String> localizedSkillNameList = new ArrayList<>();
for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
localizedSkillNameList.add(getLocalizedSkillName(primarySkillType));
}
Collections.sort(localizedSkillNameList);
return localizedSkillNameList;
}
/**
* Builds a map containing a HashSet of SubSkillTypes considered Children of PrimarySkillType
* Disgusting Hacky Fix until the new skill system is in place
*/
private void initPrimaryChildMap() {
primarySkillChildrenMap = new EnumMap<PrimarySkillType, HashSet<SubSkillType>>(PrimarySkillType.class);
//Init the empty Hash Sets
for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
primarySkillChildrenMap.put(primarySkillType, new HashSet<SubSkillType>());
}
//Fill in the hash sets
for(SubSkillType subSkillType : SubSkillType.values()) {
PrimarySkillType parentSkill = subSkillParentRelationshipMap.get(subSkillType);
//Add this subskill as a child
primarySkillChildrenMap.get(parentSkill).add(subSkillType);
}
}
/**
* Makes a list of the "nice" version of sub skill names
* Used in tab completion mostly
* @return a list of formatted sub skill names
*/
private ArrayList<String> buildFormattedSubSkillNameList() {
ArrayList<String> subSkillNameList = new ArrayList<>();
for(SubSkillType subSkillType : SubSkillType.values()) {
subSkillNameList.add(subSkillType.getNiceNameNoSpaces(subSkillType));
}
return subSkillNameList;
}
private HashSet<String> buildExactSubSkillNameList() {
HashSet<String> subSkillNameExactSet = new HashSet<>();
for(SubSkillType subSkillType : SubSkillType.values()) {
subSkillNameExactSet.add(subSkillType.toString());
}
return subSkillNameExactSet;
}
/**
* Builds a map containing the relationships of SubSkillTypes to PrimarySkillTypes
* Disgusting Hacky Fix until the new skill system is in place
*/
private void initSubSkillRelationshipMap() {
subSkillParentRelationshipMap = new EnumMap<SubSkillType, PrimarySkillType>(SubSkillType.class);
//Super hacky and disgusting
for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
for(SubSkillType subSkillType : SubSkillType.values()) {
String[] splitSubSkillName = subSkillType.toString().split("_");
if(primarySkillType.toString().equalsIgnoreCase(splitSubSkillName[0])) {
//Parent Skill Found
subSkillParentRelationshipMap.put(subSkillType, primarySkillType);
}
}
}
}
/**
* Matches a string of a skill to a skill
* This is NOT case sensitive
* First it checks the locale file and tries to match by the localized name of the skill
* Then if nothing is found it checks against the hard coded "name" of the skill, which is just its name in English
*
* @param skillName target skill name
* @return the matching PrimarySkillType if one is found, otherwise null
*/
public PrimarySkillType matchSkill(String skillName) {
if (!pluginRef.getGeneralConfig().getLocale().equalsIgnoreCase("en_US")) {
for (PrimarySkillType type : PrimarySkillType.values()) {
if (skillName.equalsIgnoreCase(LocaleLoader.getString(StringUtils.getCapitalized(type.name()) + ".SkillName"))) {
return type;
}
}
}
for (PrimarySkillType type : PrimarySkillType.values()) {
if (type.name().equalsIgnoreCase(skillName)) {
return type;
}
}
if (!skillName.equalsIgnoreCase("all")) {
pluginRef.getLogger().warning("Invalid mcMMO skill (" + skillName + ")"); //TODO: Localize
}
return null;
}
/**
* Gets the PrimarySkillStype to which a SubSkillType belongs
* Return null if it does not belong to one.. which should be impossible in most circumstances
* @param subSkillType target subskill
* @return the PrimarySkillType of this SubSkill, null if it doesn't exist
*/
public PrimarySkillType getPrimarySkillBySubSkill(SubSkillType subSkillType) {
return subSkillParentRelationshipMap.get(subSkillType);
}
/**
* Gets the PrimarySkillStype to which a SuperAbilityType belongs
* Return null if it does not belong to one.. which should be impossible in most circumstances
* @param superAbilityType target super ability
* @return the PrimarySkillType of this SuperAbilityType, null if it doesn't exist
*/
public PrimarySkillType getPrimarySkillBySuperAbility(SuperAbilityType superAbilityType) {
return superAbilityParentRelationshipMap.get(superAbilityType);
}
public SuperAbilityType getSuperAbility(PrimarySkillType primarySkillType) {
if(mainActivatedAbilityChildMap.get(primarySkillType) == null)
return null;
return mainActivatedAbilityChildMap.get(primarySkillType);
}
public boolean isSuperAbilityUnlocked(PrimarySkillType primarySkillType, Player player) {
return RankUtils.getRank(player, getSuperAbility(primarySkillType).getSubSkillTypeDefinition()) >= 1;
}
public boolean getPVPEnabled(PrimarySkillType primarySkillType) {
return pluginRef.getGeneralConfig().getPVPEnabled(primarySkillType);
}
public boolean getPVEEnabled(PrimarySkillType primarySkillType) {
return pluginRef.getGeneralConfig().getPVEEnabled(primarySkillType);
}
public boolean getHardcoreStatLossEnabled(PrimarySkillType primarySkillType) {
return pluginRef.getGeneralConfig().getHardcoreStatLossEnabled(primarySkillType);
}
public boolean getHardcoreVampirismEnabled(PrimarySkillType primarySkillType) {
return pluginRef.getGeneralConfig().getHardcoreVampirismEnabled(primarySkillType);
}
public ToolType getPrimarySkillToolType(PrimarySkillType primarySkillType) {
return primarySkillToolMap.get(primarySkillType);
}
public List<SubSkillType> getSubSkills(PrimarySkillType primarySkillType) {
//TODO: Cache this!
return new ArrayList<>(primarySkillChildrenMap.get(primarySkillType));
}
public double getXpModifier(PrimarySkillType primarySkillType) {
return ExperienceConfig.getInstance().getFormulaSkillModifier(primarySkillType);
}
// TODO: This is a little "hacky", we probably need to add something to distinguish child skills in the enum, or to use another enum for them
public boolean isChildSkill(PrimarySkillType primarySkillType) {
switch (primarySkillType) {
case SALVAGE:
case SMELTING:
return true;
default:
return false;
}
}
/**
* Get the localized name for a {@link PrimarySkillType}
* @param primarySkillType target {@link PrimarySkillType}
* @return the localized name for a {@link PrimarySkillType}
*/
public String getLocalizedSkillName(PrimarySkillType primarySkillType) {
//TODO: Replace with current impl
return StringUtils.getCapitalized(LocaleLoader.getString(StringUtils.getCapitalized(primarySkillType.toString()) + ".SkillName"));
}
public boolean doesPlayerHaveSkillPermission(PrimarySkillType primarySkillType, Player player) {
return Permissions.skillEnabled(player, primarySkillType);
}
public boolean canCombatSkillsTrigger(PrimarySkillType primarySkillType, Entity target) {
return (target instanceof Player || (target instanceof Tameable && ((Tameable) target).isTamed())) ? getPVPEnabled(primarySkillType) : getPVEEnabled(primarySkillType);
}
public String getCapitalizedPrimarySkillName(PrimarySkillType primarySkillType) {
return StringUtils.getCapitalized(primarySkillType.toString());
}
public int getSuperAbilityCooldown(SuperAbilityType superAbilityType) {
return pluginRef.getGeneralConfig().getCooldown(superAbilityType);
}
public int getSuperAbilityMaxLength(SuperAbilityType superAbilityType) {
return pluginRef.getGeneralConfig().getMaxLength(superAbilityType);
}
public String getSuperAbilityOnLocaleKey(SuperAbilityType superAbilityType) {
return "SuperAbility." + StringUtils.getPrettyCamelCaseName(superAbilityType) + ".On";
}
public String getSuperAbilityOffLocaleKey(SuperAbilityType superAbilityType) {
return "SuperAbility." + StringUtils.getPrettyCamelCaseName(superAbilityType) + ".Off";
}
public String getSuperAbilityOtherPlayerActivationLocaleKey(SuperAbilityType superAbilityType) {
return "SuperAbility." + StringUtils.getPrettyCamelCaseName(superAbilityType) + ".Other.On";
}
public String getSuperAbilityOtherPlayerDeactivationLocaleKey(SuperAbilityType superAbilityType) {
return "SuperAbility." + StringUtils.getPrettyCamelCaseName(superAbilityType) + "Other.Off";
}
public String getSuperAbilityRefreshedLocaleKey(SuperAbilityType superAbilityType) {
return "SuperAbility." + StringUtils.getPrettyCamelCaseName(superAbilityType) + ".Refresh";
}
/**
* Get the permissions for this ability.
*
* @param player Player to check permissions for
* @param superAbilityType target super ability
* @return true if the player has permissions, false otherwise
*/
public boolean superAbilityPermissionCheck(SuperAbilityType superAbilityType, Player player) {
switch (superAbilityType) {
case BERSERK:
return Permissions.berserk(player);
case BLAST_MINING:
return Permissions.remoteDetonation(player);
case GIGA_DRILL_BREAKER:
return Permissions.gigaDrillBreaker(player);
case GREEN_TERRA:
return Permissions.greenTerra(player);
case SERRATED_STRIKES:
return Permissions.serratedStrikes(player);
case SKULL_SPLITTER:
return Permissions.skullSplitter(player);
case SUPER_BREAKER:
return Permissions.superBreaker(player);
case TREE_FELLER:
return Permissions.treeFeller(player);
default:
return false;
}
}
public @NotNull List<PrimarySkillType> getChildSkills() {
return CHILD_SKILLS;
}
public @NotNull ImmutableList<PrimarySkillType> getNonChildSkills() {
return NON_CHILD_SKILLS;
}
public @NotNull ImmutableList<PrimarySkillType> getCombatSkills() {
return COMBAT_SKILLS;
}
public @NotNull ImmutableList<PrimarySkillType> getGatheringSkills() {
return GATHERING_SKILLS;
}
public @NotNull ImmutableList<PrimarySkillType> getMiscSkills() {
return MISC_SKILLS;
}
// /**
// * Check if a block is affected by this ability.
// *
// * @param blockState the block to check
// * @param superAbilityType target super ability
// * @return true if the block is affected by this ability, false otherwise
// */
// public boolean superAbilityBlockCheck(SuperAbilityType superAbilityType, BlockState blockState) {
// switch (superAbilityType) {
// case BERSERK:
// return (BlockUtils.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW);
//
// case GIGA_DRILL_BREAKER:
// return BlockUtils.affectedByGigaDrillBreaker(blockState);
//
// case GREEN_TERRA:
// return BlockUtils.canMakeMossy(blockState);
//
// case SUPER_BREAKER:
// return BlockUtils.affectedBySuperBreaker(blockState);
//
// case TREE_FELLER:
// dfss
//
// default:
// return false;
// }
// }
}

View File

@ -53,7 +53,7 @@ public final class SkillUtils {
*/
public static String[] calculateLengthDisplayValues(Player player, float skillValue, PrimarySkillType skill) {
int maxLength = skill.getAbility().getMaxLength();
int maxLength = mcMMO.p.getSkillTools().getSuperAbilityMaxLength(mcMMO.p.getSkillTools().getSuperAbility(skill));
int abilityLengthVar = mcMMO.p.getAdvancedConfig().getAbilityLength();
int abilityLengthCap = mcMMO.p.getAdvancedConfig().getAbilityLengthCap();
@ -123,7 +123,7 @@ public final class SkillUtils {
* @return true if this is a valid skill, false otherwise
*/
public static boolean isSkill(String skillName) {
return mcMMO.p.getGeneralConfig().getLocale().equalsIgnoreCase("en_US") ? PrimarySkillType.getSkill(skillName) != null : isLocalizedSkill(skillName);
return mcMMO.p.getGeneralConfig().getLocale().equalsIgnoreCase("en_US") ? mcMMO.p.getSkillTools().matchSkill(skillName) != null : isLocalizedSkill(skillName);
}
public static void sendSkillMessage(Player player, NotificationType notificationType, String key) {
@ -189,10 +189,10 @@ public final class SkillUtils {
if(abilityLengthCap > 0)
{
ticks = PerksUtils.handleActivationPerks(player, Math.min(abilityLengthCap, 2 + (mcMMOPlayer.getSkillLevel(skill) / abilityLengthVar)),
skill.getAbility().getMaxLength()) * Misc.TICK_CONVERSION_FACTOR;
mcMMO.p.getSkillTools().getSuperAbilityMaxLength(mcMMO.p.getSkillTools().getSuperAbility(skill))) * Misc.TICK_CONVERSION_FACTOR;
} else {
ticks = PerksUtils.handleActivationPerks(player, 2 + ((mcMMOPlayer.getSkillLevel(skill)) / abilityLengthVar),
skill.getAbility().getMaxLength()) * Misc.TICK_CONVERSION_FACTOR;
mcMMO.p.getSkillTools().getSuperAbilityMaxLength(mcMMO.p.getSkillTools().getSuperAbility(skill))) * Misc.TICK_CONVERSION_FACTOR;
}
PotionEffect abilityBuff = new PotionEffect(PotionEffectType.FAST_DIGGING, duration + ticks, amplifier + 10);

View File

@ -31,6 +31,35 @@ public class StringUtils {
return shortDecimal.format(ticks / 20);
}
public static String convertToCamelCaseString(String baseString, String splitBy) {
String[] substrings = baseString.split(splitBy);
String prettyString = "";
int size = 1;
for (String string : substrings) {
prettyString = prettyString.concat(getCapitalized(string));
if (size < substrings.length) {
prettyString = prettyString.concat("");
}
size++;
}
return prettyString;
}
public static String getPrettyCamelCaseName(Object o) {
return StringUtils.convertToCamelCaseString(o.toString(), "_");
}
public static String getPrettySuperAbilityName(SuperAbilityType superAbilityType) {
return StringUtils.getPrettySuperAbilityString(superAbilityType);
}
public static String getPrettySuperAbilityString(SuperAbilityType ability) {
return createPrettyString(ability.toString());
}
/**
* Creates a string from an array skipping the first n elements

View File

@ -6,7 +6,6 @@ import com.google.common.io.Files;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;