Custom Villager trades API

Discussion in 'Resources' started by Fedmand, Jun 7, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Fedmand

    Hey!
    I've recently made a merchant plugin using villagers. I spent a very long time figuring out how to add custom trades to villagers and after I figured out how I decided to make an api for all you developers out there struggling the same way I did while figuring out how to do this. This Api lets you both clear a villager's trades and add new trades!
    Dev page: http://dev.bukkit.org/bukkit-plugins/villager-trade-api/

    How to:
    Clearing trades:
    Code:java
    1. VillagerTradeApi.clearTrades(villager);

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

    Add trades:
    Code:java
    1. VillagerTrade trade = new VillagerTrade(itemstack1, itemstack2, reward);
    2. VillagerTradeApi.addTrade(villager, trade);

    Note: item2 is optional!

    Example:
    Code:java
    1. Villager villager = (Villager) event.getEntity();
    2. VillagerTradeApi.clearTrades(villager);
    3. ItemStack item1 = new ItemStack(Material.GOLD_NUGGET, 10);
    4. ItemStack item2 = new ItemStack(Material.APPLE);
    5. ItemStack reward = new ItemStack(Material.DIAMOND_HOE);
    6. VillagerTrade trade = new VillagerTrade(item1, item2, reward);
    7. VillagerTradeApi.addTrade(villager, trade);

    Output:

    [​IMG]

    Please leave some feedback and stuff if you found this useful!
     
    Gater12, AoH_Ruthless and Skyost like this.
  2. Offline

    97WaterPolo

    Fedmand
    Is there a max amount of items that you can have as the requirements?
     
  3. Offline

    Fedmand

    97WaterPolo
    Do you mean the required items for an offer?
    Villagers are made that way. I don't think I can help you with that, sorry :(
     
  4. Offline

    97WaterPolo

    Fedmand
    Yea, the required items for an offer. So I still don't understand, can you have more than 2 items required? Or it must be two. If it must be two, can it be null so you have two slots but require one item.
     
  5. Offline

    Fedmand

    97WaterPolo
    If by "more" you mean three items then, no that's not possible. It doesn't have to be two though! You can have both one and two items in your VillagerTrades. Simply remove the second item and make the trades like this:
    Code:java
    1. VillagerTrade trade = new VillagerTrade(item1, reward);
    2. VillagerTradeApi.addTrade(villager, trade);

    I hope this was the answer you needed!
     
  6. Offline

    97WaterPolo

  7. Offline

    Fedmand

    97WaterPolo Since this my first api I would love to hear a reply from you ;-) Is it working out for you? Do you have any siggestions?
     
  8. Offline

    Regablith

    Very nice job for your first API! I will be using this in the near future :)
     
  9. Offline

    Skyost

    Fedmand Nice job however, this is not open-source and we must include an entire plugin to use your API :/
     
    97WaterPolo likes this.
  10. Offline

    97WaterPolo

    Fedmand
    I agree with Skyhost, I personally prefer API's that allow you to add some classes directly into your plugin, instead of a seperate plugin required.
     
    Skyost and Onlineids like this.
  11. Offline

    Fedmand

    Skyost 97WaterPolo
    I see what you guys mean. However, I still want this api to be "mine". This may seem selfish, but I don't think I want this to be some code everyone just copies. I want this to be something people download and then use. I want to be credited. Is there any way I can achieve that without doing it like I am now?
     
  12. Offline

    Skyost

    Fedmand Give your resource with a specific license (which specify that you must be credited if someone use it) ;)
     
  13. Offline

    xTrollxDudex

    Fedmand
    There's no such thing as a closed source API. All you are doing is inconveniencing the user of the API to decompile your jar file anyways.
     
    davidovski and SoThatsIt like this.
Thread Status:
Not open for further replies.

Share This Page