Plugin: ArrayAddMoreBlocks

Let’s play with this a bit. We’ll start with the ArrayOfBlocks plugin but change it to use an ArrayList instead of an Array. We’ll call the new plugin ArrayAddMoreBlocks.

Since we can add to the array list easily, let’s make it static:

 
public​ ​static​ ​List​<BlockType> towerMaterials = ​new​ ​ArrayList​<BlockType>();

Then, thanks to the wonder of ArrayList, we can add a couple of blocks to the new tower each time we call /arrayaddmoreblocks:

ArrayAddMoreBlocks/src/arrayaddmoreblocks/ArrayAddMoreBlocks.java
 
public​ ​void​ buildTower(Player me) {
 
if​ (towerLoc == null) {
​ 
towerLoc = ​new​ Location(me.getLocation());
 
towerLoc.setX(towerLoc.getX() + 2); ​// Not right on top of player
​ 
towerBase = ...

Get Learn to Program with Minecraft Plugins, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.