Skip to content

Commit

Permalink
Добавлен метод для изменения типа зелья
Browse files Browse the repository at this point in the history
  • Loading branch information
DenaryDev committed Mar 29, 2024
1 parent e0598b8 commit 4cbe25c
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionType;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -56,6 +58,7 @@ public class ItemBuilder {
private boolean unbreakable;
private Integer customModelData;
private int damage;
private PotionType potionType;
private final Map<Enchantment, Integer> enchantments = new HashMap<>();
private final Map<PotionEffect, Boolean> potionEffects = new HashMap<>();
private final Map<Enchantment, Integer> storedEnchantments = new HashMap<>();
Expand Down Expand Up @@ -346,6 +349,20 @@ public ItemBuilder enchantments(@NotNull final Map<Enchantment, Integer> enchant

//region Методы добавления эффектов к зельям

/**
* Устанавливает тип зелья.
* <p>
* Работает только если тип предмета {@link Material#POTION},
* {@link Material#SPLASH_POTION} или {@link Material#LINGERING_POTION}.
*
* @param type тип зелья.
* @return {@link ItemBuilder} для дальнейшего использования.
*/
public ItemBuilder potionType(@NotNull final PotionType type) {
this.potionType = type;
return this;
}

/**
* Добавляет эффекты зелий к предмету.
* <p>
Expand Down Expand Up @@ -521,8 +538,9 @@ public ItemStack build() {
});
}

if (!potionEffects.isEmpty() && meta instanceof PotionMeta potion) {
potionEffects.forEach(potion::addCustomEffect);
if (meta instanceof PotionMeta potion) {
if (potionType != null) potion.setBasePotionData(new PotionData(potionType));
if (!potionEffects.isEmpty()) potionEffects.forEach(potion::addCustomEffect);
}

if (!storedEnchantments.isEmpty() && meta instanceof EnchantmentStorageMeta storage) {
Expand Down

0 comments on commit 4cbe25c

Please sign in to comment.