Critique my code

Literally the first thing I’ve written in Java. (Google is a powerful thing yo.)

I would like to know if anything isn’t a good practice, or things to make it look prettier. Its not finished yet because I don’t know how to set the armor stands as NoAI, and Marker. Also seems that the dismounting event is never called so I don’t know when to delete the armor stand.

Just a couple things I found from skimming through your code:

Instead of using Strings in your Map of rotations:

static {
        rotation.put("north", 0.0);
        rotation.put("east", 90.0);
        rotation.put("south", 180.0);
        rotation.put("west", -90.0);
    }

You might want to use an enum such as Direction. That way, you will never have typographical issues where you try to do rotation.get("nrth"), and when you misspell ‘north’ your code suddenly doesn’t work for any apparent reason. Rather, if you use an enum and you misspell NORTH, it simply won’t compile.

Also, you may want to invert your if statements so you don’t have so many curly brackets at the end. So for example instead of doing:

if (oLocation.isPresent()) {
...
}

You might want to instead have:

if(!oLocation.isPresent()) {
    return;
}
...

Other than that, job well done! :slightly_smiling:

1 Like

Thanks! Speaking about direction, is there a better way to get which way stairs are facing, instead of using EnumTraits.OAK_STAIRS_FACING?
Even though I tried and you can use it on different stairs, it would feel a little weird using it on the different blocks.

Take a look at the Data API. In your case, you would use Optional oRotation = event.getTargetBlock().getState().get(Keys.DIRECTION).get();