Make our commands respect localized skill names.

This commit is contained in:
GJ 2013-02-15 09:26:01 -05:00
parent 0419dca385
commit 1ef1d53fd9
12 changed files with 94 additions and 81 deletions

View File

@ -19,6 +19,7 @@ public class AddlevelsCommand implements CommandExecutor{
PlayerProfile profile;
int levels;
boolean allSkills = false;
SkillType skill = null;
switch (args.length) {
case 2:
@ -56,14 +57,15 @@ public class AddlevelsCommand implements CommandExecutor{
}
}
else {
profile.addLevels(SkillType.getSkill(args[0]), levels);
skill = SkillType.getSkill(args[0]);
profile.addLevels(skill, levels);
}
if (allSkills) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", levels));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", levels, StringUtils.getCapitalized(args[0])));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", levels, SkillTools.getSkillName(skill)));
}
return true;
@ -108,7 +110,8 @@ public class AddlevelsCommand implements CommandExecutor{
}
}
else {
profile.addLevels(SkillType.getSkill(args[1]), levels);
skill = SkillType.getSkill(args[1]);
profile.addLevels(skill, levels);
}
profile.save(); // Since this is a temporary profile, we save it here.
@ -128,8 +131,9 @@ public class AddlevelsCommand implements CommandExecutor{
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", levels));
}
else {
profile.addLevels(SkillType.getSkill(args[1]), levels);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", levels, StringUtils.getCapitalized(args[1])));
skill = SkillType.getSkill(args[1]);
profile.addLevels(skill, levels);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", levels, SkillTools.getSkillName(skill)));
}
}
@ -137,7 +141,7 @@ public class AddlevelsCommand implements CommandExecutor{
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", StringUtils.getCapitalized(args[1]), args[0]));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", SkillTools.getSkillName(skill), args[0]));
}
return true;

View File

@ -19,6 +19,7 @@ public class AddxpCommand implements CommandExecutor {
McMMOPlayer mcMMOPlayer;
PlayerProfile profile;
boolean allSkills = false;
SkillType skill = null;
switch (args.length) {
case 2:
@ -59,8 +60,10 @@ public class AddxpCommand implements CommandExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", xp));
}
else {
mcMMOPlayer.applyXpGain(SkillType.getSkill(args[0]), xp);
sender.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, StringUtils.getCapitalized(args[0])));
skill = SkillType.getSkill(args[0]);
mcMMOPlayer.applyXpGain(skill, xp);
sender.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, SkillTools.getSkillName(skill)));
}
return true;
@ -106,7 +109,8 @@ public class AddxpCommand implements CommandExecutor {
}
}
else {
profile.setSkillXpLevel(SkillType.getSkill(args[1]), xp);
skill = SkillType.getSkill(args[1]);
profile.setSkillXpLevel(skill, xp);
}
profile.save(); // Since this is a temporary profile, we save it here.
@ -124,8 +128,9 @@ public class AddxpCommand implements CommandExecutor {
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", xp));
}
else {
mcMMOPlayer.applyXpGain(SkillType.getSkill(args[1]), xp);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, StringUtils.getCapitalized(args[1])));
skill = SkillType.getSkill(args[1]);
mcMMOPlayer.applyXpGain(skill, xp);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, SkillTools.getSkillName(skill)));
}
}
@ -133,7 +138,7 @@ public class AddxpCommand implements CommandExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", StringUtils.getCapitalized(args[1]), args[0]));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", SkillTools.getSkillName(skill), args[0]));
}
return true;

View File

@ -19,6 +19,7 @@ public class MmoeditCommand implements CommandExecutor {
PlayerProfile profile;
int newValue;
boolean allSkills = false;
SkillType skill = null;
switch (args.length) {
case 2:
@ -58,8 +59,9 @@ public class MmoeditCommand implements CommandExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue));
}
else {
profile.modifySkill(SkillType.getSkill(args[0]), newValue);
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", StringUtils.getCapitalized(args[0]), newValue));
skill = SkillType.getSkill(args[0]);
profile.modifySkill(skill, newValue);
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", SkillTools.getSkillName(skill), newValue));
}
return true;
@ -104,7 +106,8 @@ public class MmoeditCommand implements CommandExecutor {
}
}
else {
profile.modifySkill(SkillType.getSkill(args[1]), newValue);
skill = SkillType.getSkill(args[1]);
profile.modifySkill(skill, newValue);
}
profile.save(); // Since this is a temporary profile, we save it here.
@ -124,8 +127,9 @@ public class MmoeditCommand implements CommandExecutor {
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue));
}
else {
profile.modifySkill(SkillType.getSkill(args[1]), newValue);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", StringUtils.getCapitalized(args[1]), newValue));
skill = SkillType.getSkill(args[1]);
profile.modifySkill(skill, newValue);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", SkillTools.getSkillName(skill), newValue));
}
}
@ -133,7 +137,7 @@ public class MmoeditCommand implements CommandExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", StringUtils.getCapitalized(args[1]), args[0]));
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", SkillTools.getSkillName(skill), args[0]));
}
return true;

