package in.twizmwaz.cardinal.module.modules.matchTimer;

import in.twizmwaz.cardinal.GameHandler;
import in.twizmwaz.cardinal.event.MatchStartEvent;
import in.twizmwaz.cardinal.match.Match;
import in.twizmwaz.cardinal.match.MatchState;
import in.twizmwaz.cardinal.module.Module;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;

public class MatchTimer implements Module {

    private long startTime;

    protected MatchTimer() {
    }

    @Override
    public void unload() {
        HandlerList.unregisterAll(this);
    }
    
    @EventHandler
    public void onMatchStart(MatchStartEvent event) {
        this.startTime = System.currentTimeMillis();
    }

    /**
     * @return The current time stored in the module.
     */
    public long getTime() {
        return startTime;
    }

    public static double getTimeInSeconds() {
        Match match = GameHandler.getGameHandler().getMatch();
        if (match.isRunning() || match.getState().equals(MatchState.ENDED) || match.getState().equals(MatchState.CYCLING)) {
            for (MatchTimer timer : GameHandler.getGameHandler().getMatch().getModules().getModules(MatchTimer.class)) {
                return ((double) System.currentTimeMillis() - timer.getTime()) / 1000.0;
            }
        }
        return 0;
    }
}

@@ -87,24 +87,73 @@
 ameHandler;%0A
+import in.twizmwaz.cardinal.event.MatchEndEvent;%0A
 import in.tw
@@ -187,24 +187,24 @@
 StartEvent;%0A
-
 import in.tw
@@ -321,16 +321,42 @@
 Module;%0A
+import org.bukkit.Bukkit;%0A
 import o
@@ -495,16 +495,44 @@
 artTime;
+%0A    private double endTime;
 %0A%0A    pr
@@ -550,24 +550,50 @@
 chTimer() %7B%0A
+        this.endTime = 0;%0A
     %7D%0A%0A    @
@@ -808,24 +808,265 @@
 s();%0A    %7D%0A%0A
+    @EventHandler%0A    public void onMatchEnd(MatchEndEvent event) %7B%0A        this.endTime = ((double) System.currentTimeMillis() - (GameHandler.getGameHandler().getMatch().getModules().getModule(MatchTimer.class)).getTime()) / 1000.0;%0A    %7D%0A%0A
     /**%0A    
@@ -1180,24 +1180,88 @@
 ime;%0A    %7D%0A%0A
+    public double getEndTime() %7B%0A        return endTime;%0A    %7D%0A%0A
     public s
@@ -1386,20 +1386,204 @@
 unning()
- %7C%7C 
+) %7B%0A            return ((double) System.currentTimeMillis() - (GameHandler.getGameHandler().getMatch().getModules().getModule(MatchTimer.class)).getTime()) / 1000.0;%0A        %7D%0A        if (
 match.ge
@@ -1682,31 +1682,14 @@
     
-for (MatchTimer timer :
+return
  Gam
@@ -1747,17 +1747,16 @@
 etModule
-s
 (MatchTi
@@ -1769,114 +1769,22 @@
 ass)
-) %7B%0A                return ((double) System.currentTimeMillis() - timer.getTime()) / 1000.0;%0A            %7D
+.getEndTime();
 %0A   

Stop the match timer when the match ends