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);
}
}
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);
}
}
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));
}
}
}
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;
}
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);
}
}
}
Aggregations