Adding Vault Support to Custom Economy
zerafox opened this issue ยท 10 comments
I've had developed a brand new Economy system, however after doing some trial and error and poking around I am at an understanding that Vault needs to add the Economy Plugin itself to it's code?
(Forgive me, I am not a developer and know nothing of Java..)
Is this true, or is there something we've all missed somewhere that can be done from this Economy plugin to make it work with Vault, without having Vault do anything directly itself to have it recognized as an economy plugin?
My Developer had found this thread: https://bukkit.org/threads/making-vault-hook-into-a-my-economy-plugin.128165/
And says that directions by both fireblast709 and Gablom where followed when attempting to make our plugin compatible. Unfortunately it didn't quite work out as we'd hoped.
@javacraft Thank you for your suggestion, I will pass this ticket along to our Developer and hope that we can manage something.
If I may ask, what is it you're looking for in an Economy plugin that iConomy doesn't offer?
@zerafox - The current architecture of Vault uses "hook" classes that listen for economy plugins to load and provide the interface between the two. Currently, your options are:
- Fork Vault to add your own hook class. If you intend on making your econ plugin publicly available, you might want to consider issuing a pull request such that your hook class becomes part of the mainline code.
- Another possibility, which is more of a hack, is that your econ plugin emulates one of the known econ interfaces. For example, if your plugin registers itself as being iConomy6 and supports all the same methods, then Vault would be none the wiser. Obviously, this is only a fix to treat the effect, not a solution to fix the cause.
- Something more suitable, but still a hack would be for your plugin to register itself as the
Economy.class
service, which is inherently what Vault does once it detects an econ plugin. You'd still need the Vault plugin, because well-written Vault-compatible plugins will first check if Vault exists before checking for the service. This may be the best immediate option, since it doesn't require making changes to Vault. However, for the sake of a unified, maintainable interface, the long-term solution should still be through Vault.
We are faced with a similar situation. iConomy has lasted use a very long time, but we have more complex needs and all other econ plugins just don't seem capable or flexible enough to do what we want. Thus, we are also writing our own econ plugin.
@MilkBowl, et. alia. - I would like to suggest a newer approach for detecting and binding to econ plugins. This method should equally be extendible to permissions, chat, etc. and will work in parallel with existing hooks; thus, not break backwards compatibility.
Consider a plugin that implements the Economy
interface. A single PluginEnableEvent
listener can be used to determine if a plugin is compatible. If so, the plugin reference will suffice for all other communication. If not, then it is left for one of the hooks to find.
I grant that this shifts the burden of interface compatibility to econ developers, but since Vault would implement both binding methods, it remains a choice for legacy econ developers to as whether they want to update or continue the old way.
From the econ developer's side, it's just a matter of having a dependency on VaultAPI
for the Economy
and EconomyResponse
classes.
This is the approach that we will be testing. If successful, I'll be glad to issue a pull request. Then again, I bet you could add this feature in your sleep :). I haven't yet dove into the bowels of the source code. Who knows, maybe you already have such a feature?
If I may ask, what is it you're looking for in an Economy plugin that iConomy doesn't offer?
Rather than a balanced-based system, we need a ledger-based system with transactions and descriptions. On top of that, multi-currency, conversions, UUID-compliant, etc.
@javacraft Multi-currency? Like multiple forms of a virtual currency, or a hybrid system between the standard virtual currency and a physical?
I don't think Vault can support multiple virtual types of currencies, but I may be wrong there too.
Aren't most of the eco plugins out there UUID compliant by now? I can't say I've used any but Fe recently, for a temporary Eco plugin until ours was in the works...
Oh, I'd also like to add that what you said worked for us. My Developer was able to make a working version of our Eco plugin, though he also modified Vault so that it would read ours and maintain it's ability to connect to/speak with other plugins we have as well.
@javacraft - all new economies/permissions are already instructed to implement their own hooks. I no longer pull hooks directly into Vault. The only thing to be aware of is that econ/perm systems need to set their plugins to load at startup so the hooks are available before other standard plugins try to find them. Forking Vault is not necessary, if you have developers doing this they are doing it the hard way (extra effort, unnecessary and probably wrong).
There is no difference to providing the hooks in your own plugin as long as you do it properly. (see statement above about load time)
Vault is still required on the server regardless as it provides the interfaces that are necessary for everyone to communicate together. Everything you suggested is already accomplished with the services framework provided by bukkit.
The thread the OP linked at the top is exactly how to perform this. This is how Vault handles registering them to begin with. If this does not work for you, then you are not having your economy plugin load in the correct startup stage: https://github.com/MilkBowl/Vault/blob/master/plugin.yml#L8
@Sleaker Hello, I am the developer who has been trying to implement Vault into a custom eco plugin. I initially tried this plugin but the problem with it is if I had dependancies. For example this plugin had to use some features from 'BetonQuest' but due to the fact that the plugin has to load on start up, it would not recognize BetonQuest as loaded and so would not enable itself. Is there a way around this problem? Thanks.
@Sleaker tyvm for the response. My apologies for not looking at the code first I have since then seen what you mentioned. Its been quite a while since I looked at Vault's source code. Vault always works, thus any inspection outside of our current need was more for curiosity's sake. Kudos.
@Sleaker The Economy is a standalone by itself already, at most it offers a few smaller additives to another plugin that also uses Vault.
However since the Economy also functions with a secondary (non-vault) type economy built in that interacts with the other plugin there didn't seem to be any real need to create such a tiny, small plugin for this feature.
I suppose we will have to review the options in front of us, thank you.
@TimLampen - then you need to split your economy off so it's a standalone by itself, and link to it from your main plugin. This is a separation of concerns and modularizaton. When you need different pieces to load at different times you may need to do this. Or you need to have your plugin passively detect when other plugins are loaded as a once-off event after the server starts (schedule a task for this). There are many ways to work around this programatically, you just need to think outside of a single implement/register everything all at once kind of box. Bukkit API supports different triggers on plugin loading, has events for everytime plugins load, and allows you to schedule tasks through a scheduler. Utilizing any of these pieces can provide what you're looking for without needing to utilize hard dependencies in the plugin.yml but still maintain those hard-dependencies at code-level.
@zerafox - that leaves me wondering why you can't just force the other plugin to also load in startup by modifying it's plugin.yml, or pull all of it's functionality into your own.