Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,41 @@ name: LabyAddon Build

on:
push:
branches: [ "master", "main" ]
branches: [ "master" ]
pull_request:
branches: [ "master", "main" ]
branches: [ "master" ]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'
distribution: 'corretto'
java-version: '21'
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: Cache Gradle wrapper
uses: actions/cache@v4
with:
path: ~/.gradle/wrapper
key: gradle-wrapper-${{ runner.os }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
gradle-wrapper-${{ runner.os }}-
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build --full-stacktrace
- name: Upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/*-release.jar
16 changes: 4 additions & 12 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
version = "0.1.0"

plugins {
id("java-library")
}
import net.labymod.labygradle.common.extension.LabyModAnnotationProcessorExtension.ReferenceType

dependencies {
labyProcessor()
labyApi("api")
}

labyModProcessor {
referenceType = net.labymod.gradle.core.processor.ReferenceType.INTERFACE
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
labyModAnnotationProcessor {
referenceType = ReferenceType.INTERFACE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.rappytv.screenshotuploader.api;

import net.labymod.api.client.gui.icon.Icon;
import net.labymod.api.client.resources.ResourceLocation;

public class ScreenshotUploaderTextures {

public static class SpriteUploaders {

private static final ResourceLocation TEXTURE = ResourceLocation.create("screenshotuploader", "themes/vanilla/textures/settings.png");

public static Icon IMGUR = Icon.sprite32(TEXTURE, 0, 1);
public static Icon XBACKBONE = Icon.sprite32(TEXTURE, 1, 1);
public static Icon ZIPLINE = Icon.sprite32(TEXTURE, 2, 1);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.rappytv.screenshotuploader.api;

/**
* This exception is thrown when an upload fails for whatever reason
*/
public class UploadException extends RuntimeException {

private final Uploader<?> uploader;

/**
* Constructs a new uploader exception with a custom message
* @param message The reason why the upload failed
* @param uploader The uploader the upload failed with
*/
public UploadException(String message, Uploader<?> uploader) {
super(message);
this.uploader = uploader;
}

/**
* Constructs a new uploader exception with a different cause
* @param cause The reason why the upload failed
* @param uploader The uploader the upload failed with
*/
public UploadException(Throwable cause, Uploader<?> uploader) {
super(cause);
this.uploader = uploader;
}

/**
* Get the uploader with which the upload failed
* @return The uploader the upload failed with
*/
public Uploader<?> getUploader() {
return this.uploader;
}
}
83 changes: 83 additions & 0 deletions api/src/main/java/com/rappytv/screenshotuploader/api/Uploader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.rappytv.screenshotuploader.api;

import net.labymod.api.client.gui.icon.Icon;
import net.labymod.api.configuration.loader.Config;
import org.jetbrains.annotations.NotNull;
import java.io.File;

/**
* A custom uploader which is choosable by the player to upload a screenshot
* @param <C> The Uploader config. Use {@link EmptyConfig} if you don't need a config.
*/
public abstract class Uploader<C extends Config> {

public static final EmptyConfig EMPTY_CONFIG = new EmptyConfig();

private final String id;
private final String name;

/**
* Constructs a new Screenshot Uploader
* @param id The Uploader ID
* @param name The nice name to display
*/
public Uploader(@NotNull String id, @NotNull String name) {
this.id = id;
this.name = name;
}

/**
* Get the Uploader ID
* @return The Uploader ID
*/
@NotNull
public String getId() {
return this.id;
}

/**
* Get the nice name of the Uploader
* @return The nice name of the Uploader
*/
@NotNull
public String getName() {
return this.name;
}

/**
* Get the Uploader Icon
* @return The Uploader Icon
*/
@NotNull
public abstract Icon getIcon();

/**
* Get the Uploader configuration
* @return The Uploader configuration
* @implNote Return {@link Uploader#EMPTY_CONFIG} if you don't need a config
*/
@NotNull
public abstract C getConfig();

/**
* Check if the config options are valid for uploading a screenshot
* @return {@link true} if the config options are valid for uploading a screenshot; otherwise {@link false}
*/
public abstract boolean validateConfig();

/**
* Upload a screenshot
* @param file The screenshot file to uploade
* @return The url where the screenshot can be accessed
* @throws UploadException if something goes wrong
* @implNote Wrap all exceptions using {@link UploadException} for the best error handling
*/
public abstract String uploadScreenshot(File file) throws UploadException;

/**
* An empty config placeholder for Uploaders which don't need a config
*/
public static class EmptyConfig extends Config {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.rappytv.screenshotuploader.api;

import net.labymod.api.configuration.loader.Config;
import net.labymod.api.reference.annotation.Referenceable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;

@Referenceable
public interface UploaderRegistry {

/**
* Registers a new uploader
* @param uploader The uploader to register
* @throws IllegalArgumentException when trying to register an Uploader twice
*/
void registerUploader(@NotNull Uploader<? extends Config> uploader) throws IllegalArgumentException;

/**
* Get all uploaders
* @return A collection of Uploaders
*/
Collection<Uploader<? extends Config>> getUploaders();

/**
* Gets a specific registered uploader by its ID
* @param id The Uploader ID
* @return The uploader or null if the ID is not registered
*/
@Nullable
Uploader<? extends Config> getUploader(String id);
}
90 changes: 17 additions & 73 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,95 +1,39 @@
plugins {
id("java-library")
id("net.labymod.gradle")
id("net.labymod.gradle.addon")
id("net.labymod.labygradle")
id("net.labymod.labygradle.addon")
}

group = "org.example"
version = "1.0.0"
val versions = providers.gradleProperty("net.labymod.minecraft-versions").get().split(";")

java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
group = "org.example"
version = providers.environmentVariable("VERSION").getOrElse("1.0.4")

labyMod {
defaultPackageName = "com.rappytv.uploader" //change this to your main package name (used by all modules)
defaultPackageName = "com.rappytv.screenshotuploader"
addonInfo {
namespace = "uploader"
namespace = "screenshotuploader"
displayName = "Screenshot Uploader"
author = "RappyTV"
description = "Upload your minecraft screenshots to your custom destinations."
minecraftVersion = "*"
version = System.getenv().getOrDefault("VERSION", "1.0.3")
version = rootProject.version.toString()
}

minecraft {
registerVersions(
"1.8.9",
"1.12.2",
"1.16.5",
"1.17.1",
"1.18.2",
"1.19.2",
"1.19.3",
"1.19.4",
"1.20.1",
"1.20.2",
"1.20.4"
) { version, provider ->
configureRun(provider, version)
}

subprojects.forEach {
if (it.name != "game-runner") {
filter(it.name)
registerVersion(versions.toTypedArray()) {
runs {
getByName("client") {
devLogin = true
}
}
}
}

addonDev {
productionRelease()
}
}

subprojects {
plugins.apply("java-library")
plugins.apply("net.labymod.gradle")
plugins.apply("net.labymod.gradle.addon")
plugins.apply("net.labymod.labygradle")
plugins.apply("net.labymod.labygradle.addon")

repositories {
maven("https://libraries.minecraft.net/")
maven("https://repo.spongepowered.org/repository/maven-public/")
}
}

fun configureRun(provider: net.labymod.gradle.core.minecraft.provider.VersionProvider, gameVersion: String) {
provider.runConfiguration {
mainClass = "net.minecraft.launchwrapper.Launch"
jvmArgs("-Dnet.labymod.running-version=${gameVersion}")
jvmArgs("-Dmixin.debug=true")
jvmArgs("-Dnet.labymod.debugging.all=true")
jvmArgs("-Dmixin.env.disableRefMap=true")

args("--tweakClass", "net.labymod.core.loader.vanilla.launchwrapper.LabyModLaunchWrapperTweaker")
args("--labymod-dev-environment", "true")
args("--addon-dev-environment", "true")
}

provider.javaVersion = when (gameVersion) {
else -> {
JavaVersion.VERSION_17
}
}

provider.mixin {
val mixinMinVersion = when (gameVersion) {
"1.8.9", "1.12.2", "1.16.5" -> {
"0.6.6"
}

else -> {
"0.8.2"
}
}

minVersion = mixinMinVersion
}
group = rootProject.group
version = rootProject.version
}
17 changes: 6 additions & 11 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
version = "0.1.0"

plugins {
id("java-library")
}
import net.labymod.labygradle.common.extension.LabyModAnnotationProcessorExtension.ReferenceType

dependencies {
labyProcessor()
api(project(":api"))
}

labyModProcessor {
referenceType = net.labymod.gradle.core.processor.ReferenceType.DEFAULT
// An example of how to add an external dependency that is used by the addon.
// addonMavenDependency("org.jeasy:easy-random:5.0.0")
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
labyModAnnotationProcessor {
referenceType = ReferenceType.DEFAULT
}
Loading