Java Reference
In-Depth Information
getLocation() returns the Location for this block. Only one block can exist at
any location in the world, and every location contains a block, even if it's
just air.
getType() returns the BlockType this block is made of.
rightClick(Playerplayer) simulates a right-click on the block. Useful for forcing
changes to blocks like levers, buttons, and doors.
Let's play with some blocks, Minecraft style.
Plugin: Stuck
Let's look at a plugin that will encase a player in solid rock (the full plugin is
in code/Stuck ). When you issue the command stuck with a player's name, that
player will suddenly be encased in a pile of blocks. (If you're alone on the
server, your player name might be the wonderfully descriptive name “player.”)
We'll start by looking at pieces of this plugin, and then put it all together.
All the interesting parts are in a separate helper function named stuck . The
main part of the plugin should look pretty familiar by now:
Stuck/src/stuck/Stuck.java
package stuck;
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.Block;
import net.canarymod.api.world.blocks.BlockType;
import com.pragprog.ahmine.ez.EZPlugin;
public class Stuck extends EZPlugin {
@Command(aliases = { "stuck" },
description = "Trap a player in cage of blocks" ,
permissions = { "" },
min = 2,
toolTip = "/stuck name" )
public void stuckCommand(MessageReceiver caller, String[] args) {
Player victim = Canary.getServer().getPlayer(args[1]);
if (victim != null) {
stuck(victim);
}
}
 
 
 
Search WWH ::




Custom Search