Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from Euphillya/ver/1.2.0
Browse files Browse the repository at this point in the history
Ver/1.2.0
  • Loading branch information
Euphillya authored Mar 26, 2024
2 parents 6485a8d + ea075ff commit 7642ca2
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 469 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "fr.euphyllia"
version = "1.1.9"
version = "1.2.0"

repositories {
mavenCentral()
Expand Down
138 changes: 102 additions & 36 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,111 @@
## API
## What is Energie ?
Energie is a library allowing you to maintain compatibility between Spigot and Folia. The library is still under development, but can be used.

Bukkit/Spigot/Paper :
## Lists of plugins that officially use Energie

```java
// Example Scheduler
Bukkit.getScheduler().runTask(this.plugin, () -> {
// code
});
```
| Name | Github | Download |
|---------|------------------------------------------------|------------------------------------------------------------------------|
| Skyllia | [Github](https://github.com/Euphillya/Skyllia) | [Modrinth](https://modrinth.com/plugin/skyllia/versions#all-versions) |

Folia :
## Setup
```kotlin
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id("java")
id("com.github.johnrengelman.shadow") version "8.1.1"
}

val jitpack = "https://jitpack.io"

repositories {
mavenCentral()
maven(jitpack)
}

dependencies {
implementation("com.github.Euphillya:Energie:TAG")
}

tasks.withType<ShadowJar> {
relocate("fr.euphyllia.energie", "[your plugin].dependency.energie")
}

```java
// Example Scheduler
Bukkit.getGlobalRegionScheduler().run(this.plugin, task -> {
// code
});
Bukkit.getRegionScheduler().run(this.plugin, location, task -> {
// code
});
Entity.getScheduler().run(this.plugin, task -> {
// code
}, retired);
```
## API
The API remains quite simple to use:

### Bukkit Implementation
```java
// before bukkit
private void runTaskBukkitExample() {
// Sync
Bukkit.getScheduler().runTask(JavaPlugin, Callback);
// Async
Bukkit.getScheduler().runTaskAsynchronously(JavaPlugin, Callback);
}

private void runTaskLaterExample() {
Bukkit.getScheduler().runTaskLater(JavaPlugin, Callback, Long);
}

Energie :
private void runTaskTimerExample() {
Bukkit.getScheduler().runTaskTimer(JavaPlugin, Callback, Long, Long);
}

private void runnableExample() {
new BukkitRunnable() {
@Override
public void run() {

}
}.runTask(JavaPlugin);
}
```

### Energie Implementation
```java
Energie energie = new Energie(this.plugin);

Scheduler minecraftScheduler = energie.getScheduler(SchedulerSoft.MINECRAFT);
// Example getGlobalRegionScheduler
minecraftScheduler.runTask(SchedulerType.SYNC, task -> {
// code
});
// Example getRegionScheduler
minecraftScheduler.runTask(SchedulerType.SYNC, (location/MultiRecords.WorldChunk), task -> {
// code
});
// Example EntityScheduler
minecraftScheduler.runTask(SchedulerType.SYNC, entity, task -> {
// code
}, retired);

private @NotNull Energie energie;
private @NotNull Scheduler scheduler;

@Override
public void onEnable() {
this.energie = new Energie(JavaPlugin);
this.scheduler = scheduler.getMinecraftScheduler();
}

public Scheduler getScheduler() {
return scheduler;
}


private void runTaskBukkitExample() {
// Sync
getScheduler().runTask(SchedulerType.SYNC, Callback); // GlobalScheduler
getScheduler().runTask(SchedulerType.SYNC, Location/MultipleRecords.WorldChunk, Callback); // RegionScheduler
getScheduler().runTask(SchedulerType.SYNC, Entity, Callback, Retired); // EntityScheduler

// Async
getScheduler().runTask(SchedulerType.ASYNC, Callback);
}

private void runTaskLaterExample() {
getScheduler().runDelayed(SchedulerType.SYNC, Callback, Long); // global
...
}

private void runTaskTimerExample() {
getScheduler().runAtFixedRate(SchedulerType.SYNC, Callback, Long, Long);
...
}

private void runnableExample() {
new SchedulerTaskRunnable() {
@Override
public void run() {

}
}.runTask(JavaPlugin);
}
```
15 changes: 0 additions & 15 deletions src/main/java/fr/euphyllia/energie/Energie.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,4 @@ public Scheduler getMinecraftScheduler() {
}
return this.legacyScheduler;
}

@Deprecated
public Scheduler getScheduler(SchedulerSoft schedulerSoft) {
if (schedulerSoft == SchedulerSoft.NATIVE) {
return this.getNativeScheduler();
} else if (schedulerSoft == SchedulerSoft.MINECRAFT) {
return this.getMinecraftScheduler();
}
throw new UnsupportedOperationException();
}

@Deprecated
public enum SchedulerSoft {
NATIVE, MINECRAFT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,60 +218,6 @@ public int scheduleSyncRepeating(@NotNull SchedulerType schedulerType, Entity en
throw new UnsupportedOperationException();
}

@Override
@Deprecated
public void runAtFixedRate(@NotNull SchedulerType schedulerType, long initialDelayTicks, long periodTicks, SchedulerCallBack callBack) {
this.runAtFixedRate(schedulerType, callBack, initialDelayTicks, periodTicks);
}

@Override
@Deprecated
public void runAtFixedRate(@NotNull SchedulerType schedulerType, @Nullable Object chunkOrLoc, long initialDelayTicks, long periodTicks, SchedulerCallBack callBack) {
throw new UnsupportedOperationException();
}

@Override
@Deprecated
public void runAtFixedRate(@NotNull SchedulerType schedulerType, @Nullable Object chunkOrLocOrEntity, @Nullable Runnable retired, long initialDelayTicks, long periodTicks, SchedulerCallBack callBack) {
throw new UnsupportedOperationException();
}

@Override
@Deprecated
public void runDelayed(@NotNull SchedulerType schedulerType, long delayTicks, SchedulerCallBack callBack) {
this.runDelayed(schedulerType, callBack, delayTicks);
}

@Override
@Deprecated
public void runDelayed(@NotNull SchedulerType schedulerType, @Nullable Object chunkOrLoc, long delayTicks, SchedulerCallBack callBack) {
throw new UnsupportedOperationException();
}

@Override
@Deprecated
public void runDelayed(@NotNull SchedulerType schedulerType, @Nullable Object chunkOrLocOrEntity, @Nullable Runnable retired, long delayTicks, SchedulerCallBack callBack) {
throw new UnsupportedOperationException();
}

@Override
@Deprecated
public void execute(@NotNull SchedulerType schedulerType, SchedulerCallBack callBack) {
this.runTask(schedulerType, callBack);
}

@Override
@Deprecated
public void execute(@NotNull SchedulerType schedulerType, @Nullable Object chunkOrLoc, SchedulerCallBack callBack) {
throw new UnsupportedOperationException();
}

@Override
@Deprecated
public void execute(@NotNull SchedulerType schedulerType, @Nullable Object chunkOrLocOrEntity, @Nullable Runnable retired, SchedulerCallBack callBack) {
throw new UnsupportedOperationException();
}

@Override
public List<SchedulerTaskInter> getPendingTasks() {
return new ArrayList<>(mapSchedulerTask.values());
Expand Down
Loading

0 comments on commit 7642ca2

Please # to comment.