Java Reference
In-Depth Information
it to be visible for all the functions in our plugin and to stick around as long
as the plugin is around.
Here's a recap of our story so far:
•A block of code is written inside { and } .
•Variables you declare inside the body of a block of code are local to that
block of code. They go away when the function finishes and returns.
•A function's parameters are local to that function.
•Variables declared as static will outlive any local variables declared within
Here's a quick plugin that gives us a /caketower command. The idea is that it
will build a tower of cake blocks. But there's a subtle problem in the code
involving local and global variables, and the tower may not turn out the way
you expect. Let's take a look.
Plugin: CakeTower
package caketower;
import net.canarymod.plugin.Plugin;
import net.canarymod.logger.Logman;
import net.canarymod.Canary;
import net.canarymod.commandsys.*;
import com.pragprog.ahmine.ez.EZPlugin;
public class CakeTower extends EZPlugin {
public static int cakeHeight = 100;
@Command(aliases = { "caketower" },
description = "Build a tall tower of cakes" ,
permissions = { "" },
toolTip = "/caketower" )
public void cakeTowerCommand(MessageReceiver caller, String[] parameters) {
if (caller instanceof Player) {
Player me = (Player)caller; "1) cake height is " + cakeHeight); // Print it
Search WWH ::

Custom Search