Hey everyone, so i'm trying to do a little custom enchants plugin for my server and everything was working fine until i tried to apply the enchant to an item, here the code for context : java public void onAnvilChange(PrepareAnvilEvent e){ Inventory inv = e.getInventory(); // 1 = star add / 2 = tools/armor add if(anutils.anvilcheck(inv) == 1 && anutils.enchantcheck(inv, 1) != null){ Logger log = Bukkit.getLogger(); log.warning("Type 1 event"); e.setResult(anutils.enchantcheck(inv, 1)); plugin.getServer().getScheduler().runTask(plugin, () ->{ e.getInventory().setRepairCost(5);}); } else if(anutils.anvilcheck(inv) == 2 && anutils.enchantcheck(inv, 2) != null){ ItemStack item = anutils.enchantcheck(inv, 2); Logger log = Bukkit.getLogger(); log.warning("Type 2 event"); e.setResult(item); e.getInventory().setRepairCost(8); } }
#PrepareAnvilEvent setResult bug? item in slot 1 is replaced directly
1 messages · Page 1 of 1 (latest)
so first IF statement is working as intended, but the second not so much
so the item is not null or anything, it's just that it doesn't set it in the result slot, instead it directly update the slot 1 item
bypassing the level cost and not consuming the slot 2 item
i tried with the scheduler but it's the same thing, since it update the slot 1 the repaircost is never updated
i'll upload it on pastebin one sec
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
i'm starting to have an idea of the error but still no sense as to why it's working on the first if statement :x
i think the problem is that the event is called 5 times every time someone change something in an anvil
the first 2 times the item is not null cause it's done too fast (1tick?) but after that since it updated the slot 1 my enchantcheck function is no longer returning an item but null since conditions have changed
why does it change the slot 1 though no idea
could it be because the item is exactly the same except the enchant?
hey @real parrot, i noticed you helped in other theads so i hope i'm not disturbing you :x