|
1 |
| -# Swampium |
| 1 | +# Reactant |
2 | 2 |
|
3 |
| -Swampium core is a spigot plugin framework which provide a better way for developing spigot plugins. |
4 |
| - |
5 |
| -Including: |
6 |
| - - Dependency injection |
7 |
| - - Service instance managing |
8 |
| - - Initialize order resolving |
9 |
| - - Defined common service interface (for example: economy, faction and configs) |
10 |
| - - and the utils that you need. |
| 3 | +Reactant core is a spigot plugin framework which provide a better way for developing spigot plugins. |
11 | 4 |
|
12 | 5 | ## Build
|
13 | 6 | If you would like to compile it yourself, clone the project and ensure you have JDK 8.
|
14 | 7 |
|
15 | 8 | After that, use `./gradlew build` (`gradlew build` for windows) to start your build.
|
16 | 9 |
|
17 | 10 | You can find the compiled jars in `./build/libs`.
|
18 |
| -Use `swampium-*-all.jar` which including the dependencies if you would like to load as spigot plugin. |
19 |
| - |
20 |
| -## Quick start |
21 |
| -### Add as dependency |
22 |
| -For gradle: |
23 |
| -```groovy |
24 |
| -repositories { |
25 |
| - maven { |
26 |
| - url https://dl.bintray.com/setako/swamphut |
27 |
| - } |
28 |
| -} |
29 |
| -
|
30 |
| -dependencies { |
31 |
| - compileOnly "net.swamphut:swampium:0.0.2-rc" |
32 |
| -} |
33 |
| -``` |
34 |
| -### Modify your plugin class |
35 |
| -Firstly, create your plugin just like a normal spigot plugin, and add Swampium as depend in your `plugin.yml`. |
36 |
| -```yaml |
37 |
| -depend: |
38 |
| - - Swampium |
39 |
| -``` |
40 |
| -
|
41 |
| -Add a annotation `@SwampiumPlugin` on your plugin class, and tell swampium where to find your services. |
42 |
| -The following config will match `net.swamphut.demo.*`. |
43 |
| -```java |
44 |
| -@SwampiumPlugin(servicePackages = "net.swamphut.demo") |
45 |
| -public class DemoPlugin extends JavaPlugin { |
46 |
| - |
47 |
| -} |
48 |
| -``` |
49 |
| -If your services are in multiple packages: |
50 |
| -```java |
51 |
| -@SwampiumPlugin(servicePackages = {"com.otherpackage.test.demo", "net.swamphut.demo"}) |
52 |
| -``` |
53 |
| - |
54 |
| -### Your first service |
55 |
| -We have defined a testing service interface called `HelloService`, |
56 |
| -let's use it to say hello when our service start. |
57 |
| - |
58 |
| - |
59 |
| -```java |
60 |
| -@SwObject |
61 |
| -@ServiceProvider |
62 |
| -public class DemoHelloService implements LifeCycleHook { |
63 |
| -
|
64 |
| - @Inject |
65 |
| - private HelloService helloService; |
66 |
| -
|
67 |
| - @Override |
68 |
| - public void init() { |
69 |
| - helloService.sayHello("demo"); |
70 |
| - } |
71 |
| -} |
72 |
| -``` |
73 |
| - |
74 |
| -### Define a service interface |
75 |
| -Although swampium have define the most common features service interfaces, |
76 |
| -but you can define a new service interface as you wish. |
77 |
| -Don't forgot to create an issues if you found that we are missing an important interface. |
78 |
| - |
79 |
| -Now we are going to define a simple messaging interface. |
80 |
| -Before we start working on it, we have to clearly understand what function should a messaging service have. |
81 |
| -As an example, we will just include some of them: |
82 |
| - - sendMessage(Player sender, Player receiver, String message) |
83 |
| - - getMessageSentHistory(Player sender); |
84 |
| - |
85 |
| -Then, we have to analyze should it be an async method, if it should, |
86 |
| -then let's define its return type as `Observable`/`Single`/`Completable` |
87 |
| - |
88 |
| -```java |
89 |
| -public interface ChattingService{ |
90 |
| - Completable sendMessage(Player sender, Player receiver, String message); |
91 |
| - Single<List<String>> getMessageSentHistory(Player sender); |
92 |
| - //more definition... |
93 |
| -} |
94 |
| -``` |
95 |
| - |
96 |
| -After we defined the `ChattingService` interface, |
97 |
| -all service which have implements and providing it will be consider as an available `ChattingService`. |
98 |
| - |
99 |
| -### Implement an service provider |
100 |
| -To implement an service interface, we have to use annotation `@ServiceProvider`, |
101 |
| -and declare which classes you are providing. |
102 |
| - |
103 |
| -Assume that you have completed the above task, and defined a `ChattingService` interface, |
104 |
| -the tutorial is not going to show how to save the data, so we will not save the message here. |
105 |
| -```java |
106 |
| -@SwObject |
107 |
| -@ServiceProvider(provide = ChattingService.class) |
108 |
| -public class SimpleChattingService implements ChattingService{ |
109 |
| - |
110 |
| - //Since we are not going to introduce data saving here |
111 |
| - private Map<Player, List<String>> sentHistories = new HashMap<>(); |
112 |
| - |
113 |
| - @Override |
114 |
| - public Completable sendMessage(Player sender, Player receiver, String message){ |
115 |
| - return Completable.fromAction(() -> { |
116 |
| - receiver.sendMessage("[" + sender + "]" + message); |
117 |
| - if (!sentHistories.containsKey(sender)){ |
118 |
| - sentHistories.put(sender,new ArrayList<>()); |
119 |
| - } |
120 |
| - sentHistories.get(sender).add(message); |
121 |
| - }); |
122 |
| - } |
123 |
| - |
124 |
| - @Override |
125 |
| - public Single<List<String>> getMessageSentHistory(Player sender){ |
126 |
| - return Single.fromCallable(() -> sentHistories.getOrDefault(sender, new ArrayList<>())); |
127 |
| - } |
128 |
| -} |
129 |
| -``` |
| 11 | +Use `Reactant-*-all.jar` which including the dependencies if you would like to load as spigot plugin. |
130 | 12 |
|
131 |
| -Now `SimpleChattingService` can be inject as an `ChattingService` |
| 13 | +## Where should I start? |
| 14 | +[Click here to check our cookbook guide](https://reactant.gitlab.io/cookbook-dev/) |
0 commit comments