Search in sources :

Example 1 with PlayerPortalEvent

use of org.bukkit.event.player.PlayerPortalEvent in project BKCommonLib by bergerhealer.

the class PortalHandler_1_9 method enable.

@Override
public void enable(CommonPlugin plugin) {
    // Listener to disable player portal events pre-emptively while players are viewing credits
    // This is required, otherwise other plugins get very confused and teleport players out of the
    // credits screen.
    plugin.register(new Listener() {

        @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
        public void onPortalEvent(PlayerPortalEvent event) {
            if (EntityPlayerHandle.fromBukkit(event.getPlayer()).isViewingCredits()) {
                event.setCancelled(true);
            }
        }
    });
    // While the player is inside the end portal, it continuously fires a portal enter event.
    // This causes a horrible sound effect to play, because that effect is sent every tick.
    // This is obviously very unwanted while viewing the credits!
    plugin.register(new PacketListener() {

        @Override
        public void onPacketReceive(PacketReceiveEvent event) {
        }

        @Override
        public void onPacketSend(PacketSendEvent event) {
            if (EntityPlayerHandle.fromBukkit(event.getPlayer()).isViewingCredits()) {
                event.setCancelled(true);
            }
        }
    }, PacketType.OUT_WORLD_EVENT);
}
Also used : Listener(org.bukkit.event.Listener) PacketListener(com.bergerkiller.bukkit.common.protocol.PacketListener) EventHandler(org.bukkit.event.EventHandler) PlayerPortalEvent(org.bukkit.event.player.PlayerPortalEvent) PacketListener(com.bergerkiller.bukkit.common.protocol.PacketListener) PacketReceiveEvent(com.bergerkiller.bukkit.common.events.PacketReceiveEvent) PacketSendEvent(com.bergerkiller.bukkit.common.events.PacketSendEvent)

Example 2 with PlayerPortalEvent

use of org.bukkit.event.player.PlayerPortalEvent in project BKCommonLib by bergerhealer.

the class PortalHandler_1_8 method enable.

@Override
public void enable(CommonPlugin plugin) {
    // Cleans up players ignored for a single tick. If something broke, this
    // prevents a memory leak.
    _ignorePortalEventPlayersCleanup = RunOnceTask.create(plugin, () -> _ignorePortalEventPlayers.clear());
    // Listener to disable player portal events pre-emptively while players are viewing credits
    // This is required, otherwise other plugins get very confused and teleport players out of the
    // credits screen.
    plugin.register(new Listener() {

        @EventHandler(priority = EventPriority.MONITOR)
        public void onEntityPortalEnter(EntityPortalEnterEvent event) {
            if (event.getEntity() instanceof Player) {
                Player player = (Player) event.getEntity();
                if (EntityPlayerHandle.fromBukkit(player).isViewingCredits()) {
                    _ignorePortalEventPlayers.add(player);
                    _ignorePortalEventPlayersCleanup.start();
                }
            }
        }

        @EventHandler(priority = EventPriority.LOWEST)
        public void onPortalEvent(PlayerPortalEvent event) {
            if (_ignorePortalEventPlayers.remove(event.getPlayer())) {
                event.setCancelled(true);
            }
        }
    });
}
Also used : EntityPortalEnterEvent(org.bukkit.event.entity.EntityPortalEnterEvent) Player(org.bukkit.entity.Player) Listener(org.bukkit.event.Listener) EventHandler(org.bukkit.event.EventHandler) PlayerPortalEvent(org.bukkit.event.player.PlayerPortalEvent)

Example 3 with PlayerPortalEvent

use of org.bukkit.event.player.PlayerPortalEvent in project Glowstone by GlowstoneMC.

the class GlowPlayer method teleportToEnd.

@Override
protected boolean teleportToEnd() {
    if (!server.getAllowEnd()) {
        return false;
    }
    Location target = null;
    for (World world : server.getWorlds()) {
        if (world.getEnvironment() == Environment.THE_END) {
            target = world.getSpawnLocation();
            break;
        }
    }
    if (target == null) {
        return false;
    }
    PlayerPortalEvent event = EventFactory.getInstance().callEvent(new PlayerPortalEvent(this, location.clone(), target, null));
    if (event.isCancelled()) {
        return false;
    }
    target = event.getTo();
    spawnAt(target);
    teleported = true;
    return true;
}
Also used : GlowWorld(net.glowstone.GlowWorld) World(org.bukkit.World) PlayerPortalEvent(org.bukkit.event.player.PlayerPortalEvent) Location(org.bukkit.Location)

Example 4 with PlayerPortalEvent

use of org.bukkit.event.player.PlayerPortalEvent in project Glowstone by GlowstoneMC.

the class GlowPlayer method teleportToSpawn.

@Override
protected boolean teleportToSpawn() {
    Location target = getBedSpawnLocation();
    if (target == null) {
        target = server.getWorlds().get(0).getSpawnLocation();
    }
    PlayerPortalEvent event = EventFactory.getInstance().callEvent(new PlayerPortalEvent(this, location.clone(), target, null));
    if (event.isCancelled()) {
        return false;
    }
    target = event.getTo();
    spawnAt(target);
    teleported = true;
    return true;
}
Also used : PlayerPortalEvent(org.bukkit.event.player.PlayerPortalEvent) Location(org.bukkit.Location)

Aggregations

PlayerPortalEvent (org.bukkit.event.player.PlayerPortalEvent)4 Location (org.bukkit.Location)2 EventHandler (org.bukkit.event.EventHandler)2 Listener (org.bukkit.event.Listener)2 PacketReceiveEvent (com.bergerkiller.bukkit.common.events.PacketReceiveEvent)1 PacketSendEvent (com.bergerkiller.bukkit.common.events.PacketSendEvent)1 PacketListener (com.bergerkiller.bukkit.common.protocol.PacketListener)1 GlowWorld (net.glowstone.GlowWorld)1 World (org.bukkit.World)1 Player (org.bukkit.entity.Player)1 EntityPortalEnterEvent (org.bukkit.event.entity.EntityPortalEnterEvent)1