View File

@ -18,6 +18,8 @@ public class SkillresetCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
boolean allSkills = false;
SkillType skill = null;
String skillName = "";
switch (args.length) {
case 1:
@ -38,30 +40,16 @@ public class SkillresetCommand implements CommandExecutor {
return true;
}
profile = Users.getPlayer((Player) sender).getProfile();
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
if (!sender.hasPermission("mcmmo.commands.skillreset." + args[0].toLowerCase())) {
if (!sender.hasPermission("mcmmo.commands.skillreset." + SkillTools.getSkillName(skillType).toLowerCase())) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
}
}
else {
if (!sender.hasPermission("mcmmo.commands.skillreset." + args[0].toLowerCase())) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
}
profile = Users.getPlayer((Player) sender).getProfile();
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
@ -71,8 +59,16 @@ public class SkillresetCommand implements CommandExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
else {
profile.modifySkill(SkillType.getSkill(args[0]), 0);
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", StringUtils.getCapitalized(args[0])));
skill = SkillType.getSkill(args[0]);
skillName = SkillTools.getSkillName(skill);
if (!sender.hasPermission("mcmmo.commands.skillreset." + skillName.toLowerCase())) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
profile.modifySkill(skill, 0);
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", StringUtils.getCapitalized(skillName)));
}
return true;
@ -91,20 +87,11 @@ public class SkillresetCommand implements CommandExecutor {
return true;
}
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
if (!allSkills) {
skill = SkillType.getSkill(args[1]);
skillName = SkillTools.getSkillName(skill);
if (!sender.hasPermission("mcmmo.commands.skillreset.others." + args[1].toLowerCase())) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
}
}
else {
if (!sender.hasPermission("mcmmo.commands.skillreset.others." + args[1].toLowerCase())) {
if (!sender.hasPermission("mcmmo.commands.skillreset.others." + skillName.toLowerCase())) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
@ -127,11 +114,16 @@ public class SkillresetCommand implements CommandExecutor {
continue;
}
if (!sender.hasPermission("mcmmo.commands.skillreset.others." + SkillTools.getSkillName(skillType).toLowerCase())) {
sender.sendMessage(command.getPermissionMessage());
continue;
}
profile.modifySkill(skillType, 0);
}
}
else {
profile.modifySkill(SkillType.getSkill(args[1]), 0);
profile.modifySkill(skill, 0);
}
profile.save(); // Since this is a temporary profile, we save it here.
@ -145,14 +137,19 @@ public class SkillresetCommand implements CommandExecutor {
continue;
}
if (!sender.hasPermission("mcmmo.commands.skillreset.others." + SkillTools.getSkillName(skillType).toLowerCase())) {
sender.sendMessage(command.getPermissionMessage());
continue;
}
profile.modifySkill(skillType, 0);
}
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
else {
profile.modifySkill(SkillType.getSkill(args[1]), 0);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Reset.Single", StringUtils.getCapitalized(args[1])));
profile.modifySkill(skill, 0);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Reset.Single", StringUtils.getCapitalized(skillName)));
}
}
@ -160,7 +157,7 @@ public class SkillresetCommand implements CommandExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", StringUtils.getCapitalized(args[1]), args[0]));
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", StringUtils.getCapitalized(skillName), args[0]));
}
return true;

View File

@ -99,10 +99,10 @@ public class McrankCommand implements CommandExecutor {
}
if (rankInts[1] == 0) {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.localizeSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked"))); // Don't bother showing ranking for players without skills
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.getSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked"))); // Don't bother showing ranking for players without skills
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.localizeSkillName(skillType), String.valueOf(rankInts[0])));
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.getSkillName(skillType), String.valueOf(rankInts[0])));
}
}

View File

