Vault-like Money API
#1
So, I'm currently working on a vault-like money API. For those that don't know what the Vault Bukkit plugin is, I'll just explain what this plugin does.

--====================

This plugin (henceforth referred to as "the plugin" or "MoneyAPI") acts as the middle man between "money" and "shop" plugins. Cuberite currently has 2(+?) money plugins, I believe called "Money" and "Coins". I cannot think of any current "shop" plugins, so let's pretend we have a fully ported version of the popular Bukkit plugin SignShop, called "Shoppy".

Shoppy wants to be able to work with any currency plugin the server admin has installed. As it is now, however, the Shoppy dev would have to program to fit the apis of both Money and Coins (last I saw, Money doesn't yet have an API, but it was planned). This is where my plugin comes into play. My plugin has strict specifications that, if Coins and Money were (re)built around them, would allow Shoppy to use either plugin, or even a new plugin that also follows the specifications. Instead of Shoppy having to find a currency plugin, it can instead look for my plugin. My plugin will initiate contact with any compatible economy plugins (not a name list, just a for loop through all plugins) and record some information. Then, when Shoppy wants to, say, request a balance, Shoppy will tell my plugin to request a balance (CallPlugin("MoneyAPI","EconomyCall","playerbalance","UUID"). MoneyAPI will then request the balance from the loaded economy plugin(s), and forward that information to Shoppy. This allows Shoppy to function without being built around multiple mods, with the obvious disadvantage of it and other mods having to be built around MoneyAPI.

--====================

So, here's where I'm not sure where to go. I've got most of the logic written out already. I'll share what I currently have if anyone is truly interested in the skeleton, but right now that doesn't seem totally necessary. What I am not so sure about, however, is how to handle multiple currency plugins. In the bukkit/spigot landscape, multiple currencies only work in one of two situations. 1) All the currency plugins and shop plugins can work with this setup 2) MultiWorldMoney (or similar) is used. In my plugin's current state, it can support 1 relatively well using per-world restrictions (with the "world" being an optional final argument that is left to the currency plugin to handle). This allows a currency plugin to be developed as "global" by simply ignoring the "world" argument, or for it to have a configurable list of worlds within which it functions, and ignore API calls involving any other worlds. For reference, in MoneyAPI's current state, it calls all registered currency plugin every time it receives a request, and gives a warning in console if multiple currency plugins are installed about possible conflicts.

Now that all the descriptions are out of the way, what I want help with is what should be in the API. The current list of functions that are required for any currency plugin to be considered valid are:

currencyName - Name of the currency (singular)
currencyNamePlural - Name of the currency (plural)
format - Format a number into the currency string (for example, the number 1234.561 would format to "$1234.56")
isEnabled - To verify that the currency plugin is enabled. If no currency plugins are found, returns false
fractionalDigits - Returns whether the currency plugins supports decimals, and to how many places
getPlayers - A list of all registered player accounts (UUID)
getName - Returns the currency plugin's name. This is to allow per-world plugins to be sorted properly
playerWithdraw - Remove money from player account (UUID)
playerDeposit - Add money to player acocunt (UUID)
playerBalance - Returns the balance of a player (UUID)
playerHas - This is in the Vault API, but I see no reason that the shop plugin author couldn't just >= check the balance return
playerHasExactly - Similar to above, as the Vault API (where I read about it at least) is not specific about whether "Player Has" checks exactly, or for "at least"

In addition, these optional calls are also available:

getBanks - As above, but for "banks" (string name)
bankWithdraw - As above, but for "banks" (string name)
bankDeposit - As above, but for "banks" (string name)
bankBalance - As above, but for "banks" (string name)
bankHas - As above, but for "banks" (string name)
bankHasExactly - As above, but for "banks" (string name)
bankHasPlayer - Check if a player is a member of a bank
bankOwner - Return who the owner of the bank is (UUID or string)
bankMemberDeposit - Deposit to member account in bank (if given UUID belongs to bank) (effects are implementation specific)
bankMemberWithdraw - Withdraw from member account in bank (if given UUID belongs to bank) (effects are implementation specific)
bankMemberBalance - You've probably figured this out by now. I'll more exhaustively document these before I actually release it.
bankMemberHas - You've probably figured this out by now
bankMemberHasExactly - You've probably figured this out by now



So now the help I want: can you think of any reason to include the "Has" and "HasExactly" functions? Is there anything I'm missing that should be added? This already has more options than the Vault API, although obviously being nowhere near as refined. I guess I'm also gauging interest into if anyone would actually use this (and therefore if others would use another similar plugin I'm refining).

Right now, I'm attempting to get it finished "enough" to put on github. I will edit this post with the link once that has been achieved.

I also want ideas on how to better support multiple different currencies. I'm considering a system that would allow another plugin to "override" parts of my plugin, including running outside code once, and replacing my central function. This would be possible, but it may be easier to use an open license and for someone to create a more multiworld focused plugin, without losing the current support (such as having a config file where you define specifically which plugins work in what worlds).


Edit time:

I've gotten it to a point where... I'm not ready to commit to GitHub or really release it yet, but I'll throw up a zip as an attachment. The zip file contains MoneyAPI, as well as two fake plugins, called "TestCurrency" and "TestShop". Neither actually works as currency/shop plugins, but they did enough to debug for me. Console command "shopapi" will trigger TestShop to send a request to MoneyAPI about whatever setting you currently have it on (I've completely forgotten how to properly register console commands, so I just made it like that to save some time). Do note: there's a LOT of prints in some of the files that wouldn't be there in an official release. I just needed them to bug test.

Much later edit: MoneyAPI is now on github! I wouldn't call it release ready yet, but it can now be explored, and currently has (WIP) documentation. Find it here!


Attached Files
.zip   TestPlugins.zip (Size: 6.57 KB / Downloads: 323)
Reply
Thanks given by:
#2
Wouldn't it be easier to just implement that API directly in Coiny and make it the de-facto only money plugin for Cuberite?
Reply
Thanks given by:
#3
That would be an option, sure, but then what about the newer plugin? Or person X who wants to make one to prove the can, or even to make a better one. Yeah, it's an option, it's not the worst option either, but it's probably not the best.

Also: does coiny have all the features that I could currently support? AKA, different money for different worlds or banks? If coiny doesn't, no one does yet, but someone could in the future.

And what if the Coiny dev disappears? Obviously it could be taken up by someone else, but as the modded community knows, that doesn't always happen, even with the smaller, popular mods (ignoring cases where closed source/restrictive license prevents it in the first place). Obviously, seeing as the dev is Sphinx, he almost certainly won't disappear, but the point still stands.

And by looking at his API for Coiny, the only functions that can't be made out of just the current API are the currency names (unless these are configurable, then just make them return the names) and get players. Assuming those aren't too difficult, I could probably write a small file for Coiny to get it "compliant". (N.B. on this one: no idea what the a_Channel and a_ChannelData do, so this paragraph may be wrong if those are important). I'll be awake again in a few hours, so sorry I won't be responding for a bit.
Reply
Thanks given by:
#4
Wasn't Coiny made exactly for this purpose though? I honestly think it would be better to update and extend Coiny with the features you proposed, then making an all new plugin, it just fragments the money plugins otherwise.

Not sure why you are worried about devs dissapearing. First of all it's free (as in freedom), so anyone can take it, extend and update it. If Sphinx would dissapear for some reason, someone else would just take the development further. This would just as much be an issue with your plugin as with Coiny.
Reply
Thanks given by:
#5
Coiny belongs to the core Cuberite plugins, meaning that the devs who make Cuberite actually made Coiny as well. It's actually hosted on GitHub at the Cuberite organization.

Alright, I confess, I made it Smile Re-write it, rather, after SQLite DB was implemented in Lua API, from scratch. And I'd very much prefer to have a single money plugin with all the features, than a fragmented  array of plugins, none of which work okay.

If anyone wants to write their own money plugin "because they can", they can do that and other plugins could support that by simply having a configuration for "name of the money plugin", which would be then the first parameter to the cPluginManager:CallPlugin() function.
Reply
Thanks given by: Schwertspize
#6
I would say you develop a working api in coiny, and that's it. Why do plugins need to have an api for vault and vault an api for other plugins who wants an api for cuberite or vault too..... Too many apis imo

Just define one api in coiny, make plugins use that directly and ad xoft pointed out if any other plugin wants to compete they have to implement the same api or be a complete replacement
Reply
Thanks given by:
#7
Just do it..
I won't really care how many plugins there are that do the same thing.
If one has a feature i want and the other does not i will be using that.
If somebody else does not need that feature he might use another, or the same but simply not use that feature.

The more plugins of one thing mostly means there are more developers involved going there own way with it.
Then when another developer joins he sees 20 plugins of the same and things well i like this and that, but no the rest.
He makes his own again but with just the features he likes making 21.

Though 19 of those 21 plugins wont be updated shortly after release.
When that happens simply clean those up in a separate archive, don't delete just move them to keep things clean.

Once i get time to run a mc server once again, i will probably be making my own plugins, just cause.
I will be releasing those as well, if somebody is going to use them good for them.
If they want bug fixes it will be public and they can do it themselves or ask me or perhaps another developer finds time to do it.

If i stop using it/developing it and it is not working with the newest version, move it to the archive.
Somebody later on might want to use it update it, and other people will be enjoying it once again.

---
Why i am writing this so late at night while not properly thinking i am not sure. but at this time it all makes sense.
It is just more fun when reading this myself later on when i am thinking clear. that's when the actual fun begins!
Reply
Thanks given by:
#8
@ThuGie

Thanks for expressing that. I had the exact same thought process, but couldn't transcribe it into words.

Edit:

I've officially uploaded to Github, and begun documenting the API. I'm heading to bed now, though, so I'll have to finish tomorrow after class. Link is here, and I will be adding this to the OP.
Reply
Thanks given by:
#9
I've looked a bit better into what exactly you want, and also looked into your code. Your way of doing it seems pretty good, and I would love to see it grow bigger.

From what I understand, people will be able to create plugins which handle the storage and transferring of money. They register themselves with this plugin, so other plugins can just interface with Money instead of every single money handling plugin individually. Am I right?


Would it be an option to replace Coiny with this as the official Cuberite money API system? Or use your code in Coiny instead of what's in there now?
Reply
Thanks given by:
#10
Money plugin has shopping functions Smile
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)