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

Commit

Permalink
add isSync
Browse files Browse the repository at this point in the history
  • Loading branch information
Euphillya committed Mar 16, 2024
1 parent d269c41 commit 7008c91
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 32 deletions.
7 changes: 4 additions & 3 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.6"
version = "1.1.7"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ public void cancel() {
public int getTaskId() {
return this.executors.hashCode();
}

@Override
public boolean isSync() {
return false;
}
}
57 changes: 30 additions & 27 deletions src/main/java/fr/euphyllia/energie/folia/FoliaScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@ public FoliaScheduler(Plugin pluginBukkit) {
periodTicks = 1;
}
ScheduledTask scheduledTask;
boolean isSynchronous = !schedulerType.equals(SchedulerType.ASYNC);
if (schedulerType.equals(SchedulerType.ASYNC)) {
scheduledTask = Bukkit.getAsyncScheduler().runAtFixedRate(this.plugin, task -> {
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task);
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task, isSynchronous);
mapSchedulerTask.put(schedulerTask.getTaskId(), schedulerTask);
callBack.run(schedulerTask);
}, initialDelayTicks * 50, periodTicks * 50, TimeUnit.MILLISECONDS);

} else {
scheduledTask = Bukkit.getGlobalRegionScheduler().runAtFixedRate(this.plugin, task -> {
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task);
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task, isSynchronous);
mapSchedulerTask.put(schedulerTask.getTaskId(), schedulerTask);
callBack.run(schedulerTask);
}, initialDelayTicks, periodTicks);
}
return new FoliaSchedulerTask(scheduledTask);
return new FoliaSchedulerTask(scheduledTask, isSynchronous);
}

@Override
Expand All @@ -74,11 +75,11 @@ public FoliaScheduler(Plugin pluginBukkit) {
periodTicks = 1;
}
ScheduledTask scheduledTask = Bukkit.getRegionScheduler().runAtFixedRate(this.plugin, worldChunk.world(), worldChunk.chunkX(), worldChunk.chunkZ(), task -> {
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task);
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task, true);
mapSchedulerTask.put(schedulerTask.getTaskId(), schedulerTask);
callBack.run(schedulerTask);
}, initialDelayTicks, periodTicks);
return new FoliaSchedulerTask(scheduledTask);
return new FoliaSchedulerTask(scheduledTask, true);
}
}

Expand All @@ -94,11 +95,11 @@ public FoliaScheduler(Plugin pluginBukkit) {
periodTicks = 1;
}
ScheduledTask scheduledTask = Bukkit.getRegionScheduler().runAtFixedRate(this.plugin, location, task -> {
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task);
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task, true);
mapSchedulerTask.put(schedulerTask.getTaskId(), schedulerTask);
callBack.run(schedulerTask);
}, initialDelayTicks, periodTicks);
return new FoliaSchedulerTask(scheduledTask);
return new FoliaSchedulerTask(scheduledTask, true);
}
}

Expand All @@ -114,11 +115,11 @@ public FoliaScheduler(Plugin pluginBukkit) {
periodTicks = 1;
}
ScheduledTask scheduledTask = entity.getScheduler().runAtFixedRate(this.plugin, task -> {
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task);
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task, true);
mapSchedulerTask.put(schedulerTask.getTaskId(), schedulerTask);
callBack.run(schedulerTask);
}, retired, initialDelayTicks, periodTicks);
return new FoliaSchedulerTask(scheduledTask);
return new FoliaSchedulerTask(scheduledTask, true);
}
}

Expand All @@ -128,20 +129,21 @@ public FoliaScheduler(Plugin pluginBukkit) {
delayTicks = 1;
}
ScheduledTask scheduledTask;
boolean isSynchronous = !schedulerType.equals(SchedulerType.ASYNC);
if (schedulerType.equals(SchedulerType.ASYNC)) {
scheduledTask = Bukkit.getAsyncScheduler().runDelayed(this.plugin, task -> {
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task);
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task, isSynchronous);
mapSchedulerTask.put(schedulerTask.getTaskId(), schedulerTask);
callBack.run(schedulerTask);
}, delayTicks * 50, TimeUnit.MILLISECONDS);
} else {
scheduledTask = Bukkit.getGlobalRegionScheduler().runDelayed(this.plugin, task -> {
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task);
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task, isSynchronous);
mapSchedulerTask.put(schedulerTask.getTaskId(), schedulerTask);
callBack.run(schedulerTask);
}, delayTicks);
}
return new FoliaSchedulerTask(scheduledTask);
return new FoliaSchedulerTask(scheduledTask, isSynchronous);
}

@Override
Expand All @@ -153,11 +155,11 @@ public FoliaScheduler(Plugin pluginBukkit) {
delayTicks = 1;
}
ScheduledTask scheduledTask = Bukkit.getRegionScheduler().runDelayed(this.plugin, worldChunk.world(), worldChunk.chunkX(), worldChunk.chunkZ(), task -> {
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task);
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task, true);
mapSchedulerTask.put(schedulerTask.getTaskId(), schedulerTask);
callBack.run(schedulerTask);
}, delayTicks);
return new FoliaSchedulerTask(scheduledTask);
return new FoliaSchedulerTask(scheduledTask, true);
}
}

