Skip to content

Commit

Permalink
Add suggestions for items.
Browse files Browse the repository at this point in the history
  • Loading branch information
wizjany committed May 29, 2019
1 parent 5e857b3 commit 27b58f4
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

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;
Expand All @@ -39,11 +40,7 @@ public DefaultItemParser(WorldEdit worldEdit) {

@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
Expand All @@ -54,7 +51,9 @@ public BaseItem parseFromInput(String input, ParserContext context) throws Input
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]));
Expand Down

0 comments on commit 27b58f4

Please sign in to comment.