Skip to content

Commit

Permalink
build changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Grabsky committed Jan 11, 2024
1 parent 1809666 commit 1bd2b3f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 80 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
uses: gradle/gradle-build-action@v2
with:
arguments: clean assemble
env:
# GitHub Packages
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Uploading artifact(s)
- name: Upload Artifacts
uses: actions/upload-artifact@v3
Expand Down
71 changes: 46 additions & 25 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,39 +1,62 @@
plugins {
id("java-library")
id 'net.minecrell.plugin-yml.paper' version '0.6.0'
id "java-library"
id "net.minecrell.plugin-yml.paper" version "0.6.0"
id "com.github.johnrengelman.shadow" version "8.1.1"
}

// See "deploy" task registered below as to find out why it's here.
final buildsDirectory = (System.getenv("JVM_BUILDS") ?: null)
final pluginsDirectory = (System.getenv("PLUGINS_DIR") ?: null)
// Environment-specific variables...
final WORKSPACE_BUILDS = System.getenv("WORKSPACE_BUILDS") ?: null
final WORKSPACE_PLUGINS = System.getenv("WORKSPACE_PLUGINS") ?: null

group = "cloud.grabsky"
version = "1.20.1-${System.getenv("GITHUB_RUN_NUMBER") ?: "dev"}"
version = "1.20.4-${System.getenv("GITHUB_RUN_NUMBER") ?: "DEV"}"

repositories {
mavenLocal()
mavenCentral()
maven { url = "https://repo.grabsky.cloud/releases/" }
// Repository for the Paper API.
maven { url = "https://papermc.io/repo/repository/maven-public/" }
// Repository for the PlaceholderAPI, API.
maven { url = "https://repo.extendedclip.com/content/repositories/placeholderapi/" }
// Repository containing the 'bedrock' dependency.
maven { url = "https://maven.pkg.github.com/grabsky/bedrock"
credentials {
username = findProperty("gpr.actor") ?: System.getenv("GITHUB_ACTOR")
password = findProperty("gpr.token") ?: System.getenv("GITHUB_TOKEN")
}
}
// Repository containing the 'configuration' dependency.
maven { url = "https://maven.pkg.github.com/grabsky/configuration"
credentials {
username = findProperty("gpr.actor") ?: System.getenv("GITHUB_ACTOR")
password = findProperty("gpr.token") ?: System.getenv("GITHUB_TOKEN")
}
}
// Repository containing the 'commands' dependency.
maven { url = "https://maven.pkg.github.com/grabsky/commands"
credentials {
username = findProperty("gpr.actor") ?: System.getenv("GITHUB_ACTOR")
password = findProperty("gpr.token") ?: System.getenv("GITHUB_TOKEN")
}
}
}

dependencies {
// Lombok
compileOnly("org.projectlombok:lombok:1.18.26")
annotationProcessor("org.projectlombok:lombok:1.18.26")
compileOnly("org.projectlombok:lombok:1.18.30")
annotationProcessor("org.projectlombok:lombok:1.18.30")
// Paper API
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
// Libraries
paperLibrary("cloud.grabsky:bedrock:1.20.1-44")
paperLibrary("cloud.grabsky:commands:1.20.1-34")
paperLibrary("cloud.grabsky:configuration-paper:1.20.1-42")
// PlaceholderAPI
// Plugin libraries, must be shaded.
implementation("cloud.grabsky:bedrock:1.20.1-47")
implementation("cloud.grabsky:commands:1.20.1-34")
implementation("cloud.grabsky:configuration-paper:1.20.1-42")
// Plugin dependencies, should be present in the classpath as required per 'paper-plugin.yml' file.
compileOnly("me.clip:placeholderapi:2.11.3")
}

