Compare commits

...

4 Commits

Author SHA1 Message Date
Yomamaeatstoes 0ddb913ad9
Merge 94a9d84ba0 into 882b7c5965 2024-03-08 20:23:44 +00:00
Yomamaeatstoes 94a9d84ba0
Merge branch 'PlaceholderAPI:master' into master 2024-03-08 15:23:40 -05:00
Yomamaeatstoes ca46a20671
Merge branch 'PlaceholderAPI:master' into master 2024-02-25 06:27:37 -05:00
HSGamer f8c9ee2fc3 add FoliaLib and folia-supported 2024-02-19 13:11:27 +07:00
6 changed files with 46 additions and 40 deletions

View File

@ -20,11 +20,13 @@ repositories {
maven("https://repo.codemc.org/repository/maven-public/")
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://nexuslite.gcnt.net/repos/other/")
}
dependencies {
implementation("org.bstats:bstats-bukkit:3.0.1")
implementation("net.kyori:adventure-platform-bukkit:4.3.1")
implementation("com.tcoded:FoliaLib:0.3.1")
compileOnly("org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT")
compileOnlyApi("org.jetbrains:annotations:23.0.0")
@ -88,6 +90,7 @@ tasks {
relocate("org.bstats", "me.clip.placeholderapi.metrics")
relocate("net.kyori", "me.clip.placeholderapi.libs.kyori")
relocate("com.tcoded", "me.clip.placeholderapi.libs.tcoded")
}
test {

View File

@ -20,6 +20,7 @@
package me.clip.placeholderapi;
import com.tcoded.folialib.FoliaLib;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
@ -53,6 +54,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
@NotNull
private static final Version VERSION;
private static PlaceholderAPIPlugin instance;
private static FoliaLib foliaLib;
static {
final String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
@ -90,6 +92,15 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
return instance;
}
/**
* Get the static instance of the FoliaLib class
*
* @return FoliaLib instance
*/
public static FoliaLib getFoliaLib() {
return foliaLib;
}
/**
* Get the configurable {@linkplain String} value that should be returned when a boolean is true
*
@ -134,6 +145,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
@Override
public void onLoad() {
instance = this;
foliaLib = new FoliaLib(this);
saveDefaultConfig();
}
@ -162,7 +174,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
HandlerList.unregisterAll(this);
Bukkit.getScheduler().cancelTasks(this);
foliaLib.getImpl().cancelAllTasks();
adventure.close();
adventure = null;

View File

@ -200,40 +200,33 @@ public final class CloudExpansionManager {
plugin.getLogger().log(Level.WARNING, "Failed to download expansion information", e);
}
// loop through 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);
}
});
}

View File

@ -55,7 +55,7 @@ public class UpdateChecker implements Listener {
}
public void fetch() {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
PlaceholderAPIPlugin.getFoliaLib().getImpl().runAsync(t -> {
try {
HttpsURLConnection con = (HttpsURLConnection) new URL(
"https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection();
@ -76,7 +76,7 @@ public class UpdateChecker implements Listener {
return;
}
Bukkit.getScheduler().runTask(plugin, () -> {
PlaceholderAPIPlugin.getFoliaLib().getImpl().runNextTick(t1 -> {
plugin.getLogger()
.info("An update for PlaceholderAPI (v" + getSpigotVersion() + ") is available at:");
plugin.getLogger()

View File

@ -27,7 +27,7 @@ import java.util.function.BiConsumer;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.bukkit.Bukkit;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
@ -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));
}
PlaceholderAPIPlugin.getFoliaLib().getImpl().runNextTick(t -> consumer.accept(value, exception));
});
}

View File

@ -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!"