public static CompletableFuture applyProtocolLibPatch(Plugin plugin) { return CompletableFuture.supplyAsync(() -> { try { logger.info("Patching ProtocolLib, please wait."); // TODO Remove this message if you know a better way for this! logger.warning( "This patch is a nasty way to patch ProtocolLib, since if an " + "breaking update is done to the ProtocolInjector this WILL break ProtocolLib. " + "Please do note that the latest update on the ProtocolInjector class was made " + "before 2018, so there shouldn't be anything to worry about. " + "If you do know how to fix this though, please make a PR at: https://github.com/Sculas/NachoSpigot" ); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath(new LoaderClassPath(plugin.getClass().getClassLoader())); CtClass defaultProtocolInjector = pool.get("com.comphenix.protocol.injector.netty.ProtocolInjector$1"); if (defaultProtocolInjector.isFrozen()) { defaultProtocolInjector.defrost(); } CtClass clazz = pool.makeClass(CraftServer.class.getClassLoader().getResourceAsStream("protpatch.class")); clazz.replaceClassName(clazz.getName(), "com.comphenix.protocol.injector.netty.ProtocolInjector$1"); clazz.toClass(plugin.getClass().getClassLoader(), plugin.getClass().getProtectionDomain()); logger.info("Successfully patched ProtocolLib!"); return true; } catch (Exception e) { logger.warning("Could not patch ProtocolLib."); e.printStackTrace(); } return false; }); }