Shopkeepers API
blablubbabcDEV opened this issue · 5 comments
Migrated from: https://dev.bukkit.org/projects/shopkeepers/issues/252
Originally posted by MiCrJonas1997 (Aug 19, 2014):
Hello, is there any usable API to create and manage a custom Shopkeeper? I had a look on the github page, but there's no example how to create a custom shopkeeper by the easiest way.
Maybe you can give an example how to do it on the bukkit or github page.I need something like this:
ShopKeeper ShopKeeperPlugin#createNewShopkeeper(String name)
void ShopKeeper#setTrade(ItemStack price0, ItemStack price1, ItemStack result)
void ShopKeeper#remove()Would be nice if you give me an code example or a link to the documentation of this plugin.Thanks, buddy :)
Originally commented by blablubbabc (Aug 19, 2014):
There is currently not yet official support for this, however you could try:
Registering your own ShopType (extending ShopType):
SelectableTypeRegistry<ShopType> ShopkeepersPlugin#getShopTypeRegistry() boolean SelectableTypeRegistry#register(ShopType type)
You can take a look how the default shop types are implemented here.
Then you probably also need to provide your own class extending Shopkeeper (you can find the defaults here). You might be able to extend one of those default ShopTypes.
There you implement your setTrade(..) method.
The player should then already be able to select your new ShopType with the shop creation item, or if it is an admin shop type you can probably create it via the commands.
This is completely untested and unsupported if it doesn't work, but might currently be the only possible way.
Originally commented by MiCrJonas1997 (Aug 19, 2014):
I saw, you planned to add an API for the plugin. (Some comments were about the API). Is it just a plan or are you sure to add an API? If you want to add it, is it far away or will it come in the next time? I'll wait, if you planned the API for the next time.
Originally commented by blablubbabc (Aug 19, 2014):
[at]MiCrJonas1997:
Well, I had the idea in mind to allow other plugins to register their own shop types when I wrote that shop-type-registry-thingy. However I have no idea if that already works, and making it work isn't a high priority task for me currently.. So try it out, if it works, it might break with the next updates if I change things, if it doesn't work don't expect it to work after the next updates as well...
Edited Aug 19, 2014
Originally commented by blablubbabc (Oct 24, 2017):
Closing this: While the API is still not documented and failure-proof (you currently can mess things up pretty badly if hooking into shopkeepers and doing something wrong), the things mentioned above are already possible. You can create shopkeepers, remove them, and you can for example modify the trades of admin shopkeepers. You will however have to take a look at the source code to figure out how to do those things.
Â
I will probably create a new ticket to remind me to improve the API and especially its documentation in the future, to make it easier to use and more failure-proof.