WorldEdit selections for Bukkit plugins

Here’s a quick guide to using the selection API for WorldEdit from a Bukkit plugin.

A large part of WorldEdit uses an abstract internal API for easy portability  For your convenience, we provide a Bukkit-native selection API that makes it easier to work with that part of WorldEdit. It is possible to “reach through” to access to the internal features of WorldEdit, but if you are interested in only getting selections, that shouldn’t be needed.

Getting a selection

To get a selection, you need to:

  1. Get a reference to WorldEditPlugin from Bukkit’s plugin manager.
  2. Cast the reference from JavaPlugin to a more specific WorldEditPlugin.
  3. Get the selection by calling getSelection().

See the snippet below.

Continue reading

Mirroring your Minecraft server

We moved our Minecraft server from Texas to Germany about a year ago, but we had to deal with the problem of the extra latency. It got worse when we found out that the data center’s connections had a bit network jitter that caused “pauses” at random times for users farther away. I wanted to do something about it, without moving back across the pond. Now there is a physical distance between two places on Earth, and there’s no magic you can do there, but some creativity can be applied to the trip itself. Because there’s no direct Internet cable between, for example, California and Germany, a packet has to travel through several “hops” along the way. While the Internet is pretty good at finding the best links between two places and the hops in between, depending on who a data center may “peer with” and many other factors, sometimes you can interject to improve the situation a little.

In our case, some people experienced network jitter, while others didn’t. Because it really depended on which hops the connections passed through, the idea was to force a connection through a better performing hop.

mirror

How do you do that exactly? By setting up a “proxy” Minecraft server at a strategic location, users who had network issues could connect to that instead, and that proxy server would theoretically have a better route to the real server. tl, dr; You can make your server perform better for everyone else in the world, not necessarily by leaps and bounds, but at least by a little!

This provided a sometimes massive decrease in both network jitter and sometimes latency issues. In our case, because the server was in Germany, Americans sometimes benefited a fair amount. This was especially true for those in Hawaii, which is quite a bit far from Germany, and a few Hawaiians noted that it was much better with the proxy.

Continue reading

Improving your Minecraft server’s performance

Sometimes running a Minecraft means struggling with server lag, and sometimes this struggle can keep you awake at night (maybe…). No one wants to play on a server where everything seems to lag, and it can be quite disconcerting to a server owner to know that his or her server isn’t as fun as it could be. It is not entirely hopeless, however; the first step to fixing a problem is to understand it.

As some who I have helped may know, aside from working on WorldEdit and friends, I’ve been a pretty big performance nut, having been the first person to write a /tps command for Minecraft! Reading through this article, you’ll find:

  1. An overview of the game logic loop
  2. How this all applies to modded servers
  3. An explanation of transient problems
  4. A guide to profiling your server
  5. A macro-view of improving performance

The game logic loop

The most important part of Minecraft is the game loop. In there is a clock keeping everything synchronized, going tick-tock at an ideally constant rate: twenty times per second, with each tick or tock lasting hopefully at most 50 milliseconds. During each cycle, game elements have to do their work — skeletons have to figure out where to walk, minecarts have to travel forward, grass has to spread, and light problems have to be checked. That’s a lengthy to-do list, considering how many blocks and entities are on a loaded world at at time (thousands). This tick-tock interval is called the tick rate or “TPS,” and you can get some mod or plugin to give you your server’s rate.

vanilla

Quite a few things are on the to-do list, but as far as the “main game elements” go, those items are blocks, entities, and tile entities. Blocks include simple things such as sandstone, cobble, sugar cane, and things of that nature. Entities are your standard animals and monsters, in addition to paintings, item drops, and “objects that don’t fit perfectly on a grid.” Tile entities are a special kind of block, as they can hold any type of data (think storing an inventory, something sugar cane doesn’t have to do), and sometimes they must think separately. As previously mentioned, each loop has a budget of 50ms and each portion consumes some part of this pie. Any leftover time is considered idle.

Continue reading

Make the Steam web client compact

Something wonderful I discovered just the other day was Steam’s web chat client, which is a nice changeover from the desktop application freezing all the time for me. Google Chrome users can make it a small window and make shortcuts for it with Chrome’s Tools -> “Create application shortcuts” under the main menu.

