Skip to content

Commit 34ad7bc

Browse files
committed
fix(folia): check arguments for folia
1 parent af36719 commit 34ad7bc

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

main/src/main/java/me/outspending/biomesapi/BiomeUpdater.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.outspending.biomesapi;
22

3+
import com.google.common.base.Preconditions;
34
import me.outspending.biomesapi.annotations.AsOf;
45
import me.outspending.biomesapi.misc.PointRange2D;
56
import org.bukkit.Chunk;
@@ -26,6 +27,13 @@
2627
@AsOf("1.2.0")
2728
public interface BiomeUpdater {
2829

30+
/**
31+
* Detects if the server is running Folia by checking for the presence 'io.papermc.paper.threadedregions.RegionizedServer'.
32+
* @since 1.2.0
33+
*/
34+
@AsOf("1.2.0")
35+
boolean FOLIA = classExists("io.papermc.paper.threadedregions.RegionizedServer");
36+
2937
/**
3038
* Returns an instance of BiomeUpdater.
3139
* This method returns an instance of BiomeUpdaterImpl.
@@ -37,6 +45,7 @@ public interface BiomeUpdater {
3745
@Deprecated
3846
@AsOf("1.2.0")
3947
static @NotNull BiomeUpdater of() {
48+
Preconditions.checkArgument(!FOLIA, "Folia detected, please use BiomeUpdater#of(Plugin) instead.");
4049
return new BiomeUpdaterImpl(null);
4150
}
4251

@@ -133,4 +142,13 @@ public interface BiomeUpdater {
133142
@AsOf("0.0.15")
134143
void updateChunksForPlayer(@NotNull Player player);
135144

145+
146+
private static boolean classExists(String className) {
147+
try {
148+
Class.forName(className);
149+
return true;
150+
} catch (ClassNotFoundException e) {
151+
return false;
152+
}
153+
}
136154
}

main/src/main/java/me/outspending/biomesapi/annotations/AsOf.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
ElementType.TYPE,
3131
ElementType.CONSTRUCTOR,
3232
ElementType.MODULE,
33-
ElementType.PACKAGE
33+
ElementType.PACKAGE,
34+
ElementType.FIELD
3435
})
3536
@AsOf("0.0.1")
3637
public @interface AsOf {

0 commit comments

Comments
 (0)