Skip to content
1 change: 1 addition & 0 deletions bukkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies {
implementation 'me.lucko:commodore:2.2'
implementation 'net.kyori:adventure-platform-bukkit:4.3.0'

compileOnly 'dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
compileOnly 'org.jetbrains:annotations:24.0.1'
compileOnly 'de.themoep:minedown-adventure:1.7.2-SNAPSHOT'
Expand Down
29 changes: 29 additions & 0 deletions bukkit/src/main/java/net/william278/huskhomes/BukkitHuskHomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package net.william278.huskhomes;

import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler;
import io.papermc.paper.threadedregions.scheduler.RegionScheduler;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.william278.annotaml.Annotaml;
import net.william278.desertwell.util.Version;
Expand Down Expand Up @@ -77,11 +79,13 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
*/
private static final int METRICS_ID = 8430;
private Set<SavedUser> savedUsers;
private final JavaPlugin javaPlugin = this;
private Settings settings;
private Locales locales;
private Database database;
private Validator validator;
private Manager manager;
private final boolean folia = isFolia();
private EventListener eventListener;
private RandomTeleportEngine randomTeleportEngine;
private Spawn serverSpawn;
Expand Down Expand Up @@ -460,6 +464,31 @@ && getSettings().getBrokerType() == Broker.Type.PLUGIN_MESSAGE) {
}
}

public RegionScheduler getRegionScheduler() {
if (folia) {
return this.javaPlugin.getServer().getRegionScheduler();
} else {
return null;
}
}

public GlobalRegionScheduler getGlobalRegionScheduler() {
if (folia) {
return this.javaPlugin.getServer().getGlobalRegionScheduler();
} else {
return null;
}
}

private static boolean isFolia() {
try {
Class.forName("io.papermc.paper.threadedregions.scheduler.RegionScheduler");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}

@Override
@NotNull
public HuskHomes getPlugin() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static BukkitUser adapt(@NotNull Player player) {
@Override
public Position getPosition() {
return Position.at(BukkitAdapter.adaptLocation(player.getLocation())
.orElseThrow(() -> new IllegalStateException("Failed to get the position of a BukkitPlayer (null)")),
.orElseThrow(() -> new IllegalStateException("Failed to get the position of a BukkitPlayer (null)")),
plugin.getServerName());

}
Expand Down Expand Up @@ -114,14 +114,13 @@ public void teleportLocally(@NotNull Location location, boolean asynchronous) th
if (!bukkitLocation.getWorld().getWorldBorder().isInside(resolvedLocation.get())) {
throw new TeleportationException(TeleportationException.Type.ILLEGAL_TARGET_COORDINATES);
}

Bukkit.getScheduler().runTask(plugin, () -> {
plugin.runAsync(() -> {
if (asynchronous) {
PaperLib.teleportAsync(player, bukkitLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
} else {
player.teleport(bukkitLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
}
});
}, location);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import net.william278.huskhomes.BukkitHuskHomes;
import org.bukkit.Bukkit;
import net.william278.huskhomes.position.Location;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.CompletableFuture;
Expand All @@ -29,33 +30,33 @@

public interface BukkitTaskRunner extends TaskRunner {
@Override
default int runAsync(@NotNull Runnable runnable) {
default int runAsync(@NotNull Runnable runnable, Location location) {
return Bukkit.getScheduler().runTaskAsynchronously((BukkitHuskHomes) getPlugin(), runnable).getTaskId();
}

@Override
default <T> CompletableFuture<T> supplyAsync(@NotNull Supplier<T> supplier) {
default <T> CompletableFuture<T> supplyAsync(@NotNull Supplier<T> supplier, Location location) {
final CompletableFuture<T> future = new CompletableFuture<>();
Bukkit.getScheduler().runTaskAsynchronously((BukkitHuskHomes) getPlugin(),
() -> future.complete(supplier.get()));
return future;
}

@Override
default void runSync(@NotNull Runnable runnable) {
Bukkit.getScheduler().runTask((BukkitHuskHomes) getPlugin(), runnable).getTaskId();
default void runSync(@NotNull Runnable runnable, Location location) {
Bukkit.getScheduler().runTask((BukkitHuskHomes) getPlugin(), runnable);
}

@Override
default int runAsyncRepeating(@NotNull Runnable runnable, long period) {
default int runAsyncRepeating(@NotNull Runnable runnable, long period, Location location) {
AtomicInteger taskId = new AtomicInteger();
taskId.set(Bukkit.getScheduler().runTaskTimerAsynchronously((BukkitHuskHomes) getPlugin(),
runnable, 0, period).getTaskId());
return taskId.get();
}

@Override
default void runLater(@NotNull Runnable runnable, long delay) {
default void runLater(@NotNull Runnable runnable, long delay, Location location) {
Bukkit.getScheduler().runTaskLater((BukkitHuskHomes) getPlugin(), runnable, delay).getTaskId();
}

Expand Down
1 change: 1 addition & 0 deletions bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ website: 'https://william278.net/'
main: 'net.william278.huskhomes.BukkitHuskHomes'
version: '${version}'
api-version: 1.16
folia-supported: true
softdepend:
- Vault
- RedisEconomy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ default void editUserData(@NotNull User user, @NotNull Consumer<SavedUser> edito
.ifPresent(result -> {
editor.accept(result);
getDatabase().updateUserData(result);
}));
}), null);
}

/**
Expand Down
Loading