Java Reference
In-Depth Information
Use a Configuration File
Many plugins, and the server itself, use configuration files to fine-tune and
customize different values and select different behaviors. A configuration file
is just a simple text file, designed to be read and edited directly by a person.
The idea is that you can customize aspects of the plugin without having to
fool around with the source code or recompile anything. End users, server
operators, developers—everyone can use them. And now we will too.
We're going to modify a plugin to use a configuration file. Previously, on page
83 , we built a plugin that dropped a bunch of squid on your current location—
a “squid bomb.” We're going to add configuration options to the SquidBomb plugin:
•The number of squid to drop
•The height from which the squid fall
•The ability to get rid of the squid cleanly, or set the squid on fire (a new
feature!)
Lucky for us, the Canary plugins come with a configuration-file mechanism
built in and ready to use. Here's how it works.
The configuration file itself will be named PluginName .cfg , and placed in a
subdirectory named for the plugin under Server/config . So for our SquidBombConfig
plugin, the config file would be here:
~/Desktop/server/config/SquidBombConfig/SquidBombConfig.cfg
The config file itself looks something like this:
numSquids=6
squidDropHeight=5.0
setFire=false
The format used in this file is a very simple format. In fact, you've been using
it all along—it's the format of the Canary.inf file also.
Each line represents one setting and has just the name of the value you want
to store (no spaces in the name, please), followed by an equals sign ( = ) and
then the value. You can store strings, integers, booleans (true or false), dou-
bles, and so on.
If the cfg file doesn't exist when the plugin starts up, it will create a default
one based on values you set in the plugin. That's an easy way to get started;
once the file is created, you (or a user or server operator) can go in and make
changes to the file on disk.
 
 
Search WWH ::




Custom Search