1
1
# Developer notes
2
2
3
- This document is for developers who want to contribute to this project.
3
+ ## High-level API
4
4
5
- ## API
6
-
7
- ### Summary
5
+ This section describes the simple API for developers of other plugins
6
+ without learning the concepts of Capital in depth.
8
7
9
- Capital supports different account classifications (known as [ schemas] ( #schema ) ).
10
- All operations involving player accounts require
11
- a config entry to select which account,
12
- e.g. if the user selects the Currency schema,
13
- you need a config that selects which currency to use.
8
+ Capital supports different ways of classifying accounts (known as [ schemas] ( #schema ) ),
9
+ e.g. multi-currency and multi-world.
14
10
The good news is, you don't have to consider each schema,
15
11
because Capital will figure it out.
16
- For each use case, just create an empty config entry to select the account:
12
+ You just need to leave a place in your config.yml
13
+ so that users who want to use other schemas can configure it:
17
14
18
15
``` yaml
19
- selector :
16
+ # Selects the Capital account to use.
17
+ # See https://github.com/SOF3/Capital/wiki/Schemas for more details.
18
+ selector : {}
20
19
` ` `
21
20
22
21
Users can fill this selector with options like ` allowed-currencies` etc.,
@@ -41,7 +40,7 @@ class Main extends PluginBase {
41
40
Then you can use the stored selector in the code
42
41
where you want to manipulate player money.
43
42
44
- # ### Take money from a player
43
+ # ## Take money from a player
45
44
46
45
Let's make a plugin called "ChatFee"
47
46
which charges the player $5 for every chat message :
@@ -57,7 +56,7 @@ public function onChat(PlayerChatEvent $event) : void {
57
56
$player,
58
57
$this->selector,
59
58
5,
60
- new LabelSet(["reason" => "chatting"]),
59
+ new LabelSet(["reason" => "chatting"]),
61
60
);
62
61
63
62
$player->sendMessage("You lost $5 for chatting");
@@ -94,7 +93,7 @@ However, remember that **you cannot cancel `$event` after the first `yield`**,
94
93
because transactions are asynchronous, which means that
95
94
the event already happened by that time and it is too late to cancel.
96
95
97
- # ### Giving money to a player
96
+ # ## Giving money to a player
98
97
99
98
Giving money is similar to taking money,
100
99
except `takeMoney` becomes `addMoney`.
@@ -126,7 +125,7 @@ public function onDamage(EntityDamageByEntityEvent $event) : void {
126
125
}
127
126
` ` `
128
127
129
- # ### Paying money from a player to another
128
+ # ## Paying money from a player to another
130
129
131
130
Paying money is like taking money from one player and giving to another,
132
131
but it only happens when *both* players have enough money and don't exceed limits.
@@ -188,7 +187,7 @@ It is also possible for player1 to pay less and player2 to pay more.
188
187
In that case, player1 only pays the amount to player2,
189
188
then the system account will pay the rest to player2.
190
189
191
- # ### Getting money for a player
190
+ # ## Getting money for a player
192
191
193
192
If you want to check whether the player has enough money for something,
194
193
use `takeMoney` as explained above and handle the error case.
@@ -200,6 +199,8 @@ Consider using InfoAPI to compute the messages
200
199
and let the user set their own messages.
201
200
See [InfoAPI readme](https://github.com/SOF3/InfoAPI) for usage guide.
202
201
202
+ # # API
203
+
203
204
# ## Async functions
204
205
205
206
Capital uses [await-generator](https://github.com/SOF3/await-generator),
0 commit comments