Add suggestions for items.

This commit is contained in:
wizjany 2019-05-28 16:07:29 -04:00
parent 5e857b3547
commit 27b58f4e85

View File

@ -21,6 +21,7 @@ package com.sk89q.worldedit.extension.factory.parser;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.command.util.SuggestionHelper;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.internal.registry.InputParser;
@ -39,11 +40,7 @@ public class DefaultItemParser extends InputParser<BaseItem> {
@Override
public Stream<String> getSuggestions(String input) {
if (input.indexOf(':') == -1) {
input = "minecraft:" + input;
}
String key = input;
return ItemType.REGISTRY.keySet().stream().filter(s -> s.startsWith(key));
return SuggestionHelper.getNamespacedRegistrySuggestions(ItemType.REGISTRY, input);
}
@Override
@ -54,7 +51,9 @@ public class DefaultItemParser extends InputParser<BaseItem> {
try {
String[] split = input.split(":");
ItemType type;
if (split.length == 1) {
if (split.length == 0) {
throw new InputParseException("Invalid colon.");
} else if (split.length == 1) {
type = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(split[0]));
} else {
type = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(split[0]), Integer.parseInt(split[1]));