Updating various classes for the new SkillTools class

This commit is contained in:
nossr50 2019-07-04 05:42:15 -07:00
parent 381eba8ddc
commit e001dea4d7
12 changed files with 71 additions and 65 deletions

View File

@ -44,6 +44,6 @@ public class AddLevelsCommand extends ExperienceCommand {
@Override
protected void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill) {
player.sendMessage(pluginRef.getLocaleManager().getString("Commands.addlevels.AwardSkill.1", value, skill.getLocalizedSkillName()));
player.sendMessage(pluginRef.getLocaleManager().getString("Commands.addlevels.AwardSkill.1", value, pluginRef.getSkillTools().getLocalizedSkillName(skill)));
}
}

View File

@ -46,6 +46,6 @@ public class AddXPCommand extends ExperienceCommand {
@Override
protected void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill) {
player.sendMessage(pluginRef.getLocaleManager().getString("Commands.addxp.AwardSkill", value, skill.getLocalizedSkillName()));
player.sendMessage(pluginRef.getLocaleManager().getString("Commands.addxp.AwardSkill", value, pluginRef.getSkillTools().getLocalizedSkillName(skill)));
}
}

View File

@ -28,7 +28,7 @@ public abstract class ExperienceCommand implements TabExecutor {
if (skill == null) {
sender.sendMessage(pluginRef.getLocaleManager().getString("Commands.addlevels.AwardAll.2", playerName));
} else {
sender.sendMessage(pluginRef.getLocaleManager().getString("Commands.addlevels.AwardSkill.2", skill.getLocalizedSkillName(), playerName));
sender.sendMessage(pluginRef.getLocaleManager().getString("Commands.addlevels.AwardSkill.2", pluginRef.getSkillTools().getLocalizedSkillName(skill), playerName));
}
}
@ -51,13 +51,13 @@ public abstract class ExperienceCommand implements TabExecutor {
return true;
}
skill = PrimarySkillType.matchSkill(args[0]);
skill = pluginRef.getSkillTools().matchSkill(args[0]);
if (args[1].equalsIgnoreCase("all")) {
skill = null;
}
if (skill != null && skill.isChildSkill()) {
if (skill != null && pluginRef.getSkillTools().isChildSkill(skill)) {
sender.sendMessage(pluginRef.getLocaleManager().getString("Commands.Skill.ChildSkill"));
return true;
}
@ -82,13 +82,13 @@ public abstract class ExperienceCommand implements TabExecutor {
return true;
}
skill = PrimarySkillType.matchSkill(args[1]);
skill = pluginRef.getSkillTools().matchSkill(args[1]);
if (args[1].equalsIgnoreCase("all")) {
skill = null;
}
if (skill != null && skill.isChildSkill()) {
if (skill != null && pluginRef.getSkillTools().isChildSkill(skill)) {
sender.sendMessage(pluginRef.getLocaleManager().getString("Commands.Skill.ChildSkill"));
return true;
}
@ -131,7 +131,7 @@ public abstract class ExperienceCommand implements TabExecutor {
List<String> playerNames = pluginRef.getCommandTools().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], pluginRef.getSkillTools().LOCALIZED_SKILL_NAMES, new ArrayList<>(pluginRef.getSkillTools().LOCALIZED_SKILL_NAMES.size()));
default:
return ImmutableList.of();
}

View File

@ -49,6 +49,6 @@ public class SkillEditCommand extends ExperienceCommand {
@Override
protected void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill) {
player.sendMessage(pluginRef.getLocaleManager().getString("Commands.mmoedit.Modified.1", skill.getLocalizedSkillName(), value));
player.sendMessage(pluginRef.getLocaleManager().getString("Commands.mmoedit.Modified.1", pluginRef.getSkillTools().getLocalizedSkillName(skill), value));
}
}

View File

