Merge branch 'master' of git@github.com:sk89q/worldedit.git

This commit is contained in:
hretsam
2011-08-05 12:30:27 +02:00
5 changed files with 207 additions and 111 deletions

View File

@ -101,16 +101,18 @@ public class NijiPermissionsResolver implements PermissionsResolver {
try {
Player player = server.getPlayer(name);
if (player == null) return new String[0];
String group;
String[] groups = null;
try {
group = api.getHandler().getGroup(player.getWorld().getName(), player.getName());
groups = api.getHandler().getGroups(player.getWorld().getName(), player.getName());
} catch (Throwable t) {
group = api.Security.getGroup(player.getName());
String group = api.Security.getGroup(player.getWorld().getName(), player.getName());
if (group != null)
groups = new String[] {group};
}
if (group == null) {
if (groups == null) {
return new String[0];
} else {
return new String[]{ group };
return groups;
}
} catch (Throwable t) {
t.printStackTrace();

View File

@ -1296,6 +1296,79 @@ public class EditSession {
return affected;
}
/**
* Turns the first 3 layers into dirt/grass and the bottom layers
* into rock, like a natural Minecraft mountain.
*
* @param region
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int naturalizeCuboidBlocks(Region region)
throws MaxChangedBlocksException {
Vector min = region.getMinimumPoint();
Vector max = region.getMaximumPoint();
int upperY = Math.min(127, max.getBlockY() + 1);
int lowerY = Math.max(0, min.getBlockY() - 1);
int affected = 0;
int minX = min.getBlockX();
int minZ = min.getBlockZ();
int maxX = max.getBlockX();
int maxZ = max.getBlockZ();
BaseBlock grass = new BaseBlock(BlockID.GRASS);
BaseBlock dirt = new BaseBlock(BlockID.DIRT);
BaseBlock stone = new BaseBlock(BlockID.STONE);
for (int x = minX; x <= maxX; ++x) {
for (int z = minZ; z <= maxZ; ++z) {
int level = -1;
for (int y = upperY; y >= lowerY; --y) {
Vector pt = new Vector(x, y, z);
Vector above = new Vector(x, y + 1, z);
int blockType = getBlockType(pt);
boolean isTransformable =
blockType == BlockID.GRASS
|| blockType == BlockID.DIRT
|| blockType == BlockID.STONE;
// Still searching for the top block
if (level == -1) {
if (!isTransformable) {
continue; // Not transforming this column yet
}
level = 0;
}
if (level >= 0) {
if (isTransformable) {
if (level == 0) {
setBlock(pt, grass);
affected++;
} else if (level <= 2) {
setBlock(pt, dirt);
affected++;
} else {
setBlock(pt, stone);
affected++;
}
}
level++;
}
}
}
}
return affected;
}
/**
* Stack a cuboid region.
*
@ -2203,7 +2276,7 @@ public class EditSession {
Vector pt = new Vector(x, y, z);
int id = getBlockType(pt);
if (id == 1 // stone
if (!BlockType.canPassThrough(id) /*id == 1 // stone
|| id == 2 // grass
|| id == 3 // dirt
|| id == 7 // bedrock
@ -2220,7 +2293,7 @@ public class EditSession {
|| id == 16 // gold ore
|| id == 56 // diamond ore
|| id == 73 // redstone ore
|| id == 74 // redstone ore (active)
|| id == 74 // redstone ore (active)*/
) {
return y;
}

View File

@ -121,6 +121,23 @@ public class RegionCommands {
player.print(affected + " block(s) have been overlayed.");
}
@Command(
aliases = {"/naturalize"},
usage = "",
desc = "3 layers of dirt on top then rock below",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.region.naturalize"})
public static void naturalize(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Region region = session.getSelection(player.getWorld());
int affected = editSession.naturalizeCuboidBlocks(region);
player.print(affected + " block(s) have been naturalized.");
}
@Command(
aliases = {"/walls"},
usage = "<block>",