Files
2006Scape/2006Redone Server/src/main/java/com/rebotted/tick/Scheduler.java
T
Mr Extremez ef6968b283 Farming Skill, Orb Charging, Battle Staff Creation, etc (#377)
- Farming Skill Added
- Orb charging implemented
- Battle staff creation implemented
- Cleaned up some code
- Stuck command will now tele you from further out in wildy if you are not in combat
- Fixed an issue with amulet of glory
- Added forcechats for npcs at Gnome Agility Course, and for Cows, Ducks and Sheeps just like in actual osrs
- Added base for God Book preaching
2020-02-19 08:46:00 -05:00

59 lines
1.1 KiB
Java

package com.rebotted.tick;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
/**
* A class which schedules the execution of {@link Tick}s.
*
* @author Graham
*/
public final class Scheduler {
/**
* A list of active ticks.
*/
private final List<Tick> ticks = new ArrayList<Tick>();
/**
* A queue of ticks that still need to be added.
*/
private final Queue<Tick> newTicks = new ArrayDeque<Tick>();
/**
* Schedules the specified tick.
*
* @param tick
* The tick to schedule.
*/
public void schedule(final Tick tick) {
synchronized (newTicks) {
newTicks.add(tick);
}
}
/**
* This method is called every cycle and executes, adds and removes
* {@link Tick}s.
*/
public void process() {
synchronized (newTicks) {
Tick tick;
while ((tick = newTicks.poll()) != null)
ticks.add(tick);
}
for (Iterator<Tick> it = ticks.iterator(); it.hasNext();) {
Tick tick = it.next();
try {
if (!tick.tick())
it.remove();
} catch (Throwable t) {
t.printStackTrace();
}
}
}
}