# How to select position 1, position 2, and then make a wall?

Discussion in 'Plugin Development' started by Ambamore2000, Mar 8, 2014.

Thread Status:
Not open for further replies.
1. Offline

### Ambamore2000

So, as most of you know/heard, there is a plugin called worldedit. It is a very helpful plugin, and it includes the command //walls <blocktype>. I was wondering how they did that. I want it, so you do //specwalls <radius> for this. If there is any way you can tell me, please tell me. I don't think you would give code, because I'm expecting this'll take a long time, but please tell me with words.

#1
2. Offline

### CraftThatBlock

Idea:
loc1
loc2

xMin = Math.min(loc1.getX, loc2.getX)
xMax = Math.max(loc1.getX, loc2.getX)

yMin = Math.min(loc1.getY, loc2.getY)
yMax = Math.max(loc1.getY, loc2.getY)

zMin = Math.min(loc1.getZ, loc2.getZ)
zMax = Math.max(loc1.getZ, loc2.getZ)

for(int x = xMin; x < xMax; x++){
for(int y = yMin; y < yMax; y++){
for(int z = xMin; z < zMax; z++){
(new Location(loc1.getWorld(), x, y, z)).getBlock().setType(Material.Stone);

}
}
}
(Note: This is not real java code, I was just outlining most of the code. the min and max should be ints,

#2
AoH_Ruthless likes this.
3. Offline

#3
4. Offline

### CraftThatBlock

To expand on what ArthurMaker did, (great lib btw), you can use this code:

Code:java
` for(Location loc : getCuboid(loc1, loc2){    Block b = loc.getBlock();    b.setMaterial(Material.Stone);}  // From Arthur:public static List<Location> getCuboid(Location position1, Location position2){ if(position1.getWorld().getName() != position2.getWorld().getName()){throw new UnsupportedOperationException("'Position1' and 'Position2' location need to be in the same world!");} List<Location> cube = new ArrayList<Location>(); int minX = (int) Math.min(position1.getX(), position2.getX());int maxX = (int) Math.max(position1.getX(), position2.getX()); int minY = (int) Math.min(position1.getY(), position2.getY());int maxY = (int) Math.max(position1.getY(), position2.getY()); int minZ = (int) Math.min(position1.getZ(), position2.getZ());int maxZ = (int) Math.max(position1.getZ(), position2.getZ()); for(int x = minX; x <= maxX; x++){for(int y = minY; y <= maxY; y++){for(int z = minZ; z <= maxZ; z++){cube.add(new Location(position1.getWorld(), x, y, z));}}}return cube; }`

#4
Thread Status:
Not open for further replies.