SteamWar/MissileWars
Archiviert
13
0

Update ScriptedItem
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-02-01 11:38:14 +01:00
Ursprung 803703a6e0
Commit 20185f0264

Datei anzeigen

@ -26,6 +26,9 @@ import org.bukkit.Material;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; 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.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -40,6 +43,7 @@ public class ScriptedItem {
// "name": Item name (STRING) // "name": Item name (STRING)
// "lore": Lore array (OPTIONAL STRING.ARRAY) // "lore": Lore array (OPTIONAL STRING.ARRAY)
// "amount": Item amount (OPTIONAL [default 1] INT) // "amount": Item amount (OPTIONAL [default 1] INT)
// "potion": Object with key value pairs for PotionType and Object containing duration and amplifier (OPTIONAL OBJECT)
// "EVENT.<eventName>": Event (OPTIONAL JSONobject.ARRAY) // "EVENT.<eventName>": Event (OPTIONAL JSONobject.ARRAY)
// - onClick // - onClick
// - onHit // - onHit
@ -80,6 +84,20 @@ public class ScriptedItem {
itemMeta.setLore(lore); 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); itemStack.setItemMeta(itemMeta);
return itemStack; return itemStack;
} }