mcMMO/src/main/java/com/gmail/nossr50/skills/SkillCommand.java

171 lines
6.1 KiB
Java
Raw Normal View History

package com.gmail.nossr50.skills;
2012-05-31 19:50:37 +02:00
import java.text.DecimalFormat;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.commands.CommandHelper;
2012-05-31 19:50:37 +02:00
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.StringUtils;
2012-05-31 19:50:37 +02:00
import com.gmail.nossr50.util.Users;
2012-05-31 20:44:54 +02:00
public abstract class SkillCommand implements CommandExecutor {
2012-05-31 19:50:37 +02:00
private SkillType skill;
private String skillString;
2012-05-31 20:01:47 +02:00
protected Player player;
2012-05-31 20:24:55 +02:00
protected PlayerProfile profile;
2012-05-31 20:01:47 +02:00
protected float skillValue;
2013-01-22 04:57:54 +01:00
protected boolean isLucky;
protected boolean hasEndurance;
2012-05-31 19:50:37 +02:00
2012-05-31 20:01:47 +02:00
protected DecimalFormat percent = new DecimalFormat("##0.00%");
protected DecimalFormat decimal = new DecimalFormat("##0.00");
2012-05-31 19:50:37 +02:00
2012-05-31 20:01:47 +02:00
public SkillCommand(SkillType skill) {
2012-05-31 19:50:37 +02:00
this.skill = skill;
this.skillString = StringUtils.getCapitalized(skill.toString());
2012-05-31 19:50:37 +02:00
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandHelper.noConsoleUsage(sender)) {
return true;
}
player = (Player) sender;
profile = Users.getPlayer(player).getProfile();
2012-05-31 19:50:37 +02:00
2012-10-31 01:59:58 +01:00
if (profile == null) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
2012-06-05 15:57:10 +02:00
skillValue = profile.getSkillLevel(skill);
isLucky = player.hasPermission("mcmmo.perks.lucky." + skill.toString().toLowerCase());
hasEndurance = (player.hasPermission("mcmmo.perks.activationtime.twelveseconds") || player.hasPermission("mcmmo.perks.activationtime.eightseconds") || player.hasPermission("mcmmo.perks.activationtime.fourseconds"));
2013-01-22 04:57:54 +01:00
2012-05-31 19:50:37 +02:00
dataCalculations();
permissionsCheck();
2013-02-02 08:55:49 +01:00
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString(skillString + ".SkillName")));
2013-01-23 22:34:01 +01:00
if (!skill.isChildSkill()) {
2013-02-02 08:55:49 +01:00
player.sendMessage(LocaleLoader.getString("Commands.XPGain", LocaleLoader.getString("Commands.XPGain." + skillString)));
player.sendMessage(LocaleLoader.getString("Effects.Level", profile.getSkillLevel(skill), profile.getSkillXpLevel(skill), profile.getXpToLevel(skill)));
2013-01-23 22:34:01 +01:00
}
2012-05-31 19:50:37 +02:00
if (effectsHeaderPermissions()) {
2013-02-02 08:55:49 +01:00
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Effects.Effects")));
2012-05-31 19:50:37 +02:00
}
effectsDisplay();
if (statsHeaderPermissions()) {
2013-02-02 08:55:49 +01:00
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Commands.Stats.Self")));
2012-05-31 19:50:37 +02:00
}
statsDisplay();
return SkillGuide.grabGuidePageForSkill(skill, player, args);
2012-05-31 19:50:37 +02:00
}
protected String calculateRank(int maxLevel, int rankChangeLevel) {
if (skillValue >= maxLevel) {
return String.valueOf(maxLevel / rankChangeLevel);
}
return String.valueOf((int) (skillValue / rankChangeLevel));
}
protected String[] calculateAbilityDisplayValues(double chance) {
if (isLucky) {
double luckyChance = chance * 1.3333D;
if (luckyChance >= 100D) {
return new String[] { percent.format(chance / 100.0D), percent.format(1.0D) };
}
return new String[] { percent.format(chance / 100.0D), percent.format(luckyChance / 100.0D) };
}
return new String[] { percent.format(chance / 100.0D), null };
}
2013-01-22 04:57:54 +01:00
protected String[] calculateAbilityDisplayValues(int maxBonusLevel, double maxChance) {
double abilityChance;
if (skillValue >= maxBonusLevel) {
abilityChance = maxChance;
}
else {
abilityChance = (maxChance / maxBonusLevel) * skillValue;
}
if (isLucky) {
double luckyChance = abilityChance * 1.3333D;
2013-01-22 04:57:54 +01:00
if (luckyChance >= 100D) {
return new String[] { percent.format(abilityChance / 100.0D), percent.format(1.0D) };
}
return new String[] { percent.format(abilityChance / 100.0D), percent.format(luckyChance / 100.0D) };
}
return new String[] { percent.format(abilityChance / 100.0D), null };
}
protected String[] calculateLengthDisplayValues() {
int maxLength = skill.getAbility().getMaxTicks();
int length = 2 + (int) (skillValue / SkillTools.abilityLengthIncreaseLevel);
2013-01-22 04:57:54 +01:00
int enduranceLength = 0;
if (player.hasPermission("mcmmo.perks.activationtime.twelveseconds")) {
2013-01-22 04:57:54 +01:00
enduranceLength = length + 12;
}
else if (player.hasPermission("mcmmo.perks.activationtime.eightseconds")) {
2013-01-22 04:57:54 +01:00
enduranceLength = length + 8;
}
else if (player.hasPermission("mcmmo.perks.activationtime.fourseconds")) {
2013-01-22 04:57:54 +01:00
enduranceLength = length + 4;
}
if (maxLength != 0) {
if (length > maxLength) {
length = maxLength;
}
if (enduranceLength > maxLength) {
enduranceLength = maxLength;
}
}
return new String[] { String.valueOf(length), String.valueOf(enduranceLength) };
}
protected void luckyEffectsDisplay() {
if (isLucky) {
String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix");
player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.lucky.name"), LocaleLoader.getString("Perks.lucky.desc", SkillTools.getSkillName(skill))));
2013-01-22 04:57:54 +01:00
}
}
2012-05-31 19:50:37 +02:00
protected abstract void dataCalculations();
protected abstract void permissionsCheck();
protected abstract boolean effectsHeaderPermissions();
protected abstract void effectsDisplay();
protected abstract boolean statsHeaderPermissions();
2012-05-31 20:01:47 +02:00
protected abstract void statsDisplay();
2012-05-31 19:50:37 +02:00
}