It’s all web-based and powered by HTML, and so with a few changes to the page to make it more compact…

steam

To do the same, you’ll need Stylebot if you’re on Chrome, or something equivalent for other browsers (Stylish for Firefox). After installing Stylebot, navigate to the Steam chat page, click the “css” button in the address bar (it’s to the right), click the “Edit CSS” button on the new sidebar, and then paste in the code below:

Continue reading

From GitHub, to Redmine, to YouTrack

The first issue tracker (for reporting bugs and keeping track of issue requests) for WorldEdit, et al. was that provided of GitHub. Primarily tag-based, you could design how people would mark issues in the way that you wanted. While the situation has gotten slightly better since we last relied on the tracker, our ultimate problem with this flexibility was that some users would tag issues correctly, and many others would not. The lack of consistency meant that some time would have to be spent weeding out the bad reports and keeping track of the bugs or issues that needed more priority – a problem you tend to have when you allow public reporters. It was a problem that could be dealt with, but we just weren’t willing to deal with it in any capacity.

We briefly tested out Assembla 2-3 years ago to replace the tracker. It is more of an overall solution than simply a bug tracker, providing a “workspace” with optional support for its own hosted repositories, wiki, messaging, and file uploading. The features were optional and we were able to disable what we did not need. Unfortunately, the interface was cluttered – we felt that the interface was built more for the developer than your public issue reporter. As the goal was to promote the reporting of bugs and feature requests, we were hesitant to continue using Assembla. One proposal was to make a more user-friendly frontend, but we felt that it was outside the scope of our responsibility. In addition, my main concern with ditching GitHub was that it meant that new issues added on Assembla wouldn’t appear to users on GitHub who had starred the project (the community aspect is useful for an open source project), meaning that we weren’t far from the tipping point for the decision. It was not too long until we decided to return back to GitHub.

Sometime later, once our issues came to light again, we decided to try out Redmine. A popular open source Ruby-powered issue tracker, it had a few things going for it:

Continue reading

Version control all the things

Version control is practically essential to any software project, and it can be extremely useful even for your Minecraft server. What it does is simple: track any change, either large or small, knowing exactly who made the change, when the change was made, and exactly what the changes were. Software projects tend to use them because of those benefits, but if you aren’t already, there are many benefits to tracking every plugin, mod, or configuration change made to your server.
changelog

  • Easily spread around the work of updating the server (or corresponding client) with others. No more figuring out how to merge changes when you need to send files to other team members. Compared to Dropbox, you have far more tools available to you with a proper version control system — easily see differences down to individual lines.
  • Track every “release” of your server, which means that you can know exactly what was updated on what day, and most importantly, allow you to rollback to a prior release without having to scrounge around for the old files or old configurations.
  • If combined with a “deployment script,” you can just plug in a version that you want (i.e. release-2013-02-20) and your server could be automatically updated. Did the update go badly? Return to an old version (release-2013-02-16 perhaps?) instantly.

Continue reading

Minecraft server on a full disk

Recently, a Minecraft server I host used up all the disk space on its RAM drive, and consequently bad things resulted, but it further worsened by the fact that my friend kept the server running for eight hours more. The following is an explanation of what occurs when the Minecraft server keeps running but with no actual available disk space.

Running out of disk space

Does running out of disk space cause data loss? Not necessarily. Picture a chunk file as the example below, with three different chunks stored in different “slots.” The three squares represent disk space already “acquired” on the disk as one single .mca file, with the white areas representing acquired (from the PoV of a hard drive) but unused (from the PoV of Minecraft) space.

chunk

Sometimes a chunk needs to be enlarged, but only some activities do that. If you are placing down “simple” blocks like sandstone or cobble, you’re just changing a few bits of data in the chunk, so the chunk does not need to be resized. However, this is different when you add new entities (mobs, such as skeletons, or item drops, etc.) or new tile entities (more complex blocks, like chests, furnaces, etc.) because the existing space isn’t enough to store all the new data (think inventories!). Those changes require more disk space to store the chunk.

chunk1

But even then, even if the hard drive itself is out of space, sometimes it is OK. The middle chunk above still has “room” to expand. The white space available was already, as mentioned previously, acquired on the disk.

The problems appear when the slot that the chunk is already contained within becomes too small to fit the newest version of that chunk. What happens is that a new free area has to be found in the file that can fit the chunk, but if that cannot be found, the chunk is placed at the end of the file. Placing data at the end of the file means that the entire file itself has to be enlarged, therefore requiring more actual disk space usage. When the hard disk is out of space, the extra data has nowhere to go. Because the header of the .mca file indexes where a particular chunk is stored, the index for this chunk may now point to this section of the file that cannot actually be written, causing the chunk to simply “disappear” on next load.

chunk2

As seemingly irrelevant this information is to the world outside Minecraft, this also explains the same problem that your computer has when saving something to disk. When you save a file, it has the same, sometimes difficult, task: find a place to store the bits. If you’ve ever heard about “fragmentation,” that is when, rather than simply moving the entire file to another place, the file is split across across several areas. Of course, while Minecraft can put more data at the end of the file, your hard drive has a fixed amount of total space. The chunk format used by Minecraft does not do fragmentation.

Speaking of signature verification

One seemingly silly problem to deal with for those who host a “modded” Minecraft server is getting people to properly install those modifications. Copying a few files here and there seems simple enough, but it would be silly to say that connecting a backup generator to an electrical mains should be easy, just because it was easy to someone who dealt in the business. It comes down to an issue of numbers: if the difficulty was, for example, 10% harder, that could mean that there are 20% less people who can do it.

Several months ago, I updated my Minecraft launcher to support custom downloads and open sourced the entire launcher. While the update system worked pretty well, there was one caveat: it required that downloads be digitally signed, similar in principle to the browser verification of yourbank.com truly coming from yourbank.com. Setting up digital signatures is pretty straightforward, but it’s a straightforward in the same vein as client installation – it is easy if you are familiar with the tasks involved. For that reason, as of today, I have decided to disable digital signature verification for custom packages, which should make it vastly easier (vanilla downloads from Mojang are unaffected). I was trying hard to avoid this, but other, more elegant options require a currently unrealistic input of time and effort from me.

tl;dr: I have made a change to my Minecraft launcher which vastly makes the use of the custom update feature easier to setup, which allows you to setup a custom modified MC client for people. Use it to make playing with friends less hectic, or use it to distribute necessary files for a modded server. After following the steps described within this post, you should be able to distribute your own files and install them into a user’s game. Towards the end of the post will be a discussion of some non-technical issues involved with this. Update to the latest version of the launcher to use this newest change.

Building the package

update

You’ll need three files:

  1. A .zip file containing the files to install. This archive should contain files that would be placed into the root Minecraft folder (aka. .minecraft).
  2. A package XML file containing a list of files to install, with a link to the ZIP archive.
  3. An update XML file containing a link to the package file and a version string.

Continue reading

Hey look, I’m you with your privileges

Update: The man-in-the-middle attack described in this post is now ineffective as it was fixed in Minecraft 1.3, but the solution still works if you desire extra security.

A “session stealer” exploit in Minecraft is now being used increasingly widely to gain operator privileges on a target server. Anyone with the ability (or the freely available tools) can impersonate another user, which comes in handy to gain elevated privileges on a given server. The underlying exploit is actually extremely old, and while a small number of people have long been aware of it, news broke to the greater community recently and now it is a real relevant concern. On the flip side, the bug will finally be fixed (after three years) with the release of Minecraft 1.3. Hooray public disclosure.

exploit_logic

But I don’t want to wait for a fix

If you run a server, it’s understandable that you would want a fix now. You can ensure that you don’t expose your own account, but you also have to ensure that your own moderators do not either. That can be harder than it sounds, especially depending on who you are working with, and so some — even minor — protection to use would be nice. Unfortunately, it is not possible to fix the problem from just the server’s side, and so people have attempted to work around the problem by using a mix of some rather inconvenient solutions (mostly involving a /login command). Instead, I decided on a different novel way to protect the accounts of my moderators, described below.

Continue reading