@ -34,7 +34,7 @@ public class SkillResetCommand implements TabExecutor {
if (skill == null) {
sender.sendMessage(pluginRef.getLocaleManager().getString("Commands.addlevels.AwardAll.2", playerName));
} else {
sender.sendMessage(pluginRef.getLocaleManager().getString("Commands.addlevels.AwardSkill.2", skill.getLocalizedSkillName(), playerName));
sender.sendMessage(pluginRef.getLocaleManager().getString("Commands.addlevels.AwardSkill.2", pluginRef.getSkillTools().getLocalizedSkillName(skill), playerName));
}
}
@ -59,7 +59,7 @@ public class SkillResetCommand implements TabExecutor {
if (args[0].equalsIgnoreCase("all")) {
skill = null;
} else {
skill = PrimarySkillType.matchSkill(args[1]);
skill = pluginRef.getSkillTools().matchSkill(args[1]);
}
editValues((Player) sender, pluginRef.getUserManager().getPlayer(sender.getName()).getProfile(), skill);
@ -78,7 +78,7 @@ public class SkillResetCommand implements TabExecutor {
if (args[1].equalsIgnoreCase("all")) {
skill = null;
} else {
skill = PrimarySkillType.matchSkill(args[1]);
skill = pluginRef.getSkillTools().matchSkill(args[1]);
}
String playerName = pluginRef.getCommandTools().getMatchedPlayerName(args[0]);
@ -117,7 +117,7 @@ public class SkillResetCommand implements TabExecutor {
List<String> playerNames = pluginRef.getCommandTools().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], pluginRef.getSkillTools().LOCALIZED_SKILL_NAMES, new ArrayList<>(pluginRef.getSkillTools().LOCALIZED_SKILL_NAMES.size()));
default:
return ImmutableList.of();
}
@ -150,7 +150,7 @@ public class SkillResetCommand implements TabExecutor {
}
protected void handlePlayerMessageSkill(Player player, PrimarySkillType skill) {
player.sendMessage(pluginRef.getLocaleManager().getString("Commands.Reset.Single", skill.getLocalizedSkillName()));
player.sendMessage(pluginRef.getLocaleManager().getString("Commands.Reset.Single", pluginRef.getSkillTools().getLocalizedSkillName(skill)));
}
private boolean validateArguments(CommandSender sender, String skillName) {

View File

@ -73,7 +73,7 @@ public class LeaderboardCommand implements TabExecutor {
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
switch (args.length) {
case 1:
return StringUtil.copyPartialMatches(args[0], PrimarySkillType.SKILL_NAMES, new ArrayList<>(PrimarySkillType.SKILL_NAMES.size()));
return StringUtil.copyPartialMatches(args[0], pluginRef.getSkillTools().LOCALIZED_SKILL_NAMES, new ArrayList<>(pluginRef.getSkillTools().LOCALIZED_SKILL_NAMES.size()));
default:
return ImmutableList.of();
}

View File

@ -182,7 +182,7 @@ public class McMMOPlayer {
//Check each skill for custom XP perks
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
//Skip over child skills
if (primarySkillType.isChildSkill())
if (pluginRef.getSkillTools().isChildSkill(primarySkillType))
continue;
//Set the players custom XP modifier, defaults to 1.0D on missing entries
@ -216,7 +216,9 @@ public class McMMOPlayer {
if(hasReachedPowerLevelCap()) {
pluginRef.getNotificationManager().sendPlayerInformationChatOnly(player, "LevelCap.PowerLevel", String.valueOf(pluginRef.getConfigManager().getConfigLeveling().getPowerLevelCap()));
} else if(hasReachedLevelCap(primarySkillType)) {
pluginRef.getNotificationManager().sendPlayerInformationChatOnly(player, "LevelCap.Skill", String.valueOf(pluginRef.getConfigManager().getConfigLeveling().getSkillLevelCap(primarySkillType)), primarySkillType.getLocalizedSkillName());
pluginRef.getNotificationManager().sendPlayerInformationChatOnly(player, "LevelCap.Skill",
String.valueOf(pluginRef.getConfigManager().getConfigLeveling().getSkillLevelCap(primarySkillType)),
pluginRef.getSkillTools().getLocalizedSkillName(primarySkillType));
}
//Updates from Party sources
@ -237,7 +239,7 @@ public class McMMOPlayer {
public void updateXPBar(PrimarySkillType primarySkillType, Plugin plugin) {
//Skill Unlock Notifications
if (primarySkillType.isChildSkill())
if (pluginRef.getSkillTools().isChildSkill(primarySkillType))
return;
//XP BAR UPDATES
@ -518,9 +520,9 @@ public class McMMOPlayer {
public int getPowerLevel() {
int powerLevel = 0;
for (PrimarySkillType type : pluginRef.getSkillTools().NON_CHILD_SKILLS) {
if (type.doesPlayerHaveSkillPermission(player)) {
powerLevel += getSkillLevel(type);
for (PrimarySkillType primarySkillType : pluginRef.getSkillTools().NON_CHILD_SKILLS) {
if (pluginRef.getSkillTools().doesPlayerHaveSkillPermission(primarySkillType, player)) {
powerLevel += getSkillLevel(primarySkillType);
}
}
@ -555,22 +557,22 @@ public class McMMOPlayer {
/**
* Begins an experience gain. The amount will be affected by skill modifiers, global rate, perks, and may be shared with the party
*
* @param skill Skill being used
* @param primarySkillType Skill being used
* @param xp Experience amount to process
*/
public void beginXpGain(PrimarySkillType skill, double xp, XPGainReason xpGainReason, XPGainSource xpGainSource) {
public void beginXpGain(PrimarySkillType primarySkillType, double xp, XPGainReason xpGainReason, XPGainSource xpGainSource) {
Validate.isTrue(xp >= 0.0, "XP gained should be greater than or equal to zero.");
if (xp <= 0.0) {
return;
}
if (skill.isChildSkill()) {
Set<PrimarySkillType> parentSkills = FamilyTree.getParents(skill);
if (pluginRef.getSkillTools().isChildSkill(primarySkillType)) {
Set<PrimarySkillType> parentSkills = FamilyTree.getParents(primarySkillType);
double splitXp = xp / parentSkills.size();
for (PrimarySkillType parentSkill : parentSkills) {
if (parentSkill.doesPlayerHaveSkillPermission(player)) {
if (pluginRef.getSkillTools().doesPlayerHaveSkillPermission(parentSkill, player)) {
beginXpGain(parentSkill, splitXp, xpGainReason, xpGainSource);
}
}
@ -579,11 +581,11 @@ public class McMMOPlayer {
}
// Return if the experience has been shared
if (party != null && party.getShareHandler().handleXpShare(xp, this, skill, party.getShareHandler().getSharedXpGainReason(xpGainReason))) {
if (party != null && party.getShareHandler().handleXpShare(xp, this, primarySkillType, party.getShareHandler().getSharedXpGainReason(xpGainReason))) {
return;
}
beginUnsharedXpGain(skill, xp, xpGainReason, xpGainSource);
beginUnsharedXpGain(primarySkillType, xp, xpGainReason, xpGainSource);
}
/**
@ -614,11 +616,11 @@ public class McMMOPlayer {
* @param xp Experience amount to add
*/
public void applyXpGain(PrimarySkillType primarySkillType, double xp, XPGainReason xpGainReason, XPGainSource xpGainSource) {
if (!primarySkillType.doesPlayerHaveSkillPermission(player)) {
if (!pluginRef.getSkillTools().doesPlayerHaveSkillPermission(primarySkillType, player)) {
return;
}
if (primarySkillType.isChildSkill()) {
if (pluginRef.getSkillTools().isChildSkill(primarySkillType)) {
Set<PrimarySkillType> parentSkills = FamilyTree.getParents(primarySkillType);
for (PrimarySkillType parentSkill : parentSkills) {
@ -849,13 +851,13 @@ public class McMMOPlayer {
* @return Modified experience
*/
private double modifyXpGain(PrimarySkillType primarySkillType, double xp) {
if (((primarySkillType.getMaxLevel() <= getSkillLevel(primarySkillType))
if (((pluginRef.getConfigManager().getConfigLeveling().getSkillLevelCap(primarySkillType) <= getSkillLevel(primarySkillType))
&& pluginRef.getPlayerLevelingSettings().isSkillLevelCapEnabled(primarySkillType))
|| (pluginRef.getPlayerLevelingSettings().getConfigSectionLevelCaps().getPowerLevelSettings().getLevelCap() <= getPowerLevel())) {
return 0;
}
xp = (double) (xp / primarySkillType.getXpModifier() * pluginRef.getDynamicSettingsManager().getExperienceManager().getGlobalXpMult());
xp = (double) (xp / pluginRef.getSkillTools().getXpModifier(primarySkillType) * pluginRef.getDynamicSettingsManager().getExperienceManager().getGlobalXpMult());
//Multiply by the players personal XP rate
return xp * personalXPModifiers.get(primarySkillType);
@ -879,23 +881,24 @@ public class McMMOPlayer {
/**
* 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.getPrimarySkillToolType();
SuperAbilityType ability = skill.getSuperAbility();
public void checkAbilityActivation(PrimarySkillType primarySkillType) {
//TODO: Disgusting..
ToolType tool = pluginRef.getSkillTools().getPrimarySkillToolType(primarySkillType);
SuperAbilityType ability = pluginRef.getSkillTools().getSuperAbility(primarySkillType);
if (getAbilityMode(ability) || !ability.getPermissions(player)) {
return;
}
//TODO: This is hacky and temporary solution until skills are move to the new system
//TODO: This is hacky and temporary solution until skills are moved to the new system
//Potential problems with this include skills with two super abilities (ie mining)
if (!skill.isSuperAbilityUnlocked(getPlayer())) {
int diff = RankUtils.getSuperAbilityUnlockRequirement(skill.getSuperAbility()) - getSkillLevel(skill);
if (!pluginRef.getSkillTools().isSuperAbilityUnlocked(primarySkillType, getPlayer())) {
int diff = RankUtils.getSuperAbilityUnlockRequirement(pluginRef.getSkillTools().getSuperAbility(primarySkillType)) - getSkillLevel(primarySkillType);
//Inform the player they are not yet skilled enough
pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.ABILITY_COOLDOWN, "Skills.AbilityGateRequirementFail", String.valueOf(diff), skill.getLocalizedSkillName());
pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.ABILITY_COOLDOWN, "Skills.AbilityGateRequirementFail", String.valueOf(diff), pluginRef.getSkillTools().getLocalizedSkillName(primarySkillType));
return;
}
@ -906,7 +909,7 @@ public class McMMOPlayer {
* 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) {
pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.ABILITY_COOLDOWN, "Skills.TooTired", String.valueOf(timeRemaining));
//SoundManager.sendSound(player, player.getLocation(), SoundType.TIRED);
}
@ -914,7 +917,7 @@ public class McMMOPlayer {
return;
}
if (pluginRef.getEventManager().callPlayerAbilityActivateEvent(player, skill).isCancelled()) {
if (pluginRef.getEventManager().callPlayerAbilityActivateEvent(player, primarySkillType).isCancelled()) {
return;
}
@ -928,7 +931,7 @@ public class McMMOPlayer {
//Sounds
SoundManager.worldSendSound(player.getWorld(), player.getLocation(), SoundType.ABILITY_ACTIVATED_GENERIC);
int abilityLength = pluginRef.getSkillTools().calculateAbilityLengthPerks(this, skill, ability);
int abilityLength = pluginRef.getSkillTools().calculateAbilityLengthPerks(this, primarySkillType, ability);
// Enable the ability
profile.setAbilityDATS(ability, System.currentTimeMillis() + (abilityLength * Misc.TIME_CONVERSION_FACTOR));
@ -942,7 +945,7 @@ public class McMMOPlayer {
new AbilityDisableTask(pluginRef, this, ability).runTaskLater(pluginRef, abilityLength * Misc.TICK_CONVERSION_FACTOR);
}
public void processAbilityActivation(PrimarySkillType skill) {
public void processAbilityActivation(PrimarySkillType primarySkillType) {
if (pluginRef.getConfigManager().getConfigSuperAbilities().isMustSneakToActivate() && !player.isSneaking()) {
return;
}
@ -963,15 +966,15 @@ public class McMMOPlayer {
}
}
SuperAbilityType ability = skill.getSuperAbility();
ToolType tool = skill.getPrimarySkillToolType();
SuperAbilityType ability = pluginRef.getSkillTools().getSuperAbility(primarySkillType);
ToolType tool = pluginRef.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 (!getAbilityMode(ability) && timeRemaining > 0) {

View File

@ -59,9 +59,9 @@ public class LeaderboardsCommandDisplayTask extends BukkitRunnable {
}
} else {
if (sender instanceof Player) {
sender.sendMessage(pluginRef.getLocaleManager().getString("Commands.Skill.Leaderboard", skill.getLocalizedSkillName()));
sender.sendMessage(pluginRef.getLocaleManager().getString("Commands.Skill.Leaderboard", pluginRef.getSkillTools().getLocalizedSkillName(skill)));
} else {
sender.sendMessage(ChatColor.stripColor(pluginRef.getLocaleManager().getString("Commands.Skill.Leaderboard", skill.getLocalizedSkillName())));
sender.sendMessage(ChatColor.stripColor(pluginRef.getLocaleManager().getString("Commands.Skill.Leaderboard", pluginRef.getSkillTools().getLocalizedSkillName(skill))));
}
}

View File

@ -53,7 +53,7 @@ public class RankCommandDisplayTask extends BukkitRunnable {
// }
rank = skills.get(skill);
sender.sendMessage(pluginRef.getLocaleManager().getString("Commands.mcrank.Skill", skill.getLocalizedSkillName(), (rank == null ? pluginRef.getLocaleManager().getString("Commands.mcrank.Unranked") : rank)));
sender.sendMessage(pluginRef.getLocaleManager().getString("Commands.mcrank.Skill", pluginRef.getSkillTools().getLocalizedSkillName(skill), (rank == null ? pluginRef.getLocaleManager().getString("Commands.mcrank.Unranked") : rank)));
}
rank = skills.get(null);

View File

@ -35,9 +35,9 @@ public final class CommandRegistrationManager {
}
private void registerSkillCommands() {
for (PrimarySkillType skill : PrimarySkillType.values()) {
String commandName = skill.toString().toLowerCase();
String localizedName = skill.getLocalizedSkillName().toLowerCase();
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
String commandName = primarySkillType.toString().toLowerCase();
String localizedName = pluginRef.getSkillTools().getLocalizedSkillName(primarySkillType).toLowerCase();
PluginCommand command;
@ -48,7 +48,7 @@ public final class CommandRegistrationManager {
command.setUsage(pluginRef.getLocaleManager().getString("Commands.Usage.0", localizedName));
command.setUsage(command.getUsage() + "\n" + pluginRef.getLocaleManager().getString("Commands.Usage.2", localizedName, "?", "[" + pluginRef.getLocaleManager().getString("Commands.Usage.Page") + "]"));
switch (skill) {
switch (primarySkillType) {
case ACROBATICS:
command.setExecutor(new AcrobaticsCommand(pluginRef));
break;

View File

@ -97,14 +97,14 @@ public class ScoreboardStrings {
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.getLocalizedSkillName(), false));
skillLabelBuilder.put(primarySkillType, getShortenedName(colors.get(i) + pluginRef.getSkillTools().getLocalizedSkillName(primarySkillType), false));
if (type.getSuperAbility() != null) {
abilityLabelBuilder.put(type.getSuperAbility(), getShortenedName(colors.get(i) + type.getSuperAbility().getName()));
if (pluginRef.getSkillTools().getSuperAbility(primarySkillType) != null) {
abilityLabelBuilder.put(pluginRef.getSkillTools().getSuperAbility(primarySkillType), getShortenedName(colors.get(i) + pluginRef.getSkillTools().getSuperAbility(primarySkillType).getName()));
if (type == PrimarySkillType.MINING) {
if (primarySkillType == PrimarySkillType.MINING) {
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, getShortenedName(colors.get(i) + SuperAbilityType.BLAST_MINING.getName()));
}
}
@ -119,14 +119,14 @@ public class ScoreboardStrings {
* 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.getLocalizedSkillName()));
skillLabelBuilder.put(primarySkillType, getShortenedName(ChatColor.GREEN + pluginRef.getSkillTools().getLocalizedSkillName(primarySkillType)));
if (type.getSuperAbility() != null) {
abilityLabelBuilder.put(type.getSuperAbility(), formatAbility(type.getSuperAbility().getName()));
if (pluginRef.getSkillTools().getSuperAbility(primarySkillType) != null) {
abilityLabelBuilder.put(pluginRef.getSkillTools().getSuperAbility(primarySkillType), formatAbility(pluginRef.getSkillTools().getSuperAbility(primarySkillType).getName()));
if (type == PrimarySkillType.MINING) {
if (primarySkillType == PrimarySkillType.MINING) {
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, formatAbility(SuperAbilityType.BLAST_MINING.getName()));
}
}

View File

@ -636,10 +636,13 @@ public class SkillTools {
}
public SuperAbilityType getSuperAbility(PrimarySkillType primarySkillType) {
if(mainActivatedAbilityChildMap.get(primarySkillType) == null)
return null;
return mainActivatedAbilityChildMap.get(primarySkillType);
}
public boolean isSuperAbilityUnlocked(Player player, PrimarySkillType primarySkillType) {
public boolean isSuperAbilityUnlocked(PrimarySkillType primarySkillType, Player player) {
return RankUtils.getRank(player, getSuperAbility(primarySkillType).getSubSkillTypeDefinition()) >= 1;
}