Compare commits

..

No commits in common. "5ced572237661214ff9a777d4d217848a8d4e3a6" and "02e10104fc281596d526edf9393942b8b55fd13c" have entirely different histories.

12 changed files with 64 additions and 157 deletions

2
.gitignore vendored
View File

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

41
Jenkinsfile vendored
View File

@ -1,41 +0,0 @@
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
}
}
}
}

View File

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

View File

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

View File

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

View File

@ -4,19 +4,48 @@ 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("io.papermc.paper:paper-api:1.21.6-R0.1-SNAPSHOT")
compileOnly("com.alttd:Galaxy-API:1.19.2-R0.1-SNAPSHOT") // Galaxy
}
tasks {
jar {
enabled = true
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")
}
}
@ -25,7 +54,7 @@ bukkit {
name = rootProject.name
main = "$group.${rootProject.name}"
version = gitCommit()
apiVersion = "1.21"
apiVersion = "1.19"
authors = listOf("Teriuihi")
}
@ -45,4 +74,4 @@ fun download(link: String, path: File) {
input.copyTo(output)
}
}
}
}

View File

@ -6,7 +6,6 @@ import org.bukkit.scheduler.BukkitRunnable;
import java.util.HashSet;
import java.util.UUID;
import java.util.logging.Level;
public class DataLock implements DataLockAPI {
@ -14,15 +13,14 @@ public class DataLock implements DataLockAPI {
public static DataLock getInstance() {
if (instance == null)
new DataLock();
instance = new DataLock();
return instance;
}
private final PluginMessageListener pluginMessageListener;
private final DataLockLib plugin;
private final Idempotency activeRequests;
private DataLock() {
instance = this;
protected DataLock() {
DataLockAPI.Provider.register(this);
pluginMessageListener = new PluginMessageListener();
plugin = DataLockLib.getInstance();
@ -35,7 +33,6 @@ 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());
}
@ -47,7 +44,6 @@ 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);
@ -76,8 +72,8 @@ public class DataLock implements DataLockAPI {
@Override
public void run() {
for (RequestType requestType : RequestType.values()) {
for (IdempotencyData idempotencyData : activeRequests.getIdempotencyData(requestType)) {
sendPluginMessage(requestType, idempotencyData);
for (IdempotencyData next : activeRequests.getIdempotencyData(requestType)) {
sendPluginMessage(requestType, next);
}
}
}

View File

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

View File

@ -1,12 +1,13 @@
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 static final HandlerList handlers = new HandlerList();
private final HandlerList handlers = new HandlerList();
private final String channel;
private final ResponseType responseType;
private final String data;
@ -36,11 +37,6 @@ public class LockResponseEvent extends Event {
return result;
}
public static @NotNull HandlerList getHandlerList() {
return handlers;
}
@Override
public @NotNull HandlerList getHandlers() {
return handlers;
}

View File

@ -7,7 +7,6 @@ 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 {
@ -24,45 +23,43 @@ class PluginMessageListener implements org.bukkit.plugin.messaging.PluginMessage
return;
}
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
String subChannel = in.readUTF();
boolean result = in.readBoolean();
String data = in.readUTF();
boolean result = in.readBoolean();
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 (subChannel) {
switch (in.readUTF()) {
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).callEvent();
new LockResponseEvent(true, channel, ResponseType.TRY_LOCK_RESULT, data, result);
}
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).callEvent();
new LockResponseEvent(true, channel, ResponseType.QUEUE_LOCK_FAILED, data, result);
}
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).callEvent();
new LockResponseEvent(true, channel, ResponseType.TRY_UNLOCK_RESULT, data, result);
}
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).callEvent();
new LockResponseEvent(true, channel, ResponseType.LOCKED_QUEUE_LOCK, data, result);
}
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).callEvent();
new LockResponseEvent(true, channel, ResponseType.CHECK_LOCK_RESULT, data, result);
}
}
}

View File

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