-
Notifications
You must be signed in to change notification settings - Fork 0
Debugging Minecraft Plugins
Andrew Crawley edited this page Oct 8, 2018
·
6 revisions
All of my plugins are set up to be easily debuggable from IntelliJ. Each provides a Maven profile called dev that deploys a copy of the plugin JAR to the server's plugins folder (specified by the spigot.plugindir variable).
- Run -> Edit Configurations
- Click "Add new configuration" (green plus)
- Choose "JAR application"
- Name the configuration, e.g. "Spigot"
- Check "Single instance only"
- In the "Configuration" tab:
- Set "Path to JAR" to the location of your Spigot JAR
- Set "Working directory" to the Spigot server path
- In the "Before launch" section:
- Click "Add" (green plus)
- Choose "Run Maven Goal"
- In the "Select Maven Goal" dialog:
- Click the "Select Maven Project" button (folder) and choose a project
- Set "Command line" to
-o install -P dev -D spigot.plugindir="/path/to/plugin/dir" - Click OK
- Repeat for any other of my plugins you may be building
- In the "Before launch" section:
- Click OK

Note that actually debugging (stopping at breakpoints, stepping, etc) can be difficult, as the client and server both contain timeouts that will cause a disconnection if much time is spent stopped in a debugger. This can be avoided by patching the client and server to remove the timeouts. Instructions are provided for the official Windows client and Spigot server.
- Follow Spigot instructions to get set up to build (download BuildTools.jar, etc)
- Run a build once to get all the sources synced
- Open
<BuildTools dir>\Spigot\Spigot-Server\src\main\java\net\minecraft\server\ServerConnection.javain your editor of choice- If this path changes, grep under
Spigotfor a .java file containingReadTimeoutHandler
- If this path changes, grep under
- Remove the call to
addLaston that line that adds theReadTimeoutHandler, e.g.:
--- a/src/main/java/net/minecraft/server/ServerConnection.java
+++ b/src/main/java/net/minecraft/server/ServerConnection.java
@@ -91,7 +91,7 @@ public class ServerConnection {
;
}
- channel.pipeline().addLast("timeout", new ReadTimeoutHandler(30)).addLast("legacy_query", new LegacyPingHandler(ServerConnection.this)).addLast("splitter", new PacketSplitter()).addLast("decoder", new PacketDecoder(EnumProtocolDirection.SERVERBOUND)).addLast("prepender", new PacketPrepender()).addLast("encoder", new PacketEncoder(EnumProtocolDirection.CLIENTBOUND));
+ channel.pipeline().addLast("legacy_query", new LegacyPingHandler(ServerConnection.this)).addLast("splitter", new PacketSplitter()).addLast("decoder", new PacketDecoder(EnumProtocolDirection.SERVERBOUND)).addLast("prepender", new PacketPrepender()).addLast("encoder", new PacketEncoder(EnumProtocolDirection.CLIENTBOUND));
NetworkManager networkmanager = new NetworkManager(EnumProtocolDirection.SERVERBOUND);
ServerConnection.this.h.add(networkmanager);
cd Spigot- Rebuild just the server:
../apache-maven-3.2.5/bin/mvn package - Copy the new Spigot JAR from the
Spigot-Server/targetfolder to your server folder
- Download the appropriate version of MCP from http://www.modcoderpack.com/website/releases
- NOTE: If no version of MCP is available for the version of Minecraft you want to debug, try these instructions
- Unpack somewhere on your local box
- Make sure you have the exact version of Minecraft installed that MCP expects - if MCP requires 1.10, having 1.10.2 installed won't work
- Run MCP's
decompile.batand wait a few minutes while it does its work - Open
<MCP DIR>\src\minecraft\net\minecraft\network\NetworkManager.javain your editor of choice- If this path is wrong, grep for
ReadTimeoutHandlerto figure out which file to edit. In 1.10, there is another hit inNetworkSystem.javarelated to allowing other players on your local network to join your game - this does not need to be changed to fix debugging, but it won't hurt anything.
- If this path is wrong, grep for
- Remove the call to
addLaston that line that adds theReadTimeoutHandler, e.g.:
--- a/orig/minecraft/net/minecraft/network/NetworkManager.java
+++ b/src/minecraft/net/minecraft/network/NetworkManager.java
@@ -370,7 +370,7 @@ public class NetworkManager extends SimpleChannelInboundHandler < Packet<? >>
;
}
- p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new NettyVarint21FrameDecoder())).addLast((String)"decoder", (ChannelHandler)(new NettyPacketDecoder(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new NettyVarint21FrameEncoder())).addLast((String)"encoder", (ChannelHandler)(new NettyPacketEncoder(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager);
+ p_initChannel_1_.pipeline().addLast((String)"splitter", (ChannelHandler)(new NettyVarint21FrameDecoder())).addLast((String)"decoder", (ChannelHandler)(new NettyPacketDecoder(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new NettyVarint21FrameEncoder())).addLast((String)"encoder", (ChannelHandler)(new NettyPacketEncoder(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager);
}
})).channel(oclass)).connect(address, serverPort).syncUninterruptibly();
return networkmanager;
- Save and run
recompile.bat - Run
reobfuscate.bat - Browse to
%APPDATA%\.minecraft\versions - Make a copy of the folder for the version edited (e.g.
1.10) and name it (e.g.1.10-Debug) - Rename the .jar and .json in that folder to the same thing as the containing folder, e.g.
1.10-Debug.jsonand1.10-Debug.jar - Open the .jar file in a ZIP program
- Delete the
META-INFfolder - Copy all the .class files in MCP's
reobf\minecraftfolder to the root of the JAR, overwriting any existing files
- Delete the
- Open the .json file in a text editor
- Change the
idfield to the name of the containing folder (e.g. 1.10-Debug) - Delete the
downloadssection to prevent the launcher from replacing our edited JAR with a clean copy
- Change the
- Run the Minecraft Launcher
- Click "New Profile"
- Name the profile (e.g. "v1.10 - Debug")
- In the "Use version" dropdown, select "release 1.10-Debug"
- Click "Save Profile"
- Select the new profile
- Click "Play"
