.
This commit is contained in:
parent
e4fd6a8c5f
commit
d3e20606d9
10 changed files with 130 additions and 37 deletions
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
|
|
@ -11,6 +11,7 @@
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
<option value="$PROJECT_DIR$/core-bukkit-api" />
|
<option value="$PROJECT_DIR$/core-bukkit-api" />
|
||||||
<option value="$PROJECT_DIR$/core-bukkit-impl" />
|
<option value="$PROJECT_DIR$/core-bukkit-impl" />
|
||||||
|
<option value="$PROJECT_DIR$/core-lib" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
|
|
|
||||||
15
README.md
15
README.md
|
|
@ -17,14 +17,15 @@ access the mongo-db web interface at http://localhost:8081; username `a`, passwo
|
||||||
|
|
||||||
## modules
|
## modules
|
||||||
|
|
||||||
### APIs
|
### core-lib
|
||||||
|
|
||||||
* core-api contains api for all java development
|
core-lib is a stateless java util library
|
||||||
* core-bukkit-api contains api for bukkit development
|
|
||||||
* depends on core-api
|
### core-bukkit-api
|
||||||
|
|
||||||
|
core-bukkit-api is stateful and contains api for bukkit development
|
||||||
|
* depends on core-lib
|
||||||
|
|
||||||
### implementations
|
### implementations
|
||||||
|
|
||||||
the `-impl` suffix indicates that this module implements the API with the same prefix.
|
core-bukkit-impl is a spigot plugin. It shades and implements core-bukkit-api
|
||||||
So `core-impl` implements `core-api`.
|
|
||||||
* core-bukkit-impl is a spigot plugin. It shades core-impl.
|
|
||||||
|
|
@ -29,11 +29,7 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation(platform("org.junit:junit-bom:5.10.0"))
|
//api("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT")
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
|
||||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
|
||||||
|
|
||||||
api("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT")
|
|
||||||
|
|
||||||
// Source: https://mvnrepository.com/artifact/io.nats/jnats
|
// Source: https://mvnrepository.com/artifact/io.nats/jnats
|
||||||
implementation("io.nats:jnats:2.25.2")
|
implementation("io.nats:jnats:2.25.2")
|
||||||
|
|
@ -53,8 +49,4 @@ publishing {
|
||||||
from(components["java"])
|
from(components["java"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
tasks.test {
|
|
||||||
useJUnitPlatform()
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
package de.kentoj.scrow.bukkit.message;
|
|
||||||
|
|
||||||
import io.nats.client.Message;
|
|
||||||
import io.nats.client.Subscription;
|
|
||||||
import org.bson.Document;
|
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public interface NatsDocumentRepository {
|
|
||||||
|
|
||||||
void publish(String topic, Document document);
|
|
||||||
|
|
||||||
Subscription subscribe(String topic, Consumer<Document> document);
|
|
||||||
|
|
||||||
Message request(String topic, Document document);
|
|
||||||
}
|
|
||||||
|
|
@ -3,6 +3,7 @@ package de.kentoj.scrow.bukkit;
|
||||||
import de.kentoj.scrow.bukkit.crown.command.CrownCommand;
|
import de.kentoj.scrow.bukkit.crown.command.CrownCommand;
|
||||||
import de.kentoj.scrow.bukkit.economy.CoinsCommand;
|
import de.kentoj.scrow.bukkit.economy.CoinsCommand;
|
||||||
import de.kentoj.scrow.bukkit.friends.command.FriendCommand;
|
import de.kentoj.scrow.bukkit.friends.command.FriendCommand;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
|
@ -26,7 +27,8 @@ public class CoreImplPlugin extends JavaPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerServer() {
|
private void registerServer() {
|
||||||
ScrowAPI.getServerManager().updateState(System.getenv("SERVER_HANDLE"), "UP");
|
ScrowAPI.getServerManager().updateState(System.getenv("SERVER_HANDLE"), "UP")
|
||||||
|
.subscribe(__ -> Bukkit.getLogger().info("registered self"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -5,20 +5,21 @@ import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||||
import de.kentoj.scrow.bukkit.ServerManager;
|
import de.kentoj.scrow.bukkit.ServerManager;
|
||||||
import io.nats.client.Connection;
|
import io.nats.client.Connection;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.bson.Document;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class CrownServerManager implements ServerManager {
|
public class CrownServerManager implements ServerManager {
|
||||||
|
|
||||||
private final Connection nats;
|
private final
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<@NotNull String> deployServer(String template) {
|
public Mono<@NotNull String> deployServer(String template) {
|
||||||
return Mono.fromFuture(nats.request("crown.deploy-server", template.getBytes()))
|
return Mono.fromFuture(nats.request("crown.deploy-server", new Document()
|
||||||
|
.append("template", template))
|
||||||
.map(msg -> new String(msg.getData()));
|
.map(msg -> new String(msg.getData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
50
core-lib/build.gradle.kts
Normal file
50
core-lib/build.gradle.kts
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
val scrowToken = providers.gradleProperty("scrowMavenToken")
|
||||||
|
.orElse(providers.environmentVariable("SCROW_MAVEN_TOKEN")).get()
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("java")
|
||||||
|
id("java-library")
|
||||||
|
id("maven-publish")
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "de.kentoj.scrow"
|
||||||
|
version = "0.1"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// https://mvnrepository.com/artifact/io.nats/jnats
|
||||||
|
implementation("io.nats:jnats:2.25.2")
|
||||||
|
api("io.nats:jnats:2.25.2")
|
||||||
|
|
||||||
|
// https://mvnrepository.com/artifact/org.mongodb/bson
|
||||||
|
implementation("org.mongodb:bson:5.8.0")
|
||||||
|
api("org.mongodb:bson:5.8.0")
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
create<MavenPublication>("CoreLib") {
|
||||||
|
groupId = project.group.toString()
|
||||||
|
artifactId = project.name
|
||||||
|
version = project.version.toString()
|
||||||
|
from(components["java"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
name = "scrow"
|
||||||
|
url = uri("http://forge.kentoj.de/api/packages/scrow/maven")
|
||||||
|
isAllowInsecureProtocol = true
|
||||||
|
credentials(HttpHeaderCredentials::class) {
|
||||||
|
name = "Authorization"
|
||||||
|
value = "token $scrowToken"
|
||||||
|
}
|
||||||
|
authentication {
|
||||||
|
create<HttpHeaderAuthentication>("header")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package de.kentoj.scrowlib;
|
||||||
|
|
||||||
|
import io.nats.client.Message;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.bson.Document;
|
||||||
|
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
public class DocumentRepository {
|
||||||
|
|
||||||
|
public static Document fromMessage(Message message) {
|
||||||
|
return Document.parse(new String(message.getData()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] toBytes(Document document) {
|
||||||
|
return document.toJson().getBytes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package de.kentoj.scrowlib;
|
||||||
|
|
||||||
|
import io.nats.client.Connection;
|
||||||
|
import io.nats.client.Dispatcher;
|
||||||
|
import io.nats.client.Message;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
public class NatsRepository {
|
||||||
|
|
||||||
|
private final Connection nats;
|
||||||
|
|
||||||
|
private final Dispatcher dispatcher;
|
||||||
|
|
||||||
|
public NatsRepository(Connection nats) {
|
||||||
|
this.nats = nats;
|
||||||
|
this.dispatcher = nats.createDispatcher();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mono<@NotNull Void> publish(String subject, byte[] data) {
|
||||||
|
return Mono.fromRunnable(() -> nats.publish(subject, data));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Flux<@NotNull Message> subscribe(String subject) {
|
||||||
|
return Flux.create(sink -> {
|
||||||
|
var handler = dispatcher.subscribe(subject, msg -> {
|
||||||
|
try {
|
||||||
|
sink.next(msg);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
sink.error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sink.onCancel(handler::unsubscribe);
|
||||||
|
sink.onDispose(handler::unsubscribe);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mono<@NotNull Message> request(String subject, byte[] data) {
|
||||||
|
return Mono.fromFuture(nats.request(subject, data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,4 +8,5 @@ plugins {
|
||||||
}
|
}
|
||||||
rootProject.name = "core"
|
rootProject.name = "core"
|
||||||
include("core-bukkit-api")
|
include("core-bukkit-api")
|
||||||
include("core-bukkit-impl")
|
include("core-bukkit-impl")
|
||||||
|
include("core-lib")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue