Skip to content

Commit 6bed219

Browse files
committed
chore: drop usage of unmaintained paper lib
1 parent d1369f9 commit 6bed219

File tree

6 files changed

+99
-37
lines changed

6 files changed

+99
-37
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ implementation("io.github.juliarn", "(module name from the list above)", "(lates
6565
Depending on your setup you might need to add the following repositories as well to download all the transitive
6666
dependencies coming from the modules:
6767

68-
- `https://repo.papermc.io/repository/maven-public/` (For [PaperLib](https://github.com/PaperMC/PaperLib))
6968
- `https://repository.derklaro.dev/releases/` (You can also use `https://jitpack.io` instead, used e.g.
7069
for [ProtocolLib](https://github.com/dmulloy2/ProtocolLib)).
7170
- `https://repo.codemc.io/repository/maven-releases/` (For [PacketEvents](https://github.com/retrooper/packetevents))
@@ -76,7 +75,6 @@ are used by this library and that you probably want to relocate to prevent depen
7675
including the same libraries. You can use the gradle or maven shade plugin to achieve this:
7776

7877
- `net.kyori`
79-
- `io.papermc.lib`
8078
- `io.leangen.geantyref`
8179
- `io.github.retrooper`
8280
- `com.github.retrooper`
@@ -165,7 +163,7 @@ BukkitPlatform.bukkitNpcPlatformBuilder()
165163
// when on paper 1.12 or later the paper profile resolver is used, when on spigot
166164
// 1.18.2 or later the spigot profile resolver is used, else a fallback mojang api
167165
// based access is used.
168-
// see BukkitVersionAccessor for the bukkit implementations (PaperLib based)
166+
// see BukkitVersionAccessor for the bukkit implementation
169167
// see MinestomVersionAccessor for the minestom implementation
170168
// Defaults to a platform-specific implementation.
171169
.versionAccessor()

bukkit/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ dependencies {
2626
api(projects.npcLibApi)
2727
api(projects.npcLibCommon)
2828

29-
implementation(libs.paperLib)
3029
implementation(libs.geantyref)
3130
implementation(libs.packetEvents)
3231

bukkit/src/main/java/com/github/juliarn/npclib/bukkit/BukkitProfileResolver.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import com.github.juliarn.npclib.api.profile.Profile;
2929
import com.github.juliarn.npclib.api.profile.ProfileProperty;
3030
import com.github.juliarn.npclib.api.profile.ProfileResolver;
31-
import io.papermc.lib.PaperLib;
31+
import com.github.juliarn.npclib.common.util.ClassHelper;
3232
import java.lang.reflect.Method;
3333
import java.util.HashSet;
3434
import java.util.List;
@@ -47,13 +47,13 @@ private BukkitProfileResolver() {
4747
}
4848

4949
public static @NotNull ProfileResolver profileResolver() {
50-
// check if we're on paper and newer than 1.12 (when the profile API was introduced)
51-
if (PaperLib.isPaper() && PaperLib.isVersion(12)) {
50+
boolean hasPaperProfileApi = ClassHelper.classExists("com.destroystokyo.paper.profile.PlayerProfile");
51+
if (hasPaperProfileApi) {
5252
return PaperProfileResolver.INSTANCE;
5353
}
5454

55-
// check if we're on spigot and newer than 1.18.2 (when the profile API was introduced)
56-
if (PaperLib.isSpigot() && PaperLib.isVersion(18, 2)) {
55+
boolean hasSpigotProfileApi = ClassHelper.classExists("org.bukkit.profile.PlayerProfile");
56+
if (hasSpigotProfileApi) {
5757
return SpigotProfileResolver.INSTANCE;
5858
}
5959

bukkit/src/main/java/com/github/juliarn/npclib/bukkit/BukkitVersionAccessor.java

Lines changed: 89 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,107 @@
2525
package com.github.juliarn.npclib.bukkit;
2626

2727
import com.github.juliarn.npclib.api.PlatformVersionAccessor;
28-
import io.papermc.lib.PaperLib;
28+
import io.papermc.paper.ServerBuildInfo;
29+
import java.util.regex.Matcher;
30+
import java.util.regex.Pattern;
31+
import org.bukkit.Bukkit;
32+
import org.jetbrains.annotations.NotNull;
2933

30-
public final class BukkitVersionAccessor {
34+
public final class BukkitVersionAccessor implements PlatformVersionAccessor {
3135

32-
private BukkitVersionAccessor() {
33-
throw new UnsupportedOperationException();
34-
}
36+
/**
37+
* Regex for any {@code number.number.number} combination, where the last number is optional.
38+
*/
39+
private static final Pattern MC_VERSION_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.?(\\d+)?");
40+
/**
41+
* Regex for the bukkit mc version representation.
42+
*/
43+
private static final Pattern BUKKIT_VERSION_PATTERN = Pattern.compile("\\(MC: (\\d+)\\.(\\d+)\\.?(\\d+)?");
44+
45+
/**
46+
* The version string that couldn't be parsed when no default instance could be constructed. {@code null} in case a
47+
* default instance was constructed successfully.
48+
*/
49+
private static final String FAILED_PARSE_INPUT;
50+
/**
51+
* Default instance parsed from a version string. {@code null} in case the version input string couldn't be converted
52+
* to a SemVer version. In this case the failed parse input field is non-null and holds the parse input that failed.
53+
*/
54+
private static final PlatformVersionAccessor DEFAULT_INSTANCE;
3555

36-
public static PlatformVersionAccessor versionAccessor() {
37-
return PaperLibPlatformVersionAccessor.INSTANCE;
56+
static {
57+
Matcher versionMatcher;
58+
try {
59+
// try to use the modern approach via Paper ServerBuildInfo
60+
ServerBuildInfo buildInfo = ServerBuildInfo.buildInfo();
61+
versionMatcher = MC_VERSION_PATTERN.matcher(buildInfo.minecraftVersionId());
62+
} catch (Throwable throwable) {
63+
// use the legacy approach via Bukkit.getVersion()
64+
versionMatcher = BUKKIT_VERSION_PATTERN.matcher(Bukkit.getVersion());
65+
}
66+
67+
if (versionMatcher.find()) {
68+
String major = versionMatcher.group(1);
69+
String minor = versionMatcher.group(2);
70+
String patch = versionMatcher.group(3);
71+
DEFAULT_INSTANCE = new BukkitVersionAccessor(
72+
Integer.parseInt(major),
73+
Integer.parseInt(minor),
74+
patch == null ? 0 : Integer.parseInt(patch));
75+
FAILED_PARSE_INPUT = null;
76+
} else {
77+
DEFAULT_INSTANCE = null;
78+
FAILED_PARSE_INPUT = versionMatcher.replaceAll(""); // this returns the full text when there is no match
79+
}
3880
}
3981

40-
private static final class PaperLibPlatformVersionAccessor implements PlatformVersionAccessor {
82+
private final int major;
83+
private final int minor;
84+
private final int patch;
4185

42-
private static final PaperLibPlatformVersionAccessor INSTANCE = new PaperLibPlatformVersionAccessor();
86+
public BukkitVersionAccessor(int major, int minor, int patch) {
87+
this.major = major;
88+
this.minor = minor;
89+
this.patch = patch;
90+
}
4391

44-
@Override
45-
public int major() {
46-
return 1;
47-
}
92+
public static boolean hasDefaultAccessor() {
93+
return DEFAULT_INSTANCE != null;
94+
}
4895

49-
@Override
50-
public int minor() {
51-
return PaperLib.getMinecraftVersion();
96+
public static @NotNull PlatformVersionAccessor versionAccessor() {
97+
if (DEFAULT_INSTANCE != null) {
98+
return DEFAULT_INSTANCE;
5299
}
53100

54-
@Override
55-
public int patch() {
56-
return PaperLib.getMinecraftPatchVersion();
101+
throw new IllegalStateException("Version is not available as '" + FAILED_PARSE_INPUT + "' couldn't be parsed");
102+
}
103+
104+
@Override
105+
public int major() {
106+
return this.major;
107+
}
108+
109+
@Override
110+
public int minor() {
111+
return this.minor;
112+
}
113+
114+
@Override
115+
public int patch() {
116+
return this.patch;
117+
}
118+
119+
@Override
120+
public boolean atLeast(int major, int minor, int patch) {
121+
if (this.major != major) {
122+
return this.major > major;
57123
}
58124

59-
@Override
60-
public boolean atLeast(int major, int minor, int patch) {
61-
return PaperLib.isVersion(minor, patch);
125+
if (this.minor != minor) {
126+
return this.minor > minor;
62127
}
128+
129+
return this.patch >= patch;
63130
}
64131
}

bukkit/src/main/java/com/github/juliarn/npclib/bukkit/BukkitWorldAccessor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
package com.github.juliarn.npclib.bukkit;
2626

2727
import com.github.juliarn.npclib.api.PlatformWorldAccessor;
28-
import io.papermc.lib.PaperLib;
2928
import org.bukkit.Bukkit;
3029
import org.bukkit.NamespacedKey;
3130
import org.bukkit.World;
@@ -39,10 +38,11 @@ private BukkitWorldAccessor() {
3938
}
4039

4140
public static @NotNull PlatformWorldAccessor<World> worldAccessor() {
42-
// check if we are on paper and newer (or equal) to 1.16.5
43-
if (PaperLib.isPaper() && PaperLib.isVersion(16, 5)) {
41+
try {
42+
// default to the modern accessor on 1.16.5 and above
43+
Bukkit.class.getMethod("getWorld", NamespacedKey.class);
4444
return ModernAccessor.INSTANCE;
45-
} else {
45+
} catch (Throwable throwable) {
4646
return LegacyAccessor.INSTANCE;
4747
}
4848
}

gradle/libs.versions.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ fabricLoader = "0.17.2"
2424
fabricApi = "0.133.14+1.21.9"
2525

2626
# platform extensions
27-
paperLib = "1.0.8"
2827
packetEvents = "2.9.5"
2928
protocolLib = "9417eee444"
3029

@@ -49,7 +48,6 @@ fabricApiBom = { module = "net.fabricmc.fabric-api:fabric-api-bom", version.ref
4948
fabricApiNetworkingV1 = { module = "net.fabricmc.fabric-api:fabric-networking-api-v1" }
5049

5150
# platform extensions
52-
paperLib = { group = "io.papermc", name = "paperlib", version.ref = "paperLib" }
5351
protocolLib = { group = "com.github.dmulloy2", name = "ProtocolLib", version.ref = "protocolLib" }
5452
packetEvents = { group = "com.github.retrooper", name = "packetevents-spigot", version.ref = "packetEvents" }
5553

0 commit comments

Comments
 (0)