From a38267fe7421cf1246ae687e43547a00856a75a6 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Wed, 3 Aug 2011 15:38:54 -0500 Subject: [PATCH] Error handling for user entering non-integer value for radius of safeclaim and warclaim, along with usage info --- .../factions/commands/FCommandSafeclaim.java | 10 +++++++++- .../factions/commands/FCommandWarclaim.java | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/com/massivecraft/factions/commands/FCommandSafeclaim.java b/src/com/massivecraft/factions/commands/FCommandSafeclaim.java index db949e5c..7ca8d110 100644 --- a/src/com/massivecraft/factions/commands/FCommandSafeclaim.java +++ b/src/com/massivecraft/factions/commands/FCommandSafeclaim.java @@ -36,7 +36,15 @@ public class FCommandSafeclaim extends FBaseCommand { // Was a radius set? if (parameters.size() > 0) { - int radius = Integer.parseInt(parameters.get(0)); + int radius; + try { + radius = Integer.parseInt(parameters.get(0)); + } + catch(NumberFormatException ex) { + sendMessage("Usage: " + getUseageTemplate(false)); + sendMessage("The radius value must be an integer."); + return; + } FLocation from = playerFlocation.getRelative(radius, radius); FLocation to = playerFlocation.getRelative(-radius, -radius); diff --git a/src/com/massivecraft/factions/commands/FCommandWarclaim.java b/src/com/massivecraft/factions/commands/FCommandWarclaim.java index 9b036689..2643430a 100644 --- a/src/com/massivecraft/factions/commands/FCommandWarclaim.java +++ b/src/com/massivecraft/factions/commands/FCommandWarclaim.java @@ -35,7 +35,15 @@ public class FCommandWarclaim extends FBaseCommand { // Was a radius set? if (parameters.size() > 0) { - int radius = Integer.parseInt(parameters.get(0)); + int radius; + try { + radius = Integer.parseInt(parameters.get(0)); + } + catch(NumberFormatException ex) { + sendMessage("Usage: " + getUseageTemplate(false)); + sendMessage("The radius value must be an integer."); + return; + } FLocation from = playerFlocation.getRelative(radius, radius); FLocation to = playerFlocation.getRelative(-radius, -radius);