Let ShopItem no longer extend CraftItemStack and instead extend ItemStack to remain useful to other plugins and use ItemMeta
This commit is contained in:
parent
d5d9e2eb14
commit
e56970a212
@ -1,15 +1,16 @@
|
||||
package mineplex.core.shop.item;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import net.minecraft.server.v1_7_R4.NBTTagList;
|
||||
import net.minecraft.server.v1_7_R4.NBTTagString;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilInv;
|
||||
|
||||
public class ShopItem extends CraftItemStack
|
||||
public class ShopItem extends ItemStack
|
||||
{
|
||||
protected String _name;
|
||||
private String _deliveryName;
|
||||
@ -31,11 +32,11 @@ public class ShopItem extends CraftItemStack
|
||||
else
|
||||
_lore = new String[0];
|
||||
|
||||
CraftItemStack craftItem = CraftItemStack.asCraftCopy(itemStack);
|
||||
getHandle().tag = craftItem.getHandle().tag;
|
||||
|
||||
UpdateVisual(true);
|
||||
getHandle().tag.set("AttributeModifiers", new NBTTagList());
|
||||
}
|
||||
|
||||
public net.minecraft.server.v1_7_R4.ItemStack getHandle() {
|
||||
return CraftItemStack.asNMSCopy(this);
|
||||
}
|
||||
|
||||
public ShopItem(Material type, String name, int deliveryAmount, boolean locked)
|
||||
@ -96,8 +97,7 @@ public class ShopItem extends CraftItemStack
|
||||
|
||||
UpdateVisual(false);
|
||||
|
||||
getHandle().tag.setByte("Count", (byte)Math.max(deliveryAmount, 1));
|
||||
getHandle().tag.set("AttributeModifiers", new NBTTagList());
|
||||
setAmount(Math.max(deliveryAmount, 1));
|
||||
}
|
||||
|
||||
public boolean IsLocked()
|
||||
@ -111,7 +111,11 @@ public class ShopItem extends CraftItemStack
|
||||
|
||||
//Delivery Name
|
||||
if (_deliveryName != null)
|
||||
this.getHandle().c(_deliveryName);
|
||||
{
|
||||
ItemMeta meta = getItemMeta();
|
||||
meta.setDisplayName(_deliveryName);
|
||||
setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
||||
public ShopItem clone()
|
||||
@ -122,43 +126,30 @@ public class ShopItem extends CraftItemStack
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (!super.equals(obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
net.minecraft.server.v1_7_R4.ItemStack original = ((CraftItemStack)this).getHandle();
|
||||
net.minecraft.server.v1_7_R4.ItemStack comparison = ((CraftItemStack)obj).getHandle();
|
||||
|
||||
return original.tag == null || original.tag.equals(comparison.tag);
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
protected void UpdateVisual(boolean clone)
|
||||
{
|
||||
ItemMeta meta = getItemMeta();
|
||||
if (!clone)
|
||||
{
|
||||
if (_locked && !_displayItem)
|
||||
{
|
||||
this.getHandle().c(ChatColor.RED + "§l" + _name);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getHandle().c(ChatColor.GREEN + "§l" + _name);
|
||||
}
|
||||
meta.setDisplayName((_locked && !_displayItem? C.cRed:C.cGreen) + C.Bold + _name);
|
||||
}
|
||||
|
||||
NBTTagList lore = new NBTTagList();
|
||||
ArrayList<String> lore = new ArrayList<String>();
|
||||
|
||||
if (_lore != null)
|
||||
{
|
||||
for (String line : _lore)
|
||||
{
|
||||
if (line != null && !line.isEmpty())
|
||||
lore.add(new NBTTagString(line));
|
||||
lore.add(line);
|
||||
}
|
||||
}
|
||||
meta.setLore(lore);;
|
||||
|
||||
getHandle().tag.getCompound("display").set("Lore", lore);
|
||||
setItemMeta(meta);
|
||||
}
|
||||
|
||||
public boolean IsDisplay()
|
||||
@ -191,17 +182,19 @@ public class ShopItem extends CraftItemStack
|
||||
{
|
||||
_lore = string;
|
||||
|
||||
NBTTagList lore = new NBTTagList();
|
||||
ArrayList<String> lore = new ArrayList<String>();
|
||||
|
||||
if (_lore != null)
|
||||
{
|
||||
for (String line : _lore)
|
||||
{
|
||||
if (line != null && !line.isEmpty())
|
||||
lore.add(new NBTTagString(line));
|
||||
lore.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
getHandle().tag.getCompound("display").set("Lore", lore);
|
||||
ItemMeta meta = getItemMeta();
|
||||
meta.setLore(lore);
|
||||
setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user