diff options
author | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-01-05 22:40:45 +0000 |
---|---|---|
committer | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-01-05 22:40:45 +0000 |
commit | 9b227081f589700a365d760e9e9af90248ffa9e2 (patch) | |
tree | 40c5f2b0b9a336e4838a4a92630f071eb397b771 | |
parent | d2d468b374ae2d003394d1d92c6e1905769788de (diff) | |
download | bukkit-9b227081f589700a365d760e9e9af90248ffa9e2.tar bukkit-9b227081f589700a365d760e9e9af90248ffa9e2.tar.gz bukkit-9b227081f589700a365d760e9e9af90248ffa9e2.tar.lz bukkit-9b227081f589700a365d760e9e9af90248ffa9e2.tar.xz bukkit-9b227081f589700a365d760e9e9af90248ffa9e2.zip |
Slightly better "invalid plugin.yml" errors
-rw-r--r-- | src/main/java/org/bukkit/plugin/InvalidDescriptionException.java | 98 | ||||
-rw-r--r-- | src/main/java/org/bukkit/plugin/PluginDescriptionFile.java | 40 |
2 files changed, 92 insertions, 46 deletions
diff --git a/src/main/java/org/bukkit/plugin/InvalidDescriptionException.java b/src/main/java/org/bukkit/plugin/InvalidDescriptionException.java index 11797212..17f36851 100644 --- a/src/main/java/org/bukkit/plugin/InvalidDescriptionException.java +++ b/src/main/java/org/bukkit/plugin/InvalidDescriptionException.java @@ -1,36 +1,62 @@ - -package org.bukkit.plugin; - -/** - * Thrown when attempting to load an invalid PluginDescriptionFile - */ -public class InvalidDescriptionException extends Exception { - private static final long serialVersionUID = 5721389122281775894L; - private final Throwable cause; - - /** - * Constructs a new InvalidDescriptionException based on the given Exception - * - * @param throwable Exception that triggered this Exception - */ - public InvalidDescriptionException(Throwable throwable) { - cause = throwable; - } - - /** - * Constructs a new InvalidDescriptionException - */ - public InvalidDescriptionException() { - cause = null; - } - - /** - * If applicable, returns the Exception that triggered this Exception - * - * @return Inner exception, or null if one does not exist - */ - @Override - public Throwable getCause() { - return cause; - } -} +
+package org.bukkit.plugin;
+
+/**
+ * Thrown when attempting to load an invalid PluginDescriptionFile
+ */
+public class InvalidDescriptionException extends Exception {
+ private static final long serialVersionUID = 5721389122281775894L;
+ private final Throwable cause;
+ private final String message;
+
+ /**
+ * Constructs a new InvalidDescriptionException based on the given Exception
+ *
+ * @param throwable Exception that triggered this Exception
+ */
+ public InvalidDescriptionException(Throwable throwable) {
+ this(throwable, "Invalid plugin.yml");
+ }
+
+ /**
+ * Constructs a new InvalidDescriptionException with the given message
+ *
+ * @param message Brief message explaining the cause of the exception
+ */
+ public InvalidDescriptionException(final String message) {
+ this(null, message);
+ }
+
+ /**
+ * Constructs a new InvalidDescriptionException based on the given Exception
+ *
+ * @param message Brief message explaining the cause of the exception
+ * @param throwable Exception that triggered this Exception
+ */
+ public InvalidDescriptionException(final Throwable throwable, final String message) {
+ this.cause = null;
+ this.message = message;
+ }
+
+ /**
+ * Constructs a new InvalidDescriptionException
+ */
+ public InvalidDescriptionException() {
+ this(null, "Invalid plugin.yml");
+ }
+
+ /**
+ * If applicable, returns the Exception that triggered this Exception
+ *
+ * @return Inner exception, or null if one does not exist
+ */
+ @Override
+ public Throwable getCause() {
+ return cause;
+ }
+
+ @Override
+ public String getMessage() {
+ return super.getMessage();
+ }
+}
diff --git a/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java b/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java index 52fd7093..44dddbfa 100644 --- a/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java +++ b/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java @@ -20,11 +20,7 @@ public final class PluginDescriptionFile { @SuppressWarnings("unchecked") public PluginDescriptionFile(final InputStream stream) throws InvalidDescriptionException { - try { - loadMap((Map<String, Object>)yaml.load(stream)); - } catch (ClassCastException ex) { - throw new InvalidDescriptionException(ex); - } + loadMap((Map<String, Object>)yaml.load(stream)); } /** @@ -32,7 +28,7 @@ public final class PluginDescriptionFile { * @param reader */ @SuppressWarnings("unchecked") - public PluginDescriptionFile(final Reader reader) { + public PluginDescriptionFile(final Reader reader) throws InvalidDescriptionException { loadMap((Map<String, Object>)yaml.load(reader)); } @@ -84,10 +80,34 @@ public final class PluginDescriptionFile { return main; } - private void loadMap(Map<String, Object> map) throws ClassCastException { - name = map.get("name").toString(); - main = map.get("main").toString(); - version = map.get("version").toString(); + private void loadMap(Map<String, Object> map) throws InvalidDescriptionException { + if (name == null) { + throw new InvalidDescriptionException("Name is not defined"); + } + + try { + name = map.get("name").toString(); + } catch (NullPointerException ex) { + throw new InvalidDescriptionException(ex, "name is not defined"); + } catch (ClassCastException ex) { + throw new InvalidDescriptionException(ex, "name is of wrong type"); + } + + try { + version = map.get("version").toString(); + } catch (NullPointerException ex) { + throw new InvalidDescriptionException(ex, "version is not defined"); + } catch (ClassCastException ex) { + throw new InvalidDescriptionException(ex, "version is of wrong type"); + } + + try { + main = map.get("main").toString(); + } catch (NullPointerException ex) { + throw new InvalidDescriptionException(ex, "main is not defined"); + } catch (ClassCastException ex) { + throw new InvalidDescriptionException(ex, "main is of wrong type"); + } } private Map<String, Object> saveMap() { |