diff --git a/src/com/massivecraft/mcore5/PS.java b/src/com/massivecraft/mcore5/PS.java index 254aa222..a1551d0a 100644 --- a/src/com/massivecraft/mcore5/PS.java +++ b/src/com/massivecraft/mcore5/PS.java @@ -222,6 +222,7 @@ public class PS implements Cloneable protected synchronized Location innerLocation(Double x, Double y, Double z) { World world = this.getWorld(); + if (world == null) return null; if (x == null) return null; if (y == null) return null; @@ -477,7 +478,7 @@ public class PS implements Cloneable // WRITERS //----------------------------------------------// - public synchronized void write(Entity entity) + public synchronized void write(Entity entity) throws PSTeleporterException { teleporter.teleport(entity, this); } diff --git a/src/com/massivecraft/mcore5/PSTeleporter.java b/src/com/massivecraft/mcore5/PSTeleporter.java index 402ff823..92cdaa9e 100644 --- a/src/com/massivecraft/mcore5/PSTeleporter.java +++ b/src/com/massivecraft/mcore5/PSTeleporter.java @@ -4,5 +4,9 @@ import org.bukkit.entity.Entity; public interface PSTeleporter { - public void teleport(Entity entity, PS ps); + /** + * @param entity The entity to be teleported + * @param ps The target PhysicalState + */ + public void teleport(Entity entity, PS ps) throws PSTeleporterException; } diff --git a/src/com/massivecraft/mcore5/PSTeleporterDefault.java b/src/com/massivecraft/mcore5/PSTeleporterDefault.java index 78354baa..7cee87b1 100644 --- a/src/com/massivecraft/mcore5/PSTeleporterDefault.java +++ b/src/com/massivecraft/mcore5/PSTeleporterDefault.java @@ -4,16 +4,22 @@ import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.util.Vector; +import com.massivecraft.mcore5.util.Txt; + public class PSTeleporterDefault implements PSTeleporter { @Override - public void teleport(Entity entity, PS ps) + public void teleport(Entity entity, PS ps) throws PSTeleporterException { - Location location = ps.calcLocation(); - if (location != null) entity.teleport(location); + Location location = ps.calcLocation(); + if (location == null) throw new PSTeleporterException(Txt.parse("Could not calculate the location")); + + entity.teleport(location); Vector velocity = ps.getVelocity(); - if (velocity != null) entity.setVelocity(velocity); + if (velocity == null) return; + + entity.setVelocity(velocity); } // -------------------------------------------- // diff --git a/src/com/massivecraft/mcore5/PSTeleporterException.java b/src/com/massivecraft/mcore5/PSTeleporterException.java new file mode 100644 index 00000000..376d3a21 --- /dev/null +++ b/src/com/massivecraft/mcore5/PSTeleporterException.java @@ -0,0 +1,31 @@ +package com.massivecraft.mcore5; + +public class PSTeleporterException extends Exception +{ + private static final long serialVersionUID = 1L; + + public PSTeleporterException() + { + super(); + } + + public PSTeleporterException(String message) + { + super(message); + } + + public PSTeleporterException(String message, Throwable cause) + { + super(message, cause); + } + + public PSTeleporterException(Throwable cause) + { + super(cause); + } + + protected PSTeleporterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) + { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/src/com/massivecraft/mcore5/cmd/req/ReqIsPlayer.java b/src/com/massivecraft/mcore5/cmd/req/ReqIsPlayer.java index 9d478680..e5114662 100644 --- a/src/com/massivecraft/mcore5/cmd/req/ReqIsPlayer.java +++ b/src/com/massivecraft/mcore5/cmd/req/ReqIsPlayer.java @@ -20,14 +20,11 @@ public class ReqIsPlayer implements IReq return Lang.commandSenderMustBePlayer; } - protected static ReqIsPlayer instance= new ReqIsPlayer(); - public static ReqIsPlayer getInstance() - { - return instance; - } + // -------------------------------------------- // + // INSTANCE + // -------------------------------------------- // + + public static ReqIsPlayer i = new ReqIsPlayer(); + public static ReqIsPlayer get() { return i; } - public static ReqIsPlayer get() - { - return instance; - } }