2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.commands.skills;
|
|
|
|
|
|
|
|
import java.text.DecimalFormat;
|
2013-03-28 17:57:49 +01:00
|
|
|
import java.util.List;
|
2013-03-08 14:39:28 +01:00
|
|
|
import java.util.Set;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2013-03-28 17:57:49 +01:00
|
|
|
import org.bukkit.command.TabExecutor;
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
mcMMO - Now with 100% more scoreboards!
mcMMO now allows for the use of scoreboards to display information in
several instances. By default, all scoreboards are enabled in the config,
and will only display for 10 seconds. After 10 seconds, the scoreboard
will go away and revert to the previously displayed scoreboard, if one
exists.
A global scoreboard now exists for tracking all player stats, and will be
displayed when /mctop is used. Your name will be highlighted in gold when
looking through the scoreboard. Additionally, the scoreboard will display
players in groups of 15, rather than groups of 10 like in chat.
Unfortunately, due to the limitations of scoreboards, the player's rank
will not be displayed in front of their name.
The scoreboard area is now also used for displaying data for /mcrank,
/inspect. and /mcstats. Due to the way scoreboards are handled, the power
level is not guarenteed to show up at any given location in the
scoreboard, but is instead displayed in gold so that it can be easily
found.
Lastly, the scoreboard area is also now used for displaying current data
on skills when the relevant /<skillname> command is used. The effects and
ability stats will still be shown in chat, but the current level, xp, and
remaining xp will be shown in the scoreboard.
2013-04-14 05:16:25 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-03-12 21:25:42 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-03-08 14:39:28 +01:00
|
|
|
import com.gmail.nossr50.skills.child.FamilyTree;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
import com.gmail.nossr50.util.StringUtils;
|
|
|
|
import com.gmail.nossr50.util.commands.CommandUtils;
|
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
mcMMO - Now with 100% more scoreboards!
mcMMO now allows for the use of scoreboards to display information in
several instances. By default, all scoreboards are enabled in the config,
and will only display for 10 seconds. After 10 seconds, the scoreboard
will go away and revert to the previously displayed scoreboard, if one
exists.
A global scoreboard now exists for tracking all player stats, and will be
displayed when /mctop is used. Your name will be highlighted in gold when
looking through the scoreboard. Additionally, the scoreboard will display
players in groups of 15, rather than groups of 10 like in chat.
Unfortunately, due to the limitations of scoreboards, the player's rank
will not be displayed in front of their name.
The scoreboard area is now also used for displaying data for /mcrank,
/inspect. and /mcstats. Due to the way scoreboards are handled, the power
level is not guarenteed to show up at any given location in the
scoreboard, but is instead displayed in gold so that it can be easily
found.
Lastly, the scoreboard area is also now used for displaying current data
on skills when the relevant /<skillname> command is used. The effects and
ability stats will still be shown in chat, but the current level, xp, and
remaining xp will be shown in the scoreboard.
2013-04-14 05:16:25 +02:00
|
|
|
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.skills.PerksUtils;
|
|
|
|
|
2013-03-28 17:57:49 +01:00
|
|
|
import com.google.common.collect.ImmutableList;
|
|
|
|
|
|
|
|
public abstract class SkillCommand implements TabExecutor {
|
2013-03-01 06:52:01 +01:00
|
|
|
protected SkillType skill;
|
2013-03-12 21:25:42 +01:00
|
|
|
protected String skillName;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
protected Player player;
|
|
|
|
protected PlayerProfile profile;
|
2013-03-12 21:25:42 +01:00
|
|
|
protected McMMOPlayer mcMMOPlayer;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
protected float skillValue;
|
|
|
|
protected boolean isLucky;
|
|
|
|
protected boolean hasEndurance;
|
|
|
|
|
|
|
|
protected DecimalFormat percent = new DecimalFormat("##0.00%");
|
|
|
|
protected DecimalFormat decimal = new DecimalFormat("##0.00");
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
private CommandExecutor skillGuideCommand;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
public SkillCommand(SkillType skill) {
|
|
|
|
this.skill = skill;
|
2013-10-28 18:04:06 +01:00
|
|
|
skillName = skill.getName();
|
2013-03-12 21:25:42 +01:00
|
|
|
skillGuideCommand = new SkillGuideCommand(skill);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
if (CommandUtils.noConsoleUsage(sender)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-28 19:33:20 +02:00
|
|
|
player = (Player) sender;
|
|
|
|
mcMMOPlayer = UserManager.getPlayer(player);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
switch (args.length) {
|
|
|
|
case 0:
|
|
|
|
profile = mcMMOPlayer.getProfile();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
skillValue = profile.getSkillLevel(skill);
|
|
|
|
isLucky = Permissions.lucky(sender, skill);
|
|
|
|
hasEndurance = (PerksUtils.handleActivationPerks(player, 0, 0) != 0);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
permissionsCheck();
|
|
|
|
dataCalculations();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-09-12 04:42:27 +02:00
|
|
|
if (Config.getInstance().getSkillUseBoard()) {
|
|
|
|
ScoreboardManager.enablePlayerSkillScoreboard(player, skill);
|
|
|
|
}
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
if (!skill.isChildSkill()) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.Header", skillName));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.XPGain", LocaleLoader.getString("Commands.XPGain." + StringUtils.getCapitalized(skill.toString()))));
|
2013-09-12 04:42:27 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Effects.Level", (int) skillValue, profile.getSkillXpLevel(skill), profile.getXpToLevel(skill)));
|
2013-03-12 21:25:42 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.Header", skillName + " " + LocaleLoader.getString("Skills.Child")));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.XPGain", LocaleLoader.getString("Commands.XPGain.Child")));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Effects.Child", (int) skillValue));
|
2013-03-08 14:39:28 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Skills.Parents")));
|
|
|
|
Set<SkillType> parents = FamilyTree.getParents(skill);
|
2013-03-08 14:39:28 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
for (SkillType parent : parents) {
|
2013-10-28 18:04:06 +01:00
|
|
|
player.sendMessage(parent.getName() + " - " + LocaleLoader.getString("Effects.Level", profile.getSkillLevel(parent), profile.getSkillXpLevel(parent), profile.getXpToLevel(parent)));
|
2013-03-12 21:25:42 +01:00
|
|
|
}
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
if (effectsHeaderPermissions()) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Effects.Effects")));
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
effectsDisplay();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
if (statsHeaderPermissions()) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Commands.Stats.Self")));
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
statsDisplay();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Guides.Available", skillName, skillName.toLowerCase()));
|
|
|
|
return true;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
default:
|
|
|
|
return skillGuideCommand.onCommand(sender, command, label, args);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-03-12 21:25:42 +01:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-28 17:57:49 +01:00
|
|
|
@Override
|
|
|
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
|
|
|
switch (args.length) {
|
|
|
|
case 1:
|
|
|
|
return ImmutableList.of("?");
|
|
|
|
default:
|
|
|
|
return ImmutableList.of();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
protected int calculateRank(int maxLevel, int rankChangeLevel) {
|
|
|
|
return Math.min((int) skillValue, maxLevel) / rankChangeLevel;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected String[] calculateAbilityDisplayValues(double chance) {
|
2013-03-12 21:25:42 +01:00
|
|
|
String[] displayValues = new String[2];
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
displayValues[0] = percent.format(Math.min(chance, 100.0D) / 100.0D);
|
|
|
|
displayValues[1] = isLucky ? percent.format(Math.min(chance * 1.3333D, 100.0D) / 100.0D) : null;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
return displayValues;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected String[] calculateAbilityDisplayValues(int maxBonusLevel, double maxChance) {
|
2013-03-16 20:55:53 +01:00
|
|
|
return calculateAbilityDisplayValues((maxChance / maxBonusLevel) * Math.min(skillValue, maxBonusLevel));
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected String[] calculateLengthDisplayValues() {
|
2013-09-15 19:47:20 +02:00
|
|
|
int maxLength = skill.getAbility().getMaxLength();
|
2013-03-01 06:52:01 +01:00
|
|
|
int length = 2 + (int) (skillValue / AdvancedConfig.getInstance().getAbilityLength());
|
|
|
|
int enduranceLength = PerksUtils.handleActivationPerks(player, length, maxLength);
|
|
|
|
|
|
|
|
if (maxLength != 0) {
|
2013-03-12 21:25:42 +01:00
|
|
|
length = Math.min(length, maxLength);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return new String[] { String.valueOf(length), String.valueOf(enduranceLength) };
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void luckyEffectsDisplay() {
|
|
|
|
if (isLucky) {
|
|
|
|
String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix");
|
2013-09-30 11:32:35 +02:00
|
|
|
player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.Lucky.Name"), LocaleLoader.getString("Perks.Lucky.Desc", skillName)));
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected abstract void dataCalculations();
|
|
|
|
|
|
|
|
protected abstract void permissionsCheck();
|
|
|
|
|
|
|
|
protected abstract boolean effectsHeaderPermissions();
|
|
|
|
|
|
|
|
protected abstract void effectsDisplay();
|
|
|
|
|
|
|
|
protected abstract boolean statsHeaderPermissions();
|
|
|
|
|
|
|
|
protected abstract void statsDisplay();
|
|
|
|
}
|