#Make a Runnable run for a dynamic amount of time

1 messages · Page 1 of 1 (latest)

tawdry gulch
#

@charred acorn

charred acorn
#

yeah

tawdry gulch
#

ok so what i am trying to do is

#

make a game that lasts until u get to the end, and i want the runnable to last until the player gets to the end

#

but that can be different for different people

#

im thinking that if i start a loop that runs forever, i can cancel it when the player hits the end

#

but idk how to run a loop indefinitely

charred acorn
#
public class GameRunnable extends BukkitRunnable {

  private final GameState gameState;

  public GameRunnable(GameState gameState) {
    this.gameState = gameState;
  }

  @Override
  public void run() {
    if(gameState.hasEnded()) {
      this.cancel();
      return;
    }
    gameState.tick();
  }
  
}

Example for a BukkitRunnable which stops itself when a condition is met.

tawdry gulch
#

thanks!

charred acorn
#

It would be run like this:

new GameRunnable(state).runTaskTimer(plugin, 10, 10);

10 -> runs once every 10 ticks

tawdry gulch
#

ohhh ive already done this before

#

i just didnt understand it

#

thanks

#

you helped clear up my confusion about it a little

#

do you know how to make a title in the actionbar

#

i cant find any documentation on it