Fix NumberFormatException in stat commands (#320)

This commit is contained in:
MedicOP
2019-01-14 01:13:54 +01:00
committed by Ronan Lana
parent 20bc1985b1
commit 21f2713300
4 changed files with 44 additions and 4 deletions

View File

@@ -38,7 +38,17 @@ public class StatDexCommand extends Command {
MapleCharacter player = c.getPlayer();
int remainingAp = player.getRemainingAp();
int amount = (params.length > 0) ? Math.min(Integer.parseInt(params[0]), remainingAp) : Math.min(remainingAp, ServerConstants.MAX_AP - player.getDex());
int amount;
if (params.length > 0) {
try {
amount = Math.min(Integer.parseInt(params[0]), remainingAp);
} catch (NumberFormatException e) {
player.dropMessage("That is not a valid number!");
return;
}
} else {
amount = Math.min(remainingAp, ServerConstants.MAX_AP - player.getDex());
}
if (!player.assignDex(Math.max(amount, 0))) {
player.dropMessage("Please make sure your AP is not over " + ServerConstants.MAX_AP + " and you have enough to distribute.");
}

View File

@@ -38,7 +38,17 @@ public class StatIntCommand extends Command {
MapleCharacter player = c.getPlayer();
int remainingAp = player.getRemainingAp();
int amount = (params.length > 0) ? Math.min(Integer.parseInt(params[0]), remainingAp) : Math.min(remainingAp, ServerConstants.MAX_AP - player.getInt());
int amount;
if (params.length > 0) {
try {
amount = Math.min(Integer.parseInt(params[0]), remainingAp);
} catch (NumberFormatException e) {
player.dropMessage("That is not a valid number!");
return;
}
} else {
amount = Math.min(remainingAp, ServerConstants.MAX_AP - player.getInt());
}
if (!player.assignInt(Math.max(amount, 0))) {
player.dropMessage("Please make sure your AP is not over " + ServerConstants.MAX_AP + " and you have enough to distribute.");
}

View File

@@ -38,7 +38,17 @@ public class StatLukCommand extends Command {
MapleCharacter player = c.getPlayer();
int remainingAp = player.getRemainingAp();
int amount = (params.length > 0) ? Math.min(Integer.parseInt(params[0]), remainingAp) : Math.min(remainingAp, ServerConstants.MAX_AP - player.getLuk());
int amount;
if (params.length > 0) {
try {
amount = Math.min(Integer.parseInt(params[0]), remainingAp);
} catch (NumberFormatException e) {
player.dropMessage("That is not a valid number!");
return;
}
} else {
amount = Math.min(remainingAp, ServerConstants.MAX_AP - player.getLuk());
}
if (!player.assignLuk(Math.max(amount, 0))) {
player.dropMessage("Please make sure your AP is not over " + ServerConstants.MAX_AP + " and you have enough to distribute.");
}

View File

@@ -37,7 +37,17 @@ public class StatStrCommand extends Command {
public void execute(MapleClient c, String[] params) {
MapleCharacter player = c.getPlayer();
int remainingAp = player.getRemainingAp();
int amount = (params.length > 0) ? Math.min(Integer.parseInt(params[0]), remainingAp) : Math.min(remainingAp, ServerConstants.MAX_AP - player.getStr());
int amount;
if (params.length > 0) {
try {
amount = Math.min(Integer.parseInt(params[0]), remainingAp);
} catch (NumberFormatException e) {
player.dropMessage("That is not a valid number!");
return;
}
} else {
amount = Math.min(remainingAp, ServerConstants.MAX_AP - player.getStr());
}
if (!player.assignStr(Math.max(amount, 0))) {
player.dropMessage("Please make sure your AP is not over " + ServerConstants.MAX_AP + " and you have enough to distribute.");