/** * Print an error message to the user. * * @param message a message */ public void error(String message) { player.printError(message); }
@Override public void printError(String msg) { basePlayer.printError(msg); }
public Location getTargetFace(Player player) { Location target = player.getBlockTraceFace(getRange(), true); if (target == null) { player.printError("No block in sight!"); return null; } return target; }
public Location getTarget(Player player) { Location target; if (this.range > -1) { target = player.getBlockTrace(getRange(), true); } else { target = player.getBlockTrace(MAX_RANGE); } if (target == null) { player.printError("No block in sight!"); return null; } return target; } }
@Override public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) { try (EditSession editSession = session.createEditSession(player)) { try { boolean successful = false; for (int i = 0; i < 10; i++) { if (treeType.generate(editSession, clicked.toVector().add(0, 1, 0).toBlockPoint())) { successful = true; break; } } if (!successful) { player.printError("A tree can't go there."); } } catch (MaxChangedBlocksException e) { player.printError("Max. blocks changed reached."); } finally { session.remember(editSession); } } return true; }
@Command( aliases = { "thru" }, usage = "", desc = "Passthrough walls", min = 0, max = 0 ) @CommandPermissions("worldedit.navigation.thru.command") public void thru(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { if (player.passThroughForwardWall(6)) { player.print("Whoosh!"); } else { player.printError("No free spot ahead of you found."); } }
@Command( aliases = { "descend", "desc" }, usage = "[# of floors]", desc = "Go down a floor", min = 0, max = 1 ) @CommandPermissions("worldedit.navigation.descend") public void descend(Player player, @Optional("1") int levelsToDescend) throws WorldEditException { int descentLevels = 0; while (player.descendLevel()) { ++descentLevels; if (levelsToDescend == descentLevels) { break; } } if (descentLevels == 0) { player.printError("No free spot below you found."); } else { player.print((descentLevels != 1) ? "Descended " + Integer.toString(descentLevels) + " levels." : "Descended a level."); } }
@Command( aliases = { "ascend", "asc" }, usage = "[# of levels]", desc = "Go up a floor", min = 0, max = 1 ) @CommandPermissions("worldedit.navigation.ascend") public void ascend(Player player, @Optional("1") int levelsToAscend) throws WorldEditException { int ascentLevels = 0; while (player.ascendLevel()) { ++ascentLevels; if (levelsToAscend == ascentLevels) { break; } } if (ascentLevels == 0) { player.printError("No free spot above you found."); } else { player.print((ascentLevels != 1) ? "Ascended " + Integer.toString(ascentLevels) + " levels." : "Ascended a level."); } }
@Command( aliases = { "jumpto", "j" }, usage = "", desc = "Teleport to a location", min = 0, max = 0 ) @CommandPermissions("worldedit.navigation.jumpto.command") public void jumpTo(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { Location pos = player.getSolidBlockTrace(300); if (pos != null) { player.findFreePosition(pos); player.print("Poof!"); } else { player.printError("No block in sight!"); } }
@Command( aliases = { "ceil" }, usage = "[clearance]", desc = "Go to the celing", flags = "fg", min = 0, max = 1 ) @CommandPermissions("worldedit.navigation.ceiling") @Logging(POSITION) public void ceiling(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { final int clearance = args.argsLength() > 0 ? Math.max(0, args.getInteger(0)) : 0; final boolean alwaysGlass = getAlwaysGlass(args); if (player.ascendToCeiling(clearance, alwaysGlass)) { player.print("Whoosh!"); } else { player.printError("No free spot above you found."); } }
@Command( aliases = { "up" }, usage = "<block>", desc = "Go upwards some distance", flags = "fg", min = 1, max = 1 ) @CommandPermissions("worldedit.navigation.up") @Logging(POSITION) public void up(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { final int distance = args.getInteger(0); final boolean alwaysGlass = getAlwaysGlass(args); if (player.ascendUpwards(distance, alwaysGlass)) { player.print("Whoosh!"); } else { player.printError("You would hit something above you."); } }
@Command( aliases = { "/hpos2" }, usage = "", desc = "Set position 2 to targeted block", min = 0, max = 0 ) @CommandPermissions("worldedit.selection.hpos") public void hpos2(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { Location pos = player.getBlockTrace(300); if (pos != null) { if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) { player.printError("Position already set."); return; } session.getRegionSelector(player.getWorld()) .explainSecondarySelection(player, session, pos.toVector().toBlockPoint()); } else { player.printError("No block in sight!"); } }
@Command( aliases = { "/hpos1" }, usage = "", desc = "Set position 1 to targeted block", min = 0, max = 0 ) @CommandPermissions("worldedit.selection.hpos") public void hpos1(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { Location pos = player.getBlockTrace(300); if (pos != null) { if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) { player.printError("Position already set."); return; } session.getRegionSelector(player.getWorld()) .explainPrimarySelection(player, session, pos.toVector().toBlockPoint()); } else { player.printError("No block in sight!"); } }
@Command( aliases = { "area" }, usage = "<radius>", desc = "Enable the area super pickaxe pickaxe mode", min = 1, max = 1 ) @CommandPermissions("worldedit.superpickaxe.area") public void area(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { LocalConfiguration config = we.getConfiguration(); int range = args.getInteger(0); if (range > config.maxSuperPickaxeSize) { player.printError("Maximum range: " + config.maxSuperPickaxeSize); return; } session.setSuperPickaxe(new AreaPickaxe(range)); session.enableSuperPickAxe(); player.print("Mode changed. Left click with a pickaxe. // to disable."); }
@Override public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) { World world = (World) clicked.getExtent(); BlockVector3 origin = clicked.toVector().toBlockPoint(); BlockType initialType = world.getBlock(origin).getBlockType(); if (initialType.getMaterial().isAir()) { return true; } if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) { return true; } try (EditSession editSession = session.createEditSession(player)) { try { recurse(editSession, origin, origin, range, initialType, new HashSet<>()); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); } finally { session.remember(editSession); } } return true; }
@Command( aliases = { "recur", "recursive" }, usage = "<radius>", desc = "Enable the recursive super pickaxe pickaxe mode", min = 1, max = 1 ) @CommandPermissions("worldedit.superpickaxe.recursive") public void recursive(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { LocalConfiguration config = we.getConfiguration(); double range = args.getDouble(0); if (range > config.maxSuperPickaxeSize) { player.printError("Maximum range: " + config.maxSuperPickaxeSize); return; } session.setSuperPickaxe(new RecursivePickaxe(range)); session.enableSuperPickAxe(); player.print("Mode changed. Left click with a pickaxe. // to disable."); } }
@Command( aliases = { "floodfill", "flood" }, usage = "<pattern> <range>", desc = "Flood fill tool", min = 2, max = 2 ) @CommandPermissions("worldedit.tool.flood-fill") public void floodFill(Player player, LocalSession session, Pattern pattern, int range) throws WorldEditException { LocalConfiguration config = we.getConfiguration(); if (range > config.maxSuperPickaxeSize) { player.printError("Maximum range: " + config.maxSuperPickaxeSize); return; } BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); session.setTool(itemStack.getType(), new FloodFillTool(range, pattern)); player.print("Block flood fill tool bound to " + itemStack.getType().getName() + "."); }
@Command( aliases = { "cs" }, usage = "<filename> [args...]", desc = "Execute a CraftScript", min = 1, max = -1 ) @CommandPermissions("worldedit.scripting.execute") @Logging(ALL) public void execute(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { String[] scriptArgs = args.getSlice(1); String name = args.getString(0); if (!player.hasPermission("worldedit.scripting.execute." + name)) { player.printError("You don't have permission to use that script."); return; } session.setLastScript(name); File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir); File f = worldEdit.getSafeOpenFile(player, dir, name, "js", "js"); worldEdit.runScript(player, f, scriptArgs); }
@Command( aliases = { "tree" }, usage = "[type]", desc = "Tree generator tool", min = 0, max = 1 ) @CommandPermissions("worldedit.tool.tree") public void tree(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { TreeGenerator.TreeType type = args.argsLength() > 0 ? TreeGenerator.lookup(args.getString(0)) : TreeGenerator.TreeType.TREE; if (type == null) { player.printError("Tree type '" + args.getString(0) + "' is unknown."); return; } BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); session.setTool(itemStack.getType(), new TreePlanter(type)); player.print("Tree tool bound to " + itemStack.getType().getName() + "."); }
@Override public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { World world = (World) clicked.getExtent(); BlockVector3 blockPoint = clicked.toVector().toBlockPoint(); final BlockType blockType = world.getBlock(blockPoint).getBlockType(); if (blockType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) { return true; } try (EditSession editSession = session.createEditSession(player)) { editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop); editSession.setBlock(blockPoint, BlockTypes.AIR.getDefaultState()); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); } world.playEffect(clicked.toVector(), 2001, blockType.getLegacyId()); return true; }