Cant get a repeating task to work

Discussion in 'Plugin Development' started by Awesom_AA, Aug 16, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    Awesom_AA

    Code:
        @EventHandler
        public void onEnable() {
            BukkitScheduler scheduler = getServer().getScheduler();
            scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
                @Override
                public void run() {
                    for (Player player : Bukkit.getOnlinePlayers()) {
                        int oldFood = player.getFoodLevel();
                        int newFood = oldFood + 5;
                        if(newFood > 20) {
                            newFood = 20;
                        }
                        player.setFoodLevel(newFood);
                    }
                }
            }, 0L, 20L);
        }
    Im trying to give everyone online player 5 food every second. I put a couple of broadcast messages and it seems like nothing is running at all.
    Yes I implemented listener/plugin
    Yes I registered the class
    No Errors in terminal

    Am I missing something?
     
  2. Offline

    timtower Moderator Moderator

    @Awesom_AA If that isn't your main class: only the main class gets its onEnable called
     
  3. Offline

    Awesom_AA

    oh ok ty didnt realize that
     
Thread Status:
Not open for further replies.

Share This Page