mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-10-31 17:23:42 +01:00 
			
		
		
		
	 c34230a82e
			
		
	
	c34230a82e
	
	
	
		
			
			Folia Support --------- Co-authored-by: Rockyers <ethan@yocom.org> Co-authored-by: TechnicallyCoded <technicallycoded@gmail.com> Co-authored-by: HSGamer <huynhqtienvtag@gmail.com>
		
			
				
	
	
		
			29 lines
		
	
	
		
			649 B
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			649 B
		
	
	
	
		
			Java
		
	
	
	
	
	
| package com.gmail.nossr50.util;
 | |
| 
 | |
| import com.tcoded.folialib.wrapper.task.WrappedTask;
 | |
| 
 | |
| import java.util.function.Consumer;
 | |
| 
 | |
| public abstract class CancellableRunnable implements Consumer<WrappedTask> {
 | |
|     private boolean cancelled = false;
 | |
| 
 | |
|     public void cancel() {
 | |
|         cancelled = true;
 | |
|     }
 | |
| 
 | |
|     public abstract void run();
 | |
| 
 | |
|     @Override
 | |
|     public void accept(WrappedTask wrappedTask) {
 | |
|         // Run the task if it hasn't been cancelled
 | |
|         if (!cancelled) {
 | |
|             run();
 | |
|         }
 | |
| 
 | |
|         // Cancel the task if it has been cancelled after running
 | |
|         if (cancelled) {
 | |
|             wrappedTask.cancel();
 | |
|         }
 | |
|     }
 | |
| }
 |