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
|
|
|
|
2014-01-20 22:58:40 +01:00
|
|
|
import com.gmail.nossr50.util.Motd;
|
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-11-22 18:48:53 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
|
2013-03-01 06:52:01 +01:00
|
|
|
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-10-29 20:38:20 +01:00
|
|
|
private String skillName;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
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-03-12 21:25:42 +01:00
|
|
|
switch (args.length) {
|
|
|
|
case 0:
|
2013-10-29 20:38:20 +01:00
|
|
|
Player player = (Player) sender;
|
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
boolean isLucky = Permissions.lucky(player, skill);
|
|
|
|
boolean hasEndurance = (PerksUtils.handleActivationPerks(player, 0, 0) != 0);
|
|
|
|
float skillValue = mcMMOPlayer.getSkillLevel(skill);
|
|
|
|
|
|
|
|
permissionsCheck(player);
|
|
|
|
dataCalculations(player, skillValue, isLucky);
|
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-10-29 16:02:57 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Effects.Level", (int) skillValue, mcMMOPlayer.getSkillXpLevel(skill), mcMMOPlayer.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-29 16:02:57 +01:00
|
|
|
player.sendMessage(parent.getName() + " - " + LocaleLoader.getString("Effects.Level", mcMMOPlayer.getSkillLevel(parent), mcMMOPlayer.getSkillXpLevel(parent), mcMMOPlayer.getXpToLevel(parent)));
|
2013-03-12 21:25:42 +01:00
|
|
|
}
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
List<String> effectMessages = effectsDisplay();
|
|
|
|
|
|
|
|
if (!effectMessages.isEmpty()) {
|
2013-03-12 21:25:42 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Effects.Effects")));
|
2013-10-29 20:38:20 +01:00
|
|
|
|
|
|
|
if (isLucky) {
|
2014-01-20 22:58:40 +01:00
|
|
|
player.sendMessage(Motd.PERK_PREFIX + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.Lucky.Name"), LocaleLoader.getString("Perks.Lucky.Desc", skillName)));
|
2013-10-29 20:38:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (String message : effectMessages) {
|
|
|
|
player.sendMessage(message);
|
|
|
|
}
|
2013-03-12 21:25:42 +01:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
List<String> statsMessages = statsDisplay(player, skillValue, hasEndurance, isLucky);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
if (!statsMessages.isEmpty()) {
|
2013-03-12 21:25:42 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Commands.Stats.Self")));
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
for (String message : statsMessages) {
|
|
|
|
player.sendMessage(message);
|
|
|
|
}
|
|
|
|
}
|
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-10-29 20:38:20 +01:00
|
|
|
protected int calculateRank(float skillValue, int maxLevel, int rankChangeLevel) {
|
2013-03-12 21:25:42 +01:00
|
|
|
return Math.min((int) skillValue, maxLevel) / rankChangeLevel;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
protected String[] calculateAbilityDisplayValues(double chance, boolean isLucky) {
|
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
|
|
|
}
|
|
|
|
|
2013-11-22 18:48:53 +01:00
|
|
|
protected String[] calculateAbilityDisplayValues(float skillValue, SecondaryAbility skillAbility, boolean isLucky) {
|
2013-11-22 18:32:23 +01:00
|
|
|
int maxBonusLevel = AdvancedConfig.getInstance().getMaxBonusLevel(skillAbility);
|
|
|
|
|
|
|
|
return calculateAbilityDisplayValues((AdvancedConfig.getInstance().getMaxChance(skillAbility) / maxBonusLevel) * Math.min(skillValue, maxBonusLevel), isLucky);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
protected String[] calculateLengthDisplayValues(Player player, float skillValue) {
|
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) };
|
|
|
|
}
|
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
protected abstract void dataCalculations(Player player, float skillValue, boolean isLucky);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
protected abstract void permissionsCheck(Player player);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
protected abstract List<String> effectsDisplay();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
protected abstract List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|