mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2024-10-31 19:44:03 +01:00
Started working on Folia support
This commit is contained in:
parent
e862abe0b4
commit
95786e32d2
@ -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()
|
||||||
|
@ -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;
|
||||||
|
@ -203,13 +203,7 @@ 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
|
|
||||||
.getServer()
|
|
||||||
.getScheduler()
|
|
||||||
.runTask(
|
|
||||||
plugin,
|
|
||||||
() -> {
|
|
||||||
try {
|
try {
|
||||||
for (Map.Entry<String, CloudExpansion> entry : values.entrySet()) {
|
for (Map.Entry<String, CloudExpansion> entry : values.entrySet()) {
|
||||||
String name = entry.getKey();
|
String name = entry.getKey();
|
||||||
@ -237,7 +231,6 @@ public final class CloudExpansionManager {
|
|||||||
.log(Level.WARNING, "Failed to download expansion information", e);
|
.log(Level.WARNING, "Failed to download expansion information", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDownloading(@NotNull final CloudExpansion expansion) {
|
public boolean isDownloading(@NotNull final CloudExpansion expansion) {
|
||||||
|
@ -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 {
|
||||||
|
@ -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,8 +55,10 @@ 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();
|
||||||
@ -63,26 +66,32 @@ public class UpdateChecker implements Listener {
|
|||||||
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);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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!"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user