From 6eaf5895e47e08d6e81a36cfb8f8e7d193f9a758 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 2 Oct 2010 01:36:33 -0700 Subject: [PATCH] Hard-coded a list of items that can be used for WorldEdit. --- src/DisallowedItemException.java | 26 +++++++++++++++++++++++ src/WorldEdit.java | 36 ++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 src/DisallowedItemException.java diff --git a/src/DisallowedItemException.java b/src/DisallowedItemException.java new file mode 100644 index 000000000..9cf417fcf --- /dev/null +++ b/src/DisallowedItemException.java @@ -0,0 +1,26 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +/** + * + * @author sk89q + */ +public class DisallowedItemException extends Exception { + +} diff --git a/src/WorldEdit.java b/src/WorldEdit.java index 1c1486434..daea31912 100644 --- a/src/WorldEdit.java +++ b/src/WorldEdit.java @@ -93,17 +93,38 @@ public class WorldEdit extends Plugin { * @param id * @return * @throws UnknownItemException + * @throws DisallowedItemException */ - private int getItem(String id) throws UnknownItemException { + private int getItem(String id) throws UnknownItemException, + DisallowedItemException { + int foundID; + try { - return Integer.parseInt(id); + foundID = Integer.parseInt(id); } catch (NumberFormatException e) { try { - return etc.getInstance().getDataSource().getItem(id); + foundID = etc.getInstance().getDataSource().getItem(id); } catch (NumberFormatException e2) { throw new UnknownItemException(); } } + + if ((foundID >= 0 && foundID <= 5) || + (foundID >= 7 && foundID <= 20) || + foundID == 35 || + (foundID >= 41 && foundID <= 45) || + (foundID >= 47 && foundID <= 49) || + (foundID >= 52 && foundID <= 54) || + (foundID >= 56 && foundID <= 58) || + (foundID >= 60 && foundID <= 62) || + foundID == 67 || + foundID == 73 || + (foundID >= 78 && foundID <= 82) || + foundID == 85) { + return foundID; + } else { + throw new DisallowedItemException(); + } } /** @@ -165,8 +186,11 @@ public class WorldEdit extends Plugin { } catch (UnknownItemException e3) { player.sendMessage(Colors.Rose + "Unknown item."); return true; - } catch (InsufficientArgumentsException e4) { - player.sendMessage(Colors.Rose + e4.getMessage()); + } catch (DisallowedItemException e4) { + player.sendMessage(Colors.Rose + "Disallowed item."); + return true; + } catch (InsufficientArgumentsException e5) { + player.sendMessage(Colors.Rose + e5.getMessage()); return true; } } @@ -186,7 +210,7 @@ public class WorldEdit extends Plugin { private boolean handleEditCommand(Player player, String[] split) throws UnknownItemException, IncompleteRegionException, - InsufficientArgumentsException + InsufficientArgumentsException, DisallowedItemException { WorldEditSession session = getSession(player);