Search in sources :

Example 41 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project QualityArmory by ZombieStriker.

the class GunUtil method basicReload.

public static void basicReload(final Gun g, final Player player, boolean doNotRemoveAmmo, double seconds) {
    @SuppressWarnings("deprecation") final ItemStack temp = player.getInventory().getItemInHand();
    ItemMeta im = temp.getItemMeta();
    if (ItemFact.getAmount(temp) == g.getMaxBullets() - 1) {
        return;
    }
    if (im.getLore() != null && im.getDisplayName().contains("Reloading.")) {
        try {
            /*
				 * player.getWorld().playSound(player.getLocation(), Sound.BLOCK_LEVER_CLICK, 5,
				 * 1);
				 */
            player.getWorld().playSound(player.getLocation(), WeaponSounds.RELOAD_MAG_OUT.getName(), 1, 1f);
            return;
        } catch (Error e2) {
            player.getWorld().playSound(player.getLocation(), Sound.valueOf("CLICK"), 5, 1);
        }
    } else {
        try {
            /*
				 * player.getWorld().playSound(player.getLocation(), Sound.BLOCK_LEVER_CLICK, 5,
				 * 0.7f);
				 */
            player.getWorld().playSound(player.getLocation(), WeaponSounds.RELOAD_MAG_OUT.getName(), 1, 1f);
        } catch (Error e2) {
            player.getWorld().playSound(player.getLocation(), Sound.valueOf("CLICK"), 5, 0.7f);
        }
        final int slot = player.getInventory().getHeldItemSlot();
        Ammo ammo = g.getAmmoType();
        final int initialAmount = ItemFact.getAmount(temp) + 1;
        final int reloadAmount = doNotRemoveAmmo ? g.getMaxBullets() : Math.min(g.getMaxBullets(), initialAmount + AmmoUtil.getAmmoAmount(player, ammo));
        final int subtractAmount = reloadAmount - initialAmount;
        if (!doNotRemoveAmmo)
            AmmoUtil.removeAmmo(player, ammo, subtractAmount);
        im.setLore(ItemFact.getGunLore(g, temp, 1));
        im.setDisplayName(g.getDisplayName() + " [Reloading...]");
        temp.setItemMeta(im);
        if (Main.enableVisibleAmounts)
            temp.setAmount(1);
        player.getInventory().setItem(slot, temp);
        BukkitTask r = new BukkitRunnable() {

            @Override
            public void run() {
                try {
                    /*
						 * player.getWorld().playSound(player.getLocation(), Sound.BLOCK_LEVER_CLICK, 5,
						 * 1); player.getWorld().playSound(player.getLocation(),
						 * Sound.BLOCK_LEVER_CLICK, 5, 1.4f);
						 */
                    player.getWorld().playSound(player.getLocation(), WeaponSounds.RELOAD_MAG_IN.getName(), 1, 1f);
                } catch (Error e2) {
                    player.getWorld().playSound(player.getLocation(), Sound.valueOf("CLICK"), 5, 1);
                    player.getWorld().playSound(player.getLocation(), Sound.valueOf("CLICK"), 5, 1.4f);
                }
                ItemMeta newim = temp.getItemMeta();
                newim.setLore(ItemFact.getGunLore(g, temp, reloadAmount));
                newim.setDisplayName(g.getDisplayName());
                temp.setItemMeta(newim);
                if (Main.enableVisibleAmounts)
                    temp.setAmount(reloadAmount);
                player.getInventory().setItem(slot, temp);
            }
        }.runTaskLater(Main.getInstance(), (long) (20 * seconds));
        if (!Main.reloadingTasks.containsKey(player.getUniqueId())) {
            Main.reloadingTasks.put(player.getUniqueId(), new ArrayList<BukkitTask>());
        }
        List<BukkitTask> rr = Main.reloadingTasks.get(player.getUniqueId());
        rr.add(r);
        Main.reloadingTasks.put(player.getUniqueId(), rr);
    }
}
Also used : Ammo(me.zombie_striker.qg.ammo.Ammo) BukkitTask(org.bukkit.scheduler.BukkitTask) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 42 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project QualityArmory by ZombieStriker.

the class CopyOfGunUtil method basicReload.

