mirror of
https://github.com/songoda/UltimateStacker.git
synced 2025-01-19 05:51:23 +01:00
Added the ability to set name and lore for dropped items.
This commit is contained in:
parent
1c6703fcc3
commit
41bc5377b5
@ -1,6 +1,7 @@
|
|||||||
package com.songoda.ultimatestacker.lootables;
|
package com.songoda.ultimatestacker.lootables;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import com.songoda.ultimatestacker.utils.Methods;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
@ -23,6 +24,14 @@ public class Loot {
|
|||||||
@SerializedName("Data")
|
@SerializedName("Data")
|
||||||
private Short 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<String> loreOverride = null;
|
||||||
|
|
||||||
// Material used if entity died on fire.
|
// Material used if entity died on fire.
|
||||||
@SerializedName("Burned Type")
|
@SerializedName("Burned Type")
|
||||||
private Material burnedMaterial = null;
|
private Material burnedMaterial = null;
|
||||||
@ -85,6 +94,26 @@ public class Loot {
|
|||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getNameOverride() {
|
||||||
|
return Methods.formatText(nameOverride);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameOverride(String nameOverride) {
|
||||||
|
this.nameOverride = nameOverride;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getLoreOverride() {
|
||||||
|
List<String> lore = new ArrayList<>();
|
||||||
|
for (String line : loreOverride)
|
||||||
|
lore.add(Methods.formatText(line));
|
||||||
|
|
||||||
|
return lore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoreOverride(List<String> loreOverride) {
|
||||||
|
this.loreOverride = new ArrayList<>(loreOverride);
|
||||||
|
}
|
||||||
|
|
||||||
public Material getBurnedMaterial() {
|
public Material getBurnedMaterial() {
|
||||||
return burnedMaterial;
|
return burnedMaterial;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ package com.songoda.ultimatestacker.lootables;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public final class LootBuilder {
|
public final class LootBuilder {
|
||||||
|
|
||||||
private final Loot loot;
|
private final Loot loot;
|
||||||
@ -26,6 +28,16 @@ public final class LootBuilder {
|
|||||||
return this;
|
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) {
|
public LootBuilder setBurnedMaterial(Material material) {
|
||||||
this.loot.setBurnedMaterial(material);
|
this.loot.setBurnedMaterial(material);
|
||||||
return this;
|
return this;
|
||||||
|
@ -5,6 +5,7 @@ import com.google.gson.GsonBuilder;
|
|||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import com.songoda.ultimatestacker.UltimateStacker;
|
import com.songoda.ultimatestacker.UltimateStacker;
|
||||||
import com.songoda.ultimatestacker.utils.ServerVersion;
|
import com.songoda.ultimatestacker.utils.ServerVersion;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Ageable;
|
import org.bukkit.entity.Ageable;
|
||||||
@ -12,6 +13,7 @@ import org.bukkit.entity.EntityType;
|
|||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Sheep;
|
import org.bukkit.entity.Sheep;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -90,6 +92,16 @@ public class LootManager {
|
|||||||
ItemStack item = new ItemStack(loot.getBurnedMaterial() != null && entity.getFireTicks() != -1
|
ItemStack item = new ItemStack(loot.getBurnedMaterial() != null && entity.getFireTicks() != -1
|
||||||
? loot.getBurnedMaterial() : material, amount);
|
? loot.getBurnedMaterial() : material, amount);
|
||||||
item.setDurability(data);
|
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));
|
toDrop.add(new Drop(item));
|
||||||
}
|
}
|
||||||
if (command != null) {
|
if (command != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user