Search in sources :

Example 61 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Ublisk by Derkades.

the class Voting method onInvClose.

@EventHandler
public void onInvClose(final InventoryCloseEvent event) {
    if (event.getInventory().getName().contains("Box") && !event.getInventory().getName().contains("Shulker")) {
        Voting.playerOpeningBox = null;
        new BukkitRunnable() {

            public void run() {
                HumanEntity human = event.getPlayer();
                human.teleport(Voting.oldPlayerLocation);
                Voting.oldPlayerLocation = null;
            }
        }.runTaskLater(Main.getInstance(), 2L);
    }
}
Also used : HumanEntity(org.bukkit.entity.HumanEntity) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EventHandler(org.bukkit.event.EventHandler)

Example 62 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Ublisk by Derkades.

the class Guild method invitePlayer.

public synchronized void invitePlayer(final UPlayer source, final UPlayer target) {
    if (!this.exists())
        throw new UnsupportedOperationException("Cannot invite player to non-existent guild.");
    final GuildInvite invite = new GuildInvite(this, source);
    // Add invite to list of invites, and remove it after 60 seconds (if it hasn't been accepted)
    GUILD_INVITES.put(target.getName(), invite);
    new BukkitRunnable() {

        public void run() {
            if (GUILD_INVITES.containsKey(target.getName())) {
                GUILD_INVITES.remove(target.getName());
            }
        }
    }.runTaskLater(Main.getInstance(), 60 * 20);
    TextComponent inviteMessage = new TextComponent(source.getName() + " has invited you to join " + this.getName() + ". ");
    inviteMessage.setColor(ChatColor.DARK_AQUA);
    inviteMessage.setBold(true);
    BaseComponent[] hoverText = new ComponentBuilder("Click me!").color(ChatColor.YELLOW).create();
    TextComponent clickToAccept = new TextComponent("Click here to accept.");
    clickToAccept.setColor(ChatColor.AQUA);
    clickToAccept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText));
    clickToAccept.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/guild accept"));
    BaseComponent[] components = new BaseComponent[] { inviteMessage, clickToAccept };
    target.sendMessage(components);
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 63 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Ublisk by Derkades.

the class PacketListener method listenForPacket.

public static void listenForPacket(final int port, final int packetLength, final PacketRecievedListener runnable) {
    if (Var.DEBUG) {
        Logger.log(LogLevel.WARNING, "PacketListener", "Packet listener on port " + port + " has not been started, because debug mode is enabled.");
        return;
    }
    new BukkitRunnable() {

        public void run() {
            try (final DatagramSocket serverSocket = new DatagramSocket(port)) {
                byte[] receiveData = new byte[packetLength];
                Logger.log(LogLevel.INFO, "PacketListener", "Started listening on " + port);
                final DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
                while (RUNNING) {
                    serverSocket.receive(receivePacket);
                    final String string = new String(receivePacket.getData(), 0, receivePacket.getLength());
                    runnable.onPacketRecieved(string);
                }
                Logger.log(LogLevel.INFO, "PacketListener", "Shutting down listener on port " + port);
                serverSocket.close();
                this.cancel();
                return;
            } catch (BindException e) {
                if (e.getMessage().contains("in use")) {
                    Logger.log(LogLevel.WARNING, "Could not start listener on port " + port + ", because this port is already in use.");
                    Ublisk.RESTART_ERROR = true;
                } else {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }.runTaskAsynchronously(Main.getInstance());
}
Also used : DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) BindException(java.net.BindException) IOException(java.io.IOException)

Example 64 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Ublisk by Derkades.

the class RemoveMobs method run.

@Override
public void run() {
    Ublisk.broadcastPrefixedMessage("Clearing all mobs and items in 30 seconds!");
    new BukkitRunnable() {

        public void run() {
            Ublisk.broadcastPrefixedMessage("Clearing all mobs and items in 5 seconds!");
            new BukkitRunnable() {

                public void run() {
                    Mobs.clearMobs();
                    Ublisk.broadcastMessage(Message.ENTITIES_REMOVED);
                }
            }.runTaskLater(Main.getInstance(), 5 * 20);
        }
    }.runTaskLater(Main.getInstance(), 25 * 20);
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 65 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Fusion by GummyPvP.

the class Utils method sendActionBar.

public static void sendActionBar(final Player player, final String message, int duration) {
    sendActionBar(player, message);
    if (duration >= 0) {
        // Sends empty message at the end of the duration. Allows messages shorter than 3 seconds, ensures precision.
        new BukkitRunnable() {

            @Override
            public void run() {
                sendActionBar(player, "");
            }
        }.runTaskLater(plugin, duration + 1);
    }
    // Re-sends the messages every 3 seconds so it doesn't go away from the player's screen.
    while (duration > 60) {
        duration -= 60;
        int sched = duration % 60;
        new BukkitRunnable() {

            @Override
            public void run() {
                sendActionBar(player, message);
            }
        }.runTaskLater(plugin, (long) sched);
    }
}
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