Add destination desc to the event and rename parameters for PS teleport mixin.

This commit is contained in:
Olof Larsson 2013-06-12 08:44:41 +02:00
parent b4095ed4ab
commit dc3cb5e1d1
4 changed files with 39 additions and 33 deletions

View File

@ -35,15 +35,20 @@ public class MCorePlayerPSTeleportEvent extends Event implements Cancellable, Ru
public PS getTo() { return this.to; } public PS getTo() { return this.to; }
public void setTo(PS to) { this.to = to; } public void setTo(PS to) { this.to = to; }
private String desc;
public String getDesc() { return this.desc; }
public void setDesc(String desc) { this.desc = desc; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public MCorePlayerPSTeleportEvent(String teleporteeId, PS from, PS to) public MCorePlayerPSTeleportEvent(String teleporteeId, PS from, PS to, String desc)
{ {
this.teleporteeId = teleporteeId; this.teleporteeId = teleporteeId;
this.from = from; this.from = from;
this.to = to; this.to = to;
this.desc = desc;
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -18,24 +18,24 @@ public interface TeleportMixin
// PLAYER // PLAYER
// -------------------------------------------- // // -------------------------------------------- //
public void teleport(Player teleportee, PS destinationPs) throws TeleporterException; public void teleport(Player teleportee, PS to) throws TeleporterException;
public void teleport(Player teleportee, PS destinationPs, String destinationDesc) throws TeleporterException; public void teleport(Player teleportee, PS to, String desc) throws TeleporterException;
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, Permissible delayPermissible) throws TeleporterException; public void teleport(Player teleportee, PS to, String desc, Permissible delayPermissible) throws TeleporterException;
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException; public void teleport(Player teleportee, PS to, String desc, int delaySeconds) throws TeleporterException;
// -------------------------------------------- // // -------------------------------------------- //
// PLAYER ID // PLAYER ID
// -------------------------------------------- // // -------------------------------------------- //
public void teleport(String teleporteeId, PS destinationPs) throws TeleporterException; public void teleport(String teleporteeId, PS to) throws TeleporterException;
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc) throws TeleporterException; public void teleport(String teleporteeId, PS to, String desc) throws TeleporterException;
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, Permissible delayPermissible) throws TeleporterException; public void teleport(String teleporteeId, PS to, String desc, Permissible delayPermissible) throws TeleporterException;
// The only one not covered in abstract // The only one not covered in abstract
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException; public void teleport(String teleporteeId, PS to, String desc, int delaySeconds) throws TeleporterException;
} }

View File

@ -21,49 +21,49 @@ public abstract class TeleportMixinAbstract implements TeleportMixin
} }
@Override @Override
public void teleport(Player teleportee, PS destinationPs) throws TeleporterException public void teleport(Player teleportee, PS to) throws TeleporterException
{ {
this.teleport(teleportee, destinationPs, null); this.teleport(teleportee, to, null);
} }
@Override @Override
public void teleport(Player teleportee, PS destinationPs, String destinationDesc) throws TeleporterException public void teleport(Player teleportee, PS to, String desc) throws TeleporterException
{ {
this.teleport(teleportee, destinationPs, destinationDesc, 0); this.teleport(teleportee, to, desc, 0);
} }
@Override @Override
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, Permissible delayPermissible) throws TeleporterException public void teleport(Player teleportee, PS to, String desc, Permissible delayPermissible) throws TeleporterException
{ {
int delaySeconds = getTpdelay(delayPermissible); int delaySeconds = getTpdelay(delayPermissible);
this.teleport(teleportee, destinationPs, destinationDesc, delaySeconds); this.teleport(teleportee, to, desc, delaySeconds);
} }
@Override @Override
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException public void teleport(Player teleportee, PS to, String desc, int delaySeconds) throws TeleporterException
{ {
this.teleport(SenderUtil.getSenderId(teleportee), destinationPs, destinationDesc, delaySeconds); this.teleport(SenderUtil.getSenderId(teleportee), to, desc, delaySeconds);
} }
// ---- // ----
@Override @Override
public void teleport(String teleporteeId, PS destinationPs) throws TeleporterException public void teleport(String teleporteeId, PS to) throws TeleporterException
{ {
this.teleport(teleporteeId, destinationPs, null); this.teleport(teleporteeId, to, null);
} }
@Override @Override
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc) throws TeleporterException public void teleport(String teleporteeId, PS to, String desc) throws TeleporterException
{ {
this.teleport(teleporteeId, destinationPs, destinationDesc, 0); this.teleport(teleporteeId, to, desc, 0);
} }
@Override @Override
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, Permissible delayPermissible) throws TeleporterException public void teleport(String teleporteeId, PS to, String desc, Permissible delayPermissible) throws TeleporterException
{ {
int delaySeconds = getTpdelay(delayPermissible); int delaySeconds = getTpdelay(delayPermissible);
this.teleport(teleporteeId, destinationPs, destinationDesc, delaySeconds); this.teleport(teleporteeId, to, desc, delaySeconds);
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -69,48 +69,49 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException public void teleport(String teleporteeId, PS to, String desc, int delaySeconds) throws TeleporterException
{ {
if (!SenderUtil.isPlayerId(teleporteeId)) throw new TeleporterException(Txt.parse("<white>%s <b>is not a player.", Mixin.getDisplayName(teleporteeId))); if (!SenderUtil.isPlayerId(teleporteeId)) throw new TeleporterException(Txt.parse("<white>%s <b>is not a player.", Mixin.getDisplayName(teleporteeId)));
if (delaySeconds > 0) if (delaySeconds > 0)
{ {
// With delay // With delay
if (destinationDesc != null) if (desc != null)
{ {
Mixin.msg(teleporteeId, "<i>Teleporting to <h>"+destinationDesc+" <i>in <h>"+delaySeconds+"s <i>unless you move."); Mixin.msg(teleporteeId, "<i>Teleporting to <h>"+desc+" <i>in <h>"+delaySeconds+"s <i>unless you move.");
} }
else else
{ {
Mixin.msg(teleporteeId, "<i>Teleporting in <h>"+delaySeconds+"s <i>unless you move."); Mixin.msg(teleporteeId, "<i>Teleporting in <h>"+delaySeconds+"s <i>unless you move.");
} }
new ScheduledTeleport(teleporteeId, destinationPs, destinationDesc, delaySeconds).schedule(); new ScheduledTeleport(teleporteeId, to, desc, delaySeconds).schedule();
} }
else else
{ {
// Without delay AKA "now"/"at once" // Without delay AKA "now"/"at once"
// Run event // Run event
MCorePlayerPSTeleportEvent event = new MCorePlayerPSTeleportEvent(teleporteeId, Mixin.getSenderPs(teleporteeId), destinationPs); MCorePlayerPSTeleportEvent event = new MCorePlayerPSTeleportEvent(teleporteeId, Mixin.getSenderPs(teleporteeId), to, desc);
event.run(); event.run();
if (event.isCancelled()) return; if (event.isCancelled()) return;
if (event.getTo() == null) return; if (event.getTo() == null) return;
destinationPs = event.getTo(); to = event.getTo();
desc = event.getDesc();
if (destinationDesc != null) if (desc != null)
{ {
Mixin.msg(teleporteeId, "<i>Teleporting to <h>"+destinationDesc+"<i>."); Mixin.msg(teleporteeId, "<i>Teleporting to <h>"+desc+"<i>.");
} }
Player teleportee = SenderUtil.getPlayer(teleporteeId); Player teleportee = SenderUtil.getPlayer(teleporteeId);
if (teleportee != null) if (teleportee != null)
{ {
teleportPlayer(teleportee, destinationPs); teleportPlayer(teleportee, to);
} }
else else
{ {
Mixin.setSenderPs(teleporteeId, destinationPs); Mixin.setSenderPs(teleporteeId, to);
} }
} }
} }