[Fixed] Scheduler not working

Discussion in 'Spigot Plugin Development' started by WitherAssassin, Jun 21, 2015.

  1. This is part of the code. It's an event that checks if the player right clicks an item. If so he will be added in the arraylist called "gunpowder" which will let him shoot explosive. The problem is I don't know how to remove him from the arraylist after 5/10 seconds.

    All the code is part of the "PlayerInteractEvent".

    Any help is much appreciated. Sorry if my problem is silly.. I am learning! <3

    I fixed it... in case someone has the same error I replaced

    Code (Text):
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask((Plugin) this, ...

    Code (Text):
    sched.scheduleSyncDelayedTask(JavaPlugin.getProvidingPlugin( class ), ...
    #1 WitherAssassin, Jun 21, 2015
    Last edited: Jun 23, 2015
  2. You've forgotten the Long which tells the Scheduler when to remove the first time.
    Code (Text):
                          Bukkit.getServer().getScheduler().scheduleSyncDelayedTask((Plugin) this, new Runnable() {
                                public void run() {
                                    if (BlockBreak.gunpowder.contains(player.getName()) {
                            }, 0L, 200L);
    If that doesnt work, give me the part wehere you create the Array, please. Do you use Eclipse?
  3. @TimoCrafter Erm it says "The method scheduleSyncDelayedTask(Plugin, Runnable, long) in the type BukkitScheduler is not applicable for the arguments (Plugin, new Runnable(){}, long, long)"

    Yes I use Eclipse
  4. I know I am doing this too early but anyone maybe knows a fix to this?
  5. ?? why shall you give a delayed runnable two longs? one is enough.

    Correct me If I'm wrong, but is #scheduleSyncRepeatingTask() not the only method which requires 2 longs?
  6. yes I knew the same.
  7. Ohhh sry i read "RepatingTask" :D
    Sry, wait, i´ll look for a solution
  8. So does it work?
  9. I would use BukkitRunnable instead.
  10. Look, now i am telling you something to solve every problem while programming:
    Send messages in the chat. For example at the Beginnung of your code do Bukkit.broadcastMessage("1"); , then after something Bukkit.broadcastMessage("2"); ... And when there is a problem, the countig will be stopped (or like that: 1 2 3 5 6 7). Then you know, where exactly the problem is. I think, it´s there where you say (Plugin)this. That´s one of few problems of Eclipse: The converting. Eclipse thinks that it´s ok, but perhaps Spigot can´t convert from this to Plugin....... :D
    Try it out with the numbers!
    I would be grateful for a like if i could help
    • Like Like x 1
  11. lets say
    players is an array list ok.
    // add a try/catch method which waits 10 seconds before the next option available
            try {
            } catch (InterruptedException e) {
  12. Do not do this. Just use the scheduler to schedule a syncDelayedTask for 10 seconds later.
    • Agree Agree x 1
  13. No it does not :( The problem is it doesn't do the task at all.

    So the problem is that the SyncDelayedTask doesn't work at all. I think you might be right it doesn't work because (Plugin) this but if I don't put (Plugin) the SyncDelayedTask gives me an error:/
  14. Can you show use your updated code?
  15. How did you fix it? (because of [Fixed] in the title)
    I think i know how to fix it:
    in the beginning of your class:
    Code (Text):
    public class X extends JavaPlugin implements Listener {
    When you type "extends JavaPlugin", you can write "this" in the Scheduler because then the Class is a plugin and you don't have to convert it. Hava had the same problem yesterday, forgot the extends JavaPlugin :D
    (but you don't have to write it in every class, but in the main and in the classes with the Scheduler
  16. sothatsit


    I think player needed to be final, not even sure how it compiled.
  17. i think that it works with my post :D
    Try it :D
  18. I changed the op post with the fix.. silly fix I guess but I am still a nooby.
  19. come on, everybody has to learn it :D
  20. Hello,
    I had the same problem so I tried your fix, but I need a variable for the sched. part.

    Can you please tell me?
    (I am new to this)