Item Stack issue

Discussion in 'Spigot Plugin Development' started by Lolok, Apr 1, 2019.

  1. https://pastebin.com/13sKuUCU

    this is my code, but my plugin always says I don't have enough heads (the head it's a player head with the skin of a creeper and a custom name)
    [​IMG]
     
    • Like Like x 1
  2. First of all, you should learn about Java's naming coventions at https://www.google.com/url?sa=t&sou...FjACegQIBRAC&usg=AOvVaw2CDhO7efJ9zObo1Bnj1Rgw

    And about the ItemStacks, the item you made doesn't have a creeper skin, it's just a skinless player head. Adding a skin with SkullMeta#setSkin(String) should work. Another way to do this is looping through the inventory contents and checking if any of the ItemStacks has a similar name.
     
  3. what I need to add?
     
    • Like Like x 1
  4. I just told you. You can either set the skull's skin or loop through the items and check their custom name.
     
  5. I need to set skull's skin to null?
     
    • Like Like x 1
  6. No. You need the item to be similar to the one in the picture, so you need to set the skin to the skin from the picture.
    Btw, I its SkullMeta#setOwner(String) and not setSkin. Sorry about that.
     
  7. I used the loop but if the plugin found the heads how can I remove 10 of this heads?
     
    • Like Like x 1
  8. I also got this error https://prnt.sc/n61689
    that's the new code
    Code (Java):
    for(int i = 0; i < player.getInventory().getSize(); i++) {
                        if(player.getInventory().getItem(i).getType() != null) {
                            if(player.getInventory().getItem(i).getAmount() >= 10 && player.getInventory().getItem(i).getItemMeta().getDisplayName().equalsIgnoreCase("§aTesta di Creeper")) {
                                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mobcoins give " + player.getName() + " 10 -s");
                                player.sendMessage("§e§l[!] §eHai ricevuto §610 §eMobCoins");
                                player.closeInventory();
                            }
                        }
                    }
     
    • Winner Winner x 1
  9. First of all you should decide what you'd like to use. The first ItemStack you're creating is a player head and the second is a creeper head.
    1. ItemStack CreeperItem = new ItemStack (Material.SKULL_ITEM, 1, (short) 3); -> 3 = player head
    2. player.getInventory().removeItem(new ItemStack(Material.SKULL_ITEM, 10, (short) SkullType.CREEPER.ordinal())); -> the ordinal is 4 = creeper head
    If you'd like to stick to the approach of using a skinned player head, remove a player head, not a creeper head. The rest is easy.

    Code (Text):
    SkullMeta meta = (SkullMeta) skullItemStack.getItemMeta();
    meta.setOwner("MHF_Creeper");
    skullItemStack.setItemMeta(meta);
    The deprecation in this case can be ignored as the MHF heads are provided by Mojang under their names. If you mind, you can use the not deprecated method that uses OfflinePlayer.

    It shouldn't because no such method exists.
     
    • Useful Useful x 1
  10. I need to use a player head and I got only the head texture (eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjQyNTQ4MzhjMzNlYTIyN2ZmY2EyMjNkZGRhYWJmZTBiMDIxNWY3MGRhNjQ5ZTk0NDQ3N2Y0NDM3MGNhNjk1MiJ9fX0) not the player owener and I don't know how to set the head texture
     
    • Optimistic Optimistic x 1
  11. There is no API for Base64 encoded profile data. You can use this or take code from it: https://www.spigotmc.org/threads/headlib.331178/
     
    • Creative Creative x 1
  12. So I need to install the jar, add to dependencies and use texture attribute? (It's my first plugin sorry)
     
    • Funny Funny x 1
  13. It is a library that is supposed to be incorporated in your plugin jar sothat users don't need to install any plugin dependencies. If you use Maven, the shade plugin can do this for you:
    Code (Text):
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>3.2.1</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <artifactSet>
                                    <includes>
                                        <include>de.erethon:headlib</include>
                                    </includes>
                                </artifactSet>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    If you don't use Maven, add HeadLib to your dependencies and make sure to include it in the final jar. How this works depends on your IDE.

    To get a creeper head, use:
    Code (Text):
    ItemStack creeperHead = HeadLib.MONSTER_CREEPER.toItemStack();
     
    • Creative Creative x 1