public class Timer {
private long period;
private long start;
public Timer(long period) {
this.period = period;
this.start = System.currentTimeMillis();
}
public long getElapsed() {
return System.currentTimeMillis() - this.start;
}
public long getRemaining() {
return this.period - this.getElapsed();
}
public boolean isRunning() {
return this.getElapsed() <= this.period;
}
public void setPeriod(long period) {
this.period = period;
}
public void reset() {
this.start = System.currentTimeMillis();
}
public static String format(long milliSeconds) {
long secs = milliSeconds / 1000L;
return String.format("%02d:%02d:%02d", secs / 3600L,
secs % 3600L / 60L, secs % 60L);
}
}
//method
public boolean isSmithing() {
boolean isSmith = false;
Timer timer = new Timer(1800);
while (timer.isRunning() && !isSmith) {
isSmith = myPlayer().getAnimation() != -1 ? true : isSmith;
}
return isSmith;
}