#Make a Runnable run for a dynamic amount of time
1 messages · Page 1 of 1 (latest)
yeah
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
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.
thanks!
It would be run like this:
new GameRunnable(state).runTaskTimer(plugin, 10, 10);
10 -> runs once every 10 ticks