Minecraft Server with Emacs
So I haven't posted anything in a week or two, and I guess I'm deviating from the main theme of my blog, especially with a bunch of AP content for an IB student. Anyway, at least we'll be going back to Emacs, and this time how to host a Minecraft server with scripts without mods. I suppose this post won't be long.
I got out an unused, strong laptop at home and got Java and the Minecraft server jar and just ran it (with port forwarding from the router) inside screen so that I could disconnect from the server and still have it run. I also had to mess with systemd-logind to make the computer not sleep when the screen was closed.
Anyway the most annoying part was that I couldn't run any scripts and I had no tab-completion in the server, and searching the internet only lead me to Craftbukkit, whose server I couldn't download thanks to DMCA complaints from Mojang.
So, I turned to Emacs.
I used screen and emacs24, which can be apt-get fairly easily.
Then we start the screen with a name:
screen -r mcserver
And within the screen we start Emacs. I actually remember that I had Emacs Live on it which makes Emacs nice and flashy, plus it came with the Emacs packages I used to upgrade the Minecraft serving experience. Check out https://github.com/overtone/emacs-live for more information on Emacs Live.
The server is actually run in shell-mode (M-x shell), which I found from experience was better than ansi-term and eshell (which I think barely worked at all).
The computer is just a strong laptop with 8GB of memory, so I gave 7GB to Minecraft, which makes it run nice and smoothly:
java -jar java -Xmx7168M -Xms7168M -jar minecraft_server.1.8.9.jar nogui
Within the server directory, of course.
The Power of Emacs
The main component of Emacs that I used to get tab-completion (which was the thing I wanted the most) was a combination of yasnippet and auto-complete-mode, both which come with Emacs Live. These could be installed manually as well, of course, but I just happened to have Emacs Live.
For auto-complete, within the ~/.dict file I have all the commands, the names of my users (I use a whitelist so it's fairly short), the gamerules, the enchantment names, the status names, and the slot names (for /replaceitem). Of course, more things could be added, but this was all I needed.
For yasnippet, I just added snippets (M-x yas-new-snippet) of long commands that I use commonly. For instance, I like to summon mobs at the location of a player, so I have a snippet for that:
# -*- mode: snippet; require-final-newline: nil -*- # name: summon-mob-at-character # key: smab # binding: direct-keybinding # -- execute $1 ~ ~ ~ summon $2 ~ ~ ~ $0
$0 where the cursor ends after summoning the snippet, $1 where the cursor is placed first, and $2 where the cursor is placed last. auto-complete lets me tab-complete the player name at $1 and the mob name at $2.
So with a combination of screen and Emacs with auto-complete-mode and yasnippet we can get primitive tab-completion and ease the typing a bit.
It's primitive but it works. It can't do as much as plugins or mods can do though, such as getting player positions or detecting griefing and hacks. If only Craftbukkit would work...
Hopefully I can get Emacs to read the server log input live and get it to react to things happening. That would be cool.