2021-02-11 15:53:54 +01:00
|
|
|
package net.knarcraft.stargate.thread;
|
|
|
|
|
|
|
|
import net.knarcraft.stargate.Stargate;
|
2021-09-20 13:56:30 +02:00
|
|
|
import net.knarcraft.stargate.portal.Portal;
|
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 {
|
|
|
|
|
2021-02-23 19:43:49 +01:00
|
|
|
@Override
|
2021-02-07 03:37:25 +01:00
|
|
|
public void run() {
|
|
|
|
long time = System.currentTimeMillis() / 1000;
|
2021-10-09 03:57:24 +02:00
|
|
|
//Close open portals
|
2021-09-20 18:22:20 +02:00
|
|
|
for (Iterator<Portal> iterator = Stargate.openPortalsQueue.iterator(); iterator.hasNext(); ) {
|
2021-02-22 20:36:37 +01:00
|
|
|
Portal portal = iterator.next();
|
2021-10-09 03:57:24 +02:00
|
|
|
//Skip always open and non-open gates
|
2021-10-08 01:26:12 +02:00
|
|
|
if (portal.getOptions().isAlwaysOn() || !portal.isOpen()) {
|
2021-02-22 20:36:37 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (time > portal.getOpenTime() + Stargate.getOpenTime()) {
|
|
|
|
portal.close(false);
|
2021-02-07 03:37:25 +01:00
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
}
|
2021-10-09 03:57:24 +02:00
|
|
|
//Deactivate active portals
|
2021-09-20 18:22:20 +02:00
|
|
|
for (Iterator<Portal> iterator = Stargate.activePortalsQueue.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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|