Advertisement
DPOH-VAR

mc: class NameEdit

Nov 7th, 2012
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. package me.dpohvar.varscript.utils.minecraft;
  2.  
  3. import net.minecraft.server.NBTTagCompound;
  4. import org.bukkit.craftbukkit.inventory.CraftItemStack;
  5. import org.bukkit.inventory.ItemStack;
  6.  
  7. /**
  8.  * Created by IntelliJ IDEA.
  9.  * User: DPOH-VAR
  10.  * Date: 10.08.12
  11.  * Time: 22:35
  12.  * To change this template use File | Settings | File Templates.
  13.  */
  14.  
  15. public class NameEdit {
  16.     public final ItemStack item;
  17.     private NBTTagCompound tagData;
  18.  
  19.     public NameEdit(ItemStack s){
  20.         this.item = s;
  21.         net.minecraft.server.ItemStack i = ((CraftItemStack) s).getHandle();
  22.         if (i.tag == null) {
  23.             tagData = new NBTTagCompound();
  24.             i.tag = tagData;
  25.         } else {
  26.             tagData = i.tag;
  27.         }
  28.     }
  29.  
  30.     public String getName(){
  31.         if (tagData.hasKey("display")) return tagData.getCompound("display").getString("Name");
  32.         else return null;
  33.     }
  34.  
  35.     public NameEdit setName(String name){
  36.         if(name==null){
  37.             removeName();
  38.             return this;
  39.         }
  40.         if(tagData.hasKey("display")){
  41.             NBTTagCompound d = tagData.getCompound("display");
  42.             d.setString("Name",name);
  43.         } else {
  44.             NBTTagCompound d = new NBTTagCompound();
  45.             d.setString("Name",name);
  46.             tagData.setCompound("display",d);
  47.         }
  48.         return this;
  49.     }
  50.  
  51.     public void removeName(){
  52.         tagData.getCompound("display").remove("Name");
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement