inject
inject is a server-side library designed to significantly simplify the process of injecting into Netty for developers.
Usage Capabilities
Using the HttpInjector class, developers can process HTTP requests sent to the Minecraft server. Let's consider a practical example:
class MyEpicHttpInjector extends HttpInjector {
@Override
public HttpByteBuf intercept(ChannelHandlerContext ctx, HttpRequest request) {
HttpByteBuf buf = HttpByteBuf.httpBuf(ctx);
buf.writeStatusLine("1.1", 200, "OK");
buf.writeText("Hello from Minecraft!");
return buf;
}
}
Registration Process
For Fabric, use the InjectFabric class:
public class MyMod implements ModInitializer {
@Override
public void onInitialize() {
InjectFabric.INSTANCE.registerInjector(new MyEpicHttpInjector());
}
}
For Spigot, Paper, and compatible platforms, use the InjectSpigot class:
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
InjectSpigot.INSTANCE.registerInjector(new MyEpicHttpInjector());
}
}
After configuration, the HTTP injector will respond with "Hello from Minecraft!" text to any HTTP request sent to the Minecraft server port.
$ curl http://localhost:25565
Hello from Minecraft!
Supported Web Servers
The library is compatible with various popular web servers:
- Spring Boot:
springmodule - Javalin:
javalinmodule - Ktor:
ktormodule - Jetty:
jettymodule - Manual request handling:
httpmodule
For more detailed study, practical examples are available in the examples module.
Project Integration
Add the andante repository to gradle:
repositories {
maven("https://maven.mcbrawls.net/releases/")
}
Include the necessary dependencies:
dependencies {
implementation("net.mcbrawls.inject:api:VERSION")
// For HTTP operations
implementation("net.mcbrawls.inject:http:VERSION")
// Fabric:
include(modImplementation("net.mcbrawls.inject:fabric:VERSION")!!)
// Spigot/Paper:
implementation("net.mcbrawls.inject:spigot:VERSION")
// Additional modules for Spring, Ktor, and other platforms can be found: Github repo.
}
Replace VERSION with the current version from the releases section.