Skip to content

Instantly share code, notes, and snippets.

@leonardosnt
Last active February 22, 2017 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonardosnt/ea205f7e4f1bfaf841af639985054761 to your computer and use it in GitHub Desktop.
Save leonardosnt/ea205f7e4f1bfaf841af639985054761 to your computer and use it in GitHub Desktop.
ItemStack dummy = new ItemStack(Material.AIR);
Iterable<String> split = Splitter.on(',').trimResults().omitEmptyStrings().split("276:2, 10, §3Sei la, DAMAGE_ALL:5, FIRE_ASPECT:2");
Spliterator<String> it = split.spliterator();
/* Id e data */
it.tryAdvance(raw -> {
String[] rawSpl = raw.split(":"); // 0 = id, 1 = data
dummy.setTypeId(Integer.parseInt(rawSpl[0]));
dummy.getData().setData(Byte.parseByte(rawSpl[1]));
});
ItemMeta dummyMeta = dummy.getItemMeta();
/* Quantidade */
it.tryAdvance(amt -> dummy.setAmount(Integer.valueOf(amt)));
/* DisplayName */
it.tryAdvance(dummyMeta::setDisplayName);
/* Enchantments */
it.forEachRemaining(rawEnch -> {
String[] rawSpl = rawEnch.split(":");
dummy.addEnchantment(Enchantment.getByName(rawSpl[0]),
Short.parseShort(rawSpl[1]));
});
dummy.setItemMeta(dummyMeta);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment