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, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access