From 20185f026417f57a4abe4199b415761b4af05241 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 1 Feb 2022 11:38:14 +0100 Subject: [PATCH] Update ScriptedItem --- .../misslewars/scripts/ScriptedItem.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/de/steamwar/misslewars/scripts/ScriptedItem.java b/src/de/steamwar/misslewars/scripts/ScriptedItem.java index 8f6aa75..c70fb60 100644 --- a/src/de/steamwar/misslewars/scripts/ScriptedItem.java +++ b/src/de/steamwar/misslewars/scripts/ScriptedItem.java @@ -26,6 +26,9 @@ import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import java.util.ArrayList; import java.util.HashMap; @@ -40,6 +43,7 @@ public class ScriptedItem { // "name": Item name (STRING) // "lore": Lore array (OPTIONAL STRING.ARRAY) // "amount": Item amount (OPTIONAL [default 1] INT) + // "potion": Object with key value pairs for PotionType and Object containing duration and amplifier (OPTIONAL OBJECT) // "EVENT.": Event (OPTIONAL JSONobject.ARRAY) // - onClick // - onHit @@ -80,6 +84,20 @@ public class ScriptedItem { itemMeta.setLore(lore); } + if (jsonObject.has("potion") && itemMeta instanceof PotionMeta) { + JsonObject potionObject = jsonObject.getAsJsonObject("potion"); + potionObject.entrySet().forEach(stringJsonElementEntry -> { + String key = stringJsonElementEntry.getKey(); + JsonObject currentObject = stringJsonElementEntry.getValue().getAsJsonObject(); + PotionEffectType potionEffectType = PotionEffectType.getByName(key); + if (potionEffectType == null) return; + int duration = JsonUtils.getInt(currentObject, "duration", 0); + int amplifier = JsonUtils.getInt(currentObject, "amplifier", 0); + PotionMeta potionMeta = (PotionMeta) itemMeta; + potionMeta.addCustomEffect(new PotionEffect(potionEffectType, duration, amplifier), true); + }); + } + itemStack.setItemMeta(itemMeta); return itemStack; }