Villager Trade API
Villager Trade API - A smooth and simple way to configure villager trades
I've recently made a merchant plugin using villagers. I spent a very long time figuring out how to add custom trades to villagers. After I figured out how I decided to make an Api for all you developers out there struggling the same way I did while finding out how to do this. This Api lets you both clear a villager's trades and add new trades. I will add more features in the future. I just don't know what to add at the moment so please feel free to suggest new features down below!
How to use:
1: Install the Api
First you add the api to your plugins folder like you would do with any other plugin.
Then you add it to your project like you added your bukkit api.
2: The coding:
Here comes the hardest part. Oh wait, it's not even hard! Because I simplified it for you ;)
Note: You don't have to clear the trades before adding new ones.
VillagerTrade trade = new VillagerTrade(itemstack1, itemstack2, reward); VillagerTradeApi.addTrade(villager, trade);
Note: item2 is optional!
Villager villager = (Villager) event.getEntity(); VillagerTradeApi.clearTrades(villager); ItemStack item1 = new ItemStack(Material.GOLD_NUGGET, 10); ItemStack item2 = new ItemStack(Material.APPLE); ItemStack reward = new ItemStack(Material.DIAMOND_HOE); VillagerTrade trade = new VillagerTrade(item1, item2, reward); VillagerTradeApi.addTrade(villager, trade);
And that's pretty much it! Feel free to leave feedback, bug-reports, questions and suggestions down below.