Optimized our String/number conversions a bit. Also moved all

String-related util functions from Misc.java to StringUtils.java
This commit is contained in:
GJ
2013-02-13 11:45:48 -05:00
parent b1db0d037d
commit 2ad73e9b2c
26 changed files with 325 additions and 325 deletions

View File

@ -10,7 +10,7 @@ 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.Misc;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.Users;
public class AddlevelsCommand implements CommandExecutor{
@ -39,11 +39,11 @@ public class AddlevelsCommand implements CommandExecutor{
return true;
}
if (!Misc.isInt(args[1])) {
if (!StringUtils.isInt(args[1])) {
return false;
}
levels = Integer.valueOf(args[1]);
levels = Integer.parseInt(args[1]);
profile = Users.getPlayer((Player) sender).getProfile();
if (allSkills) {
@ -63,7 +63,7 @@ public class AddlevelsCommand implements CommandExecutor{
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", levels));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", levels, Misc.getCapitalized(args[0])));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", levels, StringUtils.getCapitalized(args[0])));
}
return true;
@ -82,12 +82,12 @@ public class AddlevelsCommand implements CommandExecutor{
return true;
}
if (!Misc.isInt(args[2])) {
if (!StringUtils.isInt(args[2])) {
return false;
}
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
levels = Integer.valueOf(args[2]);
levels = Integer.parseInt(args[2]);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
@ -129,7 +129,7 @@ public class AddlevelsCommand implements CommandExecutor{
}
else {
profile.addLevels(SkillType.getSkill(args[1]), levels);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", levels, Misc.getCapitalized(args[1])));
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", levels, StringUtils.getCapitalized(args[1])));
}
}
@ -137,7 +137,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", Misc.getCapitalized(args[1]), args[0]));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", StringUtils.getCapitalized(args[1]), args[0]));
}
return true;

View File

@ -9,7 +9,7 @@ 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.Misc;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.Users;
public class AddxpCommand implements CommandExecutor {
@ -39,11 +39,11 @@ public class AddxpCommand implements CommandExecutor {
return true;
}
if (!Misc.isInt(args[1])) {
if (!StringUtils.isInt(args[1])) {
return false;
}
xp = Integer.valueOf(args[1]);
xp = Integer.parseInt(args[1]);
mcMMOPlayer = Users.getPlayer((Player) sender);
profile = mcMMOPlayer.getProfile();
@ -60,7 +60,7 @@ public class AddxpCommand implements CommandExecutor {
}
else {
mcMMOPlayer.applyXpGain(SkillType.getSkill(args[0]), xp);
sender.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, Misc.getCapitalized(args[0])));
sender.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, StringUtils.getCapitalized(args[0])));
}
return true;
@ -79,12 +79,12 @@ public class AddxpCommand implements CommandExecutor {
return true;
}
if (!Misc.isInt(args[2])) {
if (!StringUtils.isInt(args[2])) {
return false;
}
mcMMOPlayer = Users.getPlayer(args[0]);
xp = Integer.valueOf(args[2]);
xp = Integer.parseInt(args[2]);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
@ -125,7 +125,7 @@ public class AddxpCommand implements CommandExecutor {
}
else {
mcMMOPlayer.applyXpGain(SkillType.getSkill(args[1]), xp);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, Misc.getCapitalized(args[1])));
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, StringUtils.getCapitalized(args[1])));
}
}
@ -133,7 +133,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", Misc.getCapitalized(args[1]), args[0]));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", StringUtils.getCapitalized(args[1]), args[0]));
}
return true;

View File

