Villager Trade API

Villager Trade API - A smooth and simple way to configure villager trades

Logo

Description:

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.

In plugins folder

Then you add it to your project like you added your bukkit api.

In project folder

2: The coding:

Here comes the hardest part. Oh wait, it's not even hard! Because I simplified it for you ;)

Clear trades:

VillagerTradeApi.clearTrades(villager);

Note: You don't have to clear the trades before adding new ones.

Add trades:

VillagerTrade trade = new VillagerTrade(itemstack1, itemstack2, reward);

VillagerTradeApi.addTrade(villager, trade);

Note: item2 is optional!

Example:

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);

Output:

In-game

And that's pretty much it! Feel free to leave feedback, bug-reports, questions and suggestions down below.


Comments

Posts Quoted:
Reply
Clear All Quotes

About This Project

  • Project ID
    80737
  • Created
    Jun 1, 2014
  • Last Released File
    Never
  • Total Downloads
    2,724
  • License

Categories

Members

Recent Files