tasks {
jar {
shadowJar {
archiveFileName = "${rootProject.name}-${project.version}.jar"
}
compileJava {
Expand All @@ -44,25 +67,23 @@ tasks {
}
}

// Copies produced .jar to $JVM_BUILDS and $PLUGINS_DIR directories specfied as environment variables.
// Copies produced .jar to $WORKSPACE_BUILDS and $WORKSPACE_PLUGINS directories specified as environment variables.
// This is solely for debugging/development purposes and does nothing when said variables are not set.
tasks.register("deploy") {
dependsOn(jar)
dependsOn(shadowJar)
doLast {
// Copying to the builds directory specified by 'JVM_BUILDS' environment variable.
if (buildsDirectory != null)
copy { from(jar) into(buildsDirectory) }
// Copying to the plugins directory specified by 'PLUGINS_DIR' environment variable.
if (pluginsDirectory != null)
copy { from(jar) into(pluginsDirectory) }
// Copying to the builds directory specified by 'WORKSPACE_BUILDS' environment variable.
if (WORKSPACE_BUILDS != null)
copy { from(shadowJar) into(WORKSPACE_BUILDS) }
// Copying to the plugins directory specified by 'WORKSPACE_PLUGINS' environment variable.
if (WORKSPACE_PLUGINS != null)
copy { from(shadowJar) into(WORKSPACE_PLUGINS) }
}
}

paper {
main = "cloud.grabsky.dialogs.Dialogs"
loader = "cloud.grabsky.dialogs.Dialogs\$PluginLoader"
apiVersion = "1.20"
generateLibrariesJson = true
serverDependencies {
"PlaceholderAPI" { load = "BEFORE"; required = false }
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cloud/grabsky/dialogs/Dialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void trigger(final @NotNull Player target) {

if (element instanceof AnimatedActionBarElement animatedActionBar) {
final Iterator<Component> frames = animatedActionBar.frames().iterator();
// Scheduling a new asynchrnous repeat task.
// Scheduling a new asynchronous repeat task.
plugin.getBedrockScheduler().repeatAsync(nextTaskStartsIn, animatedActionBar.refreshRate(), element.ticksToWait() / animatedActionBar.refreshRate(), (iteration) -> {
// Cancelling task in case Player connection has been reset OR other dialog has been started in the meanwhile.
if (isDialogStillValid(target, dialogIdentifier) == false)
Expand Down Expand Up @@ -96,7 +96,7 @@ else if (element instanceof MessageElement messageElement) {
final Message.StringMessage message = (Dialogs.isPlaceholderAPI() == true)
? Message.of(PlaceholderAPI.setPlaceholders(target, messageElement.value()))
: Message.of(messageElement.value());
// Scheduling a new asynchrnous run task.
// Scheduling a new asynchronous run task.
plugin.getBedrockScheduler().runAsync(nextTaskStartsIn, (task) -> {
// Cancelling task in case Player connection has been reset OR other dialog has been started in the meanwhile.
if (isDialogStillValid(target, dialogIdentifier) == false)
Expand Down
53 changes: 0 additions & 53 deletions src/main/java/cloud/grabsky/dialogs/Dialogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,13 @@
import cloud.grabsky.dialogs.configuration.PluginLocale;
import cloud.grabsky.dialogs.configuration.adapter.DialogElementAdapter;
import cloud.grabsky.dialogs.loader.DialogsLoader;
import com.google.gson.Gson;
import io.papermc.paper.plugin.loader.PluginClasspathBuilder;
import io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver;
import org.bukkit.event.Listener;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.repository.RemoteRepository;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import static cloud.grabsky.configuration.paper.util.Resources.ensureResourceExistence;

Expand Down Expand Up @@ -125,43 +111,4 @@ public boolean onReload() throws ConfigurationMappingException, IllegalStateExce
}
}


@SuppressWarnings("UnstableApiUsage")
public static final class PluginLoader implements io.papermc.paper.plugin.loader.PluginLoader {

@Override
public void classloader(final @NotNull PluginClasspathBuilder classpathBuilder) throws IllegalStateException {
final MavenLibraryResolver resolver = new MavenLibraryResolver();
// Parsing the file.
try (final InputStream in = getClass().getResourceAsStream("/paper-libraries.json")) {
final PluginLibraries libraries = new Gson().fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), PluginLibraries.class);
// Adding repositorties.
libraries.asRepositories().forEach(resolver::addRepository);
// Adding dependencies.
libraries.asDependencies().forEach(resolver::addDependency);
// Adding library resolver.
classpathBuilder.addLibrary(resolver);
} catch (final IOException e) {
throw new IllegalStateException(e);
}
}

@RequiredArgsConstructor(access = AccessLevel.PUBLIC)
private static final class PluginLibraries {

private final Map<String, String> repositories;
private final List<String> dependencies;

public Stream<RemoteRepository> asRepositories() {
return repositories.entrySet().stream().map(entry -> new RemoteRepository.Builder(entry.getKey(), "default", entry.getValue()).build());
}

public Stream<Dependency> asDependencies() {
return dependencies.stream().map(value -> new Dependency(new DefaultArtifact(value), null));
}

}

}

}

0 comments on commit 1bd2b3f

Please sign in to comment.