2021-02-11 15:53:54 +01:00
|
|
|
package net.knarcraft.stargate.thread;
|
|
|
|
|
2021-02-22 17:01:47 +01:00
|
|
|
import net.knarcraft.stargate.portal.Portal;
|
2021-02-11 15:53:54 +01:00
|
|
|
import net.knarcraft.stargate.Stargate;
|
2021-02-07 03:37:25 +01:00
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class contains the function used to close servers which should no longer be open/active
|
|
|
|
*/
|
|
|
|
public class StarGateThread implements Runnable {
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
long time = System.currentTimeMillis() / 1000;
|
|
|
|
// Close open portals
|
|
|
|
for (Iterator<Portal> iterator = Stargate.openList.iterator(); iterator.hasNext(); ) {
|
2021-02-22 20:36:37 +01:00
|
|
|
Portal portal = iterator.next();
|
|
|
|
// Skip always open and non-open gates
|
|
|
|
if (portal.isAlwaysOn() || !portal.isOpen()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (time > portal.getOpenTime() + Stargate.getOpenTime()) {
|
|
|
|
portal.close(false);
|
2021-02-07 03:37:25 +01:00
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Deactivate active portals
|
|
|
|
for (Iterator<Portal> iterator = Stargate.activeList.iterator(); iterator.hasNext(); ) {
|
2021-02-22 20:36:37 +01:00
|
|
|
Portal portal = iterator.next();
|
|
|
|
if (!portal.isActive()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (time > portal.getOpenTime() + Stargate.getActiveTime()) {
|
|
|
|
portal.deactivate();
|
2021-02-07 03:37:25 +01:00
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|