Search in sources :

Example 1 with Listener

use of org.bukkit.event.Listener in project MagicPlugin by elBukkit.

the class Mage method onPlayerQuit.

public void onPlayerQuit(PlayerEvent event) {
    Player player = getPlayer();
    if (player == null || player != event.getPlayer()) {
        return;
    }
    // Must allow listeners to remove themselves during the event!
    List<Listener> active = new ArrayList<>(quitListeners);
    for (Listener listener : active) {
        callEvent(listener, event);
    }
}
Also used : Player(org.bukkit.entity.Player) Listener(org.bukkit.event.Listener) ArrayList(java.util.ArrayList)

Example 2 with Listener

use of org.bukkit.event.Listener in project MassiveCore by MassiveCraft.

the class EventUtil method callEventAfter.

public static void callEventAfter(Event event, Listener listener, EventPriority priority) {
    HandlerList handlers = event.getHandlers();
    RegisteredListener[] listeners = handlers.getRegisteredListeners().clone();
    boolean run = false;
    for (RegisteredListener registration : listeners) {
        if (run) {
            fireEventRegistration(event, registration);
        } else {
            try {
                EventPriority thisPriority = (EventPriority) fieldRegisteredListenerDotPriority.get(registration);
                Listener thisListener = (Listener) fieldRegisteredListenerDotListener.get(registration);
                if (thisListener == listener && thisPriority == priority)
                    run = true;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : HandlerList(org.bukkit.event.HandlerList) RegisteredListener(org.bukkit.plugin.RegisteredListener) Listener(org.bukkit.event.Listener) RegisteredListener(org.bukkit.plugin.RegisteredListener) AuthorNagException(org.bukkit.plugin.AuthorNagException) EventPriority(org.bukkit.event.EventPriority)

Example 3 with Listener

use of org.bukkit.event.Listener in project Skills by StarTux.

the class BukkitSkillsPlugin method onEnable.

@Override
public void onEnable() {
    // Files
    writeDefaultFiles(false);
    reloadConfig();
    // Economy
    if (!setupEconomy()) {
        getLogger().warning("Economy setup failed. Disabling skills.");
        getServer().getPluginManager().disablePlugin(this);
        return;
    }
    // Database
    db = new SQLDatabase(this);
    for (Class<?> clazz : SQLDB.getDatabaseClasses()) db.registerTable(clazz);
    if (!db.createAllTables()) {
        getLogger().warning("Database setup failed. Disabling skills.");
        getServer().getPluginManager().disablePlugin(this);
        return;
    }
    // Skills
    skills.configure();
    for (BukkitSkill skill : skills.getSkills()) {
        if (skill instanceof Listener) {
            getServer().getPluginManager().registerEvents((Listener) skill, this);
        } else {
            getLogger().warning("Not an Event Listener: " + skill.getDisplayName());
        }
    }
    // Double check skills
    for (BukkitSkillType type : BukkitSkillType.values()) {
        BukkitSkill skill = skills.getSkillMap().get(type);
        if (skill == null) {
            getLogger().warning("Missing skill: " + type.name());
        } else {
            skill.configureSkill();
            skill.onEnable();
        }
    }
    // Commands
    getCommand("skillsadmin").setExecutor(adminCommand);
    getCommand("skills").setExecutor(skillsCommand);
    getCommand("highscore").setExecutor(highscoreCommand);
    // Events
    getServer().getPluginManager().registerEvents(this, this);
    // Tasks
    new BukkitRunnable() {

        @Override
        public void run() {
            saveSome();
            updateAllPlayers();
        }
    }.runTaskTimer(this, 20, 20);
    // 
    skills.buildNameMap();
}
Also used : Listener(org.bukkit.event.Listener) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) SQLDatabase(com.winthier.sql.SQLDatabase)

Example 4 with Listener

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

the class Essentials method handleCrash.

private void handleCrash(Throwable exception) {
    final PluginManager pm = getServer().getPluginManager();
    LOGGER.log(Level.SEVERE, exception.toString());
    exception.printStackTrace();
    pm.registerEvents(new Listener() {

        @EventHandler(priority = EventPriority.LOW)
        public void onPlayerJoin(final PlayerJoinEvent event) {
            event.getPlayer().sendMessage("Essentials failed to load, read the log file.");
        }
    }, this);
    for (Player player : getOnlinePlayers()) {
        player.sendMessage("Essentials failed to load, read the log file.");
    }
    this.setEnabled(false);
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) Player(org.bukkit.entity.Player) SignBlockListener(com.earth2me.essentials.signs.SignBlockListener) SignEntityListener(com.earth2me.essentials.signs.SignEntityListener) SignPlayerListener(com.earth2me.essentials.signs.SignPlayerListener) Listener(org.bukkit.event.Listener) EventHandler(org.bukkit.event.EventHandler)

Example 5 with Listener

use of org.bukkit.event.Listener in project VoxelGamesLibv2 by VoxelGamesLib.

the class AbstractPhase method enable.

@Override
public void enable() {
    if (!checkDependencies()) {
        game.abortGame();
        return;
    }
    if (!checkVictoryConditionDependencies()) {
        game.abortGame();
        return;
    }
    if (victoryConditions.size() == 0) {
        addVictoryCondition(getGame().createVictoryCondition(EmptyVictoryCondition.class, this));
    }
    // enable timer
    startTime = LocalDateTime.now();
    log.finer("enable phase" + getName());
    phaseTickables.values().forEach(Tickable::enable);
    for (Feature feature : features) {
        if (game.isAborting()) {
            return;
        }
        log.finer("enable " + feature.getName());
        try {
            feature.enable();
        } catch (Exception ex) {
            log.severe("error while starting " + feature.getName());
            ex.printStackTrace();
            game.abortGame();
            return;
        }
        if (feature instanceof Listener) {
            eventHandler.registerEvents((Listener) feature, getGame());
        }
        if (feature instanceof FeatureCommandImplementor) {
            AbstractFeatureCommand cmd = injector.getInstance(((FeatureCommandImplementor) feature).getCommandClass());
            // noinspection unchecked
            cmd.setFeature(feature);
            commandHandler.register(cmd, this);
        }
        startedFeatures.add(feature);
    }
    for (VictoryCondition victoryCondition : victoryConditions) {
        if (victoryCondition instanceof Listener) {
            eventHandler.registerEvents((Listener) victoryCondition, getGame());
        }
    }
}
Also used : EmptyVictoryCondition(com.voxelgameslib.voxelgameslib.condition.conditions.EmptyVictoryCondition) Listener(org.bukkit.event.Listener) Tickable(com.voxelgameslib.voxelgameslib.tick.Tickable) FeatureCommandImplementor(com.voxelgameslib.voxelgameslib.feature.FeatureCommandImplementor) VictoryCondition(com.voxelgameslib.voxelgameslib.condition.VictoryCondition) EmptyVictoryCondition(com.voxelgameslib.voxelgameslib.condition.conditions.EmptyVictoryCondition) Feature(com.voxelgameslib.voxelgameslib.feature.Feature) VoxelGameLibException(com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException) NoSuchFeatureException(com.voxelgameslib.voxelgameslib.exception.NoSuchFeatureException) DependencyGraphException(com.voxelgameslib.voxelgameslib.exception.DependencyGraphException) AbstractFeatureCommand(com.voxelgameslib.voxelgameslib.feature.AbstractFeatureCommand)

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