Skip to content
Seppe Volkaerts edited this page Apr 9, 2017 · 19 revisions

Description

The merchants api is a expansion of the bukkit api to be able to create custom merchants without any need of an attached entity and being able to modify it.

Download?

You can find the builds for the api and all the implementation versions are in this stack.

Which download do I chose?

I prefer that you choose the 'all' version as it contains all the available implementations, only the required classes will be loaded and if the version isn't available there will be a message send to the console.

If you want to use a minecraft specific version, you may go ahead and open up your craftbukkit, spigot or any other server jar in program that allows you to see the contents like 'winrar' or '7zip' and go to the path net/minecraft/server. In that path you will see a folder name something like V1_8_R3 and you will need to match this version with one of the available plugin versions, in this case will it be v18r3.

There are only builds for spigot and I am using craftbukkit?

The implementations are build against spigot builds, but they should work for craftbukkit, if there are any issues, just open a ticket on the issue tracker of github.

How to use it?

// Access the merchants api
MerchantAPI api = Merchants.get();
// Create a new merchant
Merchant merchant = api.newMerchant("My Name");
// Add some offers
// Arg: 1=result; 2=first offer item; 3=(optional)second offer item
merchant.addOffer(api.newOffer(new ItemStack(Material.EMERALD, 10), new ItemStack(Material.DIAMOND, 3));
merchant.addOffer(api.newOffer(new ItemStack(Material.EMERALD, 30), new ItemStack(Material.DIAMOND, 3), new ItemStack(Material.STONE, 64));
// Open the inventory for a player
Player player = ...; // Access by any way
merchant.addCustomer(player);

How can I use the merchant trade listener?

Merchant merchant = ...; // Access by any way
merchant.addListener(new MerchantTradeListener() {

	@Override
	public void onTrade(Merchant merchant, MerchantOffer offer, Player customer) {
		// Do stuff
	}

});

How can I access the merchant inside inventory events?

@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
	Inventory inventory = event.getInventory();

	// Check the instance, make sure that imported the inventory class from the library
	// and not the bukkit one (they are named the same), or it won't work
	if (inventory instanceof MerchantInventory) {
		MerchantInventory merchantInventory = (MerchantInventory) inventory;
		// Gets the merchant
		Merchant merchant = merchantInventory.getMerchant();
		// Gets the currently selected offer
		MerchantOffer offer = merchantInventory.getSelectedOffer();

		// Do stuff
	}
}