@ -13,6 +13,7 @@ import com.gmail.nossr50.database.Database;
import com.gmail.nossr50.database.Leaderboard;
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;
public class MctopCommand implements CommandExecutor {
@ -30,10 +31,7 @@ public class MctopCommand implements CommandExecutor {
display(Integer.parseInt(args[0]), "ALL", sender, useMySQL, command);
}
else if (SkillTools.isSkill(args[0])) {
display(1, args[0], sender, useMySQL, command);
}
else if (SkillTools.isLocalizedSkill(args[0])) {
display(1, SkillTools.translateLocalizedSkill(args[0]), sender, useMySQL, command);
display(1, SkillType.getSkill(args[0]).toString(), sender, useMySQL, command);
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
@ -47,10 +45,7 @@ public class MctopCommand implements CommandExecutor {
}
if (SkillTools.isSkill(args[0])) {
display(Integer.parseInt(args[1]), args[0], sender, useMySQL, command);
}
else if (SkillTools.isLocalizedSkill(args[0])) {
display(Integer.parseInt(args[1]), SkillTools.translateLocalizedSkill(args[0]), sender, useMySQL, command);
display(Integer.parseInt(args[1]), SkillType.getSkill(args[0]).toString(), sender, useMySQL, command);
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));

View File

@ -36,10 +36,10 @@ public class McRankAsync implements Runnable {
}
if (skills.get(skillType.name()) == null) {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.localizeSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked")));
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.getSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked")));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.localizeSkillName(skillType), skills.get(skillType.name())));
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.getSkillName(skillType), skills.get(skillType.name())));
}
}

View File

@ -154,7 +154,7 @@ public abstract class SkillCommand implements CommandExecutor {
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.localizeSkillName(skill))));
player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.lucky.name"), LocaleLoader.getString("Perks.lucky.desc", SkillTools.getSkillName(skill))));
}
}

View File

@ -56,7 +56,7 @@ public final class SkillGuide {
public static boolean grabGuidePageForSkill(SkillType skilltype, Player player, String[] args) {
String skillName = skilltype.toString();
String capitalized = StringUtils.getCapitalized(skillName);
String localized = SkillTools.localizeSkillName(skilltype);
String localized = SkillTools.getSkillName(skilltype);
player.sendMessage(LocaleLoader.getString("Guides.Available", localized, localized.toLowerCase()));
String address = "Guides." + capitalized;

View File

@ -289,6 +289,10 @@ public class SkillTools {
* @return true if this is a valid skill, false otherwise
*/
public static boolean isSkill(String skillName) {
if (!Config.getInstance().getLocale().equalsIgnoreCase("en_US")) {
return isLocalizedSkill(skillName);
}
if (SkillType.getSkill(skillName) != null) {
return true;
}
@ -296,9 +300,9 @@ public class SkillTools {
return false;
}
public static boolean isLocalizedSkill(String skillName) {
private static boolean isLocalizedSkill(String skillName) {
for (SkillType skill : SkillType.values()) {
if (skillName.equalsIgnoreCase(LocaleLoader.getString(StringUtils.getCapitalized(skill.toString() + ".SkillName")))) {
if (skillName.equalsIgnoreCase(LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".SkillName"))) {
return true;
}
}
@ -306,18 +310,12 @@ public class SkillTools {
return false;
}
public static String translateLocalizedSkill(String skillName) {
for (SkillType skill : SkillType.values()) {
if (skillName.equalsIgnoreCase(LocaleLoader.getString(StringUtils.getCapitalized(skill.toString() + ".SkillName")))) {
return skill.toString();
}
public static String getSkillName(SkillType skill) {
if (!Config.getInstance().getLocale().equalsIgnoreCase("en_US")) {
return StringUtils.getCapitalized(LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".SkillName"));
}
return null;
}
public static String localizeSkillName(SkillType skill) {
return StringUtils.getCapitalized(LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".SkillName"));
return StringUtils.getCapitalized(skill.toString());
}
/**

View File

@ -4,7 +4,9 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
public enum SkillType {
ACROBATICS(Config.getInstance().getLevelCapAcrobatics(), Config.getInstance().getFormulaMultiplierAcrobatics()),
@ -119,6 +121,14 @@ public enum SkillType {
}
public static SkillType getSkill(String skillName) {
if (!Config.getInstance().getLocale().equalsIgnoreCase("en_US")) {
for (SkillType type : values()) {
if (skillName.equalsIgnoreCase(LocaleLoader.getString(StringUtils.getCapitalized(type.name()) + ".SkillName"))) {
return type;
}
}
}
for (SkillType type : values()) {
if (type.name().equalsIgnoreCase(skillName)) {
return type;

View File

@ -554,7 +554,7 @@ public class SpoutTools {
break;
}
spoutPlayer.sendNotification(LocaleLoader.getString("Spout.LevelUp.1"), LocaleLoader.getString("Spout.LevelUp.2", SkillTools.localizeSkillName(skillType), profile.getSkillLevel(skillType)), mat);
spoutPlayer.sendNotification(LocaleLoader.getString("Spout.LevelUp.1"), LocaleLoader.getString("Spout.LevelUp.2", SkillTools.getSkillName(skillType), profile.getSkillLevel(skillType)), mat);
SpoutSounds.playLevelUpNoise(spoutPlayer, plugin);
}