Handle Chat Commands

The bit with the @Command at ​​ tells the system that this function, skyCommand, is responsible for handling the /sky command. That is, when the player types the /sky command, your skyCommand function will be called.

The first thing we need to check is a little awkward; it turns out that the MessageReceiver that gets passed to us here may not be a Player. It could be a Player object, or who knows what else. We want to make sure it’s really a Player, so we’ll check for that explicitly at ​​, using the Java keyword instanceof. This tests to see if the thing passed in is really a Player. If it is, then we’re going to do the bulk of the command starting at ​​. (If it’s not a Player, then it’s probably a console command, ...

Get Learn to Program with Minecraft Plugins, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.