Search in sources :

Example 6 with PacketListener

use of com.bergerkiller.bukkit.common.protocol.PacketListener 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)

Aggregations

PacketListener (com.bergerkiller.bukkit.common.protocol.PacketListener)6 PacketType (com.bergerkiller.bukkit.common.protocol.PacketType)3 PacketReceiveEvent (com.bergerkiller.bukkit.common.events.PacketReceiveEvent)2 PacketSendEvent (com.bergerkiller.bukkit.common.events.PacketSendEvent)2 CommonPacket (com.bergerkiller.bukkit.common.protocol.CommonPacket)2 PacketMonitor (com.bergerkiller.bukkit.common.protocol.PacketMonitor)2 EventHandler (org.bukkit.event.EventHandler)1 Listener (org.bukkit.event.Listener)1 PlayerPortalEvent (org.bukkit.event.player.PlayerPortalEvent)1 Plugin (org.bukkit.plugin.Plugin)1