#Cannot compare PDC INTEGER DATA TYPE
1 messages · Page 1 of 1 (latest)
if(data.get(new NamespacedKey(GioxMC.getPlugin(), "magnet"), PersistentDataType.INTEGER) == 0) return;```
This should be able to compare the value that it return to 0, but it doesn't work.
Is there a specific way of comparing PDCs ?
Show your code you use to set it
data.set(new NamespacedKey(GioxMC.getPlugin(), "magnet"), PersistentDataType.INTEGER, 0);```
is this going through yaml serialisation ?
I mean, if data.get(new NamespacedKey(GioxMC.getPlugin(), "magnet"), PersistentDataType.INTEGER) prints 0 to the console for you
then data.get(new NamespacedKey(GioxMC.getPlugin(), "magnet"), PersistentDataType.INTEGER) == 0 should be true
Last I used PDC it worked fine on Integers
it should auto unbox here
this is in my dataType Integer type = primitive.get(key("type"), PersistentDataType.INTEGER);
works fine
those all look fine. Are you sure that your if statement is failing here
e.g. print data.get(new NamespacedKey(GioxMC.getPlugin(), "magnet"), PersistentDataType.INTEGER) == 0 to your logger
Yeap
System.out.println(1);
if(item.getItemMeta() == null) return;
PersistentDataContainer data = item.getItemMeta().getPersistentDataContainer();
System.out.println(2);
if(data.get(new NamespacedKey(GioxMC.getPlugin(), "owner"), PersistentDataType.STRING) == null) return;
if(data.get(new NamespacedKey(GioxMC.getPlugin(), "magnet"), PersistentDataType.INTEGER) == 0) return; // <(==
System.out.println(3);```
you sure its not exiting on owner?
Eh I mean, save the return val into a variable, print it and its type and then also it compared to 0 using the == operator
huuuuh ???
You did get me to spot an error in my PDC DataType code though
I'm really wondering why this thing wont work.
Really no clue, its workgin fine here
unless.
did you at some point write that key with a different data type?
Nope, it's INTEGER.
it has always been INTEGER?
what is the error on that?
There is literally no error.
its underlined, shows a warning?
@EventHandler
void playerClickEvent(InventoryClickEvent e) {
Inventory i = e.getClickedInventory();
ItemStack itemClicked = e.getCurrentItem();
InventoryView view = e.getView();
if (i == e.getWhoClicked().getInventory()) return;
if (itemClicked == null) return;
if (view.getTitle().equalsIgnoreCase("Upgrade Menu")) {
if (e.getSlot() == 20)
upgradeMagnet((Player) e.getWhoClicked(), e.getWhoClicked().getInventory().getItemInMainHand());
if (e.getSlot() == 30)
upgradeBlessing((Player) e.getWhoClicked(), e.getWhoClicked().getInventory().getItemInMainHand());
}
}
public void upgradeMagnet(Player p, ItemStack item) {
if(item.getItemMeta() == null) return;
PersistentDataContainer data = item.getItemMeta().getPersistentDataContainer();
if (!data.has(new NamespacedKey(GioxMC.getPlugin(), "owner"), PersistentDataType.STRING)) return;
if (!data.get(new NamespacedKey(GioxMC.getPlugin(), "owner"), PersistentDataType.STRING).equalsIgnoreCase(p.getUniqueId().toString())) {
p.sendMessage(GioxMC.prefix + "This hoe can only be upgraded by it's owner.");
return;
}
if (data.get(new NamespacedKey(GioxMC.getPlugin(), "magnet"), PersistentDataType.INTEGER) == 1) {
p.sendMessage(GioxMC.prefix + "The charm that you're trying to update is already on it's max level.");
return;
} else {
data.set(new NamespacedKey(GioxMC.getPlugin(), "magnet"), PersistentDataType.INTEGER, 1);
p.sendMessage(GioxMC.prefix + "Magnet upgrated to level " + 1);
}
}```
This is the code.
And whenever I try to get it's value, it shows me this.
I think you forgot to set the ItemMeta back to the item
that you did
also, I recommend you start using some has methods
you don;t have to get to check if it exists, there is a has method
same for item.hasItemMeta()
ohh okay
let us know if putting teh meta back fixes this, so we can leave the thread
My server crashed, but I think it did.
The meta may've been the problem.
Coz I never actually updated it's meta.
Thinking that it's the Itemstack itself handling it.
Sounds promising
this is also why has is a nice method. it literally tells you if it exists, any value
nice
I forgot to set it, therefor the value was never updated.
yep