diff --git a/src/main/java/com/songoda/ultimatestacker/lootables/Loot.java b/src/main/java/com/songoda/ultimatestacker/lootables/Loot.java index 39bfe8e..98e289c 100644 --- a/src/main/java/com/songoda/ultimatestacker/lootables/Loot.java +++ b/src/main/java/com/songoda/ultimatestacker/lootables/Loot.java @@ -1,6 +1,7 @@ package com.songoda.ultimatestacker.lootables; import com.google.gson.annotations.SerializedName; +import com.songoda.ultimatestacker.utils.Methods; import org.bukkit.Material; import org.bukkit.entity.EntityType; @@ -23,6 +24,14 @@ public class Loot { @SerializedName("Data") private Short data; + // The override for the item name. + @SerializedName("Name") + private String nameOverride = null; + + // The override for the item lore. + @SerializedName("Lore") + private List loreOverride = null; + // Material used if entity died on fire. @SerializedName("Burned Type") private Material burnedMaterial = null; @@ -85,6 +94,26 @@ public class Loot { this.data = data; } + public String getNameOverride() { + return Methods.formatText(nameOverride); + } + + public void setNameOverride(String nameOverride) { + this.nameOverride = nameOverride; + } + + public List getLoreOverride() { + List lore = new ArrayList<>(); + for (String line : loreOverride) + lore.add(Methods.formatText(line)); + + return lore; + } + + public void setLoreOverride(List loreOverride) { + this.loreOverride = new ArrayList<>(loreOverride); + } + public Material getBurnedMaterial() { return burnedMaterial; } diff --git a/src/main/java/com/songoda/ultimatestacker/lootables/LootBuilder.java b/src/main/java/com/songoda/ultimatestacker/lootables/LootBuilder.java index b483c3a..967ecf7 100644 --- a/src/main/java/com/songoda/ultimatestacker/lootables/LootBuilder.java +++ b/src/main/java/com/songoda/ultimatestacker/lootables/LootBuilder.java @@ -4,6 +4,8 @@ package com.songoda.ultimatestacker.lootables; import org.bukkit.Material; import org.bukkit.entity.EntityType; +import java.util.Arrays; + public final class LootBuilder { private final Loot loot; @@ -26,6 +28,16 @@ public final class LootBuilder { return this; } + public LootBuilder setNameOverride(String name) { + this.loot.setNameOverride(name); + return this; + } + + public LootBuilder addLoreOverrides(String... lore) { + this.loot.setLoreOverride(Arrays.asList(lore)); + return this; + } + public LootBuilder setBurnedMaterial(Material material) { this.loot.setBurnedMaterial(material); return this; diff --git a/src/main/java/com/songoda/ultimatestacker/lootables/LootManager.java b/src/main/java/com/songoda/ultimatestacker/lootables/LootManager.java index 1d8939d..c8fa11f 100644 --- a/src/main/java/com/songoda/ultimatestacker/lootables/LootManager.java +++ b/src/main/java/com/songoda/ultimatestacker/lootables/LootManager.java @@ -5,6 +5,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.stream.JsonReader; import com.songoda.ultimatestacker.UltimateStacker; import com.songoda.ultimatestacker.utils.ServerVersion; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Ageable; @@ -12,6 +13,7 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Sheep; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import java.io.*; import java.util.*; @@ -90,6 +92,16 @@ public class LootManager { ItemStack item = new ItemStack(loot.getBurnedMaterial() != null && entity.getFireTicks() != -1 ? loot.getBurnedMaterial() : material, amount); item.setDurability(data); + ItemMeta meta = item.getItemMeta() == null ? Bukkit.getItemFactory().getItemMeta(loot.getMaterial()) + : item.getItemMeta(); + + if (loot.getNameOverride() != null) + meta.setDisplayName(loot.getNameOverride()); + + if (loot.getLoreOverride() != null) + meta.setLore(loot.getLoreOverride()); + item.setItemMeta(meta); + toDrop.add(new Drop(item)); } if (command != null) {