Expand All @@ -170,11 +172,11 @@ public FoliaScheduler(Plugin pluginBukkit) {
delayTicks = 1;
}
ScheduledTask scheduledTask = Bukkit.getRegionScheduler().runDelayed(this.plugin, location, task -> {
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task);
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task, true);
mapSchedulerTask.put(schedulerTask.getTaskId(), schedulerTask);
callBack.run(schedulerTask);
}, delayTicks);
return new FoliaSchedulerTask(scheduledTask);
return new FoliaSchedulerTask(scheduledTask, true);
}
}

Expand All @@ -187,31 +189,32 @@ public FoliaScheduler(Plugin pluginBukkit) {
delayTicks = 1;
}
ScheduledTask scheduledTask = entity.getScheduler().runDelayed(this.plugin, task -> {
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task);
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task, true);
mapSchedulerTask.put(schedulerTask.getTaskId(), schedulerTask);
callBack.run(schedulerTask);
}, retired, delayTicks);
return new FoliaSchedulerTask(scheduledTask);
return new FoliaSchedulerTask(scheduledTask, true);
}
}

@Override
public @Nullable SchedulerTaskInter runTask(@NotNull SchedulerType schedulerType, SchedulerCallBack callBack) {
ScheduledTask scheduledTask;
boolean isSynchronous = !schedulerType.equals(SchedulerType.ASYNC);
if (schedulerType.equals(SchedulerType.ASYNC)) {
scheduledTask = Bukkit.getAsyncScheduler().runNow(this.plugin, task -> {
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task);
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task, isSynchronous);
mapSchedulerTask.put(schedulerTask.getTaskId(), schedulerTask);
callBack.run(schedulerTask);
});
} else {
scheduledTask = Bukkit.getGlobalRegionScheduler().run(this.plugin, task -> {
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task);
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task, isSynchronous);
mapSchedulerTask.put(schedulerTask.getTaskId(), schedulerTask);
callBack.run(schedulerTask);
});
}
return new FoliaSchedulerTask(scheduledTask);
return new FoliaSchedulerTask(scheduledTask, isSynchronous);
}

@Override
Expand All @@ -220,11 +223,11 @@ public FoliaScheduler(Plugin pluginBukkit) {
return this.runTask(schedulerType, callBack);
} else {
ScheduledTask scheduledTask = Bukkit.getRegionScheduler().run(this.plugin, worldChunk.world(), worldChunk.chunkX(), worldChunk.chunkZ(), task -> {
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task);
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task, true);
mapSchedulerTask.put(schedulerTask.getTaskId(), schedulerTask);
callBack.run(schedulerTask);
});
return new FoliaSchedulerTask(scheduledTask);
return new FoliaSchedulerTask(scheduledTask, true);
}
}

Expand All @@ -234,11 +237,11 @@ public FoliaScheduler(Plugin pluginBukkit) {
return this.runTask(schedulerType, callBack);
} else {
ScheduledTask scheduledTask = Bukkit.getRegionScheduler().run(this.plugin, location, task -> {
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task);
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task, true);
mapSchedulerTask.put(schedulerTask.getTaskId(), schedulerTask);
callBack.run(schedulerTask);
});
return new FoliaSchedulerTask(scheduledTask);
return new FoliaSchedulerTask(scheduledTask, true);
}
}

Expand All @@ -248,11 +251,11 @@ public FoliaScheduler(Plugin pluginBukkit) {
return this.runTask(schedulerType, callBack);
} else {
ScheduledTask scheduledTask = entity.getScheduler().run(this.plugin, task -> {
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task);
SchedulerTaskInter schedulerTask = new FoliaSchedulerTask(task, true);
mapSchedulerTask.put(schedulerTask.getTaskId(), schedulerTask);
callBack.run(schedulerTask);
}, retired);
return new FoliaSchedulerTask(scheduledTask);
return new FoliaSchedulerTask(scheduledTask, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
public class FoliaSchedulerTask implements SchedulerTaskInter {

private final ScheduledTask schedulerTask;
private boolean isSynchronous = false;

public FoliaSchedulerTask(ScheduledTask schedulerTask) {
public FoliaSchedulerTask(ScheduledTask schedulerTask, boolean sync) {
this.schedulerTask = schedulerTask;
this.isSynchronous = sync;
}


Expand All @@ -33,4 +35,9 @@ public void cancel() {
public int getTaskId() {
return this.schedulerTask.hashCode();
}

@Override
public boolean isSync() {
return this.isSynchronous;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ public void cancel() {
public int getTaskId() {
return this.task.getTaskId();
}

@Override
public boolean isSync() {
return this.task.isSync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface SchedulerTaskInter {
void cancel();

int getTaskId();

boolean isSync();
}

0 comments on commit 7008c91

Please # to comment.