Search in sources :

Example 1 with Ammo

use of me.zombie_striker.qg.ammo.Ammo 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 2 with Ammo

use of me.zombie_striker.qg.ammo.Ammo 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 3 with Ammo

use of me.zombie_striker.qg.ammo.Ammo 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)

Aggregations

Ammo (me.zombie_striker.qg.ammo.Ammo)3 ItemStack (org.bukkit.inventory.ItemStack)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 BukkitTask (org.bukkit.scheduler.BukkitTask)3