Stargate Rewritten

Stargate Rewritten

241 Downloads

Scheduled Stargate verification

EpicKnarvik97 opened this issue ยท 1 comments

commented

As there are cases where Stargate might be broken by external causes which are undetectable, it would make sense to periodically verify the integrity of Stargates and remove any Stargates that have a broken frame.

Example code logic:

public class PortalVerification implements Runnable {
    
    private boolean isRunning;
    private boolean hasQueue;
    private Set<RealPortal> portalsToVerify;
    
    @Override
    public static void run() {
        //If already running or no work is necessary, skip
        if (isRunning || !hasQueue) {
            return;
        }
        //Update running and queue state
        hasQueue = false;
        isRunning = true;

        //Store and reset the portals to verify
        Set<RealPortal> portalsToCheck;
        if (portalsToVerify != null) {
          portalsToCheck = new HashSet(portalsToVerify);
          portalsToVerify = null;
        } else {
          portalsToCheck = null;//TODO: Get all portals
        }

        //TODO: Do verification stuff here

        //Update running state when finished
        isRunning = false;
    }

    /**
    * Schedules the verification of the given set of Stargates
    */
    public void scheduleVerification(Set<RealPortal> portals) {
      if (portalsToVerify == null) {
        portalsToVerify = portals;
      } else {
        portalsToVerify.addAll(portals);
      }
      scheduleVerification();
    }
    
    /**
    * Schedules the verification of all Stargates 
    */
    public void scheduleVerification() {
        //Notify run() of additional work
        hasQueue = true;
        //Run immediately if possible
        if (!isRunning) {
            run();
        }
    }

}

PortalVerification would basically be run asynchronously every second or so, with scheduleVerification() being called every 5-60 seconds. The method which supplies a set of portals can be used for WorldEdit or similar where the set of affected Stargates is known.

commented

The behavior for #208 has been implemented, I think that's enough for this, I will close this as not planned.