Add ability to lock TickTask.

Prevents adding new entries.
This commit is contained in:
asofold 2012-12-02 16:58:16 +01:00
parent 44b6eb2b2a
commit 2a8b6e3ad2

View File

@ -61,6 +61,9 @@ public class TickTask implements Runnable {
protected static long timeLast = 0; protected static long timeLast = 0;
/** Lock flag set on disable. */
protected static boolean locked = false;
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
// Special static methods, usually not called from outside. // Special static methods, usually not called from outside.
@ -115,6 +118,7 @@ public class TickTask implements Runnable {
* @param checkType * @param checkType
*/ */
public static void requestPermissionUpdate(final String playerName, final CheckType checkType){ public static void requestPermissionUpdate(final String playerName, final CheckType checkType){
if (locked) return;
permissionUpdates.add(new PermissionUpdateEntry(playerName, checkType)); permissionUpdates.add(new PermissionUpdateEntry(playerName, checkType));
} }
@ -124,6 +128,7 @@ public class TickTask implements Runnable {
* @param actions * @param actions
*/ */
public static void requestActionsExecution(final ViolationData actions) { public static void requestActionsExecution(final ViolationData actions) {
if (locked) return;
delayedActions.add(actions); delayedActions.add(actions);
} }
@ -144,10 +149,22 @@ public class TickTask implements Runnable {
return timeStart; return timeStart;
} }
/**
* Time when last time processing was finished.
* @return
*/
public static final long getTimeLast(){ public static final long getTimeLast(){
return timeLast; return timeLast;
} }
/**
* Check if new permission update requests and actions can be added.
* @return True if locked.
*/
public boolean isLocked(){
return locked;
}
//////////////////////////////////////// ////////////////////////////////////////
// Public methods for internal use. // Public methods for internal use.
//////////////////////////////////////// ////////////////////////////////////////
@ -165,6 +182,14 @@ public class TickTask implements Runnable {
taskId = -1; taskId = -1;
} }
/**
* Control if new elements can be added to request queues.
* @param locked
*/
public static void setLocked(boolean locked){
TickTask.locked = locked;
}
////////////////////////// //////////////////////////
// Instance methods // Instance methods
////////////////////////// //////////////////////////