From 8bb0629d79ecc5b9b5100dcbf7dfa4c3b47cdfc9 Mon Sep 17 00:00:00 2001 From: sk89q Date: Tue, 2 Aug 2011 15:46:11 -0700 Subject: [PATCH 1/3] Added //naturalize. --- plugin.yml | 210 +++++++++--------- .../java/com/sk89q/worldedit/EditSession.java | 73 ++++++ .../worldedit/commands/RegionCommands.java | 17 ++ 3 files changed, 197 insertions(+), 103 deletions(-) diff --git a/plugin.yml b/plugin.yml index e662e702e..d53ef2cac 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: WorldEdit main: com.sk89q.worldedit.bukkit.WorldEditPlugin -version: "${project.version}" +version: ${project.version} commands: chunkinfo: description: Get information about the chunk that you are inside @@ -14,10 +14,6 @@ commands: description: Delete chunks that your selection includes usage: / permissions: 'worldedit.delchunks' - clearclipboard: - description: Clear your clipboard - usage: / - permissions: 'worldedit.clipboard.clear' /load: description: Load a schematic into your clipboard usage: / @@ -46,6 +42,19 @@ commands: description: Paste the clipboard's contents usage: / [-ao] permissions: 'worldedit.clipboard.paste' + clearclipboard: + description: Clear your clipboard + usage: / + permissions: 'worldedit.clipboard.clear' + /limit: + description: Modify block change limit + usage: / + permissions: 'worldedit.limit' + /gmask: + description: Set the global mask + usage: / [mask] + aliases: ['gmask'] + permissions: 'worldedit.global-mask' we: description: WorldEdit commands usage: / @@ -61,15 +70,6 @@ commands: description: Search for an item usage: / [-bi] aliases: ['/l', 'search'] - /limit: - description: Modify block change limit - usage: / - permissions: 'worldedit.limit' - /gmask: - description: Set the global mask - usage: / [mask] - aliases: ['gmask'] - permissions: 'worldedit.global-mask' /hcyl: description: Generate a hollow cylinder usage: / [height] @@ -94,32 +94,36 @@ commands: description: Generate pumpkin patches usage: / [size] permissions: 'worldedit.generation.pumpkins' - clearhistory: - description: Clear your history - usage: / - permissions: 'worldedit.history.clear' - /redo: - description: Redoes the last action (from history) - usage: / [times] - aliases: ['redo'] - permissions: 'worldedit.history.redo' /undo: description: Undoes the last action usage: / [times] aliases: ['undo'] permissions: 'worldedit.history.undo' + /redo: + description: Redoes the last action (from history) + usage: / [times] + aliases: ['redo'] + permissions: 'worldedit.history.redo' + clearhistory: + description: Clear your history + usage: / + permissions: 'worldedit.history.clear' unstuck: description: Escape from being stuck inside a block usage: / permissions: 'worldedit.navigation.unstuck' ascend: description: Go up a floor - usage: / + usage: / [# of levels] permissions: 'worldedit.navigation.ascend' descend: description: Go down a floor - usage: / + usage: / [# of floors] permissions: 'worldedit.navigation.descend' + ceil: + description: Go to the celing + usage: / [clearance] + permissions: 'worldedit.navigation.ceiling' thru: description: Passthrough walls usage: / @@ -128,18 +132,30 @@ commands: description: Teleport to a location usage: / permissions: 'worldedit.navigation.jumpto' - ceil: - description: Go to the celing - usage: / [clearance] - permissions: 'worldedit.navigation.ceiling' up: description: Go upwards some distance usage: / permissions: 'worldedit.navigation.up' + /replace: + description: Replace all blocks in the selection with another + usage: / [from-block] + permissions: 'worldedit.region.replace' + /stack: + description: Repeat the contents of the selection + usage: / [-sa] [count] [direction] + permissions: 'worldedit.region.stack' + /set: + description: Set all the blocks inside the selection to a block + usage: / + permissions: 'worldedit.region.set' /overlay: description: Set a block on top of blocks in the region usage: / permissions: 'worldedit.region.overlay' + /naturalize: + description: 3 layers of dirt on top then rock below + usage: / + permissions: 'worldedit.region.naturalize' /walls: description: Build the four sides of the selection usage: / @@ -153,38 +169,46 @@ commands: description: Smooth the elevation in the selection usage: / [iterations] permissions: 'worldedit.region.smooth' - /regen: - description: Regenerates the contents of the selection - usage: / - permissions: 'worldedit.regen' - /replace: - description: Replace all blocks in the selection with another - usage: / [from-block] - permissions: 'worldedit.region.replace' - /stack: - description: Repeat the contents of the selection - usage: / [-sa] [count] [direction] - permissions: 'worldedit.region.stack' - /set: - description: Set all the blocks inside the selection to a block - usage: / - permissions: 'worldedit.region.set' /move: description: Move the contents of the selection usage: / [-s] [count] [direction] [leave-id] permissions: 'worldedit.region.move' - .s: - description: Execute last CraftScript - usage: / [args...] - permissions: 'worldedit.scripting.execute' + /regen: + description: Regenerates the contents of the selection + usage: / + permissions: 'worldedit.regen' cs: description: Execute a CraftScript usage: / [args...] permissions: 'worldedit.scripting.execute' + .s: + description: Execute last CraftScript + usage: / [args...] + permissions: 'worldedit.scripting.execute' + /count: + description: Counts the number of a certain type of block + usage: / + permissions: 'worldedit.analysis.count' + /size: + description: Get information about the selection + usage: / + permissions: 'worldedit.selection.size' + /shift: + description: Shift the selection area + usage: / [direction] + permissions: 'worldedit.selection.shift' + /sel: + description: Choose a region selector + usage: / [type] + aliases: [','] /chunk: description: Set the selection to your current chunk usage: / permissions: 'worldedit.selection.chunk' + /expand: + description: Expand the selection area + usage: / [reverse-amount] + permissions: 'worldedit.selection.expand' /contract: description: Contract the selection area usage: / [reverse-amount] [direction] @@ -217,34 +241,14 @@ commands: description: Outset the selection area usage: / [-hv] permissions: 'worldedit.selection.outset' - /distr: - description: Get the distribution of blocks in the selection - usage: / [-c] - permissions: 'worldedit.analysis.distr' - /count: - description: Counts the number of a certain type of block - usage: / - permissions: 'worldedit.analysis.count' - /size: - description: Get information about the selection - usage: / - permissions: 'worldedit.selection.size' - /shift: - description: Shift the selection area - usage: / [direction] - permissions: 'worldedit.selection.shift' - /expand: - description: Expand the selection area - usage: / [reverse-amount] - permissions: 'worldedit.selection.expand' - /sel: - description: Choose a region selector - usage: / [type] - aliases: [','] /inset: description: Inset the selection area usage: / [-hv] permissions: 'worldedit.selection.inset' + /distr: + description: Get the distribution of blocks in the selection + usage: / [-c] + permissions: 'worldedit.analysis.distr' snapshot: description: Snapshot commands usage: / @@ -254,6 +258,14 @@ commands: usage: / [snapshot] aliases: ['/restore'] permissions: 'worldedit.snapshots.restore' + size: + description: Set the brush size + usage: / [pattern] + permissions: 'worldedit.brush.options.size' + mask: + description: Set the brush mask + usage: / [mask] + permissions: 'worldedit.brush.options.mask' /: description: Toggle the super pickaxe pickaxe function usage: / @@ -271,21 +283,21 @@ commands: usage: / [pattern] aliases: ['material', 'fill'] permissions: 'worldedit.brush.options.material' - size: - description: Set the brush size - usage: / [pattern] - permissions: 'worldedit.brush.options.size' range: description: Set the brush range - usage: / [range] + usage: / [pattern] permissions: 'worldedit.brush.options.range' - mask: - description: Set the brush mask - usage: / [mask] - permissions: 'worldedit.brush.options.mask' + info: + description: Block information tool + usage: / + permissions: 'worldedit.tool.info' none: description: Turn off all superpickaxe alternate modes usage: / + tree: + description: Tree generator tool + usage: / [type] + permissions: 'worldedit.tool.tree' repl: description: Block replacer tool usage: / @@ -307,18 +319,23 @@ commands: description: Floating tree remover tool usage: / permissions: 'worldedit.tool.deltree' - info: - description: Block information tool - usage: / - permissions: 'worldedit.tool.info' - tree: - description: Tree generator tool - usage: / [type] - permissions: 'worldedit.tool.tree' + remove: + description: Remove all entities of a type + usage: / + aliases: ['rem', 'rement'] + permissions: 'worldedit.remove' + /fill: + description: Fill a hole + usage: / [depth] + permissions: 'worldedit.fill' /fillr: description: Fill a hole recursively usage: / [depth] permissions: 'worldedit.fill.recursive' + /drain: + description: Drain a pool + usage: / + permissions: 'worldedit.drain' fixlava: description: Fix lava to be stationary usage: / @@ -360,16 +377,3 @@ commands: description: Kill all or nearby mobs usage: / [-p] [radius] permissions: 'worldedit.butcher' - remove: - description: Remove all entities of a type - usage: / - aliases: ['rem', 'rement'] - permissions: 'worldedit.remove' - /fill: - description: Fill a hole - usage: / [depth] - permissions: 'worldedit.fill' - /drain: - description: Drain a pool - usage: / - permissions: 'worldedit.drain' diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index 7482a558a..0eb92c9de 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -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. * diff --git a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java index d14c0696b..5ff3ba607 100644 --- a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java @@ -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 = "", From 8ea980a303e1fb35da6d391ebc58c398d4059537 Mon Sep 17 00:00:00 2001 From: sk89q Date: Tue, 2 Aug 2011 15:52:26 -0700 Subject: [PATCH 2/3] Changed //smooth to smooth nearly everything. --- src/main/java/com/sk89q/worldedit/EditSession.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index 0eb92c9de..5735238e0 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -2276,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 @@ -2293,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; } From 37f8b8927a2e5c3dec08267f93f3070c84a66584 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Thu, 4 Aug 2011 21:58:14 -0700 Subject: [PATCH 3/3] Made getGroups() work properly for nijiperms. --- pom.xml | 2 +- .../bukkit/migration/NijiPermissionsResolver.java | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index fd3c46960..0701375e0 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ com.sk89q dummypermscompat - 1.2 + 1.3 diff --git a/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java b/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java index 84f32e674..df87acd18 100644 --- a/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java +++ b/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java @@ -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();