Closed Lildirt closed 4 months ago
Looks like you matched 'viewers' from item_pre_craft, whereas we should probably get a player for both of these from the InventoryView. I don't think there can be multiple viewers, at least for these events on these GUIs. I would recommend removing 'viewers' and add 'player' for this event.
There's one hitch. InventoryView was changed from an abstract class to an interface a couple of weeks ago. Directly using methods from that interface may not work on older versions of the server. Might need reflection. Something like:
@Override
public MCHumanEntity getPlayer() {
return new BukkitMCHumanEntity(ReflectionUtils.invokeMethod(e.getView(), "getPlayer"));
}
Let me test the other event to see if reflection is needed here too. [edit] Confirmed. Needs reflection.
Actually can probably just do e.getViewers.get(0) instead of reflection. That's probably the way to go.
Actually can probably just do e.getViewers.get(0) instead of reflection. That's probably the way to go.
Pushed a commit. Something like that?
That looks fine. It looks impossible to have more than one viewer for an anvil. Unlike shared inventory views, the list of tracked viewers of an anvil is created every time a call to open an anvil is used.
Just noticed you have question marks in the description of the repair costs. Perhaps they were temporary?
Kind of flying blind with creating a new event. It's been many years since I've written one, in an extension. :joy: Let me know if there's any validation you'd like for me to do on my end.
Example payload (pretty printed):