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: 328)
Reply
Thanks given by:


Messages In This Thread
Vault-like Money API - by Zee1234 - 06-12-2016, 11:05 AM
RE: Vault-like Money API - by xoft - 06-12-2016, 04:01 PM
RE: Vault-like Money API - by Zee1234 - 06-12-2016, 05:12 PM
RE: Vault-like Money API - by PureTryOut - 06-12-2016, 11:04 PM
RE: Vault-like Money API - by xoft - 06-13-2016, 12:10 AM
RE: Vault-like Money API - by Schwertspize - 06-13-2016, 08:02 AM
RE: Vault-like Money API - by ThuGie - 06-13-2016, 08:23 AM
RE: Vault-like Money API - by Zee1234 - 06-13-2016, 09:59 AM
RE: Vault-like Money API - by PureTryOut - 10-06-2016, 09:45 PM
RE: Vault-like Money API - by DrMasik - 10-07-2016, 07:10 PM
RE: Vault-like Money API - by PureTryOut - 10-25-2016, 08:19 PM
RE: Vault-like Money API - by Zee1234 - 12-08-2016, 08:11 AM



Users browsing this thread: 11 Guest(s)