Compare commits

...

10 Commits

12 changed files with 157 additions and 64 deletions

2
.gitignore vendored
View File

@ -45,4 +45,4 @@ out/
# Linux temp files
*~
!gradle/wrapper/gradle-wrapper.jar
*.bat

41
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,41 @@
pipeline {
agent any
stages {
stage('Gradle') {
steps {
withCredentials([usernamePassword(credentialsId: 'alttd-publish-user', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh '''
chmod +x gradlew
./gradlew build -PalttdDevPublishUser=$USERNAME -PalttdDevPublishPass=$PASSWORD
'''
}
}
}
stage('Publish to Maven') {
steps {
withCredentials([usernamePassword(credentialsId: 'alttd-publish-user', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh '''
chmod +x gradlew
./gradlew publish -PalttdDevPublishUser=$USERNAME -PalttdDevPublishPass=$PASSWORD
'''
}
}
}
stage('Archive') {
steps {
archiveArtifacts artifacts: 'build/libs/', followSymlinks: false
}
}
stage('discord') {
when {
anyOf {
branch 'main'
branch 'master'
}
}
steps {
discordSend description: "Build: ${BUILD_NUMBER}", showChangeset: true, result: currentBuild.currentResult, title: currentBuild.fullProjectName, webhookURL: env.discordwebhook
}
}
}
}

55
README.md Normal file
View File

@ -0,0 +1,55 @@
# DataLockLib
___
## **Developer API**
Repository
```kotlin
repositories {
maven {
url = uri("https://repo.destro.xyz/snapshots")
}
}
dependencies {
compileOnly("com.alttd.datalock:api:1.0.0-SNAPSHOT")
}
```
## **Usage**
An instance of DataLock can be obtained by using this code.
```
DataLockAPI datalock = DataLockAPI.get();
```
## **Downloads**
There are currently no downloads provided. Jars can only be obtained by building from source.
## **Building**
#### Initial setup
Clone the repo using `git clone https://github.com/Altitude-Devs/DataLockLib.git`.
#### Building
Use the command `./gradlew build --stacktrace` in the project root directory.
The compiled jar will be placed in directory `/plugin/build/libs/`.
## **Commands**
| Command | Description | Permission |
|---------------------|-----------------------------|-----------------------------|
## **Permissions**
| Permission | Description |
|-----------------------------|------------------------------------------------|
## **Configuration**
```yaml
```
## **Support**
## **License**
[LICENSE](LICENSE)

View File

@ -3,11 +3,13 @@ plugins {
}
dependencies {
compileOnly("com.alttd:Galaxy-API:1.19.2-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.21.6-R0.1-SNAPSHOT")
}
tasks {
jar {
enabled = true
}
}
publishing {
@ -19,9 +21,12 @@ publishing {
repositories{
maven {
name = "maven"
url = uri("https://repo.destro.xyz/snapshots")
credentials(PasswordCredentials::class)
name = "nexus"
url = uri("https://repo.alttd.com/repository/alttd-snapshot/")
credentials {
username = project.property("alttdDevPublishUser") as String
password = project.property("alttdDevPublishPass") as String
}
}
}
}
}

View File

@ -1,13 +1,12 @@
package com.alttd.datalock;
import com.alttd.datalock.ResponseType;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class LockResponseEvent extends Event {
private final HandlerList handlers = new HandlerList();
private static final HandlerList handlers = new HandlerList();
private final String channel;
private final ResponseType responseType;
private final String data;
@ -37,6 +36,11 @@ public class LockResponseEvent extends Event {
return result;
}
public static @NotNull HandlerList getHandlerList() {
return handlers;
}
@Override
public @NotNull HandlerList getHandlers() {
return handlers;
}

View File

@ -1,12 +1,11 @@
plugins {
id("java")
id("com.github.johnrengelman.shadow") version "7.1.0"
id("maven-publish")
}
allprojects {
group = "com.alttd.datalock"
version = "1.0.0-SNAPSHOT"
version = "1.2.0-SNAPSHOT"
description = "Altitude DataLock Library."
}
@ -16,14 +15,14 @@ subprojects {
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
languageVersion.set(JavaLanguageVersion.of(21))
}
}
}
tasks {
jar {
enabled = false
enabled = true
}
}
@ -36,13 +35,16 @@ publishing {
repositories{
maven {
name = "maven"
url = uri("https://repo.destro.xyz/snapshots")
credentials(PasswordCredentials::class)
name = "nexus"
url = uri("https://repo.alttd.com/repository/alttd-snapshot/")
credentials {
username = project.property("alttdDevPublishUser") as String
password = project.property("alttdDevPublishPass") as String
}
}
}
}
dependencies {
compileOnly("com.alttd:Galaxy-API:1.19.2-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.21.6-R0.1-SNAPSHOT")
}

View File

@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -4,48 +4,19 @@ import java.net.URL
plugins {
`maven-publish`
id("com.github.johnrengelman.shadow")
id("net.minecrell.plugin-yml.bukkit") version "0.5.1"
id("xyz.jpenilla.run-paper") version "1.0.6"
}
dependencies {
implementation(project(":api")) // API
compileOnly("com.alttd:Galaxy-API:1.19.2-R0.1-SNAPSHOT") // Galaxy
compileOnly("io.papermc.paper:paper-api:1.21.6-R0.1-SNAPSHOT")
}
tasks {
jar {
enabled = false
}
shadowJar {
archiveFileName.set("${rootProject.name}.jar")
}
build {
dependsOn(shadowJar)
}
runServer {
val dir = File(System.getProperty("user.home") + "/share/devserver/")
if (!dir.parentFile.exists()) {
dir.parentFile.mkdirs()
}
runDirectory.set(dir)
val fileName = "/galaxy.jar"
val file = File(dir.path + fileName)
if (!file.parentFile.exists()) {
file.parentFile.mkdirs()
}
if (!file.exists()) {
download("https://repo.destro.xyz/snapshots/com/alttd/Galaxy-Server/Galaxy-paperclip-1.19.2-R0.1-SNAPSHOT-reobf.jar", file)
}
serverJar(file)
minecraftVersion("1.19.2")
enabled = true
}
}
@ -54,7 +25,7 @@ bukkit {
name = rootProject.name
main = "$group.${rootProject.name}"
version = gitCommit()
apiVersion = "1.19"
apiVersion = "1.21"
authors = listOf("Teriuihi")
}
@ -74,4 +45,4 @@ fun download(link: String, path: File) {
input.copyTo(output)
}
}
}
}

