1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 11:45:51 +00:00

Armor Task is now asynchronous

This commit is contained in:
TheBusyBiscuit 2019-10-05 21:16:21 +02:00
parent 9ac4e7eeea
commit 2e77d306e2
2 changed files with 19 additions and 15 deletions

View File

@ -45,14 +45,16 @@ public class ArmorTask implements Runnable {
}
if (item != null && armorpiece.getItem().isPresent()) {
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,6 +71,7 @@ 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)) {
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));
@ -76,8 +79,9 @@ public class ArmorTask implements Runnable {
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
}
}
}

View File

@ -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();