Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folia support #149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions helper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<include>org.spongepowered:configurate-hocon</include>
<include>com.typesafe:config</include>
<include>net.kyori:event-api</include>
<include>com.github.Anon8281:UniversalScheduler</include>
</includes>
</artifactSet>
<relocations>
Expand Down Expand Up @@ -337,6 +338,12 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.Anon8281</groupId>
<artifactId>UniversalScheduler</artifactId>
<version>0.1.3</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
14 changes: 11 additions & 3 deletions helper/src/main/java/me/lucko/helper/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@

package me.lucko.helper;

import com.github.Anon8281.universalScheduler.UniversalScheduler;
import com.github.Anon8281.universalScheduler.scheduling.schedulers.TaskScheduler;
import me.lucko.helper.internal.LoaderUtils;
import me.lucko.helper.plugin.HelperPlugin;
import me.lucko.helper.utils.annotation.NonnullByDefault;

import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.World;
Expand All @@ -37,9 +38,8 @@
import org.bukkit.plugin.ServicesManager;
import org.bukkit.scheduler.BukkitScheduler;

import java.util.Optional;

import javax.annotation.Nullable;
import java.util.Optional;

/**
* Base class for helper, which mainly just proxies calls to {@link Bukkit#getServer()} for convenience.
Expand Down Expand Up @@ -72,6 +72,14 @@ public static ServicesManager services() {
return server().getServicesManager();
}

public static TaskScheduler scheduler() {
return UniversalScheduler.getScheduler(hostPlugin());
}

/**
* Deprecated: not supported by Folia
* */
@Deprecated
public static BukkitScheduler bukkitScheduler() {
return server().getScheduler();
}
Expand Down
21 changes: 5 additions & 16 deletions helper/src/main/java/me/lucko/helper/Schedulers.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package me.lucko.helper;

import com.github.Anon8281.universalScheduler.UniversalRunnable;
import me.lucko.helper.interfaces.Delegate;
import me.lucko.helper.internal.LoaderUtils;
import me.lucko.helper.internal.exception.HelperExceptions;
Expand All @@ -35,19 +36,16 @@
import me.lucko.helper.scheduler.Ticks;
import me.lucko.helper.scheduler.builder.TaskBuilder;
import me.lucko.helper.utils.annotation.NonnullByDefault;

import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitScheduler;

import javax.annotation.Nonnull;
import java.util.Objects;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;

import javax.annotation.Nonnull;

/**
* Provides common instances of {@link Scheduler}.
*/
Expand Down Expand Up @@ -93,9 +91,10 @@ public static Scheduler async() {

/**
* Gets Bukkit's scheduler.
*
* Deprecated: not supported by Folia
* @return bukkit's scheduler
*/
@Deprecated
public static BukkitScheduler bukkit() {
return Helper.bukkitScheduler();
}
Expand Down Expand Up @@ -168,7 +167,7 @@ public Task runRepeating(@Nonnull Consumer<Task> consumer, long delay, @Nonnull
}
}

