[Solved] Fully separating the Treasury API from platforms #130
Replies: 3 comments 11 replies
This comment has been hidden.
This comment has been hidden.
-
We're treading into territory which will become very annoying for us to deal with. I'm willing to let go of the prospect that is BungeeeCord support. Even Velocity, if developing Treasury for it proves to be too difficult, but obviously I am less bothered by dropping Bungee. This is because the overwhelming majority of what Treasury's APIs will be used for, will take place on servers (Bukkit/Sponge) and not proxies. There are few cases where Treasury would actually be useful on a proxy. This is of course my opinion and I could be completely wrong. With Treasury I'm focusing my efforts on trying to make the economy API's usage more widespread, and later on I plan on adding Chat & Permissions APIs, still targeting Bukkit servers. Now .. regarding the service provider situation on the proxies. I do not feel that the events code should be in the core at all, rather, platform-specific. If there are differences between platforms on how they handle events, 'so be it' I think. I don't want to write workarounds and hacks to get things working similar to Bukkit, even though such a result would be ideal. What I feel we should do, is take a look at the limitations of each platform. Consider what we need to do to combat these, or if we have to sacrifice either some features e.g. events or even the entire support for the platform, then we need to discuss this too. I was not expecting the events systems to be so different on these other platforms, I have never had any issues with Bukkit's design so it is quite frustrating to observe these differences. |
Beta Was this translation helpful? Give feedback.
-
Current conclusion:
Code ideas wanted. What I'm thinking about the service provider is something like bukkit's but simplified. And for the event handler - something like velocity's but again kinda simplified. I'm all ears. |
Beta Was this translation helpful? Give feedback.
-
As I've started implementing BungeeCord platform I've discovered some problems.
First, events are handled differently in different platforms. Bukkit has a hierarchy of calling events e.g. in the Treasury Economy API we have
AccountTransactionEvent
,PlayerAccountTransactionEvent
andNonPlayerAccountTransactionEvent
. ThePlayerAccountTransactionEvent
andNonPlayerAccountTransactionEvent
extend theAccountTransactionEvent
, which would mean that if you call eitherPlayerAccountTransactionEvent
orNonPlayerAccountTransactionEvent
it would result in calling theAccountTransactionEvent
.BungeeCord does not have such hierarchy, that's why I wrote this utility for economy implementations in order for the events to act how Bukkit events act, which from my standpoint is a hack.
Another problem is that we aim for Treasury's methods to be asynchronous ; both Bukkit and BungeeCord support calling them asynchronously, but the difference is again huge - in Bukkit you have to specify by a
boolean
value that this event is asynchronous, whilst BungeeCord which is not situated around 1 thread - you can call them on any thread you want. Even bigger problem is if you want to run asynchronous tasks in an event listener. BungeeCord supports this using theAsyncEvent
, but that implementation has been called out multiple times with race conditions and whatnot, whilst Bukkit has no support for that at all! There's no way on Bukkit to block event execution until an asynchronous task finishes!The solution to this is to create our own event handler implementation. Not just for Treasury Economy API, but for Treasury API as a whole. I really like the approach Velocity took with events in Velocity 3.0.0, so in my opinion we should borrow the way they did it.
The other big problem is retrieving the provider interfaces. As of writing this, Treasury has only 1 API - the Treasury Economy API with its own
EconomyProvider
. For Bukkit it's easy - you throw in a registration in the service provider for thatEconomyProvider
and you're good to go. For other platforms such as BungeeCord/Velocity, there's no such thing as a "service provider". So I wrote this, which in my standpoint is bad. It can be improved hell lot.The solution to not all implementations having a service provider is again, simple, write our own in Treasury API. But here's the con in my opinion - it has to be all
static
, because there's no other way for economy consumers to use that. The thing is that, per standards,static
shall only be used for either a) utilities or b) registries. A service provider is none of these.I want opinions on how should we proceed. Thanks for taking the time to read this :).
When we get to the point of "we should do that" I'm going to create an issue from this discussion tab and we will get to work :).
Beta Was this translation helpful? Give feedback.
All reactions