Search in sources :

Example 91 with NBTTagCompound

use of net.minecraft.server.v1_16_R1.NBTTagCompound in project MyMaid2 by jaoafa.

the class Cmd_Test method onCommand.

public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (!(sender instanceof Player)) {
        return true;
    }
    Player player = (Player) sender;
    if (args.length != 1) {
        SendMessage(sender, cmd, "arg 1 only");
        return true;
    }
    if (args[0].equalsIgnoreCase("get")) {
        ItemStack item = new ItemStack(Material.STONE);
        net.minecraft.server.v1_12_R1.ItemStack nms = CraftItemStack.asNMSCopy(item);
        NBTTagCompound nbttag = nms.getTag();
        if (nbttag == null) {
            nbttag = new NBTTagCompound();
        }
        UUID uuid = UUID.randomUUID();
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            SendMessage(sender, cmd, "NoSuchAlgorithmException error");
            return true;
        }
        byte[] digest = md.digest(uuid.toString().getBytes());
        String id = DatatypeConverter.printHexBinary(digest);
        if (id == null) {
            SendMessage(sender, cmd, "id null");
            return true;
        }
        nbttag.setString("MyMaid_testID", id);
        nms.setTag(nbttag);
        item = CraftItemStack.asBukkitCopy(nms);
        player.getInventory().addItem(item);
        SendMessage(sender, cmd, "added");
        return true;
    } else if (args[0].equalsIgnoreCase("check")) {
        ItemStack item = player.getInventory().getItemInMainHand();
        if (item == null) {
            SendMessage(sender, cmd, "item null");
            return true;
        }
        net.minecraft.server.v1_12_R1.ItemStack nms = CraftItemStack.asNMSCopy(item);
        NBTTagCompound nbttag = nms.getTag();
        if (nbttag == null) {
            SendMessage(sender, cmd, "nbttag null");
            return true;
        }
        String id = nbttag.getString("MyMaid_testID");
        if (id == null) {
            SendMessage(sender, cmd, "ID: null*");
            return true;
        } else if (id.equals("")) {
            // <-
            SendMessage(sender, cmd, "ID: notfound");
            return true;
        }
        SendMessage(sender, cmd, "ID: " + id);
        return true;
    }
    SendMessage(sender, cmd, "/test <get|check>");
    return true;
}
Also used : Player(org.bukkit.entity.Player) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) UUID(java.util.UUID) MessageDigest(java.security.MessageDigest)

Example 92 with NBTTagCompound

use of net.minecraft.server.v1_16_R1.NBTTagCompound in project Essentials by EssentialsX.

the class v1_8_R1SpawnerProvider method setEntityType.

@Override
public ItemStack setEntityType(ItemStack is, EntityType type) {
    net.minecraft.server.v1_8_R1.ItemStack itemStack;
    CraftItemStack craftStack = CraftItemStack.asCraftCopy(is);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null) {
        tag = new NBTTagCompound();
        itemStack.setTag(tag);
    }
    if (!tag.hasKey("BlockEntityTag")) {
        tag.set("BlockEntityTag", new NBTTagCompound());
    }
    tag = itemStack.getTag().getCompound("BlockEntityTag");
    tag.setString("EntityId", type.getName());
    ItemStack bukkitItemStack = CraftItemStack.asCraftMirror(itemStack).clone();
    return setDisplayName(bukkitItemStack, type);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R1.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 93 with NBTTagCompound

use of net.minecraft.server.v1_16_R1.NBTTagCompound in project Essentials by EssentialsX.

the class v1_8_R1SpawnerProvider method getEntityType.

@Override
public EntityType getEntityType(ItemStack is) {
    net.minecraft.server.v1_8_R1.ItemStack itemStack;
    CraftItemStack craftStack = CraftItemStack.asCraftCopy(is);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null || !tag.hasKey("BlockEntityTag")) {
        throw new IllegalArgumentException();
    }
    String name = tag.getCompound("BlockEntityTag").getString("EntityId");
    return EntityType.fromName(name);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R1.NBTTagCompound)

Example 94 with NBTTagCompound

use of net.minecraft.server.v1_16_R1.NBTTagCompound in project Essentials by EssentialsX.

the class v1_8_R2SpawnerProvider method setEntityType.

@Override
public ItemStack setEntityType(ItemStack is, EntityType type) {
    net.minecraft.server.v1_8_R2.ItemStack itemStack;
    CraftItemStack craftStack = CraftItemStack.asCraftCopy(is);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null) {
        tag = new NBTTagCompound();
        itemStack.setTag(tag);
    }
    if (!tag.hasKey("BlockEntityTag")) {
        tag.set("BlockEntityTag", new NBTTagCompound());
    }
    tag = itemStack.getTag().getCompound("BlockEntityTag");
    tag.setString("EntityId", type.getName());
    ItemStack bukkitItemStack = CraftItemStack.asCraftMirror(itemStack).clone();
    return setDisplayName(bukkitItemStack, type);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R2.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 95 with NBTTagCompound

use of net.minecraft.server.v1_16_R1.NBTTagCompound in project Ublisk by Derkades.

the class Item method setNBTValue.

public Item setNBTValue(String key, boolean bool) {
    NBTTagCompound compound = this.getNBT();
    compound.setBoolean(key, bool);
    return this.setNBT(compound);
}
Also used : NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)47 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)30 ListTag (com.wasteofplastic.org.jnbt.ListTag)30 StringTag (com.wasteofplastic.org.jnbt.StringTag)30 Tag (com.wasteofplastic.org.jnbt.Tag)30 Map (java.util.Map)30 ItemMeta (org.bukkit.inventory.meta.ItemMeta)29 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)27 ArrayList (java.util.ArrayList)24 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)14 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)13 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)12 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)12 TagCompound (de.keyle.knbt.TagCompound)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 NBTTagCompound (net.minecraft.server.v1_9_R1.NBTTagCompound)10 PreparedStatement (java.sql.PreparedStatement)8 HashMap (java.util.HashMap)8 NBTTagCompound (net.minecraft.server.v1_8_R1.NBTTagCompound)8 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)8