View File

@ -6,6 +6,7 @@ import org.bukkit.scheduler.BukkitRunnable;
import java.util.HashSet;
import java.util.UUID;
import java.util.logging.Level;
public class DataLock implements DataLockAPI {
@ -13,14 +14,15 @@ public class DataLock implements DataLockAPI {
public static DataLock getInstance() {
if (instance == null)
instance = new DataLock();
new DataLock();
return instance;
}
private final PluginMessageListener pluginMessageListener;
private final DataLockLib plugin;
private final Idempotency activeRequests;
protected DataLock() {
private DataLock() {
instance = this;
DataLockAPI.Provider.register(this);
pluginMessageListener = new PluginMessageListener();
plugin = DataLockLib.getInstance();
@ -33,6 +35,7 @@ public class DataLock implements DataLockAPI {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(requestType.subChannel);
out.writeUTF(idempotencyData.data());
out.writeUTF(idempotencyData.idempotencyToken().toString());
plugin.getServer().sendPluginMessage(plugin, idempotencyData.channel(), out.toByteArray());
}
@ -44,6 +47,7 @@ public class DataLock implements DataLockAPI {
@Override
public synchronized void registerChannel(String channel) {
DataLockLib.getInstance().getLogger().log(Level.INFO, "Registering plugin channel on [" + channel + "]");
activeChannels.add(channel);
plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, channel);
plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, channel, pluginMessageListener);
@ -72,8 +76,8 @@ public class DataLock implements DataLockAPI {
@Override
public void run() {
for (RequestType requestType : RequestType.values()) {
for (IdempotencyData next : activeRequests.getIdempotencyData(requestType)) {
sendPluginMessage(requestType, next);
for (IdempotencyData idempotencyData : activeRequests.getIdempotencyData(requestType)) {
sendPluginMessage(requestType, idempotencyData);
}
}
}

View File

@ -18,7 +18,7 @@ public class DataLockLib extends JavaPlugin {
@Override
public void onEnable() {
dataLock = new DataLock();
dataLock = DataLock.getInstance();
}
@Override

View File

@ -7,6 +7,7 @@ import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
import java.util.logging.Level;
class PluginMessageListener implements org.bukkit.plugin.messaging.PluginMessageListener {
@ -23,43 +24,45 @@ class PluginMessageListener implements org.bukkit.plugin.messaging.PluginMessage
return;
}
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
String data = in.readUTF();
String subChannel = in.readUTF();
boolean result = in.readBoolean();
String data = in.readUTF();
UUID idempotency = UUID.fromString(in.readUTF());
IdempotencyData idempotencyData = new IdempotencyData(channel, data, idempotency);
DataLockLib.getInstance().getLogger().log(Level.INFO, "Received plugin message on [" + subChannel + "] about data: [" + data + "]");
new BukkitRunnable() {
@Override
public void run() {
switch (in.readUTF()) {
switch (subChannel) {
case "try-lock-result" -> {
if (!alreadyReceived.putIdempotencyData(RequestType.TRY_LOCK, idempotencyData))
return;
DataLock.getInstance().removeActiveRequest(RequestType.TRY_LOCK, idempotencyData);
new LockResponseEvent(true, channel, ResponseType.TRY_LOCK_RESULT, data, result);
new LockResponseEvent(true, channel, ResponseType.TRY_LOCK_RESULT, data, result).callEvent();
}
case "queue-lock-failed" -> {
if (!alreadyReceived.putIdempotencyData(RequestType.TRY_LOCK, idempotencyData))
return;
DataLock.getInstance().removeActiveRequest(RequestType.TRY_LOCK, idempotencyData);
new LockResponseEvent(true, channel, ResponseType.QUEUE_LOCK_FAILED, data, result);
new LockResponseEvent(true, channel, ResponseType.QUEUE_LOCK_FAILED, data, result).callEvent();
}
case "try-unlock-result" -> {
if (!alreadyReceived.putIdempotencyData(RequestType.TRY_UNLOCK, idempotencyData))
return;
DataLock.getInstance().removeActiveRequest(RequestType.TRY_UNLOCK, idempotencyData);
new LockResponseEvent(true, channel, ResponseType.TRY_UNLOCK_RESULT, data, result);
new LockResponseEvent(true, channel, ResponseType.TRY_UNLOCK_RESULT, data, result).callEvent();
}
case "locked-queue-lock" -> {
if (!alreadyReceived.putIdempotencyData(RequestType.TRY_LOCK, idempotencyData))
return;
DataLock.getInstance().removeActiveRequest(RequestType.TRY_LOCK, idempotencyData);
new LockResponseEvent(true, channel, ResponseType.LOCKED_QUEUE_LOCK, data, result);
new LockResponseEvent(true, channel, ResponseType.LOCKED_QUEUE_LOCK, data, result).callEvent();
}
case "check-lock-result" -> {
if (!alreadyReceived.putIdempotencyData(RequestType.CHECK_LOCK, idempotencyData))
return;
DataLock.getInstance().removeActiveRequest(RequestType.CHECK_LOCK, idempotencyData);
new LockResponseEvent(true, channel, ResponseType.CHECK_LOCK_RESULT, data, result);
new LockResponseEvent(true, channel, ResponseType.CHECK_LOCK_RESULT, data, result).callEvent();
}
}
}

View File

@ -1,12 +1,18 @@
rootProject.name = "DataLockLib"
val nexusUser = providers.gradleProperty("alttdDevPublishUser").get()
val nexusPass = providers.gradleProperty("alttdDevPublishPass").get()
include(":api")
include(":plugin")
dependencyResolutionManagement {
repositories {
mavenCentral()
maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy
maven {
name = "papermc"
url = uri("https://repo.papermc.io/repository/maven-public/")
}
}
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
}