Fix NumberFormatException in stat commands (#320)
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
@@ -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.");
|
||||
|
||||
Reference in New Issue
Block a user