Skip to content
This repository was archived by the owner on Aug 8, 2025. It is now read-only.

Commit f8c9ee2

Browse files
committed
add FoliaLib and folia-supported
1 parent 1cd4d93 commit f8c9ee2

File tree

6 files changed

+49
-43
lines changed

6 files changed

+49
-43
lines changed

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ repositories {
2020

2121
maven("https://repo.codemc.org/repository/maven-public/")
2222
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
23+
maven("https://nexuslite.gcnt.net/repos/other/")
2324
}
2425

2526
dependencies {
2627
implementation("org.bstats:bstats-bukkit:3.0.1")
2728
implementation("net.kyori:adventure-platform-bukkit:4.3.1")
29+
implementation("com.tcoded:FoliaLib:0.3.1")
2830

2931
compileOnly("org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT")
3032
compileOnlyApi("org.jetbrains:annotations:23.0.0")
@@ -88,6 +90,7 @@ tasks {
8890

8991
relocate("org.bstats", "me.clip.placeholderapi.metrics")
9092
relocate("net.kyori", "me.clip.placeholderapi.libs.kyori")
93+
relocate("com.tcoded", "me.clip.placeholderapi.libs.tcoded")
9194
}
9295

9396
test {

src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package me.clip.placeholderapi;
2222

23+
import com.tcoded.folialib.FoliaLib;
2324
import java.text.SimpleDateFormat;
2425
import java.util.HashMap;
2526
import java.util.Map;
@@ -53,6 +54,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
5354
@NotNull
5455
private static final Version VERSION;
5556
private static PlaceholderAPIPlugin instance;
57+
private static FoliaLib foliaLib;
5658

5759
static {
5860
final String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
@@ -90,6 +92,15 @@ public static PlaceholderAPIPlugin getInstance() {
9092
return instance;
9193
}
9294

95+
/**
96+
* Get the static instance of the FoliaLib class
97+
*
98+
* @return FoliaLib instance
99+
*/
100+
public static FoliaLib getFoliaLib() {
101+
return foliaLib;
102+
}
103+
93104
/**
94105
* Get the configurable {@linkplain String} value that should be returned when a boolean is true
95106
*
@@ -134,6 +145,7 @@ public static Version getServerVersion() {
134145
@Override
135146
public void onLoad() {
136147
instance = this;
148+
foliaLib = new FoliaLib(this);
137149

138150
saveDefaultConfig();
139151
}
@@ -162,7 +174,7 @@ public void onDisable() {
162174

163175
HandlerList.unregisterAll(this);
164176

165-
Bukkit.getScheduler().cancelTasks(this);
177+
foliaLib.getImpl().cancelAllTasks();
166178

167179
adventure.close();
168180
adventure = null;

src/main/java/me/clip/placeholderapi/expansion/manager/CloudExpansionManager.java

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -200,40 +200,33 @@ public void fetch() {
200200
plugin.getLogger().log(Level.WARNING, "Failed to download expansion information", e);
201201
}
202202

203-
// loop through what's left on the main thread
204-
plugin
205-
.getServer()
206-
.getScheduler()
207-
.runTask(
208-
plugin,
209-
() -> {
210-
try {
211-
for (Map.Entry<String, CloudExpansion> entry : values.entrySet()) {
212-
String name = entry.getKey();
213-
CloudExpansion expansion = entry.getValue();
214-
215-
expansion.setName(name);
216-
217-
Optional<PlaceholderExpansion> localOpt =
218-
plugin.getLocalExpansionManager().findExpansionByName(name);
219-
if (localOpt.isPresent()) {
220-
PlaceholderExpansion local = localOpt.get();
221-
if (local.isRegistered()) {
222-
expansion.setHasExpansion(true);
223-
expansion.setShouldUpdate(
224-
!local.getVersion().equalsIgnoreCase(expansion.getLatestVersion()));
225-
}
226-
}
227-
228-
cache.put(toIndexName(expansion), expansion);
229-
}
230-
} catch (Throwable e) {
231-
// ugly swallowing of every throwable, but we have to be defensive
232-
plugin
233-
.getLogger()
234-
.log(Level.WARNING, "Failed to download expansion information", e);
235-
}
236-
});
203+
//todo: Figure out why this was being scheduled back on the main thread
204+
try {
205+
for (Map.Entry<String, CloudExpansion> entry : values.entrySet()) {
206+
String name = entry.getKey();
207+
CloudExpansion expansion = entry.getValue();
208+
209+
expansion.setName(name);
210+
211+
Optional<PlaceholderExpansion> localOpt =
212+
plugin.getLocalExpansionManager().findExpansionByName(name);
213+
if (localOpt.isPresent()) {
214+
PlaceholderExpansion local = localOpt.get();
215+
if (local.isRegistered()) {
216+
expansion.setHasExpansion(true);
217+
expansion.setShouldUpdate(
218+
!local.getVersion().equalsIgnoreCase(expansion.getLatestVersion()));
219+
}
220+
}
221+
222+
cache.put(toIndexName(expansion), expansion);
223+
}
224+
} catch (Throwable e) {
225+
// ugly swallowing of every throwable, but we have to be defensive
226+
plugin
227+
.getLogger()
228+
.log(Level.WARNING, "Failed to download expansion information", e);
229+
}
237230
});
238231
}
239232

src/main/java/me/clip/placeholderapi/updatechecker/UpdateChecker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public String getSpigotVersion() {
5555
}
5656

5757
public void fetch() {
58-
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
58+
PlaceholderAPIPlugin.getFoliaLib().getImpl().runAsync(t -> {
5959
try {
6060
HttpsURLConnection con = (HttpsURLConnection) new URL(
6161
"https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection();
@@ -76,7 +76,7 @@ public void fetch() {
7676
return;
7777
}
7878

79-
Bukkit.getScheduler().runTask(plugin, () -> {
79+
PlaceholderAPIPlugin.getFoliaLib().getImpl().runNextTick(t1 -> {
8080
plugin.getLogger()
8181
.info("An update for PlaceholderAPI (v" + getSpigotVersion() + ") is available at:");
8282
plugin.getLogger()

src/main/java/me/clip/placeholderapi/util/Futures.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import java.util.stream.Collector;
2828
import java.util.stream.Collectors;
2929
import java.util.stream.Stream;
30-
import org.bukkit.Bukkit;
30+
import me.clip.placeholderapi.PlaceholderAPIPlugin;
3131
import org.bukkit.plugin.Plugin;
3232
import org.jetbrains.annotations.NotNull;
3333

@@ -40,11 +40,7 @@ public static <T> void onMainThread(@NotNull final Plugin plugin,
4040
@NotNull final CompletableFuture<T> future,
4141
@NotNull final BiConsumer<T, Throwable> consumer) {
4242
future.whenComplete((value, exception) -> {
43-
if (Bukkit.isPrimaryThread()) {
44-
consumer.accept(value, exception);
45-
} else {
46-
Bukkit.getScheduler().runTask(plugin, () -> consumer.accept(value, exception));
47-
}
43+
PlaceholderAPIPlugin.getFoliaLib().getImpl().runNextTick(t -> consumer.accept(value, exception));
4844
});
4945
}
5046

src/main/resources/plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ main: "me.clip.placeholderapi.PlaceholderAPIPlugin"
44
version: ${version}
55
author: HelpChat
66

7+
folia-supported: true
8+
79
api-version: "1.13"
810
description: "An awesome placeholder provider!"
911

0 commit comments

Comments
 (0)