Got /<skillname> command working

This commit is contained in:
ile123ile 2014-08-30 22:21:43 -07:00
parent cf01241e2d
commit ba32e725f8
5 changed files with 78 additions and 40 deletions

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.api;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
@ -97,6 +98,12 @@ public final class AbilityAPI {
}
public static SecondaryAbility createSecondaryAbility(String name) {
return new SecondaryAbility(name);
return createSecondaryAbility(name, 0, 100);
}
public static SecondaryAbility createSecondaryAbility(String name, int maxBonusLevel, double maxChance) {
SecondaryAbility ability = new SecondaryAbility(name);
AdvancedConfig.getInstance().createNewSkill(ability, maxBonusLevel, maxChance);
return ability;
}
}

View File

@ -6,12 +6,14 @@ import java.util.List;
import org.bukkit.Color;
import com.gmail.nossr50.commands.skills.SkillCommand;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.datatypes.skills.SkillType.SkillUseType;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.commands.CommandRegistrationManager;
import com.google.common.collect.ImmutableList;
public final class SkillAPI {
@ -100,19 +102,27 @@ public final class SkillAPI {
}
public static SkillType createSkill(String name, Class<? extends SkillManager> managerClass, Class<? extends SkillCommand> commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, List<SecondaryAbility> secondaryAbilities) {
return SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, secondaryAbilities);
SkillType skill = SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, secondaryAbilities);
CommandRegistrationManager.registerSkillCommandAndPassSkillToConstructor(skill);
return skill;
}
public static SkillType createSkill(String name, Class<? extends SkillManager> managerClass, Class<? extends SkillCommand> commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, AbilityType ability, ToolType tool, List<SecondaryAbility> secondaryAbilities) {
return SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ability, tool, secondaryAbilities);
SkillType skill = SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ability, tool, secondaryAbilities);
CommandRegistrationManager.registerSkillCommandAndPassSkillToConstructor(skill);
return skill;
}
public static SkillType createSkill(String name, Class<? extends SkillManager> managerClass, Class<? extends SkillCommand> commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, SecondaryAbility... secondaryAbilities) {
return SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ImmutableList.copyOf(secondaryAbilities));
SkillType skill = SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ImmutableList.copyOf(secondaryAbilities));
CommandRegistrationManager.registerSkillCommandAndPassSkillToConstructor(skill);
return skill;
}
public static SkillType createSkill(String name, Class<? extends SkillManager> managerClass, Class<? extends SkillCommand> commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, AbilityType ability, ToolType tool, SecondaryAbility... secondaryAbilities) {
return SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ability, tool, ImmutableList.copyOf(secondaryAbilities));
SkillType skill = SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ability, tool, ImmutableList.copyOf(secondaryAbilities));
CommandRegistrationManager.registerSkillCommandAndPassSkillToConstructor(skill);
return skill;
}
public static void loadNewSkills() {

View File

@ -143,8 +143,9 @@ public abstract class SkillCommand implements TabExecutor {
protected String[] calculateAbilityDisplayValues(float skillValue, SecondaryAbility skillAbility, boolean isLucky) {
int maxBonusLevel = AdvancedConfig.getInstance().getMaxBonusLevel(skillAbility);
return calculateAbilityDisplayValues((AdvancedConfig.getInstance().getMaxChance(skillAbility) / maxBonusLevel) * Math.min(skillValue, maxBonusLevel), isLucky);
double maxChance = AdvancedConfig.getInstance().getMaxChance(skillAbility);
double chance = (maxBonusLevel == 0) ? maxChance : (maxChance / maxBonusLevel) * Math.min(skillValue, maxBonusLevel);
return calculateAbilityDisplayValues(chance, isLucky);
}
protected String[] calculateLengthDisplayValues(Player player, float skillValue) {

View File

@ -1,10 +1,10 @@
package com.gmail.nossr50.config;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.alchemy.Alchemy;
@ -685,6 +685,17 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
@Override
protected void loadKeys() {}
public void createNewSkill(SecondaryAbility skillAbility, int maxBonusLevel, double maxChance) {
String skillAbilityString = "Skills." + StringUtils.getCapitalized(SkillType.bySecondaryAbility(skillAbility).toString()) + "." + StringUtils.getPrettySecondaryAbilityString(skillAbility).replace(" ", "");
config.set(skillAbilityString + ".MaxBonusLevel", maxBonusLevel);
config.set(skillAbilityString + ".ChanceMax", maxChance);
try {
config.save(getFile());
} catch (IOException e) {
e.printStackTrace();
}
}
/* GENERAL */
public int getAbilityLength() { return config.getInt("Skills.General.Ability.IncreaseLevel", 50); }

View File

@ -35,21 +35,6 @@ import com.gmail.nossr50.commands.player.MccooldownCommand;
import com.gmail.nossr50.commands.player.McrankCommand;
import com.gmail.nossr50.commands.player.McstatsCommand;
import com.gmail.nossr50.commands.player.MctopCommand;
import com.gmail.nossr50.commands.skills.AcrobaticsCommand;
import com.gmail.nossr50.commands.skills.AlchemyCommand;
import com.gmail.nossr50.commands.skills.ArcheryCommand;
import com.gmail.nossr50.commands.skills.AxesCommand;
import com.gmail.nossr50.commands.skills.ExcavationCommand;
import com.gmail.nossr50.commands.skills.FishingCommand;
import com.gmail.nossr50.commands.skills.HerbalismCommand;
import com.gmail.nossr50.commands.skills.MiningCommand;
import com.gmail.nossr50.commands.skills.RepairCommand;
import com.gmail.nossr50.commands.skills.SalvageCommand;
import com.gmail.nossr50.commands.skills.SmeltingCommand;
import com.gmail.nossr50.commands.skills.SwordsCommand;
import com.gmail.nossr50.commands.skills.TamingCommand;
import com.gmail.nossr50.commands.skills.UnarmedCommand;
import com.gmail.nossr50.commands.skills.WoodcuttingCommand;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
@ -62,25 +47,49 @@ public final class CommandRegistrationManager {
private static void registerSkillCommands() {
for (SkillType skill : SkillType.getSkillList()) {
String commandName = skill.toString().toLowerCase();
String localizedName = skill.getLocalizedName().toLowerCase();
PluginCommand command;
command = mcMMO.p.getCommand(commandName);
command.setDescription(LocaleLoader.getString("Commands.Description.Skill", StringUtils.getCapitalized(localizedName)));
command.setPermission("mcmmo.commands." + commandName);
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.0", localizedName));
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.2", localizedName, "?", "[" + LocaleLoader.getString("Commands.Usage.Page") + "]"));
try {
command.setExecutor(skill.getCommandClass().newInstance());
} catch (Exception e) {
e.printStackTrace();
}
registerSkillCommand(skill);
}
}
public static void registerSkillCommand(SkillType skill) {
String commandName = skill.toString().toLowerCase();
String localizedName = skill.getLocalizedName().toLowerCase();
PluginCommand command;
command = mcMMO.p.getCommand(commandName);
command.setDescription(LocaleLoader.getString("Commands.Description.Skill", StringUtils.getCapitalized(localizedName)));
command.setPermission("mcmmo.commands." + commandName);
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.0", localizedName));
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.2", localizedName, "?", "[" + LocaleLoader.getString("Commands.Usage.Page") + "]"));
try {
command.setExecutor(skill.getCommandClass().newInstance());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void registerSkillCommandAndPassSkillToConstructor(SkillType skill) {
String commandName = skill.toString().toLowerCase();
String localizedName = skill.getLocalizedName().toLowerCase();
PluginCommand command;
command = mcMMO.p.getCommand(commandName);
command.setDescription(LocaleLoader.getString("Commands.Description.Skill", StringUtils.getCapitalized(localizedName)));
command.setPermission("mcmmo.commands." + commandName);
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.0", localizedName));
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.2", localizedName, "?", "[" + LocaleLoader.getString("Commands.Usage.Page") + "]"));
try {
command.setExecutor(skill.getCommandClass().getDeclaredConstructor(SkillType.class).newInstance(skill));
} catch (Exception e) {
e.printStackTrace();
}
}
private static void registerAddlevelsCommand() {
PluginCommand command = mcMMO.p.getCommand("addlevels");