Files
blockandseek/build.gradle
2025-11-29 19:22:04 +03:00

152 lines
4.2 KiB
Groovy

import java.nio.ByteBuffer
import java.nio.ByteOrder
plugins {
id 'java'
id "com.gradleup.shadow" version "9.2.2"
}
group = 'hdvtdev'
version = '0.0.1-a'
repositories {
mavenCentral()
maven { url 'https://storehouse.okaeri.eu/repository/maven-releases/'}
maven { url 'https://repo.md-5.net/content/groups/public/' }
maven { url 'https://jitpack.io' }
maven {
name = "papermc-repo"
url = "https://repo.papermc.io/repository/maven-public/"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/"
}
maven { url 'https://libraries.minecraft.net/' }
}
def okaeriConfigsVersion = '5.0.13'
dependencies {
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
compileOnly group: 'me.libraryaddict.disguises', name: 'libsdisguises', version: '11.0.6'
compileOnly 'org.projectlombok:lombok:1.18.42'
annotationProcessor 'org.projectlombok:lombok:1.18.42'
implementation "eu.okaeri:okaeri-configs-validator-okaeri:$okaeriConfigsVersion"
implementation "eu.okaeri:okaeri-configs-yaml-bukkit:$okaeriConfigsVersion"
implementation "eu.okaeri:okaeri-configs-serdes-bukkit:$okaeriConfigsVersion"
implementation "eu.okaeri:okaeri-configs-serdes-commons:$okaeriConfigsVersion"
implementation "org.incendo:cloud-paper:2.0.0-beta.13"
}
def targetJavaVersion = 17
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
options.release.set(targetJavaVersion)
}
}
processResources {
def props = [version: version]
inputs.properties props
filteringCharset 'UTF-8'
filesMatching('plugin.yml') {
expand props
}
}
tasks.shadowJar {
archiveClassifier.set("")
relocate("eu.okaeri", "hdvtdev.blockandseek.libs.okaeri")
relocate("org.incendo", "hdvtdev.blockandseek.libs.cloud")
}
tasks.build {
dependsOn(tasks.shadowJar)
}
tasks.register('deploy') {
dependsOn build
doLast {
def targetDir = project.property('server.plugins.dir')
def rconHost = project.property('rcon.host')
def rconPort = project.property('rcon.port') as int
def rconPass = project.property('rcon.password')
def jarFile = tasks.jar.archiveFile.get().asFile
if (!file(targetDir).exists()) {
println "Err folder not found : $targetDir"
return
}
copy {
from jarFile
into targetDir
}
try {
sendRconCommand(rconHost, rconPort, rconPass, "plugman reload BlockAndSeek")
sendRconCommand(rconHost, rconPort, rconPass, "reload")
println "Plugin reloaded"
} catch (Exception e) {
println "RCON: ${e.message}"
}
}
}
def sendRconCommand(String host, int port, String password, String command) {
new Socket(host, port).withCloseable { socket ->
def out = socket.outputStream
def inp = socket.inputStream
def sendPacket = { int id, int type, String body ->
byte[] bodyBytes = body.getBytes("UTF-8")
int length = 4 + 4 + bodyBytes.length + 2 // id + type + body + 2 nulls
ByteBuffer buffer = ByteBuffer.allocate(4 + length)
buffer.order(ByteOrder.LITTLE_ENDIAN)
buffer.putInt(length)
buffer.putInt(id)
buffer.putInt(type)
buffer.put(bodyBytes)
buffer.put((byte) 0)
buffer.put((byte) 0)
out.write(buffer.array())
out.flush()
}
sendPacket(1, 3, password)
inp.read(new byte[4096])
sendPacket(2, 2, command)
byte[] buffer = new byte[4096]
int read = inp.read(buffer)
if (read > 12) {
String response = new String(buffer, 12, read - 12 - 2, "UTF-8")
println "Server response: $response"
}
}
}