1.12.2 Help

Discussion in 'Spigot Plugin Development' started by Nico12, Jan 14, 2020.

  1. Hello I tried to make a scoreboard with an animated title but the title remains static, I did a
    Code (Text):
     for (int i = 0; i <list.size; i ++) {
    o.setDisplayName (list.get (i));
    }
    obviously all this within a BukkitRunnable ().
    I leave the code guys https://pastebin.com/bkbsprz2
    sorry if what I ask sounds rookie, but I am, so your help would be useful and very grateful.
    What it does is that it stays on the last line of the list.
     
    #1 Nico12, Jan 14, 2020
    Last edited: Jan 14, 2020
  2. You are creating a runnable that runs 1 second later and then goes through the for loop in a microsecond.
    What you need to do is edit the line over several ticks. (you can schedule several runnables in your case)

    Some pseudocode:

    Code (Java):
      public void concatAction(List<Runnable> bukkitRunnables) {

        for (int i = 0; i < bukkitRunnables.size(); i++) {
          Bukkit.getScheduler().runTaskLater(plugin, bukkitRunnables.get(i), i);
        }

      }
    So the first action is run at 0 ticks delay
    the second line is after 1 ticks
    the third line after 2 ticks
    ...
    the n'th line aftet n+1 ticks.
     
  3. Ore you run a synchronous, repeating task:
    Code (Java):
    int i = 0;
    Bukkit.getScheduler.scheduleSyncRepeatingTask(plugin, () -> {
        if (i > list.size()) i = 0;
        display(list.get(i++));
    }, 0, 1);
    edit: forgot increment
     
    #3 Schottky, Jan 14, 2020
    Last edited: Jan 14, 2020
  4. display(list.get(i));
    >to>
    display(list.get(i++));
    ;)
    Also you probably need to define "i" in the scope of the anonymous inner class. Otherwise you can only use it when its effectively final.
     
  5. yep. Gonna fix that once I get home.
    For now, you can see my code as „pseudocode“ as well :p