Gate will throw exceptions when something goes wrong

This commit is contained in:
Tobias Ottenweller 2012-05-17 16:43:51 +02:00
parent 69571ea511
commit 1844df81f3

View File

@ -31,8 +31,9 @@ public class Gate extends BaseGate implements ConfigurationSerializable
* CONSTRUCTORS * CONSTRUCTORS
*/ */
public Gate() public Gate(String id) throws Exception
{ {
setId(id);
} }
@ -46,17 +47,14 @@ public class Gate extends BaseGate implements ConfigurationSerializable
} }
/**
* @return true if the id has been changed; false otherwise public void setId(String id) throws Exception
*/
public boolean setId(String id)
{ {
if (!exists(id)) { if (exists(id)) {
this.id = id; throw new Exception("A gate with '" + id + "' already exists");
return true;
} }
return false; this.id = id;
} }
@ -93,7 +91,11 @@ public class Gate extends BaseGate implements ConfigurationSerializable
public Map<String, Object> serialize() public Map<String, Object> serialize()
{ {
try {
validate(); // make sure to not write invalid stuff to disk validate(); // make sure to not write invalid stuff to disk
}
catch (Exception e) {
}
Map<String, Object> retVal = new HashMap<String, Object>(); Map<String, Object> retVal = new HashMap<String, Object>();
@ -131,20 +133,18 @@ public class Gate extends BaseGate implements ConfigurationSerializable
} }
public static Gate create(String id) public static Gate create(String id) throws Exception
{ {
Gate gate = new Gate(); Gate gate = new Gate(id);
gate.id = id;
instances.put(gate.id, gate);
Plugin.log("created new gate " + gate.id);
instances.put(gate.id, gate);
return gate; return gate;
} }
public static void rename(Gate gate, String newId) throws Exception public static void rename(String oldId, String newId) throws Exception
{ {
String oldId = gate.id; Gate gate = get(oldId);
gate.setId(newId); gate.setId(newId);
@ -155,6 +155,12 @@ public class Gate extends BaseGate implements ConfigurationSerializable
public static void delete(String id) public static void delete(String id)
{ {
Gate g = get(id);
if (g != null) {
g.emptyGate();
}
instances.remove(id); instances.remove(id);
} }