Java Reference
In-Depth Information
So here we are, going through the list of offsets. At each list index (which is
in
i
), we need to pick out the three elements x, y, and z. In each of the small
arrays, x is first at index 0. The Java syntax lets you work with arrays of
arrays by writing both indexes, with the big list first. Think of this set of
numbers as a table or a matrix, with rows and columns, like you might find
in a Microsoft Excel spreadsheet. You specify indexes in “row-major order,”
which just means the row comes first, then the column. For each trip through
the loop, we'll pick out x, y, and z values from the list. That's the location of
a block we want to turn to stone.
We get the block at that location we want—in this case, by adding the x, y,
and z offset to the player's location (
playerX
,
playerY
, and
playerZ
from the code).
With the block in hand, simply set its material to stone by using the constant
BlockType.Stone
. All the different block types are listed in the documentation for
net.canarymod.api.world.blocks.BlockType
. You could, for instance, remove a block
without breaking it—you'd set the block's material to
BlockType.Air
, like we did
back with the array towers.
Here's the code for the full plugin, all together:
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);
}
}