diff --git a/build.gradle b/build.gradle index ca92552..e36830e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,115 +1,101 @@ plugins { - id 'fabric-loom' version "${loom_version}" - id 'maven-publish' - id "org.jetbrains.kotlin.jvm" version "2.1.20" + id 'fabric-loom' version "${loom_version}" + id 'maven-publish' + id "org.jetbrains.kotlin.jvm" version "2.1.20" // Ensure your kotlin_version in gradle.properties matches or is compatible } version = project.mod_version group = project.maven_group base { - archivesName = project.archives_base_name + archivesName = project.archives_base_name } repositories { - mavenCentral() - - maven { - url 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/' - } - maven { - url 'https://maven.impactdev.net/repository/development/' - } - - maven { - url 'https://oss.sonatype.org/content/repositories/snapshots' - } - + mavenCentral() + maven { url 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/' } + maven { url 'https://maven.impactdev.net/repository/development/' } + maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } } loom { - splitEnvironmentSourceSets() - - mods { - "cobblesync" { - sourceSet sourceSets.main - sourceSet sourceSets.client - } - } + splitEnvironmentSourceSets() + mods { + "cobblesync" { + sourceSet sourceSets.main + sourceSet sourceSets.client + } + } } fabricApi { - configureDataGeneration { - client = true - } + configureDataGeneration { + client = true + } } dependencies { - // To change the versions see the gradle.properties file + // Minecraft & Fabric Loader minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings loom.officialMojangMappings() modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - // Fabric API. This is technically optional, but you probably want it anyway. + // Fabric API modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + // Fabric Kotlin Language Adapter modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}" + // Other Mod Dependencies (e.g., Cobblemon) modImplementation "com.cobblemon:fabric:1.6.0+1.21.1-SNAPSHOT" + + // JSON and GSON dependencies - add implementation first, then include + implementation "org.json:json:20231013" + include "org.json:json:20231013" + implementation "com.google.code.gson:gson:2.10.1" - implementation "org.json:json:20231013" // Or the latest version + include "com.google.code.gson:gson:2.10.1" } processResources { - inputs.property "version", project.version + inputs.property "version", project.version - filesMatching("fabric.mod.json") { - expand "version": inputs.properties.version - } + filesMatching("fabric.mod.json") { + expand "version": inputs.properties.version + } } tasks.withType(JavaCompile).configureEach { - it.options.release = 21 + it.options.release = 21 } tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { - kotlinOptions { - jvmTarget = 21 - } + kotlinOptions { + jvmTarget = "21" // Ensure jvmTarget is a string + } } java { - // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task - // if it is present. - // If you remove this line, sources will not be generated. - withSourcesJar() - - sourceCompatibility = JavaVersion.VERSION_21 - targetCompatibility = JavaVersion.VERSION_21 + withSourcesJar() + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 } jar { - inputs.property "archivesName", project.base.archivesName - - from("LICENSE") { - rename { "${it}_${inputs.properties.archivesName}"} - } + inputs.property "archivesName", project.base.archivesName + from("LICENSE") { + rename { "${it}_${inputs.properties.archivesName}"} + } } -// configure the maven publication publishing { - publications { - create("mavenJava", MavenPublication) { - artifactId = project.archives_base_name - from components.java - } - } - - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - // Notice: This block does NOT have the same function as the block in the top level. - // The repositories here will be used for publishing your artifact, not for - // retrieving dependencies. - } -} \ No newline at end of file + publications { + create("mavenJava", MavenPublication) { + artifactId = project.archives_base_name + from components.java + } + } + repositories { + // Add your publishing repositories here + } +} diff --git a/src/main/kotlin/co/sirblob/CobbleSync.kt b/src/main/kotlin/co/sirblob/CobbleSync.kt index 3680e7f..030f719 100644 --- a/src/main/kotlin/co/sirblob/CobbleSync.kt +++ b/src/main/kotlin/co/sirblob/CobbleSync.kt @@ -31,7 +31,7 @@ import org.slf4j.LoggerFactory object CobbleSync : ModInitializer { private val logger = LoggerFactory.getLogger("cobblesync") - private val request = Request("http://localhost:5173") + private val request = Request("https://authserver.sirblob.co") override fun onInitialize() { @@ -64,27 +64,24 @@ object CobbleSync : ModInitializer { return@Command 1 } + var obj = box30.saveToJSON(JsonObject(), player.registryAccess()) + + val payload = JSONObject() + .put("pokemon", obj.toString()) + .put("count", pokemonCount) + + logger.info("/api/cobblesync/" + player.uuid.toString()) + try { - - var obj = box30.saveToJSON(JsonObject(), player.registryAccess()) - - val payload = JSONObject() - .put("pokemon", obj.toString()) - .put("count", pokemonCount) - var response = request.POST("/api/cobblesync/" + player.uuid.toString(), payload) - - if (response.getInt("status") != 200) { - player.sendSystemMessage(Component.literal("Failed to sync box 1!").red()) - return@Command 1 - } + logger.info(response.toString()) - player.sendSystemMessage(Component.literal("Box 1 synced successfully!").green()) + player.sendSystemMessage(Component.literal("Box 30 synced successfully!").green()) } catch (e: HTTPException) { logger.error("HTTP Exception: ${e.message}") - player.sendSystemMessage(Component.literal("Error syncing box 1!").red()) + player.sendSystemMessage(Component.literal("Error syncing box 30!").red()) return@Command 1 } catch (e: Exception) { logger.error("Exception: ${e.message}") @@ -105,6 +102,16 @@ object CobbleSync : ModInitializer { var box1 = pc.boxes.get(0) + var pokemonCount = 0 + box1.pc.forEach({ _ -> + pokemonCount++ + }) + + if (pokemonCount > 0) { + player.sendSystemMessage(Component.literal("[Load Failed] Box 1 is not empty!").red()) + return@Command 1 + } + try { var response = request.GET("/api/cobblesync/" + player.uuid.toString()) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 42b1d34..02fe080 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -5,7 +5,7 @@ "name": "CobbleSync", "description": "This is an example description! Tell everyone what your mod is about!", "authors": [ - "Me!" + "Sir_Blob_" ], "contact": { "homepage": "https://fabricmc.net/",