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
functions.
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
CakeTower/src/caketower/CakeTower.java
package caketower;
import net.canarymod.plugin.Plugin;
import net.canarymod.logger.Logman;
import net.canarymod.Canary;
import net.canarymod.commandsys.*;
import net.canarymod.chat.MessageReceiver;
import net.canarymod.api.entity.living.humanoid.Player;
import net.canarymod.api.world.position.Location;
import net.canarymod.api.world.blocks.BlockType;
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;
me.chat( "1) cake height is " + cakeHeight); // Print it
 
 
 
Search WWH ::




Custom Search