Java Reference
In-Depth Information
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.Block;
import net.canarymod.api.world.blocks.BlockType;
import com.pragprog.ahmine.ez.EZPlugin;
public class ArrayOfBlocks extends EZPlugin {
public void buildTower(Player me) {
Location loc = me.getLocation();
loc.setX(loc.getX() + 1); // Not right on top of player
BlockType [] towerMaterials = new BlockType[5];
towerMaterials[0] = BlockType.Stone;
towerMaterials[1] = BlockType.Cake;
towerMaterials[2] = BlockType.OakWood;
towerMaterials[3] = BlockType.Glass;
towerMaterials[4] = BlockType.Anvil;
for ( int i=0; i < towerMaterials.length; i++) {
loc.setY(loc.getY() + 1); // go up one each time
setBlockAt(loc, towerMaterials[i]);
}
}
@Command(aliases = { "arrayofblocks" },
description = "Create an array of blocks" ,
permissions = { "" },
toolTip = "/arrayofblocks" )
public void arrayofblocksCommand(MessageReceiver caller, String[] args) {
if (caller instanceof Player) {
Player me = (Player)caller;
buildTower(me);
}
}
}
Install the ArrayOfBlocks with build.sh , stop and restart the server, and try the
/arrayofblocks command. You should see something like Figure 1, Array of Blocks ,
on page 98 (you might need to turn around to see it).
Notice that I put the guts of the command in its own function, buildTower ,
instead of in the arrayofblocksCommand function itself.
This is just a simple Array of length 5 that we are loading up with values one
at a time. The for loop goes from index 0 to 4 and changes the block to the
new material in our list.
 
 
Search WWH ::




Custom Search