Java Reference
In-Depth Information
At the end of our function we'll call
save()
. In case the actual configuration file
didn't exist yet, this will create it with default values. Otherwise, if we haven't
changed any values, it won't do anything.
Later in the plugin, we'll use these static, class-level variables instead of the
hard-coded numbers we used in the previous version:
double
y = loc.getY();
loc.setY(y + squidDropHeight);
me.chat(
"Spawning "
+ numSquids +
" squid."
);
// Spawning some squid. Derp.
for
(
int
i = 0; i < numSquids; i++) {
spawnEntityLiving(loc, EntityType.SQUID);
}
Easy peasy.
Try This Yourself
Run
build.sh
on your new
SquidBombConfig
plugin and try the
squidbombc
com-
mand—it should work exactly as it did in the previous version (but this version
has a “c” at the end, so it's
squidbombc
).
Now go to your server's config directory, and you'll see a new
SquidBombConfig
directory. In that directory you'll find your new
SquidBombConfig.cfg
file:
~/Desktop/server$
cd config
~/Desktop/server/config$
ls
SquidBombConfig
motd.txt
plugin_priorities.cfg worlds
db.cfg
ops.cfg
server.cfg
~/Desktop/server/config$
cd SquidBombConfig/
~/Desktop/server/config/SquidBombConfig$
ls
SquidBombConfig.cfg
~/Desktop/server/config/SquidBombConfig$
cat SquidBombConfig.cfg
numSquids=6
squidDropHeight=5.0
setFire=false
Here I used the command
cat
to dump out the contents of the file.
Edit that file, and change the number of squid to something larger, say 12
or so. Save the file and restart your server.
Now when you run the
SquidBomb
command, you are inundated with squid.
Congratulations! Your users now have the ability to tweak your plugin without
needing access to the source code at all.