Added /searchitem or //l command to lookup items and block by name and ID.

Dieser Commit ist enthalten in:
sk89q 2011-01-29 21:31:07 -08:00
Ursprung ec9c9885c9
Commit 25f54a3d0c
3 geänderte Dateien mit 91 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -38,6 +38,10 @@ commands:
toggleplace: toggleplace:
description: description:
usage: /<command> usage: /<command>
searchitem:
description: Search for an item
usage: /<command> <query>
aliases: ['/l']
/limit: /limit:
description: Modify block change limit description: Modify block change limit
usage: /<command> <limit> usage: /<command> <limit>

Datei anzeigen

@ -300,6 +300,15 @@ public enum ItemType {
return name; return name;
} }
/**
* Get a list of aliases.
*
* @return
*/
public String[] getAliases() {
return lookupKeys;
}
/** /**
* Returns true if an item should not be stacked. * Returns true if an item should not be stacked.
* *

Datei anzeigen

@ -22,6 +22,7 @@ package com.sk89q.worldedit.commands;
import com.sk89q.util.commands.Command; import com.sk89q.util.commands.Command;
import com.sk89q.util.commands.CommandContext; import com.sk89q.util.commands.CommandContext;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.ItemType;
/** /**
* General WorldEdit commands. * General WorldEdit commands.
@ -74,4 +75,81 @@ public class GeneralCommands {
player.print("Now placing at the block you stand in."); player.print("Now placing at the block you stand in.");
} }
} }
@Command(
aliases = {"searchitem", "/l"},
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() + ")");
found++;
break;
}
}
}
if (found == 0) {
player.printError("No items found.");
}
}
} }