From 8d4b05c44f97de17fb69bb8c0a358f9d8195616f Mon Sep 17 00:00:00 2001
From: Nathan Poirier <nathan@poirier.io>
Date: Sun, 22 Nov 2015 14:20:38 +0100
Subject: [PATCH] Add Villager Trade API


diff --git a/src/main/java/org/bukkit/entity/Villager.java b/src/main/java/org/bukkit/entity/Villager.java
index 51035c9..235df6c 100644
--- a/src/main/java/org/bukkit/entity/Villager.java
+++ b/src/main/java/org/bukkit/entity/Villager.java
@@ -1,5 +1,9 @@
 package org.bukkit.entity;
 
+import org.bukkit.inventory.ItemStack;
+
+import java.util.Collection;
+
 /**
  * Represents a villager NPC
  */
@@ -66,4 +70,176 @@ public interface Villager extends Ageable, NPC {
             return (id >= professions.length) ? null : professions[id];
         }
     }
+
+    // FunCraft start
+
+    /**
+     * Returns a modifiable collection of the {@link Villager} trade list.
+     *
+     * @return the {@link Villager} trade list.
+     */
+    public Collection<? extends Trade> getTrades();
+
+    /**
+     * Add a new {@link Trade} to the {@link Villager} trade list.
+     *
+     * @param buyingOne the first {@link ItemStack} the {@link Player} must give to the {@link Villager}
+     * @param buyingTwo the second {@link ItemStack} the {@link Player} must give to the {@link Villager}; or null if none
+     * @param selling   the {@link ItemStack} the {@link Player} receives from the trade
+     * @return the {@link Trade} added
+     */
+    public Trade addTrade(ItemStack buyingOne, ItemStack buyingTwo, ItemStack selling);
+
+    /**
+     * Add a new {@link Trade} to the {@link Villager} trade list at the give position.
+     *
+     * @param index     the position to insert
+     * @param buyingOne the first {@link ItemStack} the {@link Player} must give to the {@link Villager}
+     * @param buyingTwo the second {@link ItemStack} the {@link Player} must give to the {@link Villager}; or null if none
+     * @param selling   the {@link ItemStack} the {@link Player} receives from the trade
+     * @return the {@link Trade} added
+     */
+    public Trade addTrade(int index, ItemStack buyingOne, ItemStack buyingTwo, ItemStack selling);
+
+    /**
+     * Remove a {@link Trade} for the {@link Villager} trade list.
+     *
+     * @param trade the {@link Trade} to remove
+     * @return {@code true} if if it existed and was deleted; {@code false} if not
+     */
+    public boolean removeTrade(Trade trade);
+
+    /**
+     * Returns whether or not this villager allow multiples traders at the same time.
+     * By default: false
+     *
+     * @return {@code true} if this villager allow multiples traders at the same time; {@code false} if not
+     */
+    public boolean isAllowMultipleTraders();
+
+    /**
+     * Set whether or not this villager allow multiples traders at the same time.
+     *
+     * @param allowMultipleTraders {@code true} if this villager allow multiples traders at the same time;
+     *                             {@code false} if not
+     */
+    public void setAllowMultipleTraders(boolean allowMultipleTraders);
+
+    public interface Trade
+    {
+
+        /**
+         * Returns the first {@link ItemStack} the {@link Player} must give to the {@link Villager}.
+         *
+         * @return the {@link ItemStack} in slot 1
+         */
+        public ItemStack getBuyingOne();
+
+        /**
+         * Sets the first {@link ItemStack} the {@link Player} must give to the {@link Villager}.
+         *
+         * @param itemStack the {@link ItemStack} to set; or null to remove the first item
+         */
+        public void setBuyingOne(ItemStack itemStack);
+
+        /**
+         * Returns the second {@link ItemStack} the {@link Player} must give to the {@link Villager}.
+         *
+         * @return the {@link ItemStack} in slot 2
+         */
+        public ItemStack getBuyingTwo();
+
+        /**
+         * Sets the second {@link ItemStack} the {@link Player} must give to the {@link Villager}.
+         *
+         * @param itemStack the {@link ItemStack} to set; or null to remove the second item
+         */
+        public void setBuyingTwo(ItemStack itemStack);
+
+        /**
+         * Returns whether or not this trade requires the {@link Player} to give the {@link Villager} two items.
+         *
+         * @return {@code true} if the {@link Player} must give two items, {@code false} if the {@link Player} must give
+         * only one
+         */
+        public boolean hasBuyingTwo();
+
+        /**
+         * Returns the {@link ItemStack} the {@link Player} receives from the trade.
+         *
+         * @return the {@link ItemStack} selling
+         */
+        public ItemStack getSelling();
+
+        /**
+         * Sets the {@link ItemStack} the {@link Player} receives from the trade.
+         *
+         * @param itemStack the {@link ItemStack} to set for selling; or null to remove the selling item
+         */
+        public void setSelling(ItemStack itemStack);
+
+        /**
+         * Returns the amount of times this trade was used.
+         *
+         * @return the amount
+         */
+        public int getUses();
+
+        /**
+         * Set the amount of times this trade was used.
+         *
+         * @param uses the amount
+         */
+        public void setUses(int uses);
+
+        /**
+         * Returns the maximum amount of times this trade can be used.
+         *
+         * @return the maximum amount
+         */
+        public int getMaxUses();
+
+        /**
+         * Set the maximum amount of times this trade can be used.
+         *
+         * @param maxUses the maximum amount
+         */
+        public void setMaxUses(int maxUses);
+
+        /**
+         * Increase the number of times this was used by one.
+         */
+        public void use();
+
+        /**
+         * Increases the maximum amount of times this trade can be used.
+         * The default max is 7
+         *
+         * @param increase the amount to increase it buy
+         */
+        public void increaseMaxUses(int increase);
+
+        /**
+         * Returns whether or not this recipe has exceeded its max usages and can no longer be used.
+         *
+         * @return {@code true} if used up; {@code false} if not
+         */
+        public boolean isUsedUp();
+
+        /**
+         * Returns whether or not this recipe can drop experience when it is purchased.
+         *
+         * @return {@code true} if it can drop experience; {@code false} if not
+         */
+        public boolean canRewardExp();
+
+        /**
+         * Set whether or not this recipe can drop experience when it is purchased.
+         *
+         * @param rewardExp {@code true} if it can drop experience; {@code false} if not
+         */
+        public void setRewardExp(boolean rewardExp);
+
+    }
+    // FunCraft end
 }
-- 
2.6.4

