scheduleAsyncRepeatingTask won't work anymore and drops warnings in console

Discussion in 'Plugin Development' started by nakadashilover69, Jul 23, 2020.

Thread Status:
Not open for further replies.
  1. Hi Plugin Coders,
    I have a problem regarding the function Bukkit.getServer().scheduleAsyncRepeatingTask. It checks every 2 seconds if any player wears a specific helmet and if so, the player is granted a regeneration effect.
    Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, new BukkitRunnable() {
                public void run() {
                    for (Player current : Bukkit.getOnlinePlayers()) {
                        if (current.getInventory().getHelmet().getItemMeta().getDisplayName().equals("§6Crown")) {
                            current.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, tics, 1));
            }, 0, tics);
    The function as it is used to be working, but after changing the code and then ctrl+z-ing back this shit just stopped working and I am starting to lose my mind. Sorry for inappropriate language. Please help, I also added SuppressWarnings for deprecation
    The console warning:
    [22:16:01 WARN]: Exception in thread "pool-3-thread-297"
    [22:16:01 WARN]: org.apache.commons.lang.UnhandledException: Plugin minecraft_plugin1 v1.0 generated an exception while executing task 2
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$ Source)
    at Source)
    Caused by: java.lang.NullPointerException
    at de.manu.minecraft_plugin1.main.Main$
    ... 3 more

    and it occurs every 2 seconds.
  2. Offline

    timtower Moderator Moderator

    @nakadashilover69 Don't do it async, there is no need for that.
    Might not be a helmet, might not have a displayname.
    2 things that can return null.
  3. Thanks for your reply.
    It is intended to do nothing if the player doesn't wear the Helmet named "§6Crown", it's a ShapedRecipe that you can craft. If a player is wearing it, the player should be granted a potion. Doing it sync instead of async won't solve the problem either, I already tried that.
  4. Offline

    timtower Moderator Moderator

    You should not call Bukkit things asyc, that is why I said that. (no need for here either)
    Your issue are the nullpointers that you can have, you are not checking if there is a helmet, not checking if there is a displayname.
  5. I did not change the code in any way and as I started it up today, it worked fine for some reason... Thank you for your help tho.
  6. Offline

    timtower Moderator Moderator

    Because you have a helmet with a custom name, try it without helmet.
Thread Status:
Not open for further replies.

Share This Page