New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[B+C] Add Merchant Trade API - Adds BUKKIT-5663 #1077
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.bukkit.event.merchant; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.commons.lang.Validate; | ||
|
||
import org.bukkit.merchant.Merchant; | ||
import org.bukkit.event.Cancellable; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.inventory.TradeOffer; | ||
|
||
/** | ||
* This event is called whenever a TradeOffer is being added to a Merchant's | ||
* list of offers. If cancelled, the TradeOffer will not be added to the list. | ||
*/ | ||
public class MerchantAddOfferEvent extends MerchantEvent implements Cancellable { | ||
private static final HandlerList handlers = new HandlerList(); | ||
|
||
private List<TradeOffer> offers; | ||
private TradeOffer offerToAdd; | ||
private boolean cancelled = false; | ||
|
||
public MerchantAddOfferEvent(Merchant merchant, TradeOffer toAdd) { | ||
super(merchant); | ||
Validate.notNull(toAdd, "Cannot add a null TradeOffer!"); | ||
this.offers = merchant.getInventory().getOffers(); | ||
this.offerToAdd = toAdd; | ||
} | ||
|
||
/** | ||
* Gets an immutable copy of the list of TradeOffers the merchant currently has. | ||
* | ||
* @return a copy of the current offers from the merchant | ||
*/ | ||
public List<TradeOffer> getCurrentOffers() { | ||
return offers; | ||
} | ||
|
||
/** | ||
* Gets the immutable TradeOffer being added to the Merchant's current offers. | ||
* | ||
* @return the offer to add | ||
*/ | ||
public TradeOffer getOfferToAdd() { | ||
return offerToAdd; | ||
} | ||
|
||
@Override | ||
public HandlerList getHandlers() { | ||
return handlers; | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return handlers; | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
return this.cancelled; | ||
} | ||
|
||
@Override | ||
public void setCancelled(boolean cancel) { | ||
this.cancelled = cancel; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.bukkit.event.merchant; | ||
|
||
import org.apache.commons.lang.Validate; | ||
|
||
import org.bukkit.event.Event; | ||
import org.bukkit.merchant.Merchant; | ||
|
||
/** | ||
* Represents a Merchant related event. | ||
*/ | ||
public abstract class MerchantEvent extends Event { | ||
|
||
protected Merchant merchant; | ||
|
||
MerchantEvent(Merchant merchant) { | ||
Validate.notNull(merchant, "Cannot have a null Merchant!"); | ||
this.merchant = merchant; | ||
} | ||
|
||
/** | ||
* Gets the merchant involved with this event. | ||
* | ||
* @return The merchant | ||
*/ | ||
public Merchant getMerchant() { | ||
return this.merchant; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,41 @@ | ||
package org.bukkit.inventory; | ||
|
||
import java.util.List; | ||
|
||
import org.bukkit.merchant.Merchant; | ||
|
||
/** | ||
* Represents the inventory of a merchant which contains a list of {@link TradeOffer}s. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You do not have to fully qualify the links. As well the wording is a bit off in general. I would start off by saying something like |
||
public interface MerchantInventory extends Inventory { | ||
|
||
/** | ||
* Gets the merchant belonging to this inventory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Period. |
||
* | ||
* @return the merchant | ||
*/ | ||
public Merchant getMerchant(); | ||
|
||
/** | ||
* Gets a copy of the offers presented to a Player. | ||
* | ||
* @return a copied list of TradeOffers being given to the Player | ||
*/ | ||
public List<TradeOffer> getOffers(); | ||
|
||
/** | ||
* Adds the given TradeOffer to this Inventory's list of trade | ||
* offers. | ||
* | ||
* @param offer to add | ||
*/ | ||
public void addOffer(TradeOffer offer); | ||
|
||
/** | ||
* Removes the specified offer if it is contained within the list of | ||
* offers by this inventory. | ||
* | ||
* @param offer to remove | ||
*/ | ||
public void removeOffer(TradeOffer offer); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not required.