Java Reference
In-Depth Information
Now we'll add some storage capability to your toolbox, and discover
some more advanced Java language features. You'll add these skills:
• Save and load user-editable configuration data from a local file
• Save and load your private game data from a database
• Build up more complex code from smaller functions
• Use Canary's DataAccess to use their built-in database functions
• Understand Java exceptions and annotations
Use Configuration Files
and Store Game Data
Now we're getting someplace. From what you've learned so far, you can listen
for events, schedule tasks to run later, keep data around in lists or hashes,
and let your whole plugin use it as long as the server is up and running. That
puts you in a good position to build some fun plugins. However, you're
missing an important piece: servers don't run forever.
Any Minecraft server (including yours) can just stop running. You've stopped
yours a bunch of times by now, just to install plugins! Even if you weren't
installing new plugins, hardware can crash, or maybe you just closed your
laptop. And once the server stops running, your plugin will forget everything
it used to know. All its data is gone.
So we need to figure out how to save important data on disk somewhere,
where we can save it often and load it back in when we need to.
There are two different kinds of data that you might care about:
•Configuration data, which contains things you need to know about how
the plugin should work. This is probably set only once and updated rarely,
but it's read every time the plugin runs. You've probably used configuration
files in other plugins or in the server setup for Minecraft itself.
•Game data, which contains things like player scores, inventory, and stuff
that changes frequently as the game plays. That gets a little tricky, as
we'll see shortly.
Let's look at each of these types of data and how to save and load them.
Search WWH ::

Custom Search