2014-04-03 02:08:50 +00:00
|
|
|
/*
|
2014-04-04 22:03:18 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
2014-04-03 02:08:50 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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 Lesser General Public License
|
|
|
|
* for more details.
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-04-03 02:08:50 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-04 22:03:18 +00:00
|
|
|
*/
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
package com.sk89q.worldedit.command;
|
|
|
|
|
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
2014-06-27 23:03:29 +00:00
|
|
|
import com.sk89q.worldedit.*;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.blocks.ItemType;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2014-06-28 00:55:39 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.Mask;
|
|
|
|
import com.sk89q.worldedit.util.command.parametric.Optional;
|
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* General WorldEdit commands.
|
|
|
|
*/
|
|
|
|
public class GeneralCommands {
|
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
private final WorldEdit worldEdit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
|
|
|
* @param worldEdit reference to WorldEdit
|
|
|
|
*/
|
|
|
|
public GeneralCommands(WorldEdit worldEdit) {
|
|
|
|
checkNotNull(worldEdit);
|
|
|
|
this.worldEdit = worldEdit;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/limit" },
|
|
|
|
usage = "<limit>",
|
|
|
|
desc = "Modify block change limit",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.limit")
|
2014-06-28 08:01:49 +00:00
|
|
|
public void limit(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
LocalConfiguration config = worldEdit.getConfiguration();
|
2014-06-27 00:43:25 +00:00
|
|
|
boolean mayDisable = player.hasPermission("worldedit.limit.unrestricted");
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
int limit = Math.max(-1, args.getInteger(0));
|
2014-06-27 00:43:25 +00:00
|
|
|
if (!mayDisable && config.maxChangeLimit > -1) {
|
2014-04-03 02:08:50 +00:00
|
|
|
if (limit > config.maxChangeLimit) {
|
2014-06-27 00:43:25 +00:00
|
|
|
player.printError("Your maximum allowable limit is " + config.maxChangeLimit + ".");
|
2014-04-03 02:08:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
session.setBlockChangeLimit(limit);
|
2014-06-27 00:43:25 +00:00
|
|
|
|
|
|
|
if (limit != -1) {
|
|
|
|
player.print("Block change limit set to " + limit + ". (Use //limit -1 to go back to the default.)");
|
|
|
|
} else {
|
|
|
|
player.print("Block change limit set to " + limit + ".");
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/fast" },
|
|
|
|
usage = "[on|off]",
|
|
|
|
desc = "Toggle fast mode",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.fast")
|
2014-06-28 08:01:49 +00:00
|
|
|
public void fast(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
String newState = args.getString(0, null);
|
|
|
|
if (session.hasFastMode()) {
|
|
|
|
if ("on".equals(newState)) {
|
|
|
|
player.printError("Fast mode already enabled.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
session.setFastMode(false);
|
|
|
|
player.print("Fast mode disabled.");
|
|
|
|
} else {
|
|
|
|
if ("off".equals(newState)) {
|
|
|
|
player.printError("Fast mode already disabled.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
session.setFastMode(true);
|
|
|
|
player.print("Fast mode enabled. Lighting in the affected chunks may be wrong and/or you may need to rejoin to see changes.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/gmask", "gmask" },
|
|
|
|
usage = "[mask]",
|
|
|
|
desc = "Set the global mask",
|
|
|
|
min = 0,
|
|
|
|
max = -1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.global-mask")
|
2014-06-28 08:01:49 +00:00
|
|
|
public void gmask(Player player, LocalSession session, EditSession editSession, @Optional Mask mask) throws WorldEditException {
|
|
|
|
if (mask == null) {
|
|
|
|
session.setMask((Mask) null);
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print("Global mask disabled.");
|
|
|
|
} else {
|
|
|
|
session.setMask(mask);
|
|
|
|
player.print("Global mask set.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/toggleplace", "toggleplace" },
|
|
|
|
usage = "",
|
|
|
|
desc = "Switch between your position and pos1 for placement",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void togglePlace(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
if (session.togglePlacementPosition()) {
|
|
|
|
player.print("Now placing at pos #1.");
|
|
|
|
} else {
|
|
|
|
player.print("Now placing at the block you stand in.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/searchitem", "/l", "/search", "searchitem" },
|
|
|
|
usage = "<query>",
|
|
|
|
flags = "bi",
|
|
|
|
desc = "Search for an item",
|
|
|
|
help =
|
|
|
|
"Searches for an item.\n" +
|
|
|
|
"Flags:\n" +
|
|
|
|
" -b only search for blocks\n" +
|
|
|
|
" -i only search for items",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
2014-06-28 00:55:39 +00:00
|
|
|
public void searchItem(Actor actor, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
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) {
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.print("#" + type.getID() + " (" + type.getName() + ")");
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.printError("No item found by ID " + id);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query.length() <= 2) {
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.printError("Enter a longer search string (len > 2).");
|
2014-04-03 02:08:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!blocksOnly && !itemsOnly) {
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.print("Searching for: " + query);
|
2014-04-03 02:08:50 +00:00
|
|
|
} else if (blocksOnly && itemsOnly) {
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.printError("You cannot use both the 'b' and 'i' flags simultaneously.");
|
2014-04-03 02:08:50 +00:00
|
|
|
return;
|
|
|
|
} else if (blocksOnly) {
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.print("Searching for blocks: " + query);
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.print("Searching for items: " + query);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
for (ItemType type : ItemType.values()) {
|
|
|
|
if (found >= 15) {
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.print("Too many results!");
|
2014-04-03 02:08:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blocksOnly && type.getID() > 255) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemsOnly && type.getID() <= 255) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (String alias : type.getAliases()) {
|
|
|
|
if (alias.contains(query)) {
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.print("#" + type.getID() + " (" + type.getName() + ")");
|
2014-04-03 02:08:50 +00:00
|
|
|
++found;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found == 0) {
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.printError("No items found.");
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|