summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormain() <main@maincraft.tk>2013-04-29 20:29:42 +0200
committermain() <main@maincraft.tk>2013-04-29 20:29:42 +0200
commit538a2425c53e08d884bfbc74513b98048c25bcab (patch)
tree12cf3abaa77b59ae383c6e8a2bca2d34e596018a
parent79bdd8a212cc02708755942cb2df96aa765fd4b2 (diff)
downloadEssentials-538a2425c53e08d884bfbc74513b98048c25bcab.tar
Essentials-538a2425c53e08d884bfbc74513b98048c25bcab.tar.gz
Essentials-538a2425c53e08d884bfbc74513b98048c25bcab.tar.lz
Essentials-538a2425c53e08d884bfbc74513b98048c25bcab.tar.xz
Essentials-538a2425c53e08d884bfbc74513b98048c25bcab.zip
Made the "throws" declaration of getWarps() more specific
It is very difficult to handle an Exception thrown by an API method when you don't have any way to **programatically** (without dirty stuff like string comparisons, so the message is not enough) distinguish errors and find out what's going on.
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsConf.java6
-rw-r--r--Essentials/src/com/earth2me/essentials/Warps.java3
-rw-r--r--Essentials/src/com/earth2me/essentials/api/IWarps.java7
-rw-r--r--Essentials/src/com/earth2me/essentials/api/InvalidWorldException.java16
4 files changed, 27 insertions, 5 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java
index 26f9d1c9d..e454db75a 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java
@@ -1,6 +1,8 @@
package com.earth2me.essentials;
import static com.earth2me.essentials.I18n._;
+
+import com.earth2me.essentials.api.InvalidWorldException;
import com.google.common.io.Files;
import java.io.*;
import java.nio.ByteBuffer;
@@ -379,7 +381,7 @@ public class EssentialsConf extends YamlConfiguration
return isSet(path);
}
- public Location getLocation(final String path, final Server server) throws Exception
+ public Location getLocation(final String path, final Server server) throws InvalidWorldException
{
final String worldName = getString((path == null ? "" : path + ".") + "world");
if (worldName == null || worldName.isEmpty())
@@ -389,7 +391,7 @@ public class EssentialsConf extends YamlConfiguration
final World world = server.getWorld(worldName);
if (world == null)
{
- throw new Exception(_("invalidWorld"));
+ throw new InvalidWorldException(worldName);
}
return new Location(world,
getDouble((path == null ? "" : path + ".") + "x", 0),
diff --git a/Essentials/src/com/earth2me/essentials/Warps.java b/Essentials/src/com/earth2me/essentials/Warps.java
index 39f31369c..c5cfb12df 100644
--- a/Essentials/src/com/earth2me/essentials/Warps.java
+++ b/Essentials/src/com/earth2me/essentials/Warps.java
@@ -3,6 +3,7 @@ package com.earth2me.essentials;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IWarps;
import com.earth2me.essentials.api.InvalidNameException;
+import com.earth2me.essentials.api.InvalidWorldException;
import com.earth2me.essentials.commands.WarpNotFoundException;
import java.io.File;
import java.io.IOException;
@@ -49,7 +50,7 @@ public class Warps implements IConf, IWarps
}
@Override
- public Location getWarp(String warp) throws Exception
+ public Location getWarp(String warp) throws WarpNotFoundException, InvalidWorldException
{
EssentialsConf conf = warpPoints.get(new StringIgnoreCase(warp));
if (conf == null)
diff --git a/Essentials/src/com/earth2me/essentials/api/IWarps.java b/Essentials/src/com/earth2me/essentials/api/IWarps.java
index 8bab07397..1866083a5 100644
--- a/Essentials/src/com/earth2me/essentials/api/IWarps.java
+++ b/Essentials/src/com/earth2me/essentials/api/IWarps.java
@@ -2,6 +2,8 @@ package com.earth2me.essentials.api;
import java.io.File;
import java.util.Collection;
+
+import com.earth2me.essentials.commands.WarpNotFoundException;
import org.bukkit.Location;
@@ -12,9 +14,10 @@ public interface IWarps
*
* @param warp - Warp name
* @return - Location the warp is set to
- * @throws Exception
+ * @throws WarpNotFoundException When the warp is not found
+ * @throws InvalidWorldException When the world the warp is in is not found
*/
- Location getWarp(String warp) throws Exception;
+ Location getWarp(String warp) throws WarpNotFoundException, InvalidWorldException;
/**
* Gets a list of warps
diff --git a/Essentials/src/com/earth2me/essentials/api/InvalidWorldException.java b/Essentials/src/com/earth2me/essentials/api/InvalidWorldException.java
new file mode 100644
index 000000000..dba6f4be6
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/api/InvalidWorldException.java
@@ -0,0 +1,16 @@
+package com.earth2me.essentials.api;
+
+import static com.earth2me.essentials.I18n._;
+
+public class InvalidWorldException extends Exception {
+ private final String world;
+
+ public InvalidWorldException(final String world) {
+ super(_("invalidWorld"));
+ this.world = world;
+ }
+
+ public String getWorld() {
+ return this.world;
+ }
+}