Skip to content

Instantly share code, notes, and snippets.

@deanveloper
Last active April 25, 2020 14:44
Show Gist options
  • Save deanveloper/06e67ee2d70def256453 to your computer and use it in GitHub Desktop.
Save deanveloper/06e67ee2d70def256453 to your computer and use it in GitHub Desktop.
Easy way to create runnable stuff in BungeeCord, compatible with lambdas as well.
//JAVA 8
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.scheduler.ScheduledTask;
import java.util.concurrent.TimeUnit;
@FunctionalInterface
public interface ProxyRunnable extends Runnable{
default ScheduledTask runAsync(){
return ProxyServer.getInstance().getScheduler().runAsync(<PLUGIN>, this);
}
default ScheduledTask runAfter(long time, TimeUnit unit){
return ProxyServer.getInstance().getScheduler().schedule(<PLUGIN>, this, time, unit);
}
default ScheduledTask runAfterEvery(long time, long repeat, TimeUnit unit){
return ProxyServer.getInstance().getScheduler().schedule(<PLUGIN>, this, time, repeat, unit);
}
}
//earlier versions
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.scheduler.ScheduledTask;
import java.util.concurrent.TimeUnit;
public abstract class ProxyRunnable implements Runnable{
@Override
public abstract void run();
public ScheduledTask runAsync(){
return ProxyServer.getInstance().getScheduler().runAsync(<PLUGIN>, this);
}
public ScheduledTask runAfter(long time, TimeUnit unit){
return ProxyServer.getInstance().getScheduler().schedule(<PLUGIN>, this, time, unit);
}
public ScheduledTask runAfterEvery(long time, long repeat, TimeUnit unit){
return ProxyServer.getInstance().getScheduler().schedule(<PLUGIN>, this, time, repeat, unit);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment