Skip to content

Commit

Permalink
Add publish to maven central tasks for Gradle.
Browse files Browse the repository at this point in the history
  • Loading branch information
HydrolienF committed Dec 30, 2024
1 parent e41551f commit 00b77d8
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 43 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ Biome to use for empty chunks & the default spawn coordinates can be edit in the
## Build

Build with `./gradlew assemble`. Plugin file will be in `build/libs/`.

Build for publication with `./gradlew clean zipStagingDeploy`
85 changes: 79 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ plugins {
id("java")
id("io.github.goooler.shadow") version "8.1.7"
id("maven-publish")
signing // Add ./gradlew signArchives
id("xyz.jpenilla.run-paper") version "2.3.1"
id("org.sonarqube") version "5.0.0.4638"
}

group="fr.formiko.voidworldgenerator"
version="1.3.0"
group="fr.formiko.mc.voidworldgenerator"
version="1.3.2"
description="Generate empty world."
val mainMinecraftVersion = "1.21.4"
val supportedMinecraftVersions = "1.20 - 1.21.4"

repositories {
mavenCentral()
Expand All @@ -17,12 +20,15 @@ repositories {
}

dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:$mainMinecraftVersion-R0.1-SNAPSHOT")
implementation("org.bstats:bstats-bukkit:3.1.0")
}

java {
// Configure the java toolchain. This allows gradle to auto-provision JDK 21 on systems that only have JDK 8 installed for example.
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
withJavadocJar()
withSourcesJar()
}

tasks {
Expand Down Expand Up @@ -50,12 +56,79 @@ tasks {
// Configure the Minecraft version for our task.
// This is the only required configuration besides applying the plugin.
// Your plugin's jar (or shadowJar if present) will be used automatically.
minecraftVersion("1.21.4")
minecraftVersion(mainMinecraftVersion)
}
}

afterEvaluate {
tasks.withType(PublishToMavenRepository::class.java) {
dependsOn(tasks.assemble)
}
}

publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])

artifactId = project.name.lowercase()
pom {
packaging = "jar"
url.set("https://github.com/HydrolienF/${project.name}")
inceptionYear.set("2024")
description = project.description
licenses {
license {
name.set("MIT license")
url.set("https://github.com/HydrolienF/${project.name}/blob/master/LICENSE.md")
}
}
developers {
developer {
id.set("hydrolienf")
name.set("HydrolienF")
email.set("hydrolien.f@gmail.com")
}
}
scm {
connection.set("scm:git:git@github.com:HydrolienF/${project.name}.git")
developerConnection.set("scm:git:ssh:git@github.com:HydrolienF/${project.name}.git")
url.set("https://github.com/HydrolienF/${project.name}")
}
}
}
}
repositories {
maven {
url = layout.buildDirectory.dir("staging-deploy").get().asFile.toURI()

}
}
}

// Custom signing task using gpg -ab
val signWithGpg = tasks.register("signWithGpg") {
dependsOn("publishMavenJavaPublicationToMavenRepository")
group = "signing"
description = "Sign the publication using gpg -ab"
val filesToSign = fileTree("${buildDir}/staging-deploy/${project.group.toString().lowercase().replace('.', '/')}/${project.name.lowercase()}/${project.version}") {
include("**/*.jar", "**/*.module", "**/*.pom")
}
doFirst {
filesToSign.forEach { file ->
val command = listOf("gpg", "-ab", "--output", "${file.absolutePath}.asc", file.absolutePath)
println("Executing command: ${command.joinToString(" ")}")
exec {
commandLine = command
}
}
}
}

