diff options
9 files changed, 72 insertions, 55 deletions
diff --git a/.github/workflows/snapshot-publish.yml b/.github/workflows/snapshot-publish.yml new file mode 100644 index 0000000..612cb40 --- /dev/null +++ b/.github/workflows/snapshot-publish.yml @@ -0,0 +1,40 @@ +name: Gradle CI + +on: + push: + branches: + - '1.19' + paths-ignore: + - 'README.md' + - 'LICENSE' + - '.gitignore' + - '.editorconfig' + - 'changelogs/**' +jobs: + build: + runs-on: ubuntu-latest + name: Publish with gradle + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: temurin + - uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + ./.gradle/loom-cache + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew publishAllPublicationsToSnapshotsRepository --no-daemon + env: + "xander-repo.username": ${{secrets.REPO_USERNAME}} + "xander-repo.password": ${{secrets.REPO_PASSWORD}} diff --git a/build.gradle.kts b/build.gradle.kts index c5b345d..deefb49 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,12 +7,19 @@ plugins { id("com.modrinth.minotaur") version "2.4.+" id("me.hypherionmc.cursegradle") version "2.+" id("com.github.breadmoirai.github-release") version "2.+" - id("io.github.p03w.machete") version "1.+" `maven-publish` + + id("io.github.p03w.machete") version "1.+" + id("org.ajoberstar.grgit") version "5.0.0" } +val ciRun = System.getenv().containsKey("GITHUB_ACTIONS") + group = "dev.isxander" -version = "1.0.0" +version = "0.1.0" + +if (ciRun) + version = grgit.head().abbreviatedId val testmod by sourceSets.registering { compileClasspath += sourceSets.main.get().compileClasspath @@ -96,7 +103,7 @@ tasks { dependsOn("modrinth") dependsOn("modrinthSyncBody") dependsOn("curseforge") - dependsOn("publish") + dependsOn("publishModPublicationToReleasesRepository") dependsOn("githubRelease") } } @@ -157,7 +164,7 @@ githubRelease { owner(split[0]) repo(split[1]) tagName("${project.version}") - targetCommitish("1.19") + targetCommitish(grgit.branch.toString()) body(changelogText) releaseAssets(tasks["remapJar"].outputs.files) } @@ -173,11 +180,21 @@ publishing { } repositories { - if (hasProperty("xander-repo.username") && hasProperty("xander-repo.password")) { + val username = "xander-repo.username".let { System.getenv(it) ?: findProperty(it) }?.toString() + val password = "xander-repo.password".let { System.getenv(it) ?: findProperty(it) }?.toString() + if (username != null && password != null) { maven(url = "https://maven.isxander.dev/releases") { + name = "Releases" + credentials { + this.username = username + this.password = password + } + } + maven(url = "https://maven.isxander.dev/snapshots") { + name = "Snapshots" credentials { - username = property("xander-repo.username")?.toString() - password = property("xander-repo.password")?.toString() + this.username = username + this.password = password } } } else { diff --git a/src/main/java/dev/isxander/yacl/api/Binding.java b/src/main/java/dev/isxander/yacl/api/Binding.java index d870d8c..37514ca 100644 --- a/src/main/java/dev/isxander/yacl/api/Binding.java +++ b/src/main/java/dev/isxander/yacl/api/Binding.java @@ -26,7 +26,7 @@ public interface Binding<T> { * @param getter should return the current value of the option * @param setter should set the option to the supplied value */ - static <T> Binding<T> of(T def, Supplier<T> getter, Consumer<T> setter) { + static <T> Binding<T> generic(T def, Supplier<T> getter, Consumer<T> setter) { Validate.notNull(def, "`def` must not be null"); Validate.notNull(getter, "`getter` must not be null"); Validate.notNull(setter, "`setter` must not be null"); @@ -37,7 +37,7 @@ public interface Binding<T> { /** * Creates a {@link Binding} for Minecraft's {@link SimpleOption} */ - static <T> Binding<T> of(SimpleOption<T> minecraftOption) { + static <T> Binding<T> minecraft(SimpleOption<T> minecraftOption) { Validate.notNull(minecraftOption, "`minecraftOption` must not be null"); return new GenericBindingImpl<>( diff --git a/src/main/java/dev/isxander/yacl/api/Option.java b/src/main/java/dev/isxander/yacl/api/Option.java index 6598b80..65eae23 100644 --- a/src/main/java/dev/isxander/yacl/api/Option.java +++ b/src/main/java/dev/isxander/yacl/api/Option.java @@ -147,7 +147,7 @@ public interface Option<T> { /** * Sets the binding for the option. - * Shorthand of {@link Binding#of(Object, Supplier, Consumer)} + * Shorthand of {@link Binding#generic(Object, Supplier, Consumer)} * * @param def default value of the option, used to reset * @param getter should return the current value of the option @@ -159,7 +159,7 @@ public interface Option<T> { Validate.notNull(getter, "`getter` must not be null"); Validate.notNull(setter, "`setter` must not be null"); - this.binding = Binding.of(def, getter, setter); + this.binding = Binding.generic(def, getter, setter); return this; } diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java b/src/main/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java index 8d74ceb..ed78abd 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java @@ -13,7 +13,7 @@ public class DoubleSliderController implements ISliderController<Double> { /** * Formats doubles to two decimal places */ - public static final Function<Double, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%.2f", value)); + public static final Function<Double, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,.2f", value)); private final Option<Double> option; diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java b/src/main/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java index 6f4192b..4297271 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java @@ -13,7 +13,7 @@ public class FloatSliderController implements ISliderController<Float> { /** * Formats floats to one decimal place */ - public static final Function<Float, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%.1f", value)); + public static final Function<Float, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,.1f", value)); private final Option<Float> option; diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java b/src/main/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java index 0d0d7b9..38efed5 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java @@ -1,7 +1,6 @@ package dev.isxander.yacl.gui.controllers.slider; import dev.isxander.yacl.api.Option; -import dev.isxander.yacl.impl.utils.NumberFormatHelper; import net.minecraft.text.Text; import org.apache.commons.lang3.Validate; @@ -11,7 +10,7 @@ import java.util.function.Function; * {@link ISliderController} for integers. */ public class IntegerSliderController implements ISliderController<Integer> { - public static final Function<Integer, Text> DEFAULT_FORMATTER = value -> Text.of(NumberFormatHelper.formatSmaller(value)); + public static final Function<Integer, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,d", value)); private final Option<Integer> option; diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java b/src/main/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java index d4c71d1..67b6a0e 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java @@ -1,7 +1,6 @@ package dev.isxander.yacl.gui.controllers.slider; import dev.isxander.yacl.api.Option; -import dev.isxander.yacl.impl.utils.NumberFormatHelper; import net.minecraft.text.Text; import org.apache.commons.lang3.Validate; @@ -11,7 +10,7 @@ import java.util.function.Function; * {@link ISliderController} for longs. */ public class LongSliderController implements ISliderController<Long> { - public static final Function<Long, Text> DEFAULT_FORMATTER = value -> Text.of(NumberFormatHelper.formatSmaller(value)); + public static final Function<Long, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,d", value)); private final Option<Long> option; diff --git a/src/main/java/dev/isxander/yacl/impl/utils/NumberFormatHelper.java b/src/main/java/dev/isxander/yacl/impl/utils/NumberFormatHelper.java deleted file mode 100644 index bbf44a1..0000000 --- a/src/main/java/dev/isxander/yacl/impl/utils/NumberFormatHelper.java +++ /dev/null @@ -1,38 +0,0 @@ -package dev.isxander.yacl.impl.utils; - -import org.jetbrains.annotations.ApiStatus; - -import java.util.Map; -import java.util.NavigableMap; -import java.util.TreeMap; - -@ApiStatus.Internal -public class NumberFormatHelper { - private static final NavigableMap<Long, String> suffixes = new TreeMap<>(); - static { - suffixes.put(1_000L, "K"); - suffixes.put(1_000_000L, "M"); - suffixes.put(1_000_000_000L, "B"); - suffixes.put(1_000_000_000_000L, "T"); - suffixes.put(1_000_000_000_000_000L, "P"); - suffixes.put(1_000_000_000_000_000_000L, "E"); - } - - /** - * @author <a href="https://stackoverflow.com/a/30661479">assylias</a> - */ - public static String formatSmaller(long value) { - // Long.MIN_VALUE == -Long.MIN_VALUE, so we need an adjustment here - if (value == Long.MIN_VALUE) return formatSmaller(Long.MIN_VALUE + 1); - if (value < 0) return "-" + formatSmaller(-value); - if (value < 1000) return Long.toString(value); //deal with easy case - - Map.Entry<Long, String> e = suffixes.floorEntry(value); - Long divideBy = e.getKey(); - String suffix = e.getValue(); - - long truncated = value / (divideBy / 10); //the number part of the output times 10 - boolean hasDecimal = truncated < 100 && (truncated / 10d) != (truncated / 10); - return hasDecimal ? (truncated / 10d) + suffix : (truncated / 10) + suffix; - } -} |