Git Product home page Git Product logo

betterrunnableapi's Introduction

BetterRunnableAPI

Its project version used in gradle/maven


Small library based on the Bukkit API that allows you to easily create a Task. The code was tested on minecraft version 1.20.4. I did not check compatibility with other versions! After creating new instance of some BetterRunnable, task will start automaticly.

Example of use:

BetterRunnable exampleTask = new BetterRunnable(plugin, task -> {
  System.out.println("Task repeated " + task.executions + " times");

  //Executions is a built-in variable that is added each time a Task executes
  if(task.executions > 50) task.cancel();
}, 20); //20 (ticks) = 1 second, current runnable will be executed every 1 second

The first example creates a synchronous task. This means that you can, for example, change the Minecraft world in it You can also create a group of Tasks that you can operate at once:

BetterRunnableGroup tasksGroup = new BetterRunnableGroup(exampleTask);
BetterRunnable exampleTask2 = new BetterRunnable(plugin, tasksGroup, task -> {}, 20); //You can add tasks to group in constructor

tasksGroup.pauseAll(); //Pause all tasks in group
tasksGroup.unpauseAll(); //Unpause all tasks in group
tasksGroup.cancelAll(); //Cancel all tasks in group

You can create async task as well. Note that the time in BetterAsyncRunnable runs in milliseconds, not ticks!

BetterRunnableGroup tasksAsyncGroup = new BetterRunnableGroup();
BetterAsyncRunnable exampleTask3 = new BetterAsyncRunnable(plugin, tasksAsyncGroup, task -> {
  System.out.println("Async task repeated " + task.executions + " times");
}, 2000); //Repeating every 2 seconds

//Another way to add task to a group
tasksAsyncGroup.addTask(exampleTask3);

tasksAsyncGroup.pauseAll(); //Pause all tasks in group
tasksAsyncGroup.unpauseAll(); //Unpause all tasks in group
tasksAsyncGroup.cancelAll(); //Cancel all tasks in group

You can create delayed task that you can pause! Example:

BetterRunnableGroup delayedTasksGroup = new BetterRunnableGroup();
BetterDelayedRunnable exampleTask4 = new BetterDelayedRunnable(plugin, delayedTasksGroup, task -> {
  System.out.println("Hello from delayed task!");
            
  task.pause(); //Pause delayed task
  new BetterDelayedRunnable(plugin, task2 -> task.unpause(), 20); //Unpause after 1 second (20 ticks)
}, 40); //Execute once after 2 seconds (including pause after 3 seconds)

Similar to BetterAsyncRunnable, you can create an asynchronous delayed task that runs on milliseconds:

//If you do not want to add a task to a group simply insert null
BetterAsyncDelayedRunnable exampleTask5 = new BetterAsyncDelayedRunnable(plugin, null, task -> {
  System.out.println("Hello from delayed async task!");
}, 4000); //Execute once after 4 seconds

Gradle:

repositories {
  mavenCentral()
  maven { url 'https://jitpack.io' }
}

dependencies {
  implementation 'com.github.KubawGaming:BetterRunnableAPI:VERSION_HERE'
}

Maven:

<repository>
  <id>jitpack.io</id>
  <url>https://jitpack.io</url>
</repository>

<dependency>
  <groupId>com.github.KubawGaming</groupId>
  <artifactId>BetterRunnableAPI</artifactId>
  <version>VERSION_HERE</version>
</dependency>

betterrunnableapi's People

Contributors

kubawgaming avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.