Search in sources :

Example 1 with EventMassiveCorePlayerPSTeleport

use of com.massivecraft.massivecore.event.EventMassiveCorePlayerPSTeleport in project MassiveCore by MassiveCraft.

the class MixinTeleport method teleport.

// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
public void teleport(Object teleporteeObject, Destination destination, int delaySeconds) throws TeleporterException {
    String teleporteeId = IdUtil.getId(teleporteeObject);
    if (!IdUtil.isPlayerId(teleporteeId))
        throw new TeleporterException(Txt.parse("<white>%s <b>is not a player.", MixinDisplayName.get().getDisplayName(teleporteeId, IdUtil.getConsole())));
    PS ps;
    try {
        ps = destination.getPs(teleporteeId);
    } catch (Exception e) {
        throw new TeleporterException(e.getMessage());
    }
    String desc = destination.getDesc(teleporteeId);
    if (delaySeconds > 0) {
        // With delay
        if (desc != null && !desc.isEmpty()) {
            MixinMessage.get().msgOne(teleporteeId, "<i>Teleporting to <h>" + desc + " <i>in <h>" + delaySeconds + "s <i>unless you move.");
        } else {
            MixinMessage.get().msgOne(teleporteeId, "<i>Teleporting in <h>" + delaySeconds + "s <i>unless you move.");
        }
        new ScheduledTeleport(teleporteeId, destination, delaySeconds).schedule();
    } else {
        // Without delay AKA "now"/"at once"
        // Run event
        EventMassiveCorePlayerPSTeleport event = new EventMassiveCorePlayerPSTeleport(teleporteeId, MixinSenderPs.get().getSenderPs(teleporteeId), destination);
        event.run();
        if (event.isCancelled())
            return;
        destination = event.getDestination();
        desc = destination.getDesc(teleporteeId);
        if (desc != null && !desc.isEmpty()) {
            MixinMessage.get().msgOne(teleporteeId, "<i>Teleporting to <h>" + desc + "<i>.");
        }
        Player teleportee = IdUtil.getPlayer(teleporteeId);
        if (teleportee != null) {
            teleportPlayer(teleportee, ps);
        } else {
            MixinSenderPs.get().setSenderPs(teleporteeId, ps);
        }
    }
}
Also used : EventMassiveCorePlayerPSTeleport(com.massivecraft.massivecore.event.EventMassiveCorePlayerPSTeleport) Player(org.bukkit.entity.Player) PS(com.massivecraft.massivecore.ps.PS) ScheduledTeleport(com.massivecraft.massivecore.teleport.ScheduledTeleport)

Aggregations

EventMassiveCorePlayerPSTeleport (com.massivecraft.massivecore.event.EventMassiveCorePlayerPSTeleport)1 PS (com.massivecraft.massivecore.ps.PS)1 ScheduledTeleport (com.massivecraft.massivecore.teleport.ScheduledTeleport)1 Player (org.bukkit.entity.Player)1