Skip to content

Commit

Permalink
GH-2015 Correct item parse (#2016)
Browse files Browse the repository at this point in the history
* Correct item parse, fixes #2015

* Handle improper item meta attribute
  • Loading branch information
Kamilkime committed Jun 23, 2022
1 parent b8faf02 commit d422254
Showing 1 changed file with 7 additions and 2 deletions.
Expand Up @@ -115,21 +115,26 @@ public static ItemStack parseItem(String itemString) {
});

Option<Integer> data = Option.attempt(NumberFormatException.class, () -> Integer.parseInt(subtype)).onEmpty(() -> {
FunnyGuilds.getPluginLogger().parser("Unknown data: " + split[0]);
FunnyGuilds.getPluginLogger().parser("Unknown data: " + subtype);
});

ItemBuilder item = new ItemBuilder(material, amount.orElseGet(1), data.orElseGet(0));
FunnyFormatter formatter = new FunnyFormatter().register("_", "").register("{HASH}", "#");

for (int index = 2; index < split.length; index++) {
String[] itemAttributes = split[index].split(":", 2);

if (itemAttributes.length != 2) {
FunnyGuilds.getPluginLogger().parser("Unknown item meta attribute: " + itemAttributes[0]);
}

String attributeName = itemAttributes[0];
String attributeValue = itemAttributes[1];

switch (attributeName.toLowerCase(Locale.ROOT)) {
case "name":
case "displayname":
item.setName(formatter.format(attributeName), true);
item.setName(formatter.format(attributeValue), true);
continue;
case "lore":
List<String> lore = PandaStream.of(attributeValue.split("#")).map(formatter::format).toList();
Expand Down

0 comments on commit d422254

Please sign in to comment.