Skip to content

Instantly share code, notes, and snippets.

@Deamon5550
Created September 14, 2014 21:12
Show Gist options
  • Save Deamon5550/d8dd9901768f0d31066c to your computer and use it in GitHub Desktop.
Save Deamon5550/d8dd9901768f0d31066c to your computer and use it in GitHub Desktop.
public void startTask(BukkitScheduler scheduler)
{
// If there is already an existing task, cancel it
if (this.task != null)
{
this.task.cancel();
}
// start the task
this.task = scheduler.runTaskTimer(PluginInstance.getPlugin(), new Runnable()
{
@Override
public void run()
{
int count = 0;
while (count < MinecraftConfiguration.WCB_SIZE && !changeQueue.isEmpty())
{
// fetch the top change in the queue
WorldChange change = changeQueue.peek();
// if the queue is not empty
if (change != null)
{
// place the next section of the change
int part = change.placePart(count);
// if the change has now finished executing, remove it
if (change.isDone())
{
// if the change has a runnable task, execute it
if (change.getRunnable() != null)
{
change.getRunnable().run();
}
// remove this change from the queue
changeQueue.remove(change);
}
count += part;
}
}
}
}, 1, this.interval);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment