Files
BattleBane/src/engine/job/JobContainer.java
T

85 lines
2.6 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.job;
public class JobContainer implements Comparable<JobContainer> {
2023-07-15 09:23:48 -04:00
final AbstractJob job;
final long timeOfExecution;
final boolean noTimer;
2022-04-30 09:41:17 -04:00
2025-02-07 11:38:12 -06:00
public JobContainer(AbstractJob job, long timeOfExecution) {
2023-07-15 09:23:48 -04:00
if (job == null) {
throw new IllegalArgumentException("No 'null' jobs allowed.");
}
this.job = job;
this.timeOfExecution = timeOfExecution;
this.noTimer = false;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public JobContainer(AbstractJob job) {
if (job == null) {
throw new IllegalArgumentException("No 'null' jobs allowed.");
}
this.job = job;
this.timeOfExecution = Long.MAX_VALUE;
this.noTimer = true;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public AbstractJob getJob() {
return job;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public boolean noTimer() {
return noTimer;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public long timeOfExection() {
return this.timeOfExecution;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public int timeToExecutionLeft() {
if (JobScheduler.getInstance().isAlive()) {
int timeLeft = (int) (timeOfExecution - System.currentTimeMillis());
if (timeLeft < 0)
timeLeft = 0;
return timeLeft;
} else
return (int) (timeOfExecution - JobScheduler.getInstance().getTimeOfKill());
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
@Override
public int compareTo(JobContainer compared) {
if (timeOfExecution < compared.timeOfExecution) {
return -1;
}
if (timeOfExecution > compared.timeOfExecution) {
return 1;
}
return 0;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
@Override
public boolean equals(Object obj) {
return job.equals(((JobContainer) obj).job);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
@Override
public int hashCode() {
return job.hashCode();
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void cancelJob() {
if (job != null && job instanceof AbstractScheduleJob)
((AbstractScheduleJob) job).cancelJob();
}
2022-04-30 09:41:17 -04:00
}