Started working on Folia support

This commit is contained in:
darbyjack 2023-03-24 13:26:56 -05:00
parent e862abe0b4
commit 95786e32d2
No known key found for this signature in database
GPG Key ID: E7AAD80A943C1F67
7 changed files with 57 additions and 56 deletions

@ -26,7 +26,7 @@ dependencies {
implementation("org.bstats:bstats-bukkit:3.0.1")
implementation("net.kyori:adventure-platform-bukkit:4.3.0")
compileOnly("org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT")
compileOnlyApi("dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT") // this is temp
compileOnlyApi("org.jetbrains:annotations:23.0.0")
testImplementation("org.openjdk.jmh:jmh-core:1.32")
@ -38,8 +38,8 @@ dependencies {
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17 // this is temp
targetCompatibility = JavaVersion.VERSION_17 // this is temp
withJavadocJar()
withSourcesJar()

@ -162,7 +162,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
HandlerList.unregisterAll(this);
Bukkit.getScheduler().cancelTasks(this);
Bukkit.getAsyncScheduler().cancelTasks(this); // this is hopefully temp
adventure.close();
adventure = null;

@ -203,13 +203,7 @@ public final class CloudExpansionManager {
plugin.getLogger().log(Level.WARNING, "Failed to download expansion information", e);
}
// loop thru what's left on the main thread
plugin
.getServer()
.getScheduler()
.runTask(
plugin,
() -> {
//todo: Figure out why this was being scheduled back on the main thread
try {
for (Map.Entry<String, CloudExpansion> entry : values.entrySet()) {
String name = entry.getKey();
@ -237,7 +231,6 @@ public final class CloudExpansionManager {
.log(Level.WARNING, "Failed to download expansion information", e);
}
});
});
}
public boolean isDownloading(@NotNull final CloudExpansion expansion) {

@ -269,12 +269,13 @@ public final class LocalExpansionManager implements Listener {
return false;
}
final ExpansionRegisterEvent event = new ExpansionRegisterEvent(expansion);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return false;
}
// this is temp
// final ExpansionRegisterEvent event = new ExpansionRegisterEvent(expansion);
// Bukkit.getPluginManager().callEvent(event);
//
// if (event.isCancelled()) {
// return false;
// }
expansionsLock.lock();
try {

@ -24,6 +24,7 @@ import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import javax.net.ssl.HttpsURLConnection;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.util.Msg;
@ -54,8 +55,10 @@ public class UpdateChecker implements Listener {
return spigotVersion;
}
//todo: Figure out a better approach for this?
public void fetch() {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
CompletableFuture<Boolean> update = new CompletableFuture<>();
CompletableFuture.supplyAsync(() -> {
try {
HttpsURLConnection con = (HttpsURLConnection) new URL(
"https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection();
@ -63,26 +66,32 @@ public class UpdateChecker implements Listener {
spigotVersion = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
} catch (Exception ex) {
plugin.getLogger().info("Failed to check for updates on spigot.");
return;
return false;
}
if (spigotVersion == null || spigotVersion.isEmpty()) {
return;
plugin.getLogger().info("Failed to check for updates on spigot.");
return false;
}
updateAvailable = spigotIsNewer();
if (!updateAvailable) {
return;
plugin.getLogger().info("PlaceholderAPI is up to date.");
return false;
}
Bukkit.getScheduler().runTask(plugin, () -> {
return true;
});
update.whenComplete((result, error) -> {
if (result) {
plugin.getLogger()
.info("An update for PlaceholderAPI (v" + getSpigotVersion() + ") is available at:");
plugin.getLogger()
.info("https://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID + "/");
Bukkit.getPluginManager().registerEvents(this, plugin);
});
Bukkit.getPluginManager().registerEvents(UpdateChecker.this, plugin);
}
});
}

@ -40,11 +40,7 @@ public final class Futures {
@NotNull final CompletableFuture<T> future,
@NotNull final BiConsumer<T, Throwable> consumer) {
future.whenComplete((value, exception) -> {
if (Bukkit.isPrimaryThread()) {
consumer.accept(value, exception);
} else {
Bukkit.getScheduler().runTask(plugin, () -> consumer.accept(value, exception));
}
});
}

@ -4,6 +4,8 @@ main: "me.clip.placeholderapi.PlaceholderAPIPlugin"
version: ${version}
author: HelpChat
folia-supported: true
api-version: "1.13"
description: "An awesome placeholder provider!"