Skip to content

Commit

Permalink
Added validation to the CSV implementation of the Locations Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkArc committed Feb 24, 2014
1 parent 8be35e7 commit 4e5ee58
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Expand Up @@ -21,6 +21,7 @@
import au.com.bytecode.opencsv.CSVReader;
import au.com.bytecode.opencsv.CSVWriter;
import com.sk89q.commandbook.CommandBook;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -211,6 +212,7 @@ public List<NamedLocation> getLocations() {

public NamedLocation create(String id, Location loc, Player player) {
id = id.trim();
Validate.isTrue(id.matches("^[a-zA-Z0-9-_]*$"), "Location ID contains invalid characters!");
NamedLocation warp = new NamedLocation(id, loc);
locations.put(id.toLowerCase(), warp);
if (player != null) {
Expand Down
Expand Up @@ -132,7 +132,11 @@ public void setHome(CommandContext args, CommandSender sender) throws CommandExc
}
}

getManager().create(homeName, loc, player);
try {
getManager().create(homeName, loc, player);
} catch (IllegalArgumentException ex) {
throw new CommandException("Invalid home name!");
}

sender.sendMessage(ChatColor.YELLOW + "Home set.");
}
Expand Down
Expand Up @@ -124,7 +124,11 @@ public void setWarp(CommandContext args, CommandSender sender) throws CommandExc
}
}

getManager().create(warpName, loc, player);
try {
getManager().create(warpName, loc, player);
} catch (IllegalArgumentException ex) {
throw new CommandException("Invalid warp name!");
}

sender.sendMessage(ChatColor.YELLOW + "Warp '" + warpName + "' created.");
}
Expand Down

0 comments on commit 4e5ee58

Please sign in to comment.