Add Merchant API

By: Xor Boole <mcyoung@mit.edu>
This commit is contained in:
Bukkit/Spigot
2016-03-01 08:30:04 +11:00
parent ccc64d57e8
commit ab952a946f
6 changed files with 400 additions and 1 deletions

View File

@@ -0,0 +1,64 @@
package org.bukkit.event.entity;
import org.bukkit.entity.Villager;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.MerchantRecipe;
/**
* Called whenever a villager acquires a new trade.
*/
public class VillagerAcquireTradeEvent extends EntityEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
//
private MerchantRecipe recipe;
public VillagerAcquireTradeEvent(Villager what, MerchantRecipe recipe) {
super(what);
this.recipe = recipe;
}
/**
* Get the recipe to be acquired.
*
* @return the new recipe
*/
public MerchantRecipe getRecipe() {
return recipe;
}
/**
* Set the recipe to be acquired.
*
* @param recipe the new recipe
*/
public void setRecipe(MerchantRecipe recipe) {
this.recipe = recipe;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
@Override
public Villager getEntity() {
return (Villager) super.getEntity();
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@@ -0,0 +1,89 @@
package org.bukkit.event.entity;
import org.bukkit.entity.Villager;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.MerchantRecipe;
/**
* Called when a villager's trade's maximum uses is increased, due to a player's
* trade.
*
* @see MerchantRecipe#getMaxUses()
*/
public class VillagerReplenishTradeEvent extends EntityEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
//
private MerchantRecipe recipe;
private int bonus;
public VillagerReplenishTradeEvent(Villager what, MerchantRecipe recipe, int bonus) {
super(what);
this.recipe = recipe;
this.bonus = bonus;
}
/**
* Get the recipe to replenish.
*
* @return the replenished recipe
*/
public MerchantRecipe getRecipe() {
return recipe;
}
/**
* Set the recipe to replenish.
*
* @param recipe the replenished recipe
*/
public void setRecipe(MerchantRecipe recipe) {
this.recipe = recipe;
}
/**
* Get the bonus uses added. The maximum uses of the recipe will be
* increased by this number.
*
* @return the extra uses added
*/
public int getBonus() {
return bonus;
}
/**
* Set the bonus uses added.
*
* @see VillagerReplenishTradeEvent#getBonus()
* @param bonus the extra uses added
*/
public void setBonus(int bonus) {
this.bonus = bonus;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
@Override
public Villager getEntity() {
return (Villager) super.getEntity();
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}