Shopkeepers

Shopkeepers

2M Downloads

ShopkeepersAPI: Adding a trade to a Shopkeeper

UZ9 opened this issue ยท 1 comments

commented

Preliminaries:

  • Shopkeepers version: 2.2.1
  • Spigot version: 1.8.8-R0.1-SNAPSHOT

As there is no official documentation wiki for all the shopkeeper API classes, I can't find anyway of adding a trade to an existing shopkeeper. I'm using

Shopkeeper shopkeeper = ShopkeepersAPI.handleShopkeeperCreation(data);

where data is my villager shop creation data. I'm not exactly sure on how to add trades and would be happy to have a bit of insight.

Thanks!

commented

The 'API' is still a WIP. There is no API for adding trades to a shopkeepers in v2.2.1 (something was added for this in v2.8.0, but that's only compatible with newer server versions). handleShopkeeperCreation only creates a new empty shopkeeper (like if a player had created it).

To modify the trades of a shopkeeper nevertheless you will have to rely on Shopkeeper internal functions: See for example the class https://github.com/Shopkeepers/Shopkeepers/blob/931b3311bac0e2d1758fd7215fc368534dd362a2/src/main/java/com/nisovin/shopkeepers/shopkeeper/admin/AdminShopkeeper.java
Cast your admin shopkeeper to that, and then use the getOffers, addOffer and clearOffers to modify the trades.