🎨 Fixed code order problem
This commit is contained in:
parent
13573d4add
commit
ed127b7e71
1 changed files with 30 additions and 29 deletions
|
@ -66,6 +66,36 @@ public class ReflectionUtil {
|
||||||
* Performance is not a concern for these specific statically initialized values.
|
* Performance is not a concern for these specific statically initialized values.
|
||||||
*/
|
*/
|
||||||
public static final String VERSION;
|
public static final String VERSION;
|
||||||
|
|
||||||
|
static { // This needs to be right below VERSION because of initialization order.
|
||||||
|
// This package loop is used to avoid implementation-dependant strings like Bukkit.getVersion() or Bukkit.getBukkitVersion()
|
||||||
|
// which allows easier testing as well.
|
||||||
|
String found = null;
|
||||||
|
for (Package pack : Package.getPackages()) {
|
||||||
|
String name = pack.getName();
|
||||||
|
|
||||||
|
// .v because there are other packages.
|
||||||
|
if (name.startsWith("org.bukkit.craftbukkit.v")) {
|
||||||
|
found = pack.getName().split("\\.")[3];
|
||||||
|
|
||||||
|
// Just a final guard to make sure it finds this important class.
|
||||||
|
// As a protection for forge+bukkit implementation that tend to mix versions.
|
||||||
|
// The real CraftPlayer should exist in the package.
|
||||||
|
// Note: Doesn't seem to function properly. Will need to separate the version
|
||||||
|
// handler for NMS and CraftBukkit for softwares like catmc.
|
||||||
|
try {
|
||||||
|
Class.forName("org.bukkit.craftbukkit." + found + ".entity.CraftPlayer");
|
||||||
|
break;
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
found = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found == null)
|
||||||
|
throw new IllegalArgumentException("Failed to parse server version. Could not find any package starting with name: 'org.bukkit.craftbukkit.v'");
|
||||||
|
VERSION = found;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The raw minor version number.
|
* The raw minor version number.
|
||||||
* E.g. {@code v1_17_R1} to {@code 17}
|
* E.g. {@code v1_17_R1} to {@code 17}
|
||||||
|
@ -99,35 +129,6 @@ public class ReflectionUtil {
|
||||||
*/
|
*/
|
||||||
private static final MethodHandle SEND_PACKET;
|
private static final MethodHandle SEND_PACKET;
|
||||||
|
|
||||||
static { // This needs to be right below VERSION because of initialization order.
|
|
||||||
// This package loop is used to avoid implementation-dependant strings like Bukkit.getVersion() or Bukkit.getBukkitVersion()
|
|
||||||
// which allows easier testing as well.
|
|
||||||
String found = null;
|
|
||||||
for (Package pack : Package.getPackages()) {
|
|
||||||
String name = pack.getName();
|
|
||||||
|
|
||||||
// .v because there are other packages.
|
|
||||||
if (name.startsWith("org.bukkit.craftbukkit.v")) {
|
|
||||||
found = pack.getName().split("\\.")[3];
|
|
||||||
|
|
||||||
// Just a final guard to make sure it finds this important class.
|
|
||||||
// As a protection for forge+bukkit implementation that tend to mix versions.
|
|
||||||
// The real CraftPlayer should exist in the package.
|
|
||||||
// Note: Doesn't seem to function properly. Will need to separate the version
|
|
||||||
// handler for NMS and CraftBukkit for softwares like catmc.
|
|
||||||
try {
|
|
||||||
Class.forName("org.bukkit.craftbukkit." + found + ".entity.CraftPlayer");
|
|
||||||
break;
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
found = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found == null)
|
|
||||||
throw new IllegalArgumentException("Failed to parse server version. Could not find any package starting with name: 'org.bukkit.craftbukkit.v'");
|
|
||||||
VERSION = found;
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Class<?> entityPlayer = getNMSClass("server.level", "EntityPlayer");
|
Class<?> entityPlayer = getNMSClass("server.level", "EntityPlayer");
|
||||||
Class<?> worldServer = getNMSClass("server.level", "WorldServer");
|
Class<?> worldServer = getNMSClass("server.level", "WorldServer");
|
||||||
|
|
Loading…
Add table
Reference in a new issue