diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a69b5a1 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,78 @@ +* text=auto eol=lf +*.[cC][mM][dD] text eol=crlf +*.[bB][aA][tT] text eol=crlf +*.[pP][sS]1 text eol=crlf +*.[sS][hH] text eol=lf + +*.patch text eol=lf + +*.png binary +*.lzma binary +*.zip binary +*.gzip binary +*.exe binary +*.ico binary +*.eot binary +*.ttf binary +*.woff binary +*.woff2 binary +*.a binary +*.lib binary +*.icns binary +*.jpg binary +*.jpeg binary +*.gif binary +*.mov binary +*.mp4 binary +*.mp3 binary +*.flv binary +*.fla binary +*.swf binary +*.gz binary +*.tar binary +*.tar.gz binary +*.7z binary +*.pyc binary +*.gpg binary +*.bin binary + +*.gitattributes text +.gitignore text + +# Java sources +*.java text diff=java +*.kt text diff=kotlin +*.groovy text diff=java +*.scala text diff=java +*.gradle text diff=java +*.gradle.kts text diff=kotlin + +# These files are text and should be normalized (Convert crlf => lf) +*.css text diff=css +*.scss text diff=css +*.sass text +*.df text +*.htm text diff=html +*.html text diff=html +*.js text +*.jsp text +*.jspf text +*.jspx text +*.properties text +*.tld text +*.tag text +*.tagx text +*.xml text + +# These files are binary and should be left untouched +# (binary is a macro for -text -diff) +*.class binary +*.dll binary +*.ear binary +*.jar binary +*.so binary +*.war binary +*.jks binary + +mvnw text eol=lf +gradlew text eol=lf \ No newline at end of file diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..3597edc --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @powercasgamer \ No newline at end of file diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..09f11ed --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,133 @@ + +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[INSERT CONTACT METHOD]. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations \ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..46ab584 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +github: powercasgamer +#patreon: # Replace with a single Patreon username +ko_fi: powercasgamer \ No newline at end of file diff --git a/.github/renovate.json b/.github/renovate.json new file mode 100644 index 0000000..a8ed8e9 --- /dev/null +++ b/.github/renovate.json @@ -0,0 +1,8 @@ +{ + "extends": [ + "local>powercasgamer/.github:renovate-config", + ":dependencyDashboard" + ], + "ignoreDeps": [], + "packageRules": [] +} diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..c6ca681 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,64 @@ +name: Java CI with Gradle + +on: + push: + branches: [ "**" ] + tags-ignore: [ "**" ] + pull_request: + +concurrency: + group: "${{ github.workflow }}-${{ github.event.number || github.ref }}" + cancel-in-progress: true + +permissions: + actions: write + contents: read + +jobs: + build: + if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }} + strategy: + matrix: + java: ["17"] + os: ["ubuntu-latest"] + fail-fast: true + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Java + uses: actions/setup-java@v3 + with: + distribution: 'adopt' + java-version: ${{ matrix.java }} + cache: 'gradle' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@main + + - name: Build with Gradle + uses: gradle/gradle-build-action@main + with: + cache-read-only: ${{ !startsWith(github.ref, 'refs/heads/master') || github.event_name == 'pull_request' }} + arguments: "build --stacktrace" + + - name: Determine status & prepare for publish + if: ${{ runner.os == 'Linux' }} + run: | + if [ "$(./gradlew properties | awk '/^version:/ { print $2; }' | grep '\-SNAPSHOT')" ]; then + echo "STATUS=snapshot" >> $GITHUB_ENV + else + echo "STATUS=release" >> $GITHUB_ENV + fi + + - name: Publish + if: ${{ runner.os == 'Linux' && env.STATUS != 'release' && github.event_name == 'push' && startsWith(github.ref, 'refs/heads/master') }} + run: ./gradlew publish -x requireClean -x signMavenPublication + env: + ORG_GRADLE_PROJECT_mizuleUsername: ${{ secrets.MAVEN_USERNAME }} + ORG_GRADLE_PROJECT_mizulePassword: ${{ secrets.MAVEN_PASSWORD }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..31835b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.gradle +.idea +**/build +release.sh +bin +**/run/ +# Ignore Gradle build output directory +build diff --git a/.spotless/mizule.importorder b/.spotless/mizule.importorder new file mode 100644 index 0000000..c232b17 --- /dev/null +++ b/.spotless/mizule.importorder @@ -0,0 +1,6 @@ +#Organize Import Order +#Tue Mar 30 19:56:59 PDT 2021 +0= +1=java +2=javax +3=\# diff --git a/HEADER b/HEADER new file mode 100644 index 0000000..3deae17 --- /dev/null +++ b/HEADER @@ -0,0 +1,22 @@ +This file is part of ${name}, licensed under the MIT License. + +Copyright (c) ${year} powercas_gamer +Copyright (c) ${year} contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1464642 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 powercas_gamer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c88d1b9 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# imagery + +A WIP ShareX file server. + +Overcomplicating? Never heard of her. \ No newline at end of file diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts new file mode 100644 index 0000000..54b97cd --- /dev/null +++ b/build-logic/build.gradle.kts @@ -0,0 +1,37 @@ +plugins { + `kotlin-dsl` +} + +repositories { + gradlePluginPortal() + mavenCentral() +} + +dependencies { + compileOnly(files(libs::class.java.protectionDomain.codeSource.location)) + implementation(libs.indra.common) + implementation(libs.indra.git) + implementation(libs.indra.spotless) + implementation(libs.shadow) + implementation(libs.kotlin.gradle) + implementation(libs.kotlin.std) + implementation(libs.idea.gradle) + implementation(libs.gremlin.gradle) + implementation(libs.run.task) + implementation(libs.blossom) +} + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +kotlin { + target { + compilations.configureEach { + kotlinOptions { + jvmTarget = "17" + } + } + } +} \ No newline at end of file diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts new file mode 100644 index 0000000..b5a0fab --- /dev/null +++ b/build-logic/settings.gradle.kts @@ -0,0 +1,7 @@ +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} diff --git a/build-logic/src/main/kotlin/base-conventions.gradle.kts b/build-logic/src/main/kotlin/base-conventions.gradle.kts new file mode 100644 index 0000000..f3bb571 --- /dev/null +++ b/build-logic/src/main/kotlin/base-conventions.gradle.kts @@ -0,0 +1,59 @@ +import net.kyori.indra.IndraExtension + +plugins { + id("net.kyori.indra") + id("org.jetbrains.gradle.plugin.idea-ext") + id("eclipse") + id("visual-studio") +} + +val libs = extensions.getByType(org.gradle.accessors.dm.LibrariesForLibs::class) + +group = rootProject.group +version = rootProject.version +description = rootProject.description + +repositories { + mavenCentral() + sonatype.s01Snapshots() + sonatype.ossSnapshots() + maven("https://repo.papermc.io/repository/maven-public/") + maven("https://maven.reposilite.com/snapshots") { + mavenContent { + snapshotsOnly() + includeGroup("io.javalin") + } + } +} + +extensions.configure(IndraExtension::class) { + gpl3OnlyLicense() + github(providers.gradleProperty("githubOrg").get(), providers.gradleProperty("githubRepo").get()) { + ci(true) + issues(true) + scm(true) + } + + configurePublications { + pom { + developers { + developer { + id.set("powercas_gamer") + name.set("Cas") + url.set("https://mizule.dev") + email.set("cas [at] mizule [dot] dev") + timezone.set("Europe/Amsterdam") + } + } + } + } +} + +tasks { + named("idea") { + notCompatibleWithConfigurationCache("https://github.com/gradle/gradle/issues/13480") + } + register("cleanAll", Delete::class) { + dependsOn("clean", "cleanIdea", "cleanVisualStudio", "cleanEclipse") + } +} \ No newline at end of file diff --git a/build-logic/src/main/kotlin/common-conventions.gradle.kts b/build-logic/src/main/kotlin/common-conventions.gradle.kts new file mode 100644 index 0000000..63dd7c7 --- /dev/null +++ b/build-logic/src/main/kotlin/common-conventions.gradle.kts @@ -0,0 +1,115 @@ +import com.diffplug.gradle.spotless.FormatExtension +import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer +import net.kyori.indra.licenser.spotless.HeaderFormat +import java.util.* + +plugins { + id("base-conventions") + id("net.kyori.indra") + id("net.kyori.indra.publishing") + id("net.kyori.indra.git") + id("net.kyori.indra.licenser.spotless") + id("com.github.johnrengelman.shadow") + id("java-library") +} + +//val libs = extensions.getByType(org.gradle.accessors.dm.LibrariesForLibs::class) + +extensions.getByType(BasePluginExtension::class.java).archivesName.set(project.nameString(true)) + +indra { + javaVersions { + minimumToolchain(17) + target(17) + } + mitLicense() + + publishSnapshotsTo("mizule", "https://repo.mizule.dev/snapshots") + publishReleasesTo("mizule", "https://repo.mizule.dev/releases") +} + +java { + withSourcesJar() + withJavadocJar() +} + +spotless { + fun FormatExtension.applyCommon() { + trimTrailingWhitespace() + endWithNewline() + encoding("UTF-8") + toggleOffOn() + } + java { + importOrderFile(rootProject.file(".spotless/mizule.importorder")) + removeUnusedImports() + formatAnnotations() + applyCommon() + target("*/src/*/java/**/*.java") + } + kotlinGradle { + applyCommon() + ktlint("0.50.0") + } + kotlin { + applyCommon() + ktlint("0.50.0") + } +} + +indraSpotlessLicenser { + headerFormat(HeaderFormat.starSlash()) + licenseHeaderFile(rootProject.projectDir.resolve("HEADER")) + + val currentYear = Calendar.getInstance().apply { + time = Date() + }.get(Calendar.YEAR) + val createdYear = providers.gradleProperty("createdYear").map { it.toInt() }.getOrElse(currentYear) + val year = if (createdYear == currentYear) createdYear.toString() else "$createdYear-$currentYear" + + property("name", providers.gradleProperty("projectName").getOrElse("template")) + property("year", year) + property("description", project.description ?: "A template project") + property("author", providers.gradleProperty("projectAuthor").getOrElse("template")) + +} + +tasks { + assemble { + dependsOn(shadowJar) + } + + jar { + archiveClassifier.set("unshaded") + from(rootProject.projectDir.resolve("LICENSE")) { + rename { "LICENSE_${providers.gradleProperty("projectName").getOrElse("template")}" } + } + } + + shadowJar { + archiveClassifier.set("") + mergeServiceFiles() + transform(Log4j2PluginsCacheFileTransformer::class.java) + } + + withType().configureEach { + options.isFork = true + options.isIncremental = true + options.encoding = "UTF-8" + options.compilerArgs.add("-parameters") + options.compilerArgs.add("-Xlint:-processing") + } + + withType().configureEach { + filteringCharset = "UTF-8" + duplicatesStrategy = DuplicatesStrategy.INCLUDE + } + + javadoc { + val options = options as? StandardJavadocDocletOptions ?: return@javadoc + options.isAuthor = true + options.encoding = "UTF-8" + options.charSet = "UTF-8" + options.linkSource(true) + } +} diff --git a/build-logic/src/main/kotlin/ext.kt b/build-logic/src/main/kotlin/ext.kt new file mode 100644 index 0000000..f8e7e22 --- /dev/null +++ b/build-logic/src/main/kotlin/ext.kt @@ -0,0 +1,90 @@ +import net.kyori.indra.git.IndraGitExtension +import org.gradle.accessors.dm.LibrariesForLibs +import org.gradle.api.Project +import org.gradle.api.artifacts.Configuration +import org.gradle.api.artifacts.ExternalModuleDependency +import org.gradle.api.tasks.bundling.Jar +import org.gradle.kotlin.dsl.* +import org.gradle.kotlin.dsl.support.uppercaseFirstChar +import java.text.SimpleDateFormat +import java.util.* + +val Project.libs: LibrariesForLibs + get() = the() + +fun Project.versionString(): String = this.version as String + +fun Project.nameString(useProjectName: Boolean = false): String = + if (useProjectName) { + val projName = providers.gradleProperty("projectName").getOrElse("template") + if (this.name.contains('-')) { + val splat = this.name.split("-").toMutableList() + splat[0] = projName + splat.joinToString("-") { it.uppercaseFirstChar() } + } else { + projName + } + } else if (this.name.contains('-')) { + this.name.split("-").joinToString("-") { it.uppercaseFirstChar() } + } else { + this.name.uppercaseFirstChar() + } + +fun Project.applyJarMetadata(moduleName: String) { + if ("jar" in tasks.names) { + tasks.named("jar") { + manifest.attributes( + "Multi-Release" to "true", + "Built-By" to System.getProperty("user.name"), + "Created-By" to System.getProperty("java.vendor.version"), + "Build-Jdk" to System.getProperty("java.version"), + "Build-Time" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm.sssZ").format(Date()), + "Automatic-Module-Name" to moduleName, + "Specification-Title" to moduleName, + "Specification-Version" to project.versionString(), + "Specification-Vendor" to providers.gradleProperty("projectAuthor").getOrElse("athena"), + ) + val indraGit = project.extensions.findByType() + indraGit?.apply { + applyVcsInformationToManifest(manifest) + + if (isPresent) { + } + } + } + } +} + +fun ExternalModuleDependency.excludeUseless() { + exclude(group = "org.jetbrains", module = "annotations") + exclude(group = "org.checkerframework", module = "checker-qual") + exclude(group = "com.google.errorprone", module = "error_prone_core") + exclude(group = "com.google.errorprone", module = "error_prone_annotations") + exclude(group = "com.google.errorprone", module = "error_prone_annotation") + exclude(group = "com.google.code.findbugs", module = "jsr305") + exclude(group = "com.google.j2objc", module = "j2objc-annotations") +} + +fun Configuration.excludeUseless() { + exclude(group = "org.jetbrains", module = "annotations") + exclude(group = "org.checkerframework", module = "checker-qual") + exclude(group = "com.google.errorprone", module = "error_prone_core") + exclude(group = "com.google.errorprone", module = "error_prone_annotations") + exclude(group = "com.google.errorprone", module = "error_prone_annotation") + exclude(group = "com.google.code.findbugs", module = "jsr305") + exclude(group = "com.google.j2objc", module = "j2objc-annotations") +} + +/** + * Returns `true` if a substring of this char sequence starting at the specified offset [startIndex] starts with any of the specified prefixes. + */ +fun CharSequence.startsWithAny(vararg prefixes: CharSequence, startIndex: Int = 0, ignoreCase: Boolean = false): Boolean { + return prefixes.any { this.startsWith(it, startIndex, ignoreCase) } +} + +/** + * Returns `true` if this char sequence ends with any of the specified suffixes. + */ +fun CharSequence.endsWithAny(vararg suffixes: CharSequence, ignoreCase: Boolean = false): Boolean { + return suffixes.any { this.endsWith(it, ignoreCase) } +} \ No newline at end of file diff --git a/build-logic/src/main/kotlin/kotlin-conventions.gradle.kts b/build-logic/src/main/kotlin/kotlin-conventions.gradle.kts new file mode 100644 index 0000000..125d8cf --- /dev/null +++ b/build-logic/src/main/kotlin/kotlin-conventions.gradle.kts @@ -0,0 +1,22 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("common-conventions") + kotlin("jvm") +} + +tasks { + withType(KotlinCompile::class).configureEach { + compilerOptions { + jvmTarget.set(JvmTarget.JVM_17) + languageVersion.set(KotlinVersion.KOTLIN_1_9) + } + } +} + +extensions.configure(KotlinProjectExtension::class) { + jvmToolchain(17) +} \ No newline at end of file diff --git a/build-logic/src/main/kotlin/paper-conventions.gradle.kts b/build-logic/src/main/kotlin/paper-conventions.gradle.kts new file mode 100644 index 0000000..0c507b7 --- /dev/null +++ b/build-logic/src/main/kotlin/paper-conventions.gradle.kts @@ -0,0 +1,67 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + +plugins { + id("common-conventions") +// id("io.papermc.paperweight.userdev") + id("xyz.jpenilla.run-paper") + id("xyz.jpenilla.gremlin-gradle") +} + +tasks { + runServer { + minecraftVersion("1.20.2") + + jvmArguments.add("-Dcom.mojang.eula.agree=true") + systemProperty("terminal.jline", false) + systemProperty("terminal.ansi", true) + args( "-p", "25519") + + downloadPlugins { + url("https://github.com/MiniPlaceholders/MiniPlaceholders/releases/download/2.2.1/MiniPlaceholders-Paper-2.2.1.jar") + url("https://download.luckperms.net/1519/bukkit/loader/LuckPerms-Bukkit-5.4.106.jar") + } + } + + named("clean", Delete::class) { + delete(project.projectDir.resolve("run")) + } + + + shadowJar { +// dependencies { +// exclude(dependency(libs.adventure.api.get())) +// exclude(dependency(libs.adventure.legacy.get())) +// exclude(dependency(libs.adventure.key.get())) +// exclude(dependency(libs.adventure.plain.get())) +// include(dependency(libs.gremlin.gradle.get().toString())) +// include(dependency(libs.gremlin.runtime.get().toString())) +// } + relocate("xyz.jpenilla.gremlin", "dev.mizule.timetriggeredperms.lib.xyz.jpenilla.gremlin") + } + +// writeDependencies { +// repos.set(listOf( +// "https://repo.papermc.io/repository/maven-public/", +// "https://repo.broccol.ai/releases", +// "https://maven.mizule.dev/", +// "https://oss.sonatype.org/content/repositories/snapshots/", +// "https://s01.oss.sonatype.org/content/repositories/snapshots/", +// "https://repo.jpenilla.xyz/snapshots/", +// "https://repo.jpenilla.xyz/releases/", +// "https://jitpack.io" +// )) +// } +} + +//configurations.runtimeDownload { +// exclude("io.papermc.paper") +// exclude("net.kyori", "adventure-api") +// exclude("net.kyori", "adventure-text-minimessage") +// exclude("net.kyori", "adventure-text-serializer-plain") +// exclude("org.slf4j", "slf4j-api") +// exclude("org.ow2.asm") +//} +// +//configurations.paperweightDevelopmentBundle { +// resolutionStrategy.cacheChangingModulesFor(3, "days") +//} \ No newline at end of file diff --git a/build-logic/src/main/kotlin/parent-conventions.gradle.kts b/build-logic/src/main/kotlin/parent-conventions.gradle.kts new file mode 100644 index 0000000..9f7b6c7 --- /dev/null +++ b/build-logic/src/main/kotlin/parent-conventions.gradle.kts @@ -0,0 +1,3 @@ +plugins { + base +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..d33cdf0 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,3 @@ +plugins { + id("parent-conventions") +} \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts new file mode 100644 index 0000000..16d8afe --- /dev/null +++ b/core/build.gradle.kts @@ -0,0 +1,29 @@ +import java.util.* + +plugins { + id("common-conventions") + id("kotlin-conventions") +} + +dependencies { + compileOnly(kotlin("stdlib")) + compileOnly(kotlin("reflect")) + compileOnlyApi("net.luckperms:api:5.4") + compileOnly("org.spongepowered:configurate-yaml:4.2.0-SNAPSHOT") + compileOnly("org.spongepowered:configurate-extra-kotlin:4.2.0-SNAPSHOT") +} + +applyJarMetadata("timetriggeredperms-core") + +tasks { + clean { + delete("run") + } +} + +idea { + module { + isDownloadJavadoc = true + isDownloadSources = true + } +} diff --git a/core/src/main/kotlin/dev/mizule/timetriggeredperms/core/config/Config.kt b/core/src/main/kotlin/dev/mizule/timetriggeredperms/core/config/Config.kt new file mode 100644 index 0000000..a4fc417 --- /dev/null +++ b/core/src/main/kotlin/dev/mizule/timetriggeredperms/core/config/Config.kt @@ -0,0 +1,42 @@ +/* + * This file is part of TimeTriggeredPerms, licensed under the MIT License. + * + * Copyright (c) 2023 powercas_gamer + * Copyright (c) 2023 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.mizule.timetriggeredperms.core.config + +import org.spongepowered.configurate.objectmapping.ConfigSerializable +import org.spongepowered.configurate.objectmapping.meta.Setting + +@ConfigSerializable +data class Config( + + @Setting(nodeFromParent = true) + val permissions: Map = mapOf("example" to PermissionThing("test.permission", listOf("broadcast example"))), + +) + +@ConfigSerializable +data class PermissionThing( + val permission: String, + val commands: List, +) diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..669007f --- /dev/null +++ b/gradle.properties @@ -0,0 +1,37 @@ +# build-logic stuff +javadocPublishRoot=https://jd.mizule.dev/personal/imagery/ +githubOrg=powercasgamer +projectAuthor=powercasgamer +githubRepo=TimeTriggeredPerms +projectName=TimeTriggeredPerms +disableJavadoc=false +createdYear=2023 + +# project stuff +group=dev.mizule.timetriggeredperms +version=0.0.2-SNAPSHOT +description=LuckyPermissions Temporary Permission Stuff! + +# kotlin stuff +kotlin.code.style=official +kotlin.caching.enabled=true +kotlin.incremental=true +kotlin.incremental.js=true +kapt.use.worker.api=true +kapt.incremental.apt=true +kotlin.incremental.useClasspathSnapshot=true +kotlin.stdlib.default.dependency=false +kotlin.native.disableCompilerDaemon=false + +# gradle stuff +org.gradle.cache=true +org.gradle.caching=true +org.gradle.configuration-cache=false +org.gradle.unsafe.configuration-cache=false +org.gradle.parallel=true +org.gradle.configureondemand=true +org.gradle.jvmargs=-Xmx4048m -Dfile.encoding=UTF-8 +org.gradle.unsafe.configuration-cache.max-problems=5 +org.gradle.daemon=true +org.gradle.unsafe.configuration-cache-problems=warn +org.gradle.vfs.watch=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..411d6dc --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,26 @@ +[libraries] +# build-logic stuff +blossom = { module = "net.kyori:blossom", version.ref = "blossom" } +indra-common = { module = "net.kyori:indra-common", version.ref = "indra" } +indra-crossdoc = { module = "net.kyori:indra-crossdoc", version.ref = "indra" } +indra-spotless = { module = "net.kyori:indra-licenser-spotless", version.ref = "indra" } +indra-git = { module = "net.kyori:indra-git", version.ref = "indra" } +shadow = { module = "com.github.johnrengelman:shadow", version.ref = "shadow" } +kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } +kotlin-std = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" } +idea-gradle = { module = "gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext", version.ref = "idea-gradle" } +gremlin-gradle = { module = "xyz.jpenilla:gremlin-gradle", version.ref = "gremlin" } +gremlin-runtime = { module = "xyz.jpenilla:gremlin-runtime", version.ref = "gremlin" } +run-task = { module = "xyz.jpenilla:run-task", version.ref = "run-task" } + +[plugins] +gremlin-gradle = { id = "xyz.jpenilla.gremlin-gradle", version.ref = "gremlin" } + +[versions] +indra = "3.1.3" +blossom = "2.1.0" +shadow = "8.1.1" +kotlin = "1.9.21" +gremlin = "0.0.3" +idea-gradle = "1.1.7" +run-task = "2.2.2" diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7f93135 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..3fa8f86 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1aa94a4 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/paper/build.gradle.kts b/paper/build.gradle.kts new file mode 100644 index 0000000..9c91348 --- /dev/null +++ b/paper/build.gradle.kts @@ -0,0 +1,64 @@ +import java.util.* + +plugins { + id("common-conventions") + id("kotlin-conventions") + id("paper-conventions") + id("xyz.jpenilla.gremlin-gradle") +} + +fun DependencyHandler.runtimeDownloadApi(dependencyNotation: Any) { + api(dependencyNotation) + runtimeDownload(dependencyNotation) +} + +fun DependencyHandler.runtimeDownloadOnlyApi(dependencyNotation: Any) { + compileOnlyApi(dependencyNotation) + runtimeDownload(dependencyNotation) +} + +dependencies { + api(projects.timetriggeredpermsCore) + compileOnly("io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT") + compileOnly("net.luckperms:api:5.4") + implementation(libs.gremlin.runtime) + + runtimeDownloadOnlyApi(kotlin("stdlib")) + runtimeDownloadOnlyApi(kotlin("reflect")) + runtimeDownloadOnlyApi("org.spongepowered:configurate-yaml:4.2.0-SNAPSHOT") + runtimeDownloadOnlyApi("org.spongepowered:configurate-extra-kotlin:4.2.0-SNAPSHOT") +} + +applyJarMetadata("timetriggeredperms-paper") + +tasks { + clean { + delete("run") + } +} + +idea { + module { + isDownloadJavadoc = true + isDownloadSources = true + } +} + +tasks.writeDependencies { + outputFileName.set("dependencies.txt") + repos.add("https://repo.papermc.io/repository/maven-public/") + repos.add("https://repo.maven.apache.org/maven2/") + repos.add("https://maven.mizule.dev/") + repos.add("https://maven.reposilite.com/snapshots/") + repos.add("https://maven.reposilite.com/releases/") +} + +gremlin { + defaultJarRelocatorDependencies.set(true) + defaultGremlinRuntimeDependency.set(false) +} + +configurations.runtimeDownload { + exclude("org.checkerframework", "checker-qual") + exclude("org.jetbrains", "annotations") +} diff --git a/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/TTP.kt b/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/TTP.kt new file mode 100644 index 0000000..1e43e4c --- /dev/null +++ b/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/TTP.kt @@ -0,0 +1,71 @@ +/* + * This file is part of TimeTriggeredPerms, licensed under the MIT License. + * + * Copyright (c) 2023 powercas_gamer + * Copyright (c) 2023 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.mizule.timetriggeredperms.paper + +import dev.mizule.timetriggeredperms.core.config.Config +import dev.mizule.timetriggeredperms.paper.command.ReloadCommand +import dev.mizule.timetriggeredperms.paper.listener.LuckPermsListener +import net.luckperms.api.LuckPermsProvider +import net.luckperms.api.event.node.NodeRemoveEvent +import org.bukkit.Bukkit +import org.bukkit.plugin.java.JavaPlugin +import org.spongepowered.configurate.kotlin.extensions.get +import org.spongepowered.configurate.kotlin.objectMapperFactory +import org.spongepowered.configurate.yaml.NodeStyle +import org.spongepowered.configurate.yaml.YamlConfigurationLoader + +class TTP : JavaPlugin() { + + private val configPath = dataFolder.resolve("permissions.yml") + + val configLoader = YamlConfigurationLoader.builder() + .file(configPath) + .nodeStyle(NodeStyle.BLOCK) + .indent(2) + .defaultOptions { options -> + options.shouldCopyDefaults(true) + options.serializers { builder -> + builder.registerAnnotatedObjects(objectMapperFactory()) + } + } + .build() + + var configNode = configLoader.load() + var config = requireNotNull(configNode.get()) { + "Could not read configuration" + } + + override fun onEnable() { + if (!configPath.exists()) { + configNode.set(config) // update the backing node to add defaults + configLoader.save(configNode) + } + LuckPermsProvider.get().eventBus.subscribe(this, NodeRemoveEvent::class.java) { + LuckPermsListener(this).onExpire(it) + } + + Bukkit.getCommandMap().register("timetriggeredperms", ReloadCommand(this)) + } +} diff --git a/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/command/ReloadCommand.kt b/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/command/ReloadCommand.kt new file mode 100644 index 0000000..395e194 --- /dev/null +++ b/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/command/ReloadCommand.kt @@ -0,0 +1,50 @@ +/* + * This file is part of TimeTriggeredPerms, licensed under the MIT License. + * + * Copyright (c) 2023 powercas_gamer + * Copyright (c) 2023 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.mizule.timetriggeredperms.paper.command + +import dev.mizule.timetriggeredperms.core.config.Config +import dev.mizule.timetriggeredperms.paper.TTP +import org.bukkit.command.Command +import org.bukkit.command.CommandSender +import org.spongepowered.configurate.kotlin.extensions.get + +class ReloadCommand(val plugin: TTP) : Command("ttpreload") { + + init { + permission = "timetriggeredperms.reload" + } + + override fun execute(sender: CommandSender, commandLabel: String, args: Array?): Boolean { + var configNode = plugin.configLoader.load() + var config = requireNotNull(configNode.get()) { + "Could not read configuration" + } + plugin.config = config + + sender.sendMessage("reloaded") + + return true + } +} diff --git a/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/listener/LuckPermsListener.kt b/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/listener/LuckPermsListener.kt new file mode 100644 index 0000000..7577116 --- /dev/null +++ b/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/listener/LuckPermsListener.kt @@ -0,0 +1,68 @@ +/* + * This file is part of TimeTriggeredPerms, licensed under the MIT License. + * + * Copyright (c) 2023 powercas_gamer + * Copyright (c) 2023 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.mizule.timetriggeredperms.paper.listener + +import dev.mizule.timetriggeredperms.core.config.PermissionThing +import dev.mizule.timetriggeredperms.paper.TTP +import net.luckperms.api.event.node.NodeRemoveEvent +import net.luckperms.api.model.user.User +import net.luckperms.api.node.types.PermissionNode +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitTask + +class LuckPermsListener(val plugin: TTP) { + + fun onExpire(event: NodeRemoveEvent) { + val node = event.node + + if (!node.hasExpired()) return + + val permissionNode = event.node as PermissionNode + + val configNode = nodeConfig(permissionNode.permission) + val isUser = event.isUser + + sync { + configNode.commands.forEach { command -> + val name = event.target.friendlyName + val uuid = if (isUser) (event.target as User).uniqueId.toString() else "" + val formattedCommand = command + .replace("%name%", name) + .replace("%uuid%", uuid) + .replace("%permission%", permissionNode.permission) + + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), formattedCommand) + } + } + } + + fun nodeConfig(perm: String): PermissionThing { + return plugin.config.permissions.values.first { it.permission == perm } + } + + fun sync(task: (BukkitTask) -> Unit) { + Bukkit.getScheduler().runTask(plugin, task) + } +} diff --git a/paper/src/main/resources/paper-plugin.yml b/paper/src/main/resources/paper-plugin.yml new file mode 100644 index 0000000..9e8d4e8 --- /dev/null +++ b/paper/src/main/resources/paper-plugin.yml @@ -0,0 +1,13 @@ +name: TimeTriggeredPerms +version: ${pluginVersion} +main: dev.mizule.timetriggeredperms.paper.TTP +description: ${pluginDescription} +api-version: "1.20" +loader: dev.mizule.timetriggeredperms.lib.xyz.jpenilla.gremlin.runtime.platformsupport.DefaultsPaperPluginLoader +author: ${pluginAuthor} + +dependencies: + server: + LuckPerms: + load: AFTER + required: true diff --git a/paper/src/main/resources/test.yml b/paper/src/main/resources/test.yml new file mode 100644 index 0000000..6794def --- /dev/null +++ b/paper/src/main/resources/test.yml @@ -0,0 +1,4 @@ +something: + permission: "permission" + commands: + - "commands to execute" \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..b98a31f --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,19 @@ +pluginManagement { + includeBuild("build-logic") +} + +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0" +} + +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") + +rootProject.name = "TimeTriggeredPerms" + +sequenceOf( + "paper", + "core" +).forEach { + include("timetriggeredperms-$it") + project(":timetriggeredperms-$it").projectDir = file(it) +}