-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix possible CraftRegistry ClassNotFoundException
- Loading branch information
Showing
2 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
.../net/megavex/scoreboardlibrary/implementation/packetAdapter/modern/util/RegistryUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.util; | ||
|
||
import net.minecraft.core.RegistryAccess; | ||
import org.bukkit.Bukkit; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
public final class RegistryUtil { | ||
public static final RegistryAccess MINECRAFT_REGISTRY; | ||
|
||
static { | ||
String cbPackage = Bukkit.getServer().getClass().getPackage().getName(); | ||
Class<?> craftRegistry; | ||
try { | ||
craftRegistry = Class.forName(cbPackage + ".CraftRegistry"); | ||
} catch (ClassNotFoundException e) { | ||
throw new ExceptionInInitializerError(e); | ||
} | ||
|
||
try { | ||
Method method = craftRegistry.getDeclaredMethod("getMinecraftRegistry"); | ||
MINECRAFT_REGISTRY = (RegistryAccess) method.invoke(null); | ||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { | ||
throw new ExceptionInInitializerError(e); | ||
} | ||
} | ||
|
||
private RegistryUtil() { | ||
} | ||
} |