From 2e77d306e2d7a223f6d2e850bbf9a1fb6b268029 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sat, 5 Oct 2019 21:16:21 +0200 Subject: [PATCH] Armor Task is now asynchronous --- .../Slimefun/Objects/tasks/ArmorTask.java | 32 +++++++++++-------- .../Slimefun/SlimefunPlugin.java | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/Objects/tasks/ArmorTask.java b/src/me/mrCookieSlime/Slimefun/Objects/tasks/ArmorTask.java index e7cb4a979..9a483af71 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/tasks/ArmorTask.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/tasks/ArmorTask.java @@ -45,14 +45,16 @@ public class ArmorTask implements Runnable { } if (item != null && armorpiece.getItem().isPresent()) { - for (PotionEffect effect: armorpiece.getItem().get().getEffects()) { - p.removePotionEffect(effect.getType()); - p.addPotionEffect(effect); - } + Bukkit.getScheduler().runTask(SlimefunPlugin.instance, () -> { + for (PotionEffect effect: armorpiece.getItem().get().getEffects()) { + p.removePotionEffect(effect.getType()); + p.addPotionEffect(effect); + } + }); } } - if (SlimefunManager.isItemSimiliar(p.getInventory().getHelmet(), SlimefunItems.SOLAR_HELMET, false) && Slimefun.hasUnlocked(p, SlimefunItem.getByID("SOLAR_HELMET"), true) && (p.getWorld().getTime() < 12300 || p.getWorld().getTime() > 23850 && p.getEyeLocation().getBlock().getLightFromSky() == 15)) { + if (SlimefunManager.isItemSimiliar(p.getInventory().getHelmet(), SlimefunItems.SOLAR_HELMET, true) && Slimefun.hasUnlocked(p, SlimefunItem.getByID("SOLAR_HELMET"), true) && (p.getWorld().getTime() < 12300 || p.getWorld().getTime() > 23850 && p.getEyeLocation().getBlock().getLightFromSky() == 15)) { ItemEnergy.chargeInventory(p, Float.valueOf(String.valueOf(Slimefun.getItemValue("SOLAR_HELMET", "charge-amount")))); } @@ -69,15 +71,17 @@ public class ArmorTask implements Runnable { // If the item is enabled in the world, then make radioactivity do its job if (Slimefun.isEnabled(p, radioactive, false)) { - p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 400, 3)); - p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 400, 3)); - p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 400, 3)); - p.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 400, 3)); - p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 400, 1)); - p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 400, 1)); - p.setFireTicks(400); - break; - // Break the loop to save some calculations + Bukkit.getScheduler().runTask(SlimefunPlugin.instance, () -> { + p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 400, 3)); + p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 400, 3)); + p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 400, 3)); + p.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 400, 3)); + p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 400, 1)); + p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 400, 1)); + p.setFireTicks(400); + }); + + break; } } } diff --git a/src/me/mrCookieSlime/Slimefun/SlimefunPlugin.java b/src/me/mrCookieSlime/Slimefun/SlimefunPlugin.java index 67017183d..1829edfe0 100644 --- a/src/me/mrCookieSlime/Slimefun/SlimefunPlugin.java +++ b/src/me/mrCookieSlime/Slimefun/SlimefunPlugin.java @@ -264,7 +264,7 @@ public final class SlimefunPlugin extends JavaPlugin { // Armor Update Task if (config.getBoolean("options.enable-armor-effects")) { - getServer().getScheduler().runTaskTimer(this, new ArmorTask(), 0L, config.getInt("options.armor-update-interval") * 20L); + getServer().getScheduler().runTaskTimerAsynchronously(this, new ArmorTask(), 0L, config.getInt("options.armor-update-interval") * 20L); } ticker = new TickerTask();