#ItemMeta

1 messages · Page 1 of 1 (latest)

olive scroll
#

Hi,

I'm having trouble to search for a specific item in the players inventory

So I have to search for a specific item which has weird naming (in the picture)

I wrote this but it doesn't work :

                            ItemStack is = p.getInventory().getItem(i);
                            if(is != null) {
                                if(is.getType() == Material.COCOA_BEANS) {
                                    ItemMeta imeta = (ItemMeta) is;
                                    if(is.getAmount() >= prix && imeta.getDisplayName() == monnaie) {
                                        p.getInventory().removeItem(new ItemStack(Material.COCOA_BEANS, prix));
                                        Quete tmp = new Quete();
                                        tmp.setPrix(prix);
                                        tmp.setMonnaie(monnaie);
                                        tmp.setType(type);
                                        tmp.setNom(bmeta.getTitle());
                                        tmp.setDemandeur(bmeta.getAuthor());
                                        tmp.setStatus(false);
                                        tmp.setPrestataire("null");
                                        QUETES[k] = tmp;
                                        k++;
                                        p.sendMessage("OK");
                                    }else{
                                        p.sendMessage("KO");
                                    }
                                }else{
                                    p.sendMessage("KO");
                                }
                            }
                        }```
#

The items I'm searching are cocoabeans renamed as "irocoin" and with a purple text saying "money" (I can't send a picture)

stray musk
#

and what exactly "doesn't work"?

candid plaza
#

ItemMeta imeta = (ItemMeta) is; hmm casting an itemstack to an itemmeta

olive scroll
stray musk
#

you must get an error from your code, why didnt you send it?

olive scroll
#
    at me.r3dtech911.pubdequete_pdq.PubDeQuete_PDQ.onCommand(PubDeQuete_PDQ.java:264) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
    ... 21 more```
stray musk
candid plaza
#

it's ItemMeta meta = itemStack.getItemMeta()

#

store it as a variable and you need to set it back on the itemstack after editing it

#

itemstack.setItemMeta(modifiedMeta)

olive scroll
#

ok I'll try it

#

btw the item I'm looking for has a displayName and a lore : cocoa_beans{display:{Name:'[{"text":"irocoin","italic":false}]',Lore:['[{"text":"money","italic":false}]']}}

olive scroll
stray musk
#

you have a lot of beginner mistakes in your code

#

for example you're comparing strings using ==

#

you should learn basic java before trying to code spigot plugins