@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.StringUtils;
public class HardcoreCommand implements CommandExecutor{
@ -52,7 +52,7 @@ public class HardcoreCommand implements CommandExecutor{
return true;
}
if (!Misc.isDouble(args[0])) {
if (!StringUtils.isDouble(args[0])) {
return false;
}
@ -62,7 +62,7 @@ public class HardcoreCommand implements CommandExecutor{
}
DecimalFormat percent = new DecimalFormat("##0.00%");
double newPercent = Misc.getDouble(args[0]);
double newPercent = Double.parseDouble(args[0]);
Config.getInstance().setHardcoreDeathStatPenaltyPercentage(newPercent);
sender.sendMessage(LocaleLoader.getString("Hardcore.PercentageChanged", percent.format(newPercent / 100D)));

View File

@ -10,7 +10,7 @@ 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.Misc;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.Users;
public class MmoeditCommand implements CommandExecutor {
@ -39,11 +39,11 @@ public class MmoeditCommand implements CommandExecutor {
return true;
}
if (!Misc.isInt(args[1])) {
if (!StringUtils.isInt(args[1])) {
return false;
}
newValue = Integer.valueOf(args[1]);
newValue = Integer.parseInt(args[1]);
profile = Users.getPlayer((Player) sender).getProfile();
if (allSkills) {
@ -59,7 +59,7 @@ public class MmoeditCommand implements CommandExecutor {
}
else {
profile.modifySkill(SkillType.getSkill(args[0]), newValue);
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", Misc.getCapitalized(args[0]), newValue));
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", StringUtils.getCapitalized(args[0]), newValue));
}
return true;
@ -78,11 +78,11 @@ public class MmoeditCommand implements CommandExecutor {
return true;
}
if (!Misc.isInt(args[2])) {
if (!StringUtils.isInt(args[2])) {
return false;
}
newValue = Integer.valueOf(args[2]);
newValue = Integer.parseInt(args[2]);
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
@ -125,7 +125,7 @@ public class MmoeditCommand implements CommandExecutor {
}
else {
profile.modifySkill(SkillType.getSkill(args[1]), newValue);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", Misc.getCapitalized(args[1]), newValue));
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", StringUtils.getCapitalized(args[1]), newValue));
}
}
@ -133,7 +133,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", Misc.getCapitalized(args[1]), args[0]));
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", StringUtils.getCapitalized(args[1]), args[0]));
}
return true;

View File

@ -10,7 +10,7 @@ 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.Misc;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.Users;
public class SkillresetCommand implements CommandExecutor {
@ -72,7 +72,7 @@ public class SkillresetCommand implements CommandExecutor {
}
else {
profile.modifySkill(SkillType.getSkill(args[0]), 0);
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", Misc.getCapitalized(args[0])));
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", StringUtils.getCapitalized(args[0])));
}
return true;
@ -152,7 +152,7 @@ public class SkillresetCommand implements CommandExecutor {
}
else {
profile.modifySkill(SkillType.getSkill(args[1]), 0);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Reset.Single", Misc.getCapitalized(args[1])));
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Reset.Single", StringUtils.getCapitalized(args[1])));
}
}
@ -160,7 +160,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", Misc.getCapitalized(args[1]), args[0]));
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", StringUtils.getCapitalized(args[1]), args[0]));
}
return true;

View File

@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.StringUtils;
public class VampirismCommand implements CommandExecutor {
@ -57,7 +57,7 @@ public class VampirismCommand implements CommandExecutor {
return true;
}
if (!Misc.isDouble(args[0])) {
if (!StringUtils.isDouble(args[0])) {
return false;
}
@ -67,7 +67,7 @@ public class VampirismCommand implements CommandExecutor {
}
DecimalFormat percent = new DecimalFormat("##0.00%");
double newPercent = Misc.getDouble(args[0]);
double newPercent = Double.parseDouble(args[0]);
Config.getInstance().setHardcoreVampirismStatLeechPercentage(newPercent);
sender.sendMessage(LocaleLoader.getString("Vampirism.PercentageChanged", percent.format(newPercent / 100D)));

View File

@ -7,7 +7,7 @@ import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.StringUtils;
public class XprateCommand implements CommandExecutor {
private static double originalRate = Config.getInstance().getExperienceGainsGlobalMultiplier();
@ -34,7 +34,7 @@ public class XprateCommand implements CommandExecutor {
return true;
case 2:
if (!Misc.isInt(args[0])) {
if (!StringUtils.isInt(args[0])) {
return false;
}
@ -48,7 +48,7 @@ public class XprateCommand implements CommandExecutor {
}
mcMMO.p.setXPEventEnabled(Boolean.valueOf(args[1]));
int newXpRate = Misc.getInt(args[0]);
int newXpRate = Integer.parseInt(args[0]);
Config.getInstance().setExperienceGainsGlobalMultiplier(newXpRate);
if (mcMMO.p.isXPEventEnabled()) {