1
1
package de .epiceric .shopchest .nms ;
2
2
3
+ import java .lang .reflect .Field ;
4
+ import java .lang .reflect .Method ;
5
+
6
+ import org .bukkit .Bukkit ;
7
+
3
8
import de .epiceric .shopchest .nms .reflection .PlatformImpl ;
4
9
import de .epiceric .shopchest .nms .reflection .ShopChestDebug ;
5
10
import de .epiceric .shopchest .utils .Utils ;
6
- import org .bukkit .Bukkit ;
7
-
8
- import java .lang .reflect .Field ;
9
- import java .lang .reflect .Method ;
10
11
11
12
public class PlatformLoader {
12
13
@@ -17,19 +18,25 @@ public PlatformLoader(ShopChestDebug debug) {
17
18
}
18
19
19
20
public Platform loadPlatform () {
20
- final String nmsVersion = Utils .getServerVersion ();
21
-
22
- Platform platform = getReflectionPlatform (nmsVersion );
23
- if (platform != null ) {
21
+ Platform platform = null ;
22
+ if (Utils .getMajorVersion () < 17 ) {
23
+ final String bukkitPackageVersion = getBukkitPackageVersion ();
24
+ platform = getReflectionPlatform (bukkitPackageVersion );
25
+ if (platform == null ) {
26
+ throw new RuntimeException (
27
+ "Could not retrieve the mappings version. The server version might be too old ("
28
+ + bukkitPackageVersion + ")." );
29
+ }
24
30
return platform ;
25
31
}
26
32
final String mappingsVersion = getMappingsVersion ();
27
33
if (mappingsVersion == null ) {
28
- throw new RuntimeException ("Could not retrieve the mappings version. The server version might be too old (" + nmsVersion + "). " );
34
+ throw new RuntimeException ("Could not get any information about the server version" );
29
35
}
30
36
platform = getSpecificPlatform (mappingsVersion );
31
37
if (platform == null ) {
32
- throw new RuntimeException ("Server version not officially supported. Version: '" + nmsVersion + "', Mappings : " + "'" + mappingsVersion + "'" );
38
+ throw new RuntimeException (
39
+ "Server version not officially supported. Mappings : " + "'" + mappingsVersion + "'" );
33
40
}
34
41
return platform ;
35
42
}
@@ -57,9 +64,15 @@ private Platform getReflectionPlatform(String nmsVersion) {
57
64
}
58
65
}
59
66
67
+ private String getBukkitPackageVersion () {
68
+ final String packageName = Bukkit .getServer ().getClass ().getPackage ().getName ();
69
+ return packageName .substring (packageName .lastIndexOf ("." ) + 1 );
70
+ }
71
+
60
72
private String getMappingsVersion () {
61
73
try {
62
- final String craftMagicNumbersClassName = Bukkit .getServer ().getClass ().getPackage ().getName () + ".util.CraftMagicNumbers" ;
74
+ final String craftMagicNumbersClassName = Bukkit .getServer ().getClass ().getPackage ().getName ()
75
+ + ".util.CraftMagicNumbers" ;
63
76
final Class <?> craftMagicNumbersClass = Class .forName (craftMagicNumbersClassName );
64
77
final Method method = craftMagicNumbersClass .getDeclaredMethod ("getMappingsVersion" );
65
78
method .setAccessible (true );
0 commit comments