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

View File

@ -26,7 +26,7 @@ dependencies {
implementation("org.bstats:bstats-bukkit:3.0.1") implementation("org.bstats:bstats-bukkit:3.0.1")
implementation("net.kyori:adventure-platform-bukkit:4.3.0") 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") compileOnlyApi("org.jetbrains:annotations:23.0.0")
testImplementation("org.openjdk.jmh:jmh-core:1.32") testImplementation("org.openjdk.jmh:jmh-core:1.32")
@ -38,8 +38,8 @@ dependencies {
java { java {
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_17 // this is temp
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_17 // this is temp
withJavadocJar() withJavadocJar()
withSourcesJar() withSourcesJar()

View File

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

View File

@ -203,40 +203,33 @@ public final class CloudExpansionManager {
plugin.getLogger().log(Level.WARNING, "Failed to download expansion information", e); plugin.getLogger().log(Level.WARNING, "Failed to download expansion information", e);
} }
// loop thru what's left on the main thread //todo: Figure out why this was being scheduled back on the main thread
plugin try {
.getServer() for (Map.Entry<String, CloudExpansion> entry : values.entrySet()) {
.getScheduler() String name = entry.getKey();
.runTask( CloudExpansion expansion = entry.getValue();
plugin,
() -> {
try {
for (Map.Entry<String, CloudExpansion> entry : values.entrySet()) {
String name = entry.getKey();
CloudExpansion expansion = entry.getValue();
expansion.setName(name); expansion.setName(name);
Optional<PlaceholderExpansion> localOpt = Optional<PlaceholderExpansion> localOpt =
plugin.getLocalExpansionManager().findExpansionByName(name); plugin.getLocalExpansionManager().findExpansionByName(name);
if (localOpt.isPresent()) { if (localOpt.isPresent()) {
PlaceholderExpansion local = localOpt.get(); PlaceholderExpansion local = localOpt.get();
if (local.isRegistered()) { if (local.isRegistered()) {
expansion.setHasExpansion(true); expansion.setHasExpansion(true);
expansion.setShouldUpdate( expansion.setShouldUpdate(
!local.getVersion().equalsIgnoreCase(expansion.getLatestVersion())); !local.getVersion().equalsIgnoreCase(expansion.getLatestVersion()));
} }
} }
cache.put(toIndexName(expansion), expansion); cache.put(toIndexName(expansion), expansion);
} }
} catch (Throwable e) { } catch (Throwable e) {
// ugly swallowing of every throwable, but we have to be defensive // ugly swallowing of every throwable, but we have to be defensive
plugin plugin
.getLogger() .getLogger()
.log(Level.WARNING, "Failed to download expansion information", e); .log(Level.WARNING, "Failed to download expansion information", e);
} }
});
}); });
} }

View File

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

View File

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

View File

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

View File

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