- Tested Minecraft Versions:
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.
2: The coding:
Note: You don't have to clear the trades before adding new ones.
VillagerAPI.spawnVillager(Player p, "villagerName", canMove(true,false), Profession ProfessionType);
VillagerAPI.spawnVillager(player, "Spigot villager", false, Profession.BLACKSMITH);
VillagerTrade trade = new VillagerTrade(itemstack1, itemstack2, reward);
Note: item2 is optional!
Villager villager = (Villager) event.getEntity();
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);