Skip to content

Commit 94e0f50

Browse files
committed
Move to gitlab
0 parents  commit 94e0f50

File tree

68 files changed

+3031
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3031
-0
lines changed

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
### MacOS
2+
.DS_Store/
3+
4+
### Intellij
5+
.idea/
6+
*.iml
7+
*.iws
8+
9+
### Eclipse
10+
.classpath
11+
.project
12+
.settings/
13+
14+
### VSCode
15+
.vscode/
16+
17+
### Gradle
18+
.gradle/
19+
build/
20+
21+
### Java
22+
*.class
23+
*.log
24+
hs_err_pid*

.gitlab-ci.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
image: java:8-jdk
2+
3+
stages:
4+
- build
5+
- deploy
6+
7+
before_script:
8+
- export GRADLE_USER_HOME=`pwd`/.gradle
9+
10+
cache:
11+
paths:
12+
- .gradle/wrapper
13+
- .gradle/caches
14+
15+
build:
16+
stage: build
17+
script:
18+
- ./gradlew build
19+
artifacts:
20+
paths:
21+
- build/libs/*.jar
22+
expire_in: 1 week
23+
only:
24+
- master
25+
26+
deploy:
27+
stage: deploy
28+
script:
29+
- ./gradlew bintrayUpload

LICENSE

+674
Large diffs are not rendered by default.

README.md

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Swampium
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.
11+
12+
## Build
13+
If you would like to compile it yourself, clone the project and ensure you have JDK 8.
14+
15+
After that, use `./gradlew build` (`gradlew build` for windows) to start your build.
16+
17+
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+
```
130+
131+
Now `SimpleChattingService` can be inject as an `ChattingService`

build.gradle.kts

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3+
import java.net.URI
4+
5+
group = "net.swamphut"
6+
version = "0.0.2-snapshot"
7+
8+
val kotlinVersion = "1.3.31"
9+
10+
11+
buildscript {
12+
repositories {
13+
jcenter()
14+
mavenCentral()
15+
}
16+
dependencies {
17+
classpath("com.github.jengelman.gradle.plugins:shadow:4.0.3")
18+
}
19+
}
20+
21+
plugins {
22+
java
23+
maven
24+
`maven-publish`
25+
kotlin("jvm") version "1.3.31"
26+
id("com.jfrog.bintray") version "1.8.4"
27+
}
28+
29+
apply(plugin = "maven-publish")
30+
apply(plugin = "com.github.johnrengelman.shadow")
31+
32+
java {
33+
sourceCompatibility = JavaVersion.VERSION_1_8
34+
targetCompatibility = JavaVersion.VERSION_1_8
35+
}
36+
37+
val compileKotlin by tasks.getting(KotlinCompile::class) {
38+
kotlinOptions.jvmTarget = "1.8"
39+
kotlinOptions.freeCompilerArgs = listOf("-Xjvm-default=compatibility")
40+
}
41+
42+
repositories {
43+
mavenCentral()
44+
maven { url = URI.create("https://hub.spigotmc.org/nexus/content/repositories/snapshots") }
45+
maven { url = URI.create("https://oss.sonatype.org/content/repositories/snapshots/") }
46+
maven { url = URI.create("https://dl.bintray.com/setako/swamphut") }
47+
maven { url = URI.create("https://repo.codemc.org/repository/maven-public") }
48+
}
49+
50+
dependencies {
51+
listOf(
52+
"stdlib-jdk8",
53+
"reflect"
54+
// "script-util",
55+
// "script-runtime",
56+
// "compiler-embeddable",
57+
// "scripting-compiler"
58+
).forEach { compile(kotlin(it, kotlinVersion)) }
59+
60+
implementation("org.bstats:bstats-bukkit:1.4")
61+
62+
compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1")
63+
compile("io.reactivex.rxjava2:rxjava:2.2.0")
64+
compile("org.reflections:reflections:0.9.11")
65+
66+
compile("com.google.code.gson:gson:2.8.5")
67+
compile("org.yaml:snakeyaml:1.24")
68+
69+
compileOnly("org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT")
70+
}
71+
72+
val sourcesJar by tasks.registering(Jar::class) {
73+
classifier = "sources"
74+
from(sourceSets.main.get().allSource)
75+
}
76+
77+
val shadowJar: ShadowJar by tasks
78+
shadowJar.apply {
79+
baseName = project.name
80+
relocate("org.bstats", "net.swamphut.swampium.core")
81+
}
82+
83+
tasks.getByName("build").dependsOn(shadowJar)
84+
85+
86+
tasks.register<Copy>("deployPlugin") {
87+
dependsOn(shadowJar)
88+
val pluginDeployPath = System.getenv("PLUGIN_DEPLOY_PATH")
89+
90+
if (pluginDeployPath != null) {
91+
from(shadowJar)
92+
into(pluginDeployPath)
93+
}
94+
}
95+
val deployPlugin = tasks.getByName("deployPlugin")
96+
tasks.getByName("build").dependsOn(deployPlugin)
97+
98+
publishing {
99+
publications {
100+
create<MavenPublication>("maven") {
101+
from(components["java"])
102+
artifact(sourcesJar.get())
103+
artifact(shadowJar)
104+
105+
groupId = group.toString()
106+
artifactId = project.name
107+
version = version
108+
}
109+
}
110+
}
111+
112+
bintray {
113+
user = System.getenv("BINTRAY_USER")
114+
key = System.getenv("BINTRAY_KEY")
115+
setPublications("maven")
116+
publish = true
117+
override = true
118+
pkg.apply {
119+
repo = "swamphut"
120+
name = project.name
121+
setLicenses("GPL-3.0")
122+
vcsUrl = "https://github.com/SwampHut/Swampium.git"
123+
}
124+
}

gradle/wrapper/gradle-wrapper.jar

54.4 KB
Binary file not shown.
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Sun Dec 30 15:34:57 HKT 2018
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip

0 commit comments

Comments
 (0)