masecla22/VillagerGUIApi

event.getTrade() in VillagerTradeCompleteEvent is 'new'

Closed this issue · 1 comments

The function event.getTrade() return a new VillagerTrade object..

@EventHandler
public void onPlayerTrade(VillagerTradeCompleteEvent event) {
  event.getTrade().getItemOne().getAmount() 
}

I suggest to replace this code :

VillagerTradeCompleteEvent completeEvent = new VillagerTradeCompleteEvent(toAdapt, (Player) event.getWhoClicked(), new VillagerTrade(itemOne, itemTwo, result, -1));
/* With this : */
VillagerTradeCompleteEvent completeEvent = new VillagerTradeCompleteEvent(toAdapt, (Player) event.getWhoClicked(), toAdapt.getTrades().get((MerchantInventory) this.toAdapt.getForWho().getOpenInventory().getTopInventory().getSelectedRecipeIndex()));
/* And of course remove lines 65, 66, 67, no more used */

in
https://github.com/masecla22/VillagerGUIApi/blob/master/src/main/java/masecla/villager/adapters/instances/MerchantAdapter_v1_16_R3.java#L69

More infos about MerchantInventory#getSelectedRecipeIndex here :
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/MerchantInventory.html#getSelectedRecipeIndex()

Altough I agree with you on the fact that it would make a lot of sense, this isn't really doable in older versions (as far as I know) and I think it would introduce inconsistencies, across versions.

Ideally, we'd have some kind of system which keeps track of them, and subtracts uses when VillagerTradeComplete event is fired.

If you manage to do that, a pull request would be welcomed :)