Keep Things Private or Make Them Public

So far, we’ve tended to use the Java keyword public when making static variables and defining functions and plugins. That tells Java that the thing we’re defining should be publicly accessible—all of our own plugin code can use it, and any other plugin in the system can use it as well (like when we use logger).

There is another option. You can create functions or variables or even helper objects that no one else can see. Instead of public, you can make them private.

In programming, there’s a simple rule—so simple it’s the kind of thing you’d tell a five-year-old: don’t expose your privates.

In other words, if you’re using a function or something that only you should use, then mark it as private to ...

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.