-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adde two events fired when a timer starts and ends. Related to #30.
- Loading branch information
1 parent
ec88403
commit cb90dcb
Showing
6 changed files
with
220 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package me.azenet.UHPlugin; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class UHTimerManager { | ||
|
||
private Map<String,UHTimer> timers = new HashMap<String,UHTimer>(); | ||
private UHTimer mainTimer = null; | ||
|
||
// Cached list of the running timers | ||
private Map<String,UHTimer> runningTimers = new HashMap<String,UHTimer>(); | ||
|
||
public UHTimerManager() { | ||
|
||
} | ||
|
||
/** | ||
* Registers the main timer, used to display the episodes countdown. | ||
* | ||
* @param timer The timer. | ||
*/ | ||
protected void registerMainTimer(UHTimer timer) { | ||
this.mainTimer = timer; | ||
timer.setRegistered(true); | ||
} | ||
|
||
/** | ||
* Returns the main timer, used to display the episodes countdown. | ||
* | ||
* @return The main timer. | ||
*/ | ||
public UHTimer getMainTimer() { | ||
return this.mainTimer; | ||
} | ||
|
||
/** | ||
* Registers a timer. | ||
* | ||
* @param timer The timer to register. | ||
* @throws IllegalArgumentException if a timer with the same name is already registered. | ||
*/ | ||
public void registerTimer(UHTimer timer) { | ||
if(timers.get(timer.getName()) != null) { | ||
throw new IllegalArgumentException("A timer with the name " + timer.getName() + " is already registered."); | ||
} | ||
|
||
timers.put(timer.getName(), timer); | ||
|
||
timer.setRegistered(true); | ||
} | ||
|
||
/** | ||
* Unregisters a timer. | ||
* <p> | ||
* If the timer was not registered, nothing is done. | ||
* | ||
* @param timer The timer to unregister. | ||
*/ | ||
public void unregisterTimer(UHTimer timer) { | ||
timers.remove(timer); | ||
runningTimers.remove(timer); | ||
|
||
timer.setRegistered(false); | ||
} | ||
|
||
/** | ||
* Updates the internal list of started timers. | ||
*/ | ||
public void updateStartedTimersList() { | ||
runningTimers = new HashMap<String,UHTimer>(); | ||
|
||
for(UHTimer timer : timers.values()) { | ||
if(timer.isRunning()) { | ||
runningTimers.put(timer.getName(), timer); | ||
} | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/me/azenet/UHPlugin/events/TimerEndsEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package me.azenet.UHPlugin.events; | ||
|
||
import me.azenet.UHPlugin.UHTimer; | ||
|
||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
|
||
/** | ||
* This event is fired when a timer ends. | ||
* | ||
* @author Amaury Carrade | ||
*/ | ||
public final class TimerEndsEvent extends Event { | ||
|
||
private static final HandlerList handlers = new HandlerList(); | ||
|
||
private UHTimer timer; | ||
private Boolean timerWasUp = false; | ||
|
||
|
||
public TimerEndsEvent(UHTimer timer, Boolean timerUp) { | ||
this.timer = timer; | ||
|
||
this.timerWasUp = timerUp; | ||
} | ||
|
||
/** | ||
* Returns the timer. | ||
* | ||
* @return the timer. | ||
*/ | ||
public UHTimer getTimer() { | ||
return timer; | ||
} | ||
|
||
/** | ||
* Returns true if the timer was stopped because it was up. | ||
* | ||
* @return true if the timer was stopped because it was up. | ||
*/ | ||
public boolean wasTimerUp() { | ||
return timerWasUp; | ||
} | ||
|
||
public HandlerList getHandlers() { | ||
return handlers; | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return handlers; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/me/azenet/UHPlugin/events/TimerStartsEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package me.azenet.UHPlugin.events; | ||
|
||
import me.azenet.UHPlugin.UHTimer; | ||
|
||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
|
||
/** | ||
* This event is fired when a timer ends. | ||
* | ||
* @author Amaury Carrade | ||
*/ | ||
public final class TimerStartsEvent extends Event { | ||
private static final HandlerList handlers = new HandlerList(); | ||
private UHTimer timer; | ||
|
||
public TimerStartsEvent(UHTimer timer) { | ||
this.timer = timer; | ||
} | ||
|
||
/** | ||
* Returns the timer. | ||
* | ||
* @return | ||
*/ | ||
public UHTimer getTimer() { | ||
return timer; | ||
} | ||
|
||
public HandlerList getHandlers() { | ||
return handlers; | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return handlers; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters