Posts Tagged ‘minecraft plugin’

Updating Minecraft Plugins

April 14, 2012

So, I updated my bukkit plugins recently.

And when I did, the users were jubilant, like the onlookers in a Tom Slick race.

And I noticed that there were some tickets associated with my plugins, some of which were submitted by me, some from others.

Neat! I’ve actually got people interested in the improvement of my software.

So, I start to address them, now that I have straightened out my Java workspaces thanks to Dropbox.

And I was cruising along, and made a few additions.

One of the most important parts any bukkit plugin is the command console processing.

Generally there is at least some sort of command that need to set configuration or otherwise check the status of the plugin.

In the one I am working on now, SpawnSurance, has to process a lot of config parameters.

And looking at the code, it was of the nature:

  • if there is one parameter
    • if the parameter is X
    • if the parameter is Y
    • if the parameter is Z
  • if there are two parameters
    • if the parameter is X
    • if the parameter is Y
    • if the parameter is Z
  • if there are three parameters
    • if the parameter is X
    • if the parameter is Y
    • if the parameter is Z

Which is obviously a mess to have to maintain and deal with, especially since added a new parameter that takes the rest of the parameters and concatenates them to add to a custom message.

So, after now acquiring quite a bit of Java experience, I know that I can use List<String>, copy my String[] of arguments over to it, and process through them in a more natural way.

  • if the first parameter is X
    • remove first parameter, then process with the processX method
  • if the first parameter is Y
    • remove first parameter, then process with the processY method
  • if the first parameter is Z
    • remove first parameter, then process with the processZ method

Which is way more maintainable.

But I got hoist on my own petard, and had a hard time finding out why or how I had done so.

I have had a bizarre fetish for not using magic numbers or strings.

I put everything into a class called Constants, and there are a large number of public final static String X = “something”; and public final static Integer Y = 0; and so on.

Which is a good idea, but here’s where I went awry.

All of my constant integers were Integer, not int.

So, when I had my List<String>, I was passing Constants.argCountZero (an Integer) into the remove function.

There are two remove functions for List<String>. One takes an int, the other takes an Object.

Integer is an Object.

So called theArgList.remove(Constants.argCountZero) DID NOTHING!

BECAUSE IT IS AN Integer, NOT AN int!

Of course, this took me about an hour to determine.

Sigh.