private static class HelperTask extends BukkitRunnable implements Task, Delegate<Consumer<Task>> {
private static class HelperTask extends UniversalRunnable implements Task, Delegate<Consumer<Task>> {
private final Consumer<Task> backingTask;

private final AtomicInteger counter = new AtomicInteger(0);
Expand Down Expand Up @@ -207,11 +206,6 @@ public boolean stop() {
return !this.cancelled.getAndSet(true);
}

@Override
public int getBukkitId() {
return getTaskId();
}

@Override
public boolean isClosed() {
return this.cancelled.get();
Expand Down Expand Up @@ -264,11 +258,6 @@ public boolean stop() {
}
}

@Override
public int getBukkitId() {
throw new UnsupportedOperationException();
}

@Override
public boolean isClosed() {
return this.cancelled.get();
Expand Down
24 changes: 7 additions & 17 deletions helper/src/main/java/me/lucko/helper/promise/HelperPromise.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,20 @@
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;

import me.lucko.helper.Helper;
import me.lucko.helper.interfaces.Delegate;
import me.lucko.helper.internal.LoaderUtils;
import me.lucko.helper.internal.exception.HelperExceptions;
import me.lucko.helper.scheduler.HelperExecutors;
import me.lucko.helper.scheduler.Ticks;

import org.bukkit.Bukkit;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.function.Supplier;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Implementation of {@link Promise} using the server scheduler.
*
Expand Down Expand Up @@ -172,23 +162,23 @@ private void executeDelayedSync(@Nonnull Runnable runnable, long delayTicks) {
if (delayTicks <= 0) {
executeSync(runnable);
} else {
Bukkit.getScheduler().runTaskLater(LoaderUtils.getPlugin(), HelperExceptions.wrapSchedulerTask(runnable), delayTicks);
Helper.scheduler().runTaskLater(HelperExceptions.wrapSchedulerTask(runnable), delayTicks);
}
}

private void executeDelayedAsync(@Nonnull Runnable runnable, long delayTicks) {
if (delayTicks <= 0) {
executeAsync(runnable);
} else {
Bukkit.getScheduler().runTaskLaterAsynchronously(LoaderUtils.getPlugin(), HelperExceptions.wrapSchedulerTask(runnable), delayTicks);
Helper.scheduler().runTaskLaterAsynchronously(HelperExceptions.wrapSchedulerTask(runnable), delayTicks);
}
}

private void executeDelayedSync(@Nonnull Runnable runnable, long delay, TimeUnit unit) {
if (delay <= 0) {
executeSync(runnable);
} else {
Bukkit.getScheduler().runTaskLater(LoaderUtils.getPlugin(), HelperExceptions.wrapSchedulerTask(runnable), Ticks.from(delay, unit));
Helper.scheduler().runTaskLater(HelperExceptions.wrapSchedulerTask(runnable), Ticks.from(delay, unit));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@

package me.lucko.helper.scheduler;

import me.lucko.helper.internal.LoaderUtils;
import me.lucko.helper.Helper;
import me.lucko.helper.internal.exception.HelperExceptions;

import org.bukkit.Bukkit;

import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;

Expand Down Expand Up @@ -60,14 +58,14 @@ public static void shutdown() {
private static final class BukkitSyncExecutor implements Executor {
@Override
public void execute(Runnable runnable) {
Bukkit.getScheduler().scheduleSyncDelayedTask(LoaderUtils.getPlugin(), HelperExceptions.wrapSchedulerTask(runnable));
Helper.scheduler().scheduleSyncDelayedTask(HelperExceptions.wrapSchedulerTask(runnable));
}
}

private static final class BukkitAsyncExecutor implements Executor {
@Override
public void execute(Runnable runnable) {
Bukkit.getScheduler().runTaskAsynchronously(LoaderUtils.getPlugin(), HelperExceptions.wrapSchedulerTask(runnable));
Helper.scheduler().runTaskAsynchronously(HelperExceptions.wrapSchedulerTask(runnable));
}
}

Expand Down
7 changes: 0 additions & 7 deletions helper/src/main/java/me/lucko/helper/scheduler/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ public interface Task extends Terminable {
*/
boolean stop();

/**
* Gets the Bukkit ID for this task
*
* @return the bukkit id for this task
*/
int getBukkitId();

/**
* {@link #stop() Stops} the task
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@

package me.lucko.helper.scheduler.threadlock;

import me.lucko.helper.internal.LoaderUtils;
import me.lucko.helper.Helper;
import me.lucko.helper.promise.ThreadContext;

import org.bukkit.Bukkit;

import java.util.concurrent.CountDownLatch;

final class ServerThreadLockImpl implements ServerThreadLock {
Expand All @@ -48,7 +46,7 @@ final class ServerThreadLockImpl implements ServerThreadLock {
}

// synchronize with the main thread, then countdown
Bukkit.getScheduler().scheduleSyncDelayedTask(LoaderUtils.getPlugin(), this::signal);
Helper.scheduler().scheduleSyncDelayedTask(this::signal);

// wait for the main thread to become synchronized
await();
Expand Down
1 change: 1 addition & 0 deletions helper/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ website: https://github.com/lucko/helper
load: STARTUP
softdepend: [ProtocolLib, Citizens, ViaVersion]
api-version: 1.13
folia-supported: true
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

</project>