public static void basicReload(final Gun g, final Player player, boolean doNotRemoveAmmo, double seconds) {
    @SuppressWarnings("deprecation") final ItemStack temp = player.getInventory().getItemInHand();
    ItemMeta im = temp.getItemMeta();
    if (ItemFact.getAmount(temp) == g.getMaxBullets() - 1)
        return;
    if (im.getLore() != null && im.getDisplayName().contains("Reloading.")) {
        try {
            player.getWorld().playSound(player.getLocation(), Sound.BLOCK_LEVER_CLICK, 5, 1);
            return;
        } catch (Error e2) {
            player.getWorld().playSound(player.getLocation(), Sound.valueOf("CLICK"), 5, 1);
        }
    } else {
        try {
            player.getWorld().playSound(player.getLocation(), Sound.BLOCK_LEVER_CLICK, 5, 0.7f);
        } catch (Error e2) {
            player.getWorld().playSound(player.getLocation(), Sound.valueOf("CLICK"), 5, 0.7f);
        }
        final int slot = player.getInventory().getHeldItemSlot();
        Ammo ammo = g.getAmmoType();
        final int initialAmount = ItemFact.getAmount(temp) + 1;
        final int reloadAmount = doNotRemoveAmmo ? g.getMaxBullets() : Math.min(g.getMaxBullets(), initialAmount + AmmoUtil.getAmmoAmount(player, ammo));
        final int subtractAmount = reloadAmount - initialAmount;
        if (!doNotRemoveAmmo)
            AmmoUtil.removeAmmo(player, ammo, subtractAmount);
        im.setLore(ItemFact.getGunLore(g, temp, 1));
        im.setDisplayName(ItemFact.getGunName(g) + " [Reloading...]");
        temp.setItemMeta(im);
        if (Main.enableVisibleAmounts)
            temp.setAmount(1);
        player.getInventory().setItem(slot, temp);
        BukkitTask r = new BukkitRunnable() {

            @Override
            public void run() {
                try {
                    player.getWorld().playSound(player.getLocation(), Sound.BLOCK_LEVER_CLICK, 5, 1);
                    player.getWorld().playSound(player.getLocation(), Sound.BLOCK_LEVER_CLICK, 5, 1.4f);
                } catch (Error e2) {
                    player.getWorld().playSound(player.getLocation(), Sound.valueOf("CLICK"), 5, 1);
                    player.getWorld().playSound(player.getLocation(), Sound.valueOf("CLICK"), 5, 1.4f);
                }
                ItemMeta newim = temp.getItemMeta();
                newim.setLore(ItemFact.getGunLore(g, temp, reloadAmount));
                newim.setDisplayName(ItemFact.getGunName(g));
                temp.setItemMeta(newim);
                if (Main.enableVisibleAmounts)
                    temp.setAmount(reloadAmount);
                player.getInventory().setItem(slot, temp);
            }
        }.runTaskLater(Main.getInstance(), (long) (20 * seconds));
        if (!Main.reloadingTasks.containsKey(player.getUniqueId())) {
            Main.reloadingTasks.put(player.getUniqueId(), new ArrayList<BukkitTask>());
        }
        List<BukkitTask> rr = Main.reloadingTasks.get(player.getUniqueId());
        rr.add(r);
        Main.reloadingTasks.put(player.getUniqueId(), rr);
    }
}
Also used : Ammo(me.zombie_striker.qg.ammo.Ammo) BukkitTask(org.bukkit.scheduler.BukkitTask) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 43 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project QualityArmory by ZombieStriker.

the class Enfield method reload.

@SuppressWarnings("deprecation")
@Override
public void reload(final Player player) {
    if (player.getItemInHand().getAmount() != getMaxBullets()) {
        double amount = (player.getItemInHand().getAmount() + 0d);
        double amountReload = (6.0 - amount) / 6.0;
        double time = (5 * (amountReload));
        GunUtil.basicReload(this, player, WeaponType.isUnlimited(WeaponType.PISTOL), time);
        for (int i = 0; i < 7 - (amount) + 1; i++) {
            new BukkitRunnable() {

                @Override
                public void run() {
                    try {
                        /*
						player.getWorld().playSound(player.getLocation(),
								Sound.BLOCK_PISTON_EXTEND, 5, 4f);
						player.getWorld().playSound(player.getLocation(),
								Sound.BLOCK_SAND_BREAK, 8, 1.4f);*/
                        player.getWorld().playSound(player.getLocation(), WeaponSounds.RELOAD_BULLET.getName(), 1, 1f);
                    } catch (Error e) {
                        player.getWorld().playSound(player.getLocation(), Sound.valueOf("PISTON_EXTEND"), 5, 4f);
                        player.getWorld().playSound(player.getLocation(), Sound.valueOf("DIG_SAND"), 8, 1.4f);
                    }
                }
            }.runTaskLater(Main.getInstance(), (int) (20 * time / 5 * i));
        }
    }
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 44 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project QualityArmory by ZombieStriker.

the class M40 method shoot.

@Override
public boolean shoot(final Player player) {
    if (time.contains(player.getUniqueId()))
        return false;
    if (super.shoot(player)) {
        time.add(player.getUniqueId());
        new BukkitRunnable() {

            @Override
            public void run() {
                try {
                    player.getWorld().playSound(player.getLocation(), Sound.BLOCK_LEVER_CLICK, 5, 1);
                } catch (Error e) {
                    player.getWorld().playSound(player.getLocation(), Sound.valueOf("CLICK"), 5, 1);
                }
            }
        }.runTaskLater(Main.getInstance(), 10);
        new BukkitRunnable() {

            @Override
            public void run() {
                try {
                    player.getWorld().playSound(player.getLocation(), Sound.BLOCK_LEVER_CLICK, 5, 1);
                } catch (Error e) {
                    player.getWorld().playSound(player.getLocation(), Sound.valueOf("CLICK"), 5, 1);
                }
                time.remove(player.getUniqueId());
            }
        }.runTaskLater(Main.getInstance(), 16);
        return true;
    }
    return false;
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 45 with BukkitRunnable

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

the class GUI method event.

// ------------------------------------------------------------
// Events
// ------------------------------------------------------------
@EventHandler(priority = EventPriority.HIGHEST)
public void event(InventoryCloseEvent event) {
    if (inventory != null && inventory.equals(event.getInventory())) {
        final Player player = (Player) event.getPlayer();
        if (watchers.contains(player)) {
            watchers.remove(player);
        }
        onClose(event, player);
        // unregister
        if (unregisterOnClose) {
            new BukkitRunnable() {

                @Override
                public void run() {
                    if (getTotalViewers().isEmpty()) {
                        unregister(false);
                    }
                }
            }.runTaskLater(plugin, 20L);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EventHandler(org.bukkit.event.EventHandler)

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