tasks.register<Zip>("zipStagingDeploy") {
dependsOn("signWithGpg")
dependsOn("publishMavenJavaPublicationToMavenRepository")
from(layout.buildDirectory.dir("staging-deploy"))
archiveFileName.set("staging-deploy-${project.name}-${project.version}.zip")
destinationDirectory.set(layout.buildDirectory)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.formiko.voidworldgenerator;
package fr.formiko.mc.voidworldgenerator;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -10,7 +10,7 @@
public class ConfigSettings {
private Registry<Biome> biomeRegistry;
private Map<String, BiomeAndSpawn> worldsSettings;
public ConfigSettings () {
public ConfigSettings() {
initBiomeRegistry();

worldsSettings = new HashMap<>();
Expand All @@ -19,61 +19,54 @@ public ConfigSettings () {

try {
config.getConfigurationSection("worlds").getKeys(false).forEach(world -> {
Biome biome = biomeRegistry == null ?
Biome.THE_VOID
: biomeRegistry.get(NamespacedKey.minecraft(config.getString("worlds." + world + ".emptyChunkBiome", "the_void").toLowerCase()));
if(biome == null) {
VoidWorldGeneratorPlugin.getInstance().getLogger().warning(() -> "Biome not found: " + config.getString("worlds." + world + ".emptyChunkBiome"));
Biome biome = biomeRegistry == null ? Biome.THE_VOID
: biomeRegistry.get(NamespacedKey
.minecraft(config.getString("worlds." + world + ".emptyChunkBiome", "the_void").toLowerCase()));
if (biome == null) {
VoidWorldGeneratorPlugin.getInstance().getLogger()
.warning(() -> "Biome not found: " + config.getString("worlds." + world + ".emptyChunkBiome"));
biome = Biome.THE_VOID;
}
int x = config.getInt("worlds." + world + ".spawn.x", 0);
int y = config.getInt("worlds." + world + ".spawn.y", 64);
int z = config.getInt("worlds." + world + ".spawn.z", 0);
worldsSettings.put(world, new BiomeAndSpawn(biome, x, y, z));
});
}catch (Exception e) {
} catch (Exception e) {
VoidWorldGeneratorPlugin.getInstance().getLogger().warning("Fail to read config, using default settings.");
worldsSettings.clear();
worldsSettings.put("*", defaultBiomeAndSpawn());
}
if(!worldsSettings.containsKey("*")) {
if (!worldsSettings.containsKey("*")) {
worldsSettings.put("*", defaultBiomeAndSpawn());
}

VoidWorldGeneratorPlugin.getInstance().getLogger().info("Config loaded: " + worldsSettings);
}

private BiomeAndSpawn defaultBiomeAndSpawn() {
return new BiomeAndSpawn(Biome.THE_VOID, 0, 64, 0);
}
private BiomeAndSpawn defaultBiomeAndSpawn() { return new BiomeAndSpawn(Biome.THE_VOID, 0, 64, 0); }

@SuppressWarnings({"unchecked", "rawtypes"})
private void initBiomeRegistry() {
try {
// biomeRegistry = io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(io.papermc.paper.registry.RegistryKey.BIOME);
// biomeRegistry =
// io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(io.papermc.paper.registry.RegistryKey.BIOME);
Class registryAccessClass = Class.forName("io.papermc.paper.registry.RegistryAccess");
Class registryKeyClass = Class.forName("io.papermc.paper.registry.RegistryKey");
Object biome = registryKeyClass.getField("BIOME").get(null);
Object registryAccess = registryAccessClass.getMethod("registryAccess").invoke(null);
biomeRegistry = (Registry<Biome>) registryAccess.getClass().getMethod("getRegistry", registryKeyClass).invoke(registryAccess, biome);
}catch (Exception e) {
biomeRegistry = (Registry<Biome>) registryAccess.getClass().getMethod("getRegistry", registryKeyClass).invoke(registryAccess,
biome);
} catch (Exception e) {
biomeRegistry = null;
VoidWorldGeneratorPlugin.getInstance().getLogger().info("Biome registry not found, using default biome.");
}
}

public Biome getBiome(String world) {
return worldsSettings.getOrDefault(world, worldsSettings.get("*")).biome;
}
public int getSpawnX(String world) {
return worldsSettings.getOrDefault(world, worldsSettings.get("*")).x;
}
public int getSpawnY(String world) {
return worldsSettings.getOrDefault(world, worldsSettings.get("*")).y;
}
public int getSpawnZ(String world) {
return worldsSettings.getOrDefault(world, worldsSettings.get("*")).z;
}
public Biome getBiome(String world) { return worldsSettings.getOrDefault(world, worldsSettings.get("*")).biome; }
public int getSpawnX(String world) { return worldsSettings.getOrDefault(world, worldsSettings.get("*")).x; }
public int getSpawnY(String world) { return worldsSettings.getOrDefault(world, worldsSettings.get("*")).y; }
public int getSpawnZ(String world) { return worldsSettings.getOrDefault(world, worldsSettings.get("*")).z; }

private record BiomeAndSpawn(Biome biome, int x, int y, int z) {}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.formiko.voidworldgenerator;
package fr.formiko.mc.voidworldgenerator;

import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -41,23 +41,23 @@ private class VoidChunkGenerator extends ChunkGenerator {
@Override
public void generateNoise(@NotNull WorldInfo worldInfo, @NotNull Random random, int chunkX, int chunkZ,
@NotNull ChunkData chunkData) {
// No need to generate noise, we want an empty world
}
// No need to generate noise, we want an empty world
}
@Override
public void generateSurface(@NotNull WorldInfo worldInfo, @NotNull Random random, int chunkX, int chunkZ,
@NotNull ChunkData chunkData) {
// No need to generate surface, we want an empty world
}
// No need to generate surface, we want an empty world
}
@Override
public void generateBedrock(@NotNull WorldInfo worldInfo, @NotNull Random random, int chunkX, int chunkZ,
@NotNull ChunkData chunkData) {
// No need to generate bedrock, we want an empty world
}
// No need to generate bedrock, we want an empty world
}
@Override
public void generateCaves(@NotNull WorldInfo worldInfo, @NotNull Random random, int chunkX, int chunkZ,
@NotNull ChunkData chunkData) {
// No need to generate caves, we want an empty world
}
// No need to generate caves, we want an empty world
}

@Override
@Nullable
Expand All @@ -68,7 +68,8 @@ public void generateCaves(@NotNull WorldInfo worldInfo, @NotNull Random random,

@Override
public Location getFixedSpawnLocation(World world, Random random) {
return new Location(world, configSettings.getSpawnX(worldName), configSettings.getSpawnY(worldName), configSettings.getSpawnZ(worldName));
return new Location(world, configSettings.getSpawnX(worldName), configSettings.getSpawnY(worldName),
configSettings.getSpawnZ(worldName));
}
}
private class VoidBiomeProvider extends BiomeProvider {
Expand Down

0 comments on commit 00b77d8

Please # to comment.