Delaying for

Discussion in 'Spigot Plugin Development' started by MaskenLP, Jun 21, 2016.

  1. Code (Text):

    for (int i = 0; i < 100;) {
                    new Thread(new Runnable() {

                        public void run() {
                            try {
                                Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

                                    public void run() {
                                        i ++;

                            } catch (InterruptedException e) {

    so far so good but the Problem is i++ how do I have to modify this code ?
    Error: Local variable i defined in an enclosing scope must be final or effectively final
  2. Why you don't put the i++ in the for loop? Like for(int i= 0;i<100;i++)
  3. can I insert also a delay there?
  4. MiniDigger


    wat are you trying to do? currently you are spawning 100 threads that sleep for a second and send the player a message. so after a second the player gets 100 messages (if that would compile of corse)
  5. I would like to send the Player every 10 seconds a Message
  6. MiniDigger


    use the bukkit scheduler for that.
    use the runTaskTimer method to schedule a task that gets executed every 10 seconds (200 ticks). then you can send the message in that task.
  7. MiniDigger


    well good idea. if you make a final copy of i its final = you can't change it anymore. op should not be playing with threads but use the bukkit scheduler for his task.
  8. would you be so nice to give me the code ? or the modifyed one ?
  9. MiniDigger


    no. I don't spoonfeed. I did explain what you should do in detail above.
  10. how can I make this final copy of i
    • Funny Funny x 1
  11. MiniDigger


    just don't as that would not fix your problem. do that: