Renames activatedTime to triggeredTime and makes some public fields private
Makes the active portals queue and open portals queue and languageLoader fields private Cleans the StargateThread a bit Renames activatedTime to triggeredTime as the dual use (open and activate) made the name confusing
This commit is contained in:
@ -3,7 +3,9 @@ package net.knarcraft.stargate.thread;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
* This class contains the function used to close servers which should no longer be open/active
|
||||
@ -13,29 +15,53 @@ public class StarGateThread implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
long time = System.currentTimeMillis() / 1000;
|
||||
//Close open portals
|
||||
for (Iterator<Portal> iterator = Stargate.openPortalsQueue.iterator(); iterator.hasNext(); ) {
|
||||
Portal portal = iterator.next();
|
||||
closeOpenPortals(time);
|
||||
deactivateActivePortals(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes portals which are open and have timed out
|
||||
*
|
||||
* @param time <p>The current time</p>
|
||||
*/
|
||||
private void closeOpenPortals(long time) {
|
||||
List<Portal> closedPortals = new ArrayList<>();
|
||||
Queue<Portal> openPortalsQueue = Stargate.getStargateConfig().getOpenPortalsQueue();
|
||||
|
||||
for (Portal portal : openPortalsQueue) {
|
||||
//Skip always open and non-open gates
|
||||
if (portal.getOptions().isAlwaysOn() || !portal.isOpen()) {
|
||||
if (portal.getOptions().isAlwaysOn() || portal.getOptions().isRandom() || portal.getOptions().isBungee() ||
|
||||
!portal.isOpen()) {
|
||||
continue;
|
||||
}
|
||||
if (time > portal.getActivatedTime() + Stargate.getGateConfig().getOpenTime()) {
|
||||
if (time > portal.getTriggeredTime() + Stargate.getGateConfig().getOpenTime()) {
|
||||
portal.getPortalOpener().closePortal(false);
|
||||
iterator.remove();
|
||||
closedPortals.add(portal);
|
||||
}
|
||||
}
|
||||
//Deactivate active portals
|
||||
for (Iterator<Portal> iterator = Stargate.activePortalsQueue.iterator(); iterator.hasNext(); ) {
|
||||
Portal portal = iterator.next();
|
||||
openPortalsQueue.removeAll(closedPortals);
|
||||
}
|
||||
|
||||
/**
|
||||
* De-activates portals which are active and have timed out
|
||||
*
|
||||
* @param time <p>The current time</p>
|
||||
*/
|
||||
private void deactivateActivePortals(long time) {
|
||||
List<Portal> deactivatedPortals = new ArrayList<>();
|
||||
Queue<Portal> activePortalsQueue = Stargate.getStargateConfig().getActivePortalsQueue();
|
||||
|
||||
for (Portal portal : activePortalsQueue) {
|
||||
//Skip portals which aren't active
|
||||
if (!portal.getPortalActivator().isActive()) {
|
||||
continue;
|
||||
}
|
||||
if (time > portal.getActivatedTime() + Stargate.getGateConfig().getActiveTime()) {
|
||||
if (time > portal.getTriggeredTime() + Stargate.getGateConfig().getActiveTime()) {
|
||||
portal.getPortalActivator().deactivate();
|
||||
iterator.remove();
|
||||
deactivatedPortals.add(portal);
|
||||
}
|
||||
}
|
||||
activePortalsQueue.removeAll(deactivatedPortals);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user