#Need help debugging code

1 messages · Page 1 of 1 (latest)

untold mango
#

@knotty carbon Sorry for another ping just moving this to a thread to make it easier. I actually have a log event in line 2 that tells me if it detects the action and it has gotten to that but it doesn't seem to ever pass the item check

knotty carbon
#

Does it even pass the event ?

#

Is the event called ?

untold mango
#

Yes

#

It registers my clicks

#

But doesn't seem to be able to detect the item

#

and I have a slightly modified version of the code I originally used that was working. the modification being I learned that some of what I was doing(mainly using == to compare strings) was wrong and so I updated it to be using .equals instead.

knotty carbon
#

First check the item is not null

#

Then check the item has item meta

untold mango
#

The event actually doesn't get called if you aren't holding an item

#

And the method I use to check is to get the item in the players hand using p.getInventory().getItemInMainHand() then I get the display name from the Item Meta and I check that against a predefined value.

knotty carbon
#

Items may not have item meta maybe. That would cause a NPE

#

So which check isn't passed ?

untold mango
#

It detects the right click but then it doesn't seem to ever pass the item meta check

#

and I was using the same item before and haven't changed the item meta check data at all. The only change was how they are being compared.

knotty carbon
#

Then output the item name, the name you want to be equals and see if the problem is here

#

You have to test your values

#

To search for everything

untold mango
#

itemmeta is basically NBT data right

knotty carbon
#

Mhhh

#

Not exactly

untold mango
#

Alright so I figured out that it seems to be something with trying to format it or change it from being just a string. Do you have any idea how I could fix that problem

knotty carbon
#

What do you mean ?

untold mango
#

So in the itemmeta check that determines whether the item is the correct one or not if I try to change it from being one set of "" to being like ChatColor.Red + "" it will no longer work

knotty carbon
#

Well

#

Imagine ChatColor.RED is "&c"

#

Then "blabla" is different from "&cblabla"

#

That's why you need to match the exact same string

#

Or you can use PDC to save secretly data into your item and check it's it