mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI.git
synced 2024-11-25 12:05:12 +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("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,40 +203,33 @@ 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,
|
||||
() -> {
|
||||
try {
|
||||
for (Map.Entry<String, CloudExpansion> entry : values.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
CloudExpansion expansion = entry.getValue();
|
||||
//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();
|
||||
CloudExpansion expansion = entry.getValue();
|
||||
|
||||
expansion.setName(name);
|
||||
expansion.setName(name);
|
||||
|
||||
Optional<PlaceholderExpansion> localOpt =
|
||||
plugin.getLocalExpansionManager().findExpansionByName(name);
|
||||
if (localOpt.isPresent()) {
|
||||
PlaceholderExpansion local = localOpt.get();
|
||||
if (local.isRegistered()) {
|
||||
expansion.setHasExpansion(true);
|
||||
expansion.setShouldUpdate(
|
||||
!local.getVersion().equalsIgnoreCase(expansion.getLatestVersion()));
|
||||
}
|
||||
}
|
||||
Optional<PlaceholderExpansion> localOpt =
|
||||
plugin.getLocalExpansionManager().findExpansionByName(name);
|
||||
if (localOpt.isPresent()) {
|
||||
PlaceholderExpansion local = localOpt.get();
|
||||
if (local.isRegistered()) {
|
||||
expansion.setHasExpansion(true);
|
||||
expansion.setShouldUpdate(
|
||||
!local.getVersion().equalsIgnoreCase(expansion.getLatestVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
cache.put(toIndexName(expansion), expansion);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// ugly swallowing of every throwable, but we have to be defensive
|
||||
plugin
|
||||
.getLogger()
|
||||
.log(Level.WARNING, "Failed to download expansion information", e);
|
||||
}
|
||||
});
|
||||
cache.put(toIndexName(expansion), expansion);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// ugly swallowing of every throwable, but we have to be defensive
|
||||
plugin
|
||||
.getLogger()
|
||||
.log(Level.WARNING, "Failed to download expansion information", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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,35 +55,43 @@ 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();
|
||||
"https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
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:");
|
||||
.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);
|
||||
});
|
||||
.info("https://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID + "/");
|
||||
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));
|
||||
}
|
||||
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!"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user