Teleporter may now throw exceptions

This commit is contained in:
Olof Larsson 2013-01-10 13:56:34 +01:00
parent 693705fc10
commit f3530d521b
5 changed files with 54 additions and 15 deletions

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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("<b>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);
}
// -------------------------------------------- //

View File

@ -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);
}
}

View File

@ -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;
}
}