Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.dpohvar.varscript.utils.minecraft;
- import net.minecraft.server.NBTTagCompound;
- import org.bukkit.craftbukkit.inventory.CraftItemStack;
- import org.bukkit.inventory.ItemStack;
- /**
- * Created by IntelliJ IDEA.
- * User: DPOH-VAR
- * Date: 10.08.12
- * Time: 22:35
- * To change this template use File | Settings | File Templates.
- */
- public class NameEdit {
- public final ItemStack item;
- private NBTTagCompound tagData;
- public NameEdit(ItemStack s){
- this.item = s;
- net.minecraft.server.ItemStack i = ((CraftItemStack) s).getHandle();
- if (i.tag == null) {
- tagData = new NBTTagCompound();
- i.tag = tagData;
- } else {
- tagData = i.tag;
- }
- }
- public String getName(){
- if (tagData.hasKey("display")) return tagData.getCompound("display").getString("Name");
- else return null;
- }
- public NameEdit setName(String name){
- if(name==null){
- removeName();
- return this;
- }
- if(tagData.hasKey("display")){
- NBTTagCompound d = tagData.getCompound("display");
- d.setString("Name",name);
- } else {
- NBTTagCompound d = new NBTTagCompound();
- d.setString("Name",name);
- tagData.setCompound("display",d);
- }
- return this;
- }
- public void removeName(){
- tagData.getCompound("display").remove("Name");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement