Search in sources :

Example 21 with Listener

use of org.bukkit.event.Listener in project BKCommonLib by bergerhealer.

the class EntityAddRemoveHandler_1_14_to_1_16_5 method onEnabled.

@Override
public void onEnabled(CommonPlugin plugin) {
    super.onEnabled(plugin);
    plugin.register(new Listener() {

        @EventHandler(priority = EventPriority.LOWEST)
        public void onChunkLoad(ChunkLoadEvent event) {
            notifyChunkEntitiesLoaded(event.getChunk());
        }

        @EventHandler(priority = EventPriority.LOWEST)
        public void onChunkUnload(ChunkUnloadEvent event) {
            notifyChunkEntitiesUnloaded(event.getChunk());
        }
    });
}
Also used : ChunkUnloadEvent(org.bukkit.event.world.ChunkUnloadEvent) ChunkLoadEvent(org.bukkit.event.world.ChunkLoadEvent) Listener(org.bukkit.event.Listener) EventHandler(org.bukkit.event.EventHandler)

Example 22 with Listener

use of org.bukkit.event.Listener 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 23 with Listener

use of org.bukkit.event.Listener 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 24 with Listener

use of org.bukkit.event.Listener in project Essentials by EssentialsX.

the class EssentialsSpawn method onEnable.

@Override
public void onEnable() {
    final PluginManager pluginManager = getServer().getPluginManager();
    ess = (IEssentials) pluginManager.getPlugin("Essentials");
    if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) {
        LOGGER.log(Level.WARNING, tl("versionMismatchAll"));
    }
    if (!ess.isEnabled()) {
        this.setEnabled(false);
        return;
    }
    spawns = new SpawnStorage(ess);
    ess.addReloadListener(spawns);
    final EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener(ess, spawns);
    EventPriority respawnPriority = ess.getSettings().getRespawnPriority();
    if (respawnPriority != null) {
        pluginManager.registerEvent(PlayerRespawnEvent.class, playerListener, respawnPriority, new EventExecutor() {

            @Override
            public void execute(final Listener ll, final Event event) throws EventException {
                ((EssentialsSpawnPlayerListener) ll).onPlayerRespawn((PlayerRespawnEvent) event);
            }
        }, this);
    }
    EventPriority joinPriority = ess.getSettings().getSpawnJoinPriority();
    if (joinPriority != null) {
        pluginManager.registerEvent(PlayerJoinEvent.class, playerListener, joinPriority, new EventExecutor() {

            @Override
            public void execute(final Listener ll, final Event event) throws EventException {
                ((EssentialsSpawnPlayerListener) ll).onPlayerJoin((PlayerJoinEvent) event);
            }
        }, this);
    }
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) EventExecutor(org.bukkit.plugin.EventExecutor) Listener(org.bukkit.event.Listener) EventException(org.bukkit.event.EventException) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) Event(org.bukkit.event.Event) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent) EventPriority(org.bukkit.event.EventPriority)

Example 25 with Listener

use of org.bukkit.event.Listener in project AuthMeReloaded by AuthMe.

the class ListenerConsistencyTest method collectListenerClasses.

@BeforeClass
public static void collectListenerClasses() {
    ClassCollector collector = new ClassCollector(TestHelper.SOURCES_FOLDER, TestHelper.PROJECT_ROOT + "listener");
    classes = collector.collectClasses(Listener.class);
    if (classes.isEmpty()) {
        throw new IllegalStateException("Did not find any Listener classes. Is the folder correct?");
    }
}
Also used : Listener(org.bukkit.event.Listener) ClassCollector(fr.xephi.authme.ClassCollector) BeforeClass(org.junit.BeforeClass)

Aggregations

Listener (org.bukkit.event.Listener)26 EventHandler (org.bukkit.event.EventHandler)10 Event (org.bukkit.event.Event)8 EventExecutor (org.bukkit.plugin.EventExecutor)7 RegisteredListener (org.bukkit.plugin.RegisteredListener)7 Player (org.bukkit.entity.Player)6 EventException (org.bukkit.event.EventException)6 EventPriority (org.bukkit.event.EventPriority)6 PluginManager (org.bukkit.plugin.PluginManager)6 PlayerJoinEvent (org.bukkit.event.player.PlayerJoinEvent)5 Method (java.lang.reflect.Method)4 HandlerList (org.bukkit.event.HandlerList)4 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 PlayerPortalEvent (org.bukkit.event.player.PlayerPortalEvent)2 AuthorNagException (org.bukkit.plugin.AuthorNagException)2 Plugin (org.bukkit.plugin.Plugin)2 PacketReceiveEvent (com.bergerkiller.bukkit.common.events.PacketReceiveEvent)1 PacketSendEvent (com.bergerkiller.bukkit.common.events.PacketSendEvent)1 BukkitWorldSupplier (com.bergerkiller.bukkit.common.offline.OfflineWorld.BukkitWorldSupplier)1