2011-01-29 10:05:22 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.commands;
|
|
|
|
|
2011-02-18 06:53:44 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
2011-02-19 09:22:28 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.NestedCommand;
|
2011-01-29 10:05:22 +00:00
|
|
|
import com.sk89q.worldedit.*;
|
2011-01-30 05:31:07 +00:00
|
|
|
import com.sk89q.worldedit.blocks.ItemType;
|
2011-06-04 19:16:10 +00:00
|
|
|
import com.sk89q.worldedit.masks.Mask;
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* General WorldEdit commands.
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
|
|
|
public class GeneralCommands {
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/limit" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "<limit>",
|
|
|
|
desc = "Modify block change limit",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.limit")
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void limit(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
|
|
|
LocalConfiguration config = we.getConfiguration();
|
|
|
|
|
|
|
|
int limit = Math.max(-1, args.getInteger(0));
|
|
|
|
if (!player.hasPermission("worldedit.limit.unrestricted")
|
|
|
|
&& config.maxChangeLimit > -1) {
|
|
|
|
if (limit > config.maxChangeLimit) {
|
|
|
|
player.printError("Your maximum allowable limit is "
|
|
|
|
+ config.maxChangeLimit + ".");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
session.setBlockChangeLimit(limit);
|
|
|
|
player.print("Block change limit set to " + limit + ".");
|
|
|
|
}
|
|
|
|
|
2011-06-04 17:30:45 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/fast" },
|
2011-10-26 20:50:46 +00:00
|
|
|
flags = "l",
|
2011-10-17 03:55:03 +00:00
|
|
|
usage = "[on|off]",
|
2011-06-04 17:30:45 +00:00
|
|
|
desc = "Toggle fast mode",
|
|
|
|
min = 0,
|
2011-10-17 03:55:03 +00:00
|
|
|
max = 1
|
2011-06-04 17:30:45 +00:00
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.fast")
|
2011-06-04 17:30:45 +00:00
|
|
|
public static void fast(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
2011-10-17 03:55:03 +00:00
|
|
|
|
2011-10-26 20:50:46 +00:00
|
|
|
boolean light = args.hasFlag('f');
|
2011-10-17 03:55:03 +00:00
|
|
|
String newState = args.getString(0, null);
|
2011-10-26 20:50:46 +00:00
|
|
|
Boolean dir = newState.equals("on") ? true : newState.equals("off") ? false : null;
|
2011-10-17 03:55:03 +00:00
|
|
|
|
2011-10-26 20:50:46 +00:00
|
|
|
boolean hadFast = session.hasFastMode();
|
|
|
|
boolean hadLight = session.hasFastLighting();
|
|
|
|
|
|
|
|
boolean setFast = dir == null ? !hadFast : dir;
|
|
|
|
boolean setLight = dir == null ? !hadLight : dir;
|
2011-10-17 03:55:03 +00:00
|
|
|
|
2011-10-26 20:50:46 +00:00
|
|
|
session.setFastMode(setFast);
|
|
|
|
if (light) {
|
|
|
|
session.setFastLighting(setLight);
|
2011-10-17 03:55:03 +00:00
|
|
|
}
|
2011-10-26 20:50:46 +00:00
|
|
|
|
|
|
|
player.print("Fast mode " + (!setFast ? "disabled." :
|
|
|
|
("enabled. You may need to rejoin to see changes"
|
|
|
|
+ (setLight ? "and lighting in affected chunks may be wrong." : "."))));
|
2011-06-04 17:30:45 +00:00
|
|
|
}
|
|
|
|
|
2011-06-04 19:16:10 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/gmask", "gmask" },
|
2011-06-04 19:16:10 +00:00
|
|
|
usage = "[mask]",
|
|
|
|
desc = "Set the global mask",
|
|
|
|
min = 0,
|
|
|
|
max = -1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.global-mask")
|
2011-06-04 19:16:10 +00:00
|
|
|
public static void mask(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
if (args.argsLength() == 0) {
|
|
|
|
session.setMask(null);
|
|
|
|
player.print("Global mask disabled.");
|
|
|
|
} else {
|
|
|
|
Mask mask = we.getBlockMask(player, session, args.getJoinedStrings(0));
|
|
|
|
session.setMask(mask);
|
|
|
|
player.print("Global mask set.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/toggleplace", "toggleplace" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "",
|
2011-09-17 22:57:34 +00:00
|
|
|
desc = "Switch between your position and pos1 for placement",
|
2011-01-29 10:05:22 +00:00
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
|
|
|
public static void togglePlace(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
|
|
|
if (session.togglePlacementPosition()) {
|
|
|
|
player.print("Now placing at pos #1.");
|
|
|
|
} else {
|
|
|
|
player.print("Now placing at the block you stand in.");
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 05:31:07 +00:00
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/searchitem", "/l", "/search", "searchitem", "search" },
|
2011-01-30 05:31:07 +00:00
|
|
|
usage = "<query>",
|
|
|
|
flags = "bi",
|
|
|
|
desc = "Search for an item",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
public static void searchItem(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
|
|
|
String query = args.getString(0).trim().toLowerCase();
|
|
|
|
boolean blocksOnly = args.hasFlag('b');
|
|
|
|
boolean itemsOnly = args.hasFlag('i');
|
|
|
|
|
|
|
|
try {
|
|
|
|
int id = Integer.parseInt(query);
|
|
|
|
|
|
|
|
ItemType type = ItemType.fromID(id);
|
|
|
|
|
|
|
|
if (type != null) {
|
|
|
|
player.print("#" + type.getID() + " (" + type.getName() + ")");
|
|
|
|
} else {
|
|
|
|
player.printError("No item found by ID " + id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query.length() <= 2) {
|
|
|
|
player.printError("Enter a longer search string (len > 2).");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!blocksOnly && !itemsOnly) {
|
|
|
|
player.print("Searching for: " + query);
|
|
|
|
} else if (blocksOnly && itemsOnly) {
|
|
|
|
player.printError("You cannot use both the 'b' and 'i' flags simultaneously.");
|
|
|
|
return;
|
|
|
|
} else if (blocksOnly) {
|
|
|
|
player.print("Searching for blocks: " + query);
|
|
|
|
} else {
|
|
|
|
player.print("Searching for items: " + query);
|
|
|
|
}
|
|
|
|
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
for (ItemType type : ItemType.values()) {
|
|
|
|
if (found >= 15) {
|
|
|
|
player.print("Too many results!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blocksOnly && type.getID() > 255) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemsOnly && type.getID() <= 255) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (String alias : type.getAliases()) {
|
|
|
|
if (alias.contains(query)) {
|
|
|
|
player.print("#" + type.getID() + " (" + type.getName() + ")");
|
2011-07-15 07:00:48 +00:00
|
|
|
++found;
|
2011-01-30 05:31:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found == 0) {
|
|
|
|
player.printError("No items found.");
|
|
|
|
}
|
|
|
|
}
|
2011-02-19 09:22:28 +00:00
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "we", "worldedit" },
|
2011-02-19 09:22:28 +00:00
|
|
|
desc = "WorldEdit commands"
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@NestedCommand(WorldEditCommands.class)
|
2011-02-19 09:22:28 +00:00
|
|
|
public static void we(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|