Search in sources :

Example 26 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.

the class ZombieNecronomicon method necronomiconVisualEffect.

private void necronomiconVisualEffect(Zombie zombie) {
    summoningEffectOn = true;
    nameScroller(zombie);
    if (!ConfigValues.defaultConfig.getBoolean("Turn on visual effects that indicate an attack is about to happen")) {
        return;
    }
    new BukkitRunnable() {

        int counter = 0;

        HashMap<Integer, List<Item>> fourTrack = new HashMap();

        @Override
        public void run() {
            if (!zombie.isValid() || zombie.hasAI()) {
                for (List<Item> itemList : fourTrack.values()) {
                    for (Item item : itemList) {
                        item.removeMetadata(MetadataHandler.MAJOR_VISUAL_EFFECT_MD, plugin);
                        item.remove();
                    }
                }
                if (zombie.isValid()) {
                    zombie.setCustomName(NameHandler.customAggressiveName(zombie));
                }
                summoningEffectOn = false;
                cancel();
                return;
            }
            if (counter == 0) {
                //establish 4tracks
                for (int i = 0; i < 8; i++) {
                    List<Item> itemList = new ArrayList<>();
                    for (int j = 0; j < 4; j++) {
                        ItemStack itemStack = new ItemStack(Material.WRITTEN_BOOK, 1);
                        Item item = zombie.getWorld().dropItem(zombie.getLocation(), itemStack);
                        item.setGravity(false);
                        item.setPickupDelay(Integer.MAX_VALUE);
                        item.setMetadata(MetadataHandler.MAJOR_VISUAL_EFFECT_MD, new FixedMetadataValue(plugin, true));
                        itemList.add(item);
                    }
                    fourTrack.put(i, itemList);
                }
            } else {
                itemMover(fourTrack, zombie, counter);
            }
            counter++;
        }
    }.runTaskTimer(plugin, 5, 5);
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) ItemStack(org.bukkit.inventory.ItemStack)

Example 27 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.

the class AttackArrow method attackArrow.

@EventHandler
public void attackArrow(EntityTargetEvent event) {
    if (event.getEntity().hasMetadata(powerMetadata) && !event.getEntity().hasMetadata(MetadataHandler.SHOOTING_ARROWS)) {
        Entity targetter = event.getEntity();
        Entity targetted = event.getTarget();
        if (targetted instanceof Player) {
            targetter.setMetadata(MetadataHandler.SHOOTING_ARROWS, new FixedMetadataValue(plugin, true));
            new BukkitRunnable() {

                @Override
                public void run() {
                    if (!targetted.isValid() || !targetter.isValid() || targetter.getWorld() != targetted.getWorld() || targetted.getLocation().distance(targetter.getLocation()) > 20) {
                        targetter.removeMetadata(MetadataHandler.SHOOTING_ARROWS, plugin);
                        cancel();
                        return;
                    }
                    Entity repeatingArrow = targetter.getWorld().spawnEntity(targetter.getLocation().add(0, 3, 0), EntityType.ARROW);
                    Vector targetterToTargetted = targetted.getLocation().toVector().subtract(repeatingArrow.getLocation().toVector());
                    double distanceNerfRepeating = (targetted.getLocation().distance(targetter.getLocation())) / 100;
                    repeatingArrow.setVelocity(targetterToTargetted.multiply(0.5 - distanceNerfRepeating));
                }
            }.runTaskTimer(plugin, 0, 100);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Example 28 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Glowstone by GlowstoneMC.

the class BlockDispenser method updatePhysics.

@Override
public void updatePhysics(GlowBlock block) {
    GlowBlock up = block.getRelative(BlockFace.UP);
    boolean powered = block.isBlockPowered() || block.isBlockIndirectlyPowered() || up.isBlockPowered() || up.isBlockIndirectlyPowered();
    GlowBlockState state = block.getState();
    MaterialData data = state.getData();
    if (!(data instanceof Dispenser)) {
        return;
    }
    boolean isTriggered = (data.getData() >> 3 & 1) != 0;
    if (powered && !isTriggered) {
        new BukkitRunnable() {

            @Override
            public void run() {
                trigger(block);
            }
        }.runTaskLater(null, 4);
        // TODO replace this with dispenser materialdata class (as soon as it provides access to this property)
        data.setData((byte) (data.getData() | 0x8));
        state.update();
    } else if (!powered && isTriggered) {
        data.setData((byte) (data.getData() & ~0x8));
        state.update();
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) Dispenser(org.bukkit.material.Dispenser) GlowDispenser(net.glowstone.block.state.GlowDispenser) GlowBlockState(net.glowstone.block.GlowBlockState) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MaterialData(org.bukkit.material.MaterialData)

Example 29 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project InfernalMobs by NyaaCat.

the class AbilityWebber method setWebWithDecay.

private static void setWebWithDecay(Block b, int seconds, boolean allowInAir) {
    if (b == null || b.getType() != Material.AIR)
        return;
    if (!allowInAir) {
        Block below_block = b.getRelative(BlockFace.DOWN);
        if (!below_block.getType().isSolid())
            return;
    }
    b.setType(Material.WEB);
    (new BukkitRunnable() {

        @Override
        public void run() {
            if (b.getType() == Material.WEB) {
                b.setType(Material.AIR);
            }
        }
    }).runTaskLater(InfernalMobs.instance, seconds * 20);
}
Also used : Block(org.bukkit.block.Block) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 30 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project MyPet by xXKeyleXx.

the class Sprint method finish.

@Override
public void finish() {
    nav.getParameters().removeSpeedModifier("Sprint");
    new BukkitRunnable() {

        public void run() {
            petEntity.setSprinting(false);
        }
    }.runTaskLater(MyPetApi.getPlugin(), 25L);
}
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