Add support for extended and/or upgraded potions in the item syntax.

This commit adds support for altering the data portion of a potion item by prefixing either `long_` or `strong_` to get extended duration or level II versions of the given potion, respectively.

Closes #520
This commit is contained in:
Andreas Troelsen 2019-07-24 19:56:36 +02:00
parent dd31a11b60
commit 054220a32e
2 changed files with 18 additions and 11 deletions

View File

@ -11,6 +11,7 @@ These changes will (most likely) be included in the next version.
## [Unreleased]
- Extended and upgraded potions are now supported in the item syntax by prepending `long_` or `strong_` to the data portion of a potion item (e.g. `potion:strong_instant_heal:1` will yield a Potion of Healing II). Check the wiki for details.
- Tridents and crossbows are now considered weapons with regards to the `unbreakable-weapons` flag. All class items that have durability now have their unbreakable flag set to true unless the `unbreakable-weapons` and/or `unbreakable-armor` flags are set to `false`.
- Leaderboards now work again on servers running Minecraft 1.14+.
- Class chests (non-linked) now work again on servers running Minecraft 1.14+.

View File

@ -100,22 +100,28 @@ public class ItemParser
}
private static ItemStack withPotionMeta(ItemStack stack, String data) {
PotionType type = getPotionType(data);
if (type == null) {
return null;
}
PotionMeta meta = (PotionMeta) stack.getItemMeta();
meta.setBasePotionData(new PotionData(type));
stack.setItemMeta(meta);
return stack;
}
PotionType type;
boolean extended = false;
boolean upgraded = false;
private static PotionType getPotionType(String data) {
if (data.startsWith("long_")) {
extended = true;
data = data.substring(5);
}
if (data.startsWith("strong_")) {
upgraded = true;
data = data.substring(7);
}
try {
return PotionType.valueOf(data.toUpperCase());
type = PotionType.valueOf(data.toUpperCase());
} catch (IllegalArgumentException e) {
return null;
}
PotionMeta meta = (PotionMeta) stack.getItemMeta();
meta.setBasePotionData(new PotionData(type, extended, upgraded));
stack.setItemMeta(meta);
return stack;
}
private static Optional<Material> getType(String item) {