asusoda / Corundum

This is a new plugin-based server-side modding A.P.I. for Minecraft. [WIP]
MIT License
7 stars 1 forks source link

The Minecraft GUI does not show log messages #12

Open Variadicism-zz opened 9 years ago

Variadicism-zz commented 9 years ago

There has been much discussion about this and a task for it in Trello for some time, but I wanted to make sure everyone knows what's going on here exactly.

So, if you build and start up Corundum right now, it will start running and the Minecraft vanilla GUI will appear. However, there are a couple error messages that appear in the command line window that you launched it from (if you used the command line) that say something like this:

ERROR Error processing element Queue: CLASS_NOT_FOUND
ERROR Unable to locate appender ServerGuiConsole for logger

The Minecraft server still starts normally and nothing appears to be wrong; the only noticeable issue is that the Minecraft GUI's console window (the box on the top-right that usually contains all the log messages that appear while the server is running) is empty.

As far as I've been able to tell, it looks like the Minecraft server is using Log4J to handle all its logging needs. To get the log messages to appear in the GUI, Log4J uses the log4j2.xml (in the default package) as a config file and Minecraft has configured it to use a "LogAppender" to give the messages to the "ServerGuiConsole". However, Log4J cannot find the right Minecraft classes to handle this LogAppender. I think this is because it uses its Loader class to find a ClassLoader and the Loader class seems to be trying to locate the highest ClassLoader available, which is the one that points to the Corundum launcher.jar, not the minecraft_server.jar. Therefore, it's looking for the Minecraft classes configured to work with it in the wrong jar.

Since we have no control over the CorundumLauncher ClassLoader since it's the start of the program and we have no control over the Loader class since it is inside the minecraft_server.jar that we can't modify, I think we're only left with one option:

We can put a Log4J configuration file into the Corundum launcher.jar and use the custom Minecraft server jar ClassLoaders to make Log4J use ours instead of its own. (That's pretty easy.) Then, we use the custom config to point Log4J to look for our own LogAppender stuff instead that we can make work with Minecraft. This will also be helpful later when we have to make our own GUI and we'll likely have to use the LogAppenders in the same way Minecraft does to display logged stuff.