diff --git a/TODO.md b/TODO.md index 0f4d592..1804060 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,5 @@ # TODO * Find a way to bypass the xaeros packets to enable entity radar. * Make a proper emc api library. -* Improve performance and try to decrease jar size. \ No newline at end of file +* Improve performance and try to decrease jar size. +* Improve testing. \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index b0c6fc6..2d1fc9d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,8 +4,9 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") version "2.2.10" id("fabric-loom") version "1.11-SNAPSHOT" - id("maven-publish") kotlin("plugin.serialization") version "1.9.10" + id("com.github.johnrengelman.shadow") version "8.1.1" + } version = project.property("mod_version") as String @@ -18,9 +19,6 @@ base { val targetJavaVersion = 21 java { toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) - // 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() } @@ -32,11 +30,6 @@ fabricApi { } repositories { - // Add repositories to retrieve artifacts from in here. - // You should only use this when depending on other mods because - // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. - // See https://docs.gradle.org/current/userguide/declaring_repositories.html - // for more information about repositories. maven ("https://maven.terraformersmc.com/") { name = "Terraformers" } @@ -45,6 +38,7 @@ repositories { } maven("https://maven.shedaniel.me/") maven("https://maven.isxander.dev/releases") + maven("https://jitpack.io") exclusiveContent { forRepository { maven("https://api.modrinth.com/maven") @@ -56,31 +50,54 @@ repositories { } +val shade: Configuration by configurations.creating { + isCanBeConsumed = false + isCanBeResolved = true + isVisible = false +} + +val mcVer = project.property("minecraft_version") +val mappings = project.property("yarn_mappings") + +val fabricVersion = project.property("fabric_version") +val fabricLoader = project.property("loader_version") +val kotlinLoader = project.property("kotlin_loader_version") +val ktSere = project.property("kt_sere") + +val xaerosVersion = project.property("xaeros_version") +val clothVersion = project.property("cloth_config") +val modmenu = project.property("modmenu") +val placeholderVersion = project.property("placeholder_api") + dependencies { - minecraft("com.mojang:minecraft:${project.property("minecraft_version")}") - mappings("net.fabricmc:yarn:${project.property("yarn_mappings")}:v2") + minecraft("com.mojang:minecraft:$mcVer") + mappings("net.fabricmc:yarn:$mappings:v2") compileOnly("org.jetbrains.kotlin:kotlin-stdlib") compileOnly("org.jetbrains.kotlin:kotlin-reflect") - compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3") + compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:$ktSere") - modImplementation("net.fabricmc:fabric-loader:${project.property("loader_version")}") - modImplementation("net.fabricmc:fabric-language-kotlin:${project.property("kotlin_loader_version")}") + modImplementation("net.fabricmc:fabric-loader:$fabricLoader") + modImplementation("net.fabricmc.fabric-api:fabric-api:$fabricVersion") - modImplementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabric_version")}") + modImplementation("net.fabricmc:fabric-language-kotlin:$kotlinLoader") - modImplementation("eu.pb4:placeholder-api:${project.property("placeholder_api")}") + modImplementation("eu.pb4:placeholder-api:$placeholderVersion") - modApi("me.shedaniel.cloth:cloth-config-fabric:${project.property("cloth_config")}") { + modApi("me.shedaniel.cloth:cloth-config-fabric:$clothVersion") { exclude("net.fabricmc.fabric-api") } - modApi("com.terraformersmc:modmenu:${project.property("modmenu")}") + modApi("com.terraformersmc:modmenu:$modmenu") + + implementation("com.github.breakthebot:breakthelibrary:1.0.4") + shade("com.github.breakthebot:breakthelibrary:1.0.4") { + isTransitive = false + } + modImplementation("maven.modrinth:xaeros-minimap:${project.property("xaeros_version")}") - testImplementation(kotlin("test")) - testImplementation("org.junit.jupiter:junit-jupiter:5.10.1") } tasks.processResources { @@ -92,22 +109,68 @@ tasks.processResources { filesMatching("fabric.mod.json") { expand( "version" to project.version, - "minecraft_version" to project.property("minecraft_version"), - "loader_version" to project.property("loader_version"), - "kotlin_loader_version" to project.property("kotlin_loader_version") + "minecraft_version" to mcVer, + "loader_version" to fabricLoader, + "kotlin_loader_version" to kotlinLoader, + "cloth_config" to clothVersion, + "placeholder_api" to placeholderVersion, + "modmenu" to modmenu ) } } tasks.withType().configureEach { - // ensure that the encoding is set to UTF-8, no matter what the system default is - // this fixes some edge cases with special characters not displaying correctly - // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html - // If Javadoc is generated, this must be specified in that task too. options.encoding = "UTF-8" options.release.set(targetJavaVersion) } +val headerText = file("header.txt").readText() + +val addHeader by tasks.registering { + group = "build" + + val targetFiles = fileTree("src") { + include("**/*.kt") + include("**/*.java") + } + + doLast { + targetFiles.forEach { file: File -> + val content = file.readText() + if (!content.startsWith(headerText)) { + file.writeText("$headerText\n$content") + } + } + } +} + +tasks.shadowJar { + dependsOn(tasks.jar) + + archiveClassifier.set("shadow-dev") + + configurations = listOf(shade) + + from(zipTree(tasks.jar.get().archiveFile)) + + relocate( + "org.breakthebot.breakthelibrary", + "net.chariskar.breakthebot.breakthelibrary" + ) +} + +val remapShadowJar by tasks.registering(net.fabricmc.loom.task.RemapJarTask::class) { + dependsOn(tasks.shadowJar) + inputFile.set(tasks.shadowJar.get().archiveFile) + archiveClassifier.set("shadowed") + + doLast { + delete(tasks.shadowJar.get().archiveFile.get().asFile) + } +} + +tasks["build"].dependsOn(addHeader, remapShadowJar) + tasks.withType().configureEach { compilerOptions.jvmTarget.set(JvmTarget.fromTarget(targetJavaVersion.toString())) } @@ -118,10 +181,6 @@ tasks.jar { } } -tasks.test { - useJUnitPlatform() -} - kotlin { compilerOptions { allWarningsAsErrors.set(true) diff --git a/gradle.properties b/gradle.properties index b790dfe..7f0f6d2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,4 +16,5 @@ fabric_version=0.136.0+1.21.8 xaeros_version=25.2.16_Fabric_1.21.8 placeholder_api=2.7.2+1.21.8 cloth_config=19.0.147 -modmenu=15.0.0 \ No newline at end of file +modmenu=15.0.0 +kt_sere = 1.6.3 diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/objects/Reference.kt b/header.txt similarity index 72% rename from src/main/kotlin/net/chariskar/breakthemod/client/objects/Reference.kt rename to header.txt index 0b321f7..b06f27c 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/objects/Reference.kt +++ b/header.txt @@ -14,13 +14,3 @@ * You should have received a copy of the GNU General Public License * along with breakthemod. If not, see . */ -package net.chariskar.breakthemod.client.objects - -import kotlinx.serialization.Serializable -import net.chariskar.breakthemod.client.utils.serialization.SerializableUUID - -@Serializable -data class Reference( - val uuid: SerializableUUID?, - val name: String? -) diff --git a/proguard-rules.pro b/proguard-rules.pro index 85ac0f8..becdce2 100644 --- a/proguard-rules.pro +++ b/proguard-rules.pro @@ -2,7 +2,7 @@ -dontnote -dontoptimize --injars build/libs/breakthemod-1.4.3.jar +-injars build/libs/breakthemod-1.4.5-shadowed.jar -outjars build/libs/btm-obf.jar -libraryjars /jmods/ @@ -14,16 +14,21 @@ -keep public class net.chariskar.breakthemod.Breakthemod { *; } --keep class net.chariskar.breakthemod.client.commands.** implements net.chariskar.breakthemod.client.api.* { *; } --keep class * implements net.fabricmc.api.ClientModInitializer { *; } --keep public class net.chariskar.breakthemod.client.api.** { *; } --keep public class net.chariskar.breakthemod.client.hooks.** { *; } +-keep class net.chariskar.breakthemod.client.commands.** implements net.chariskar.breakthemod.client.api.BaseCommand { *; } + +# -keep public class net.chariskar.breakthemod.Breakthemod implements net.fabricmc.api.ClientModInitializer { *; } + +-keep public class net.chariskar.breakthebot.breakthelibrary.models.** { *; } --keep class net.chariskar.breakthemod.client.utils.** { *; } -keep public class net.chariskar.breakthemod.mixins.** { *; } -keepclassmembers class kotlin.Metadata { *; } --keepattributes RuntimeVisibleAnnotations,RuntimeInvisibleAnnotations +-keepattributes RuntimeVisibleAnnotations, + RuntimeInvisibleAnnotations, + Signature, + InnerClasses, + EnclosingMethod, + Exceptions -keepdirectories META-INF/** -keepdirectories resources/** \ No newline at end of file diff --git a/src/main/java/net/chariskar/breakthemod/mixins/EntityRadar.java b/src/main/java/net/chariskar/breakthemod/mixins/EntityRadar.java index d67278d..3ec6fad 100644 --- a/src/main/java/net/chariskar/breakthemod/mixins/EntityRadar.java +++ b/src/main/java/net/chariskar/breakthemod/mixins/EntityRadar.java @@ -1,3 +1,20 @@ +/* + * This file is part of breakthemod. + * + * breakthemod is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * breakthemod is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with breakthemod. If not, see . + */ + package net.chariskar.breakthemod.mixins; diff --git a/src/main/java/net/chariskar/breakthemod/mixins/FairPlay.java b/src/main/java/net/chariskar/breakthemod/mixins/FairPlay.java index ca45d93..2ab571b 100644 --- a/src/main/java/net/chariskar/breakthemod/mixins/FairPlay.java +++ b/src/main/java/net/chariskar/breakthemod/mixins/FairPlay.java @@ -1,3 +1,20 @@ +/* + * This file is part of breakthemod. + * + * breakthemod is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * breakthemod is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with breakthemod. If not, see . + */ + package net.chariskar.breakthemod.mixins; diff --git a/src/main/java/net/chariskar/breakthemod/mixins/RadarStateAccessor.java b/src/main/java/net/chariskar/breakthemod/mixins/RadarStateAccessor.java index 893a49c..de718f1 100644 --- a/src/main/java/net/chariskar/breakthemod/mixins/RadarStateAccessor.java +++ b/src/main/java/net/chariskar/breakthemod/mixins/RadarStateAccessor.java @@ -1,3 +1,20 @@ +/* + * This file is part of breakthemod. + * + * breakthemod is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * breakthemod is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with breakthemod. If not, see . + */ + package net.chariskar.breakthemod.mixins; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/kotlin/net/chariskar/breakthemod/Breakthemod.kt b/src/main/kotlin/net/chariskar/breakthemod/Breakthemod.kt index 573a64a..7c36a96 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/Breakthemod.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/Breakthemod.kt @@ -16,18 +16,18 @@ */ package net.chariskar.breakthemod -import net.chariskar.breakthemod.client.api.Command +import net.chariskar.breakthemod.client.api.BaseCommand import net.chariskar.breakthemod.client.api.engine.NearbyEngine import net.chariskar.breakthemod.client.commands.Debug -import net.chariskar.breakthemod.client.commands.discordId +import net.chariskar.breakthemod.client.commands.DiscordId import net.chariskar.breakthemod.client.commands.FindPlayer import net.chariskar.breakthemod.client.commands.goto -import net.chariskar.breakthemod.client.commands.help -import net.chariskar.breakthemod.client.commands.lastSeen -import net.chariskar.breakthemod.client.commands.locate -import net.chariskar.breakthemod.client.commands.nearby -import net.chariskar.breakthemod.client.commands.onlineStaff -import net.chariskar.breakthemod.client.commands.townless +import net.chariskar.breakthemod.client.commands.Help +import net.chariskar.breakthemod.client.commands.LastSeen +import net.chariskar.breakthemod.client.commands.Locate +import net.chariskar.breakthemod.client.commands.Nearby +import net.chariskar.breakthemod.client.commands.OnlineStaff +import net.chariskar.breakthemod.client.commands.Townless import net.chariskar.breakthemod.client.hooks.nearby.Hud import net.chariskar.breakthemod.client.utils.Config import net.fabricmc.api.ClientModInitializer @@ -43,7 +43,7 @@ import com.mojang.brigadier.CommandDispatcher class Breakthemod : ClientModInitializer { val nearbyLayer: Identifier = Identifier.of("breakthemod", "nearby_layer") - private fun loadCommands(commands: MutableList) { + private fun loadCommands(commands: MutableList) { ClientCommandRegistrationCallback.EVENT.register(ClientCommandRegistrationCallback { dispatcher: CommandDispatcher, _: CommandRegistryAccess -> for (command in commands) { command.register(dispatcher) @@ -53,16 +53,16 @@ class Breakthemod : ClientModInitializer { override fun onInitializeClient() { Config.loadConfig() - val helpCmd = help() - val commandList: MutableList = mutableListOf( - nearby(), - onlineStaff(), - townless(), + val helpCmd = Help() + val commandList: MutableList = mutableListOf( + Nearby(), + OnlineStaff(), + Townless(), goto(), FindPlayer(), - lastSeen(), - discordId(), - locate(), + LastSeen(), + DiscordId(), + Locate(), Debug(), helpCmd ) diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/api/Command.kt b/src/main/kotlin/net/chariskar/breakthemod/client/api/BaseCommand.kt similarity index 98% rename from src/main/kotlin/net/chariskar/breakthemod/client/api/Command.kt rename to src/main/kotlin/net/chariskar/breakthemod/client/api/BaseCommand.kt index 10a029b..47531c2 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/api/Command.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/api/BaseCommand.kt @@ -44,9 +44,8 @@ private object CommandScope { } } -abstract class Command { +abstract class BaseCommand { val logger: Logger = LoggerFactory.getLogger("breakthemod") - val fetch: Fetch = Fetch val client: MinecraftClient = MinecraftClient.getInstance() protected val scope = CommandScope.scope diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/api/Fetch.kt b/src/main/kotlin/net/chariskar/breakthemod/client/api/Fetch.kt deleted file mode 100644 index eec79db..0000000 --- a/src/main/kotlin/net/chariskar/breakthemod/client/api/Fetch.kt +++ /dev/null @@ -1,203 +0,0 @@ -/* - * This file is part of breakthemod. - * - * breakthemod is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * breakthemod is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with breakthemod. If not, see . - */ -package net.chariskar.breakthemod.client.api - -import kotlinx.coroutines.future.await -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonArray -import kotlinx.serialization.json.JsonPrimitive -import kotlinx.serialization.json.buildJsonObject -import net.chariskar.breakthemod.client.objects.Nation -import net.chariskar.breakthemod.client.objects.Resident -import net.chariskar.breakthemod.client.objects.Town -import net.chariskar.breakthemod.client.utils.Config -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import java.net.URI -import java.net.http.HttpClient -import java.net.http.HttpRequest -import java.net.http.HttpResponse - - -object Fetch { - val logger: Logger = LoggerFactory.getLogger("breakthemod") - - val json: Json = Json { - ignoreUnknownKeys = true - } - - val client: HttpClient = HttpClient.newHttpClient() - - val urls = mapOf( - "towns" to "${Config.getApiUrl()}/towns", - "nations" to "${Config.getApiUrl()}/nations", - "players" to "${Config.getApiUrl()}/players", - "nearby" to "${Config.getApiUrl()}/nearby", - "discord" to "${Config.getApiUrl()}/discord", - "location" to "${Config.getApiUrl()}/location", - "staff" to Config.getStaffUrl() - ) - - /** - * Send a get request. - * @generic T the type to infer response to. - * @param url the url to send the request to. - */ - suspend inline fun getRequest(url: String): T? { - return try { - val request = HttpRequest.newBuilder() - .uri(URI(formatUrl(url))) - .header("Content-Type", "application/json") - .build() - val response = client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).await() - val body = response.body() - if (T::class == String::class) { body as T } - json.decodeFromString(body) - } catch (e: Exception) { - logError("Unable to send get request to target", e) - return null - } - } - - /** - * Sends a post request. - * @generic T the type to infer the response into - * @param url the url to send the request to - * @param body The body to attach to the url - */ - suspend inline fun postRequest(url: String, body: String): T? { - try { - val request = HttpRequest.newBuilder() - .uri(URI(formatUrl(url))) - .header("Content-Type", "application/json") - .POST(HttpRequest.BodyPublishers.ofString(body)) - .build() - - val response = client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).await() - var body = response.body() - if (body.startsWith("[[") && body.endsWith("]]")) { - body = body.substring(1, body.length - 1) - } - return if (T::class == String::class) { - body as T - } else { - json.decodeFromString(body) - } - } catch (e: Exception) { - logError("Unable to send request to target", e) - return null - } - } - - /** - * Sends a post request. - * only to be used for uuids/names. - * @generic T the type to infer the response into - * @param url the url to send the request to - * @param body The body to attach to the url - */ - suspend inline fun getUUIDs(url: String, body: String): T? { - try { - val uuids = body.removePrefix("[").removeSuffix("]").split(",").map { it.trim().removeSurrounding("\"") } - val jsonBody = buildJsonObject { - put("query", JsonArray(uuids.map { JsonPrimitive(it) })) - } - return postRequest(url, jsonBody.toString()) - } catch (e: Exception) { - logError("Unable to send request to target", e) - return null - } - } - - /** - * Sends a get request to the api. - * @generic T the type to infer the response into - * @param item The type of the item to fetch. - */ - @Suppress("unused") - suspend inline fun getAll(item: Items): List? { - return try { - val url: String = item.url - getRequest?>(url) - } catch (e: Exception) { - logError("Unable to fetch item", e) - null - } - } - - /** - * Sends a post request to the api. - * @generic T the type to infer the response into - * @param item The type of the item to fetch. - * @param body The body to send - */ - suspend inline fun getObjects(item: Items, body: String): List? { - return try { - val url: String = item.url - getUUIDs>(url, body) - } catch (e: Exception) { - logError("Unable to fetch item", e) - null - } - } - - /** - * List of items that can be looked up from the api, mapped to the url of each. - */ - enum class Items(val url: String) { - TOWN(urls["towns"]!!), - NATION(urls["nations"]!!), - PLAYER(urls["players"]!!), - NEARBY(urls["nearby"]!!), - DISCORD(urls["discord"]!!), - STAFF(urls["staff"]!!), - LOCATION(urls["location"]!!) - } - - suspend fun getResidents(residents: List): List? = getObjects(Items.PLAYER, residents.toString()) - - suspend fun getResident(resident: String): Resident? = getResidents(arrayListOf(resident))?.get(0) - - suspend fun getTowns(towns: List): List? = getObjects(Items.TOWN, towns.toString()) - - suspend fun getTown(town: String): Town? = getTowns(arrayListOf(town))?.get(0) - - suspend fun getNations(nations: List): List? = getObjects(Items.NATION, nations.toString()) - - suspend fun getNation(nation: String): Nation? = getNations(arrayListOf(nation))?.get(0) - - - fun logError(message: String?, e: java.lang.Exception) { - logger.error("{}{}", message, e.message) - if (Config.getDevMode()) { - e.printStackTrace() - } - } - - fun formatUrl(url: String): String { - if (url.isEmpty()) return url - val protocolEnd = url.indexOf("://") - if (protocolEnd == -1) return url - val protocol = url.take(protocolEnd + 3) - var rest = url.substring(protocolEnd + 3) - rest = rest.replace("/{2,}".toRegex(), "/") - if (rest.endsWith("/") && rest.length > 1) { - rest = rest.dropLast(1) - } - return protocol + rest - } -} \ No newline at end of file diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/api/engine/NearbyEngine.kt b/src/main/kotlin/net/chariskar/breakthemod/client/api/engine/NearbyEngine.kt index 4ad91f4..3a595b4 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/api/engine/NearbyEngine.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/api/engine/NearbyEngine.kt @@ -20,38 +20,25 @@ package net.chariskar.breakthemod.client.api.engine import kotlinx.coroutines.* import net.chariskar.breakthemod.client.utils.Config import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents -import net.minecraft.client.MinecraftClient import net.minecraft.entity.player.PlayerEntity -import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d -import net.minecraft.world.Heightmap import net.minecraft.world.World -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import kotlin.math.roundToInt -import kotlin.math.sqrt import java.util.concurrent.CopyOnWriteArraySet -private object EngineScope { - val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default) - fun shutdown() = scope.cancel() -} - object NearbyEngine { - val logger: Logger = LoggerFactory.getLogger("breakthemod") - - private const val UPDATE_INTERVAL_MS: Long = 500 private const val DISTANCE_THRESHOLD: Double = 200.0 - val scope: CoroutineScope get() = EngineScope.scope + val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default) private val playerInfoList: MutableSet = CopyOnWriteArraySet() - var engineRunning: Boolean = false - fun getPlayers(): Set { - return HashSet(playerInfoList) - } + fun getPlayers(): Set = HashSet(playerInfoList) + /** + * Checks if there are any players nearby. + * @param self The player entity + * @param world The client world + * */ fun updateNearbyPlayers( self: PlayerEntity, world: World @@ -62,7 +49,6 @@ object NearbyEngine { for (other in world.players) { if (other === self) continue - if (other.gameProfile.name == selfName) continue val info = PlayerInfo( other.gameProfile.name, @@ -83,7 +69,6 @@ object NearbyEngine { fun register() { ClientTickEvents.END_CLIENT_TICK.register { client -> if (!Config.config.radarEnabled) return@register - if (!engineRunning) return@register val player = client.player ?: return@register val world = client.world ?: return@register diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/api/engine/PlayerInfo.kt b/src/main/kotlin/net/chariskar/breakthemod/client/api/engine/PlayerInfo.kt index 981ce17..9288eda 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/api/engine/PlayerInfo.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/api/engine/PlayerInfo.kt @@ -1,3 +1,20 @@ +/* + * This file is part of breakthemod. + * + * breakthemod is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * breakthemod is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with breakthemod. If not, see . + */ + package net.chariskar.breakthemod.client.api.engine /* * This file is part of breakthemod. @@ -16,19 +33,16 @@ package net.chariskar.breakthemod.client.api.engine * along with breakthemod. If not, see . */ -import net.minecraft.block.ShapeContext import net.minecraft.client.MinecraftClient import net.minecraft.entity.player.PlayerEntity -import net.minecraft.util.hit.HitResult +import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d -import net.minecraft.world.RaycastContext import net.minecraft.world.World import kotlin.math.roundToInt import kotlin.math.sqrt - /** - * Wrapper class containing most nearby check methods. + * Helper class for the NearbyEngine. * @param name The name of the player. * @param position The position of the player. * */ @@ -43,32 +57,30 @@ data class PlayerInfo(val name: String, var position: Vec3d) { return dx * dx + dy * dy + dz * dz } - fun isUnderBlock(world: World): Boolean { - val from = position - val to = position.add(0.0, 256.0, 0.0) + fun isUnderBlock(world: World, pos: BlockPos): Boolean { + val topY = world.dimension.logicalHeight - val result = world.raycast( - RaycastContext( - from, - to, - RaycastContext.ShapeType.COLLIDER, - RaycastContext.FluidHandling.NONE, - ShapeContext.absent() - ) - ) - return result.type != HitResult.Type.MISS + for (y in pos.y + 1..topY) { + val checkPos = BlockPos(pos.x, y, pos.z) + val state = world.getBlockState(checkPos) + + if (!state.isAir) { + return true + } + } + return false } fun shouldSkipSpecial(player: PlayerEntity): Boolean { val isInVehicle = player.hasVehicle() val isSneaking = player.isSneaking val inRiptide = player.isUsingRiptide - val isInNether = MinecraftClient.getInstance().world?.registryKey?.value.toString().contains("nether") + val isInNether = MinecraftClient.getInstance() + .world?.registryKey?.value.toString().contains("nether") return isInVehicle || isSneaking || inRiptide || isInNether } - fun shouldSkip(player: PlayerEntity, world: World): Boolean = shouldSkipSpecial(player) || isUnderBlock(world) - + fun shouldSkip(player: PlayerEntity, world: World): Boolean = shouldSkipSpecial(player) || isUnderBlock(world, player.blockPos) fun directionFrom(player: PlayerEntity): String { val normalized = ((player.yaw + 180) % 360 + 360) % 360 diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/commands/Debug.kt b/src/main/kotlin/net/chariskar/breakthemod/client/commands/Debug.kt index b655cd3..e5a638c 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/commands/Debug.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/commands/Debug.kt @@ -1,7 +1,23 @@ +/* + * This file is part of breakthemod. + * + * breakthemod is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * breakthemod is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with breakthemod. If not, see . + */ package net.chariskar.breakthemod.client.commands import com.mojang.brigadier.context.CommandContext -import net.chariskar.breakthemod.client.api.Command +import net.chariskar.breakthemod.client.api.BaseCommand import net.chariskar.breakthemod.client.api.engine.NearbyEngine import net.chariskar.breakthemod.client.utils.Config import net.chariskar.breakthemod.client.utils.ServerUtils @@ -9,11 +25,9 @@ import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource import net.minecraft.client.MinecraftClient import net.minecraft.text.Text -class Debug : Command() { +class Debug : BaseCommand() { init { name = "btmdbg" - description = "" - usageSuffix = "" } override fun execute(ctx: CommandContext): Int { @@ -22,7 +36,7 @@ class Debug : Command() { Text.literal("players" + MinecraftClient.getInstance().world?.players) ) sendMessage( - Text.literal("Nearby engine state: Running(${NearbyEngine.engineRunning}), Players(${NearbyEngine.getPlayers()})") + Text.literal("Nearby engine state: Running(${Config.getRadar()}), Players(${NearbyEngine.getPlayers()})") ) sendMessage( Text.literal("Server status: isEmc(${ServerUtils.isEarthMc()}), enabled(${ServerUtils.getEnabled()})") diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/commands/discordId.kt b/src/main/kotlin/net/chariskar/breakthemod/client/commands/DiscordId.kt similarity index 70% rename from src/main/kotlin/net/chariskar/breakthemod/client/commands/discordId.kt rename to src/main/kotlin/net/chariskar/breakthemod/client/commands/DiscordId.kt index c26d3e4..e086933 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/commands/discordId.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/commands/DiscordId.kt @@ -1,3 +1,19 @@ +/* + * This file is part of breakthemod. + * + * breakthemod is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * breakthemod is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with breakthemod. If not, see . + */ package net.chariskar.breakthemod.client.commands import com.mojang.brigadier.Command as command @@ -7,25 +23,22 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder import com.mojang.brigadier.builder.RequiredArgumentBuilder import com.mojang.brigadier.context.CommandContext import kotlinx.coroutines.launch -import kotlinx.serialization.Serializable -import kotlinx.serialization.json.JsonArray -import kotlinx.serialization.json.buildJsonObject -import kotlinx.serialization.json.encodeToJsonElement -import net.chariskar.breakthemod.client.api.Command -import net.chariskar.breakthemod.client.api.Fetch -import net.chariskar.breakthemod.client.api.Fetch.json +import net.chariskar.breakthemod.client.api.BaseCommand import net.chariskar.breakthemod.client.utils.ServerUtils.getEnabled -import net.chariskar.breakthemod.client.utils.serialization.SerializableUUID import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource import net.minecraft.text.ClickEvent import net.minecraft.text.Style import net.minecraft.text.Text import net.minecraft.util.Formatting +import org.breakthebot.breakthelibrary.api.DiscordAPI +import org.breakthebot.breakthelibrary.models.DiscordPayloadMinecraft +import org.breakthebot.breakthelibrary.network.Fetch +import org.breakthebot.breakthelibrary.utils.SerializableUUID import java.net.URI import java.util.* -class discordId : Command() { +class DiscordId : BaseCommand() { init { name = "discordLinked" @@ -46,17 +59,10 @@ class discordId : Command() { return uuid.matches("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$".toRegex()) } - @Serializable - data class discordPayload( - val type: String, - val target: SerializableUUID - ) - - override fun execute(ctx: CommandContext): Int { val name: String = ctx.getArgument("name", String::class.java) scope.launch { - val mojangResponse = Fetch.getRequest("https://api.mojang.com/users/profiles/minecraft/$name") + val mojangResponse = Fetch.getRequest("https://api.mojang.com/users/profiles/minecraft/$name") val rawUuid = mojangResponse?.split(",")[0]?.split(":")[1] if (rawUuid == null) { @@ -72,25 +78,14 @@ class discordId : Command() { val uuid = UUID.fromString(formattedUuid) - val payload = buildJsonObject { - put( - "query", - JsonArray(listOf(json.encodeToJsonElement(discordPayload( - "minecraft", - SerializableUUID(uuid) - )))) - ) - } - - val emcResp = Fetch.postRequest(Fetch.Items.DISCORD.url, payload.toString()) - val userId = emcResp?.split(",")[0]?.split(":")[1]?.replace("\"", "")?.trim() + val discord = DiscordAPI.getDiscord(listOf(DiscordPayloadMinecraft( target = SerializableUUID(uuid) )))?.first() val result: Text = Text.literal("Click Here") .setStyle( Style.EMPTY .withColor(Formatting.BLUE) .withClickEvent( - ClickEvent.OpenUrl(URI("https://discord.com/users/$userId")) + ClickEvent.OpenUrl(URI("https://discord.com/users/${discord?.id}")) ) ) diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/commands/FindPlayer.kt b/src/main/kotlin/net/chariskar/breakthemod/client/commands/FindPlayer.kt index c3c4a53..c91244e 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/commands/FindPlayer.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/commands/FindPlayer.kt @@ -1,60 +1,60 @@ +/* + * This file is part of breakthemod. + * + * breakthemod is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * breakthemod is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with breakthemod. If not, see . + */ package net.chariskar.breakthemod.client.commands -import com.mojang.brigadier.Command as command +import com.mojang.brigadier.Command import com.mojang.brigadier.CommandDispatcher import com.mojang.brigadier.arguments.StringArgumentType import com.mojang.brigadier.builder.LiteralArgumentBuilder import com.mojang.brigadier.builder.RequiredArgumentBuilder import com.mojang.brigadier.context.CommandContext +import com.mojang.brigadier.exceptions.CommandSyntaxException +import com.mojang.brigadier.suggestion.SuggestionProvider +import com.mojang.brigadier.suggestion.Suggestions +import com.mojang.brigadier.suggestion.SuggestionsBuilder import kotlinx.coroutines.launch -import kotlinx.serialization.Serializable -import kotlinx.serialization.json.Json -import net.chariskar.breakthemod.client.api.Command -import net.chariskar.breakthemod.client.api.Fetch -import net.chariskar.breakthemod.client.objects.Location -import net.chariskar.breakthemod.client.objects.PlayerLocationInfo -import net.chariskar.breakthemod.client.utils.Config +import net.chariskar.breakthemod.client.api.BaseCommand import net.chariskar.breakthemod.client.utils.ServerUtils.getEnabled import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource +import net.minecraft.client.MinecraftClient import net.minecraft.text.Text import net.minecraft.util.Formatting +import org.breakthebot.breakthelibrary.api.LocationAPI +import org.breakthebot.breakthelibrary.models.PlayerLocationInfo +import java.util.Locale +import java.util.concurrent.CompletableFuture -class FindPlayer : Command() { +class FindPlayer : BaseCommand() { init { name = "findPlayer" description = "Tells you where a player is based on the map api." usageSuffix = "" } - - @Serializable - data class Payload( - val query: List> - ) - - @Serializable - data class MapResponse( - val name: String? = null, - val x: Double, - val z: Double - ) - - @Serializable - data class ApiResponse( - val max: Int? = null, - val players: MutableList? = null - ) - override fun execute(ctx: CommandContext): Int { val name: String = ctx.getArgument("name", String::class.java) scope.launch { - val players: MutableList? = Fetch.getRequest(Config.getMapUrl() + "tiles/players.json")!!.players + val players = LocationAPI.getVisiblePlayers() if (players.isNullOrEmpty()) { sendMessage(Text.literal("Received empty player list from map."), Formatting.RED) return@launch } - val playerData = PlayerLocationInfo(name, 0.0, 0.0, false,null, false) + val playerData = PlayerLocationInfo(name, 0.0, 0.0, false, null, false) for (player in players) { if (player.name.equals(name, ignoreCase = true)) { @@ -62,10 +62,9 @@ class FindPlayer : Command() { playerData.x = player.x playerData.z = player.z - val coords = listOf(player.x, player.z) - val payload = Payload(listOf(coords)) - - val locationData: Location? = Fetch.postRequest>(Fetch.Items.LOCATION.url, Json.encodeToString(payload))?.first() + val locationData = LocationAPI.getLocation(listOf( + Pair(player.x,player.z) + ))?.first() if (locationData != null && locationData.isWilderness == false) { playerData.townName = locationData.town?.name @@ -85,11 +84,30 @@ class FindPlayer : Command() { LiteralArgumentBuilder.literal(name) .then( RequiredArgumentBuilder.argument("name", StringArgumentType.string()) - .executes(command { context: CommandContext -> - if (!getEnabled()) return@command 0 - return@command run(context) + .suggests(FindPlayerSuggestion()) + .executes(Command { context: CommandContext -> + if (!getEnabled()) return@Command 0 + return@Command run(context) }) ) ) } + + class FindPlayerSuggestion : SuggestionProvider { + + @Throws(CommandSyntaxException::class) + override fun getSuggestions( + context: CommandContext?, + builder: SuggestionsBuilder + ): CompletableFuture { + val input = builder.remaining.lowercase(Locale.getDefault()) + + val players = MinecraftClient.getInstance().world?.players?.map { it.gameProfile.name } + players?.stream() + ?.filter { s -> s?.startsWith(input) == true } + ?.forEach(builder::suggest) + + return builder.buildFuture() + } + } } \ No newline at end of file diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/commands/help.kt b/src/main/kotlin/net/chariskar/breakthemod/client/commands/Help.kt similarity index 93% rename from src/main/kotlin/net/chariskar/breakthemod/client/commands/help.kt rename to src/main/kotlin/net/chariskar/breakthemod/client/commands/Help.kt index 98c1d26..56ec1b0 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/commands/help.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/commands/Help.kt @@ -18,7 +18,7 @@ package net.chariskar.breakthemod.client.commands import com.mojang.brigadier.context.CommandContext -import net.chariskar.breakthemod.client.api.Command +import net.chariskar.breakthemod.client.api.BaseCommand import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource import net.minecraft.text.MutableText import net.minecraft.text.Style @@ -26,8 +26,8 @@ import net.minecraft.text.Text import net.minecraft.util.Formatting -class help : Command() { - var commands: MutableList? = null +class Help : BaseCommand() { + var commands: MutableList? = null init { name = "commands" diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/commands/lastSeen.kt b/src/main/kotlin/net/chariskar/breakthemod/client/commands/LastSeen.kt similarity index 72% rename from src/main/kotlin/net/chariskar/breakthemod/client/commands/lastSeen.kt rename to src/main/kotlin/net/chariskar/breakthemod/client/commands/LastSeen.kt index 3d10a0e..ebb0b9f 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/commands/lastSeen.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/commands/LastSeen.kt @@ -1,3 +1,19 @@ +/* + * This file is part of breakthemod. + * + * breakthemod is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * breakthemod is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with breakthemod. If not, see . + */ package net.chariskar.breakthemod.client.commands import com.mojang.brigadier.Command as command @@ -7,15 +23,15 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder import com.mojang.brigadier.builder.RequiredArgumentBuilder import com.mojang.brigadier.context.CommandContext import kotlinx.coroutines.launch -import net.chariskar.breakthemod.client.api.Command -import net.chariskar.breakthemod.client.objects.Resident +import net.chariskar.breakthemod.client.api.BaseCommand import net.chariskar.breakthemod.client.utils.ServerUtils.getEnabled import net.chariskar.breakthemod.client.utils.Timestamps import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource import net.minecraft.text.Text import net.minecraft.util.Formatting +import org.breakthebot.breakthelibrary.api.PlayerAPI -class lastSeen : Command() { +class LastSeen : BaseCommand() { init { name = "lastSeen" description = "Shows the last time a user was online" @@ -25,7 +41,7 @@ class lastSeen : Command() { override fun execute(ctx: CommandContext): Int { val name: String = ctx.getArgument("name", String::class.java) scope.launch { - val player: Resident? = fetch.getResident(name) + val player = PlayerAPI.getPlayer(name) if (player == null) { sendMessage(Text.literal("Unable to find $name"), Formatting.RED) return@launch diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/commands/locate.kt b/src/main/kotlin/net/chariskar/breakthemod/client/commands/Locate.kt similarity index 73% rename from src/main/kotlin/net/chariskar/breakthemod/client/commands/locate.kt rename to src/main/kotlin/net/chariskar/breakthemod/client/commands/Locate.kt index e7a286c..322d59b 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/commands/locate.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/commands/Locate.kt @@ -1,3 +1,20 @@ +/* + * This file is part of breakthemod. + * + * breakthemod is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * breakthemod is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with breakthemod. If not, see . + */ + package net.chariskar.breakthemod.client.commands import com.mojang.brigadier.CommandDispatcher @@ -10,9 +27,7 @@ import com.mojang.brigadier.suggestion.SuggestionProvider import com.mojang.brigadier.suggestion.Suggestions import com.mojang.brigadier.suggestion.SuggestionsBuilder import kotlinx.coroutines.launch -import kotlinx.serialization.Serializable -import net.chariskar.breakthemod.client.api.Command -import net.chariskar.breakthemod.client.api.Fetch +import net.chariskar.breakthemod.client.api.BaseCommand import net.chariskar.breakthemod.client.utils.Config import net.chariskar.breakthemod.client.utils.ServerUtils.getEnabled import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource @@ -20,21 +35,21 @@ import net.minecraft.text.ClickEvent import net.minecraft.text.Style import net.minecraft.text.Text import net.minecraft.util.Formatting +import org.breakthebot.breakthelibrary.api.NationAPI +import org.breakthebot.breakthelibrary.api.TownAPI import java.net.URI import java.util.* import java.util.concurrent.CompletableFuture import com.mojang.brigadier.Command as command -class locate : Command() { +class Locate : BaseCommand() { init { name = "locate" description = "Gives you the coordinates of a town/nation." usageSuffix = " " } - - @Serializable /** * trying a more object-oriented style. * */ @@ -45,11 +60,11 @@ class locate : Command() { suspend fun get(): Pair? { when (type) { "town" -> { - val town = Fetch.getTown(name) ?: return null - return Pair(town.coordinates?.spawn?.x!!, town.coordinates.spawn.z!!) // we dont need NPE cause every town HAS to have a spawn so we can just tell kotlin to fuck off + val town = TownAPI.getTown(name) ?: return null + return Pair(town.coordinates?.spawn?.x!!, town.coordinates!!.spawn!!.z!!) } "nation" -> { - val nation = Fetch.getNation(name) ?: return null + val nation = NationAPI.getNation(name) ?: return null return Pair(nation.coordinates?.spawn?.x!!, nation.coordinates?.spawn?.z!!) } } @@ -70,12 +85,12 @@ class locate : Command() { Style.EMPTY .withColor(Formatting.BLUE) .withClickEvent( - ClickEvent.OpenUrl(URI("${Config.getMapUrl()}?world=minecraft_overworld&zoom=3&x=${coords?.first}&z=${coords?.second}")) + ClickEvent.OpenUrl(URI("${Config.getMapUrl()}?world=minecraft_overworld&zoom=3&x=${coords.first}&z=${coords.second}")) ) ) - sendMessage(Text.literal("$name is located at x: ${coords?.first}, z: ${coords?.second} ").append(link)) + sendMessage(Text.literal("$name is located at x: ${coords.first}, z: ${coords.second} ").append(link)) } return 0 @@ -99,17 +114,17 @@ class locate : Command() { } class LocateSuggestion : SuggestionProvider { - val allSuggestions: MutableList = mutableListOf("town", "nation") + val allSuggestions: MutableList = mutableListOf("town", "nation") @Throws(CommandSyntaxException::class) override fun getSuggestions( context: CommandContext?, builder: SuggestionsBuilder ): CompletableFuture { - val input = builder.getRemaining().lowercase(Locale.getDefault()) + val input = builder.remaining.lowercase(Locale.getDefault()) allSuggestions.stream() - .filter({ s -> s?.startsWith(input) == true }) + .filter { s -> s?.startsWith(input) == true } .forEach(builder::suggest) return builder.buildFuture() diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/commands/nearby.kt b/src/main/kotlin/net/chariskar/breakthemod/client/commands/Nearby.kt similarity index 66% rename from src/main/kotlin/net/chariskar/breakthemod/client/commands/nearby.kt rename to src/main/kotlin/net/chariskar/breakthemod/client/commands/Nearby.kt index 161c269..bf43223 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/commands/nearby.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/commands/Nearby.kt @@ -1,8 +1,24 @@ +/* + * This file is part of breakthemod. + * + * breakthemod is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * breakthemod is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with breakthemod. If not, see . + */ package net.chariskar.breakthemod.client.commands import com.mojang.brigadier.context.CommandContext import kotlinx.coroutines.launch -import net.chariskar.breakthemod.client.api.Command +import net.chariskar.breakthemod.client.api.BaseCommand import net.chariskar.breakthemod.client.api.engine.NearbyEngine import net.chariskar.breakthemod.client.api.engine.PlayerInfo import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource @@ -13,7 +29,7 @@ import net.minecraft.text.TextColor import net.minecraft.util.Formatting -class nearby : Command() { +class Nearby : BaseCommand() { init { name = "nearby" diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/commands/onlineStaff.kt b/src/main/kotlin/net/chariskar/breakthemod/client/commands/OnlineStaff.kt similarity index 87% rename from src/main/kotlin/net/chariskar/breakthemod/client/commands/onlineStaff.kt rename to src/main/kotlin/net/chariskar/breakthemod/client/commands/OnlineStaff.kt index 107d609..2a5553f 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/commands/onlineStaff.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/commands/OnlineStaff.kt @@ -24,22 +24,18 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder import com.mojang.brigadier.builder.RequiredArgumentBuilder import com.mojang.brigadier.context.CommandContext import kotlinx.coroutines.launch -import net.chariskar.breakthemod.client.api.Fetch -import net.chariskar.breakthemod.client.api.Fetch.Items -import net.chariskar.breakthemod.client.objects.Resident -import net.chariskar.breakthemod.client.objects.StaffList import net.chariskar.breakthemod.client.utils.ServerUtils.getEnabled -import net.chariskar.breakthemod.client.utils.serialization.SerializableUUID import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource import net.minecraft.text.MutableText import net.minecraft.text.Style import net.minecraft.text.Text import net.minecraft.util.Formatting -import java.util.* -import net.chariskar.breakthemod.client.api.Command as command +import org.breakthebot.breakthelibrary.api.PlayerAPI +import org.breakthebot.breakthelibrary.api.StaffAPI +import net.chariskar.breakthemod.client.api.BaseCommand as command -class onlineStaff : command() { +class OnlineStaff : command() { init { name = "onlinestaff" description = "Shows online staff" @@ -66,7 +62,7 @@ class onlineStaff : command() { suspend fun onlineStaff(api: Boolean): Text { - val staff: List? = fetch.getRequest(Items.STAFF.url)?.allStaff() + val staff = StaffAPI.get() if (staff.isNullOrEmpty()) return Text.literal("Received invalid staff list.").setStyle(Style.EMPTY.withColor(Formatting.RED)) @@ -74,7 +70,7 @@ class onlineStaff : command() { var message: MutableText val staffNames: List = if (api) { - fetch.getObjects(Items.PLAYER, staff.map { v->v.toUUID() }.toString() )!! + PlayerAPI.getPlayers( staff.map { v->v.toString() } )!! .filter { r -> r.status!!.isOnline == true } .map { r -> r.name } } else { diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/commands/townless.kt b/src/main/kotlin/net/chariskar/breakthemod/client/commands/Townless.kt similarity index 82% rename from src/main/kotlin/net/chariskar/breakthemod/client/commands/townless.kt rename to src/main/kotlin/net/chariskar/breakthemod/client/commands/Townless.kt index b4fbdf4..3b28f81 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/commands/townless.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/commands/Townless.kt @@ -18,9 +18,7 @@ package net.chariskar.breakthemod.client.commands import com.mojang.brigadier.context.CommandContext import kotlinx.coroutines.launch -import net.chariskar.breakthemod.client.api.Command -import net.chariskar.breakthemod.client.api.Fetch -import net.chariskar.breakthemod.client.objects.Resident +import net.chariskar.breakthemod.client.api.BaseCommand import net.chariskar.breakthemod.client.utils.Config import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource import net.minecraft.text.ClickEvent @@ -28,10 +26,11 @@ import net.minecraft.text.HoverEvent import net.minecraft.text.Style import net.minecraft.text.Text import net.minecraft.util.Formatting -import java.util.* +import org.breakthebot.breakthelibrary.api.PlayerAPI +import java.util.UUID -class townless : Command() { +class Townless : BaseCommand() { val batchSize: Int = 100 init { @@ -47,8 +46,9 @@ class townless : Command() { sendMessage(Text.literal("No online players found")) return@launch } - val own: Resident = Fetch.getResident(client.session.username)!! - if (own.town?.name.isNullOrEmpty()) return@launch + val own = PlayerAPI.getPlayer(client.session.username) + + if (own?.town?.name.isNullOrEmpty()) return@launch val townless: MutableList = mutableListOf() val batch: MutableList = mutableListOf() @@ -56,24 +56,24 @@ class townless : Command() { for (p in onlinePlayers) { batch.add(p) if (batch.size == batchSize) { - val players: List? = fetch.getResidents(batch.map { u -> u.toString() }) + val players = PlayerAPI.getPlayers(batch.map { u -> u.toString() }) if (players.isNullOrEmpty()) { logger.warn("Received empty batch on townless") } players?.forEach { p -> - if (p?.status?.hasTown == false) townless.add(p.name) + if (p.status?.hasTown == false) townless.add(p.name) } batch.clear() } } if (batch.isNotEmpty()) { - val players: List? = fetch.getResidents(batch.map { it.toString() }) + val players = PlayerAPI.getPlayers(batch.map { it.toString() }) if (players.isNullOrEmpty()) { logger.warn("Received empty batch on townless") } else { players.forEach { resident -> - if (resident?.status?.hasTown == false) { + if (resident.status?.hasTown == false) { townless.add(resident.name) } } @@ -95,6 +95,7 @@ class townless : Command() { message.append(userText).append(Text.literal("\n")) } + sendMessage(message) } return 0 diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/commands/goto.kt b/src/main/kotlin/net/chariskar/breakthemod/client/commands/goto.kt index cef11b7..f01f3f2 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/commands/goto.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/commands/goto.kt @@ -1,3 +1,19 @@ +/* + * This file is part of breakthemod. + * + * breakthemod is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * breakthemod is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with breakthemod. If not, see . + */ package net.chariskar.breakthemod.client.commands import com.mojang.brigadier.Command as command @@ -7,20 +23,19 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder import com.mojang.brigadier.builder.RequiredArgumentBuilder import com.mojang.brigadier.context.CommandContext import kotlinx.coroutines.launch -import kotlinx.serialization.json.buildJsonObject -import kotlinx.serialization.json.put -import kotlinx.serialization.json.putJsonArray -import net.chariskar.breakthemod.client.api.Command -import net.chariskar.breakthemod.client.api.Fetch -import net.chariskar.breakthemod.client.objects.Reference -import net.chariskar.breakthemod.client.objects.Town +import net.chariskar.breakthemod.client.api.BaseCommand import net.chariskar.breakthemod.client.utils.ServerUtils.getEnabled import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource import net.minecraft.text.MutableText import net.minecraft.text.Text import net.minecraft.util.Formatting +import org.breakthebot.breakthelibrary.api.NationAPI +import org.breakthebot.breakthelibrary.api.NearbyAPI +import org.breakthebot.breakthelibrary.api.TownAPI +import org.breakthebot.breakthelibrary.models.NearbyItem +import org.breakthebot.breakthelibrary.models.NearbyType -class goto: Command() { +class goto: BaseCommand() { init { name = "goto" description = "Shows you the nearest spawnable town of the town you selected." @@ -31,19 +46,21 @@ class goto: Command() { scope.launch { try { - val reqTown: Town? = fetch.getTown(townName) + val reqTown = TownAPI.getTown(townName) + if (reqTown == null) { sendMessage(Text.literal("$townName isn't a real town."), Formatting.RED) return@launch } - if (reqTown.status?.isPublic == true && reqTown.status.canOutsidersSpawn == true) { + if (reqTown.status?.isPublic == true && reqTown.status?.canOutsidersSpawn == true) { sendMessage(Text.literal("You can do /t spawn ${reqTown.name}"), Formatting.AQUA) return@launch } if (reqTown.status?.isCapital == true) { - val nation = fetch.getNation(reqTown.nation?.uuid.toString()) + val nation = NationAPI.getNation(reqTown.nation?.name!!) + if (nation?.status?.isPublic == true) { sendMessage(Text.literal("Found suitable spawn in:\n ${reqTown.name} (${nation.name})"), Formatting.AQUA) return@launch @@ -55,21 +72,13 @@ class goto: Command() { val validTowns: MutableList = mutableListOf() while (attempts-- > 0) { - val query = buildJsonObject { - put("target_type", "TOWN") - put("target", townName) - put("search_type", "TOWN") - put("radius", radius) - } - val body = buildJsonObject { - putJsonArray("query") { add(query) } - } - - val resp: List? = Fetch.postRequest>( - Fetch.Items.NEARBY.url, - body.toString() - ) + val resp = NearbyAPI.get(NearbyItem( + NearbyType.TOWN, + townName, + NearbyType.TOWN, + radius + )) val names: List = resp?.mapNotNull { it.name } ?: emptyList() if (names.isEmpty()) { @@ -77,19 +86,19 @@ class goto: Command() { continue } - val townDetails: List? = fetch.getTowns(names) + val townDetails = TownAPI.getTowns(names) + if (townDetails.isNullOrEmpty()) { radius += 500 continue } for (town in townDetails) { - if (town == null) continue val status = town.status if (status?.isPublic == true && status.canOutsidersSpawn == true) { validTowns.add(town.name) } else if (status?.isCapital == true) { - val nation = fetch.getNation(town.nation?.uuid.toString()) + val nation = NationAPI.getNation(town.nation?.name!!) if (nation?.status?.isPublic == true) { validTowns.add(town.name) } diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/hooks/nearby/Hud.kt b/src/main/kotlin/net/chariskar/breakthemod/client/hooks/nearby/Hud.kt index 7fefd39..7274561 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/hooks/nearby/Hud.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/hooks/nearby/Hud.kt @@ -17,50 +17,31 @@ package net.chariskar.breakthemod.client.hooks.nearby -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.launch import net.chariskar.breakthemod.client.api.engine.NearbyEngine import net.chariskar.breakthemod.client.utils.Config import net.chariskar.breakthemod.client.utils.Config.WidgetPosition +import net.chariskar.breakthemod.client.utils.ServerUtils import net.minecraft.client.MinecraftClient import net.minecraft.client.font.TextRenderer import net.minecraft.client.gui.DrawContext -import java.util.concurrent.CopyOnWriteArrayList object Hud { - private val client = MinecraftClient.getInstance() - private val engine = NearbyEngine - private val engineScope: CoroutineScope = NearbyEngine.scope - private val playerList: MutableList = CopyOnWriteArrayList() - var widgetPosition: Config.Widget = Config.getWidget() private var x: Int = 0 private var y: Int = 0 - init { - engineScope.launch { - while (Config.getRadar()) { - val players = engine.getPlayers() - synchronized(playerList) { - playerList.clear() - if (players.isEmpty()) { - playerList.add("No players nearby") - } else { - playerList.addAll(players.map { it.toString() }) - } - } - kotlinx.coroutines.delay(200) - } - } - } - - @Synchronized fun render(drawContext: DrawContext) { if (client.options.hudHidden || client.world == null || client.player == null) return - if (!Config.getRadar() || !Config.getEnabledServers()) return + if (!Config.getRadar() || !ServerUtils.getEnabled()) return + val players = NearbyEngine.getPlayers() + + val playerList = if (players.isEmpty()) { + listOf("No players nearby") + } else players.map { it.toString() } + val margin = Config.getWidget().margin val entryHeight = Config.getWidget().entryHeight diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/objects/Coordinates.kt b/src/main/kotlin/net/chariskar/breakthemod/client/objects/Coordinates.kt deleted file mode 100644 index 389fe06..0000000 --- a/src/main/kotlin/net/chariskar/breakthemod/client/objects/Coordinates.kt +++ /dev/null @@ -1,10 +0,0 @@ -package net.chariskar.breakthemod.client.objects - -import kotlinx.serialization.Serializable - -@Serializable -data class Coordinates( - val x: Double? = null, - val y: Double? = null, - val z: Double? = null -) \ No newline at end of file diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/objects/Location.kt b/src/main/kotlin/net/chariskar/breakthemod/client/objects/Location.kt deleted file mode 100644 index ff69f88..0000000 --- a/src/main/kotlin/net/chariskar/breakthemod/client/objects/Location.kt +++ /dev/null @@ -1,12 +0,0 @@ -package net.chariskar.breakthemod.client.objects - -import kotlinx.serialization.Serializable - -@Serializable -data class Location ( - val name: String? = null, - val location: Coordinates? = null, - val isWilderness: Boolean? = null, - val town: Reference? = null, - val nation: Reference? = null -) \ No newline at end of file diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/objects/Nation.kt b/src/main/kotlin/net/chariskar/breakthemod/client/objects/Nation.kt deleted file mode 100644 index e731e5e..0000000 --- a/src/main/kotlin/net/chariskar/breakthemod/client/objects/Nation.kt +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This file is part of breakthemod. - * - * breakthemod is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * breakthemod is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with breakthemod. If not, see . - */ - -package net.chariskar.breakthemod.client.objects - -import kotlinx.serialization.Serializable -import net.chariskar.breakthemod.client.utils.serialization.SerializableUUID - - -@Serializable -class Nation(val name: String) { - val uuid: SerializableUUID? = null - var board: String? = null -// var dynmapColour: String? = null -// var dynmapOutline: String? = null -// var wiki: String? = null -// var king: Reference? = null -// var capital: Reference? = null -// var timestamps: Timestamps? = null - var status: Status? = null -// var stats: Stats? = null -var coordinates: Coordinates? = null -// var residents: List? = null -// var towns: List? = null -// var allies: List? = null -// var enemies: List? = null -// var sanctioned: List? = null -// var ranks: Ranks? = null - - //@Serializable -// data class Timestamps( -// var registered: Long? = null -// ) - - @Serializable - data class Status( - var isPublic: Boolean? = null, - var isOpen: Boolean? = null, - var isNeutral: Boolean? = null - ) - -// @Serializable -// data class Stats( -// var numTownBlocks: Int? = null, -// var numResidents: Int? = null, -// var numTowns: Int? = null, -// var numAllies: Int? = null, -// var numEnemies: Int? = null, -// var balance: Float? = null -// ) - - @Serializable - data class Coordinates( - var spawn: Spawn? = null - ) - - @Serializable - data class Spawn( - var world: String? = null, - var x: Float? = null, - var y: Float? = null, - var z: Float? = null, - var pitch: Float? = null, - var yaw: Float? = null - ) - -// @Serializable -// data class Ranks( -// var Chancellor: List? = null, -// var Colonist: List? = null, -// var Diplomat: List? = null -// ) -} diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/objects/PlayerLocationInfo.kt b/src/main/kotlin/net/chariskar/breakthemod/client/objects/PlayerLocationInfo.kt deleted file mode 100644 index 146f08b..0000000 --- a/src/main/kotlin/net/chariskar/breakthemod/client/objects/PlayerLocationInfo.kt +++ /dev/null @@ -1,28 +0,0 @@ -package net.chariskar.breakthemod.client.objects - -import kotlinx.serialization.Serializable - -@Serializable -data class PlayerLocationInfo( - val username: String, - var x: Double, - var z: Double, - var isWilderness: Boolean, - var townName: String?, - var found: Boolean -) { - - init { - this.found = found - } - - override fun toString(): String { - return if (!found) { - "$username is either offline or not showing up on the map." - } else if (townName == null) { - "$username at x: $x, z: $z is in wilderness." - } else { - "$username at x: $x, z: $z is in town: $townName." - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/objects/Resident.kt b/src/main/kotlin/net/chariskar/breakthemod/client/objects/Resident.kt deleted file mode 100644 index ebf3e3b..0000000 --- a/src/main/kotlin/net/chariskar/breakthemod/client/objects/Resident.kt +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This file is part of breakthemod. - * - * breakthemod is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * breakthemod is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with breakthemod. If not, see . - */ - -package net.chariskar.breakthemod.client.objects - -import com.google.gson.annotations.SerializedName -import kotlinx.serialization.Serializable -import net.chariskar.breakthemod.client.utils.serialization.SerializableUUID - -@Serializable -class Resident(val name: String) { - val uuid: SerializableUUID? = null - var title: String? = null - var surname: String? = null - var formattedName: String? = null - var about: String? = null - var town: Reference? = null - var nation: Reference? = null - var timestamps: Timestamps? = null - var status: Status? = null -// var stats: Stats? = null -// var perms: Perms? = null -// var ranks: Ranks? = null -// var friends: List? = null - - @Serializable - data class Timestamps( - var registered: Long? = null, - var joinedTownAt: Long? = null, - var lastOnline: Long? = null - ) - - @Serializable - data class Status( - var isOnline: Boolean? = null, - var isNPC: Boolean? = null, - var isMayor: Boolean? = null, - var isKing: Boolean? = null, - var hasTown: Boolean? = null, - var hasNation: Boolean? = null - ) - -// @Serializable -// data class Stats( -// var balance: Float? = null, -// var numFriends: Int? = null -// ) -// -// @Serializable -// data class Perms( -// var build: List? = null, -// var destroy: List? = null, -// @SerializedName("switch") -// var switch: List? = null, -// var itemUse: List? = null, -// var flags: Flags? = null -// ) - -// @Serializable -// data class Flags( -// var pvp: Boolean? = null, -// var explosion: Boolean? = null, -// var fire: Boolean? = null, -// var mobs: Boolean? = null -// ) - - @Serializable - data class Ranks( - var townRanks: List? = null, - var nationRanks: List? = null - ) -} diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/objects/StaffList.kt b/src/main/kotlin/net/chariskar/breakthemod/client/objects/StaffList.kt deleted file mode 100644 index 3342916..0000000 --- a/src/main/kotlin/net/chariskar/breakthemod/client/objects/StaffList.kt +++ /dev/null @@ -1,18 +0,0 @@ -package net.chariskar.breakthemod.client.objects - -import kotlinx.serialization.Contextual -import kotlinx.serialization.Serializable -import net.chariskar.breakthemod.client.utils.serialization.SerializableUUID - -@Serializable -data class StaffList( - @Contextual val owner: List, - @Contextual val admin: List, - @Contextual val developer: List, - @Contextual val moderator: List, - @Contextual val helper: List -) { - fun allStaff(): List { - return (owner + admin + moderator + helper + developer).distinct() - } -} diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/objects/Town.kt b/src/main/kotlin/net/chariskar/breakthemod/client/objects/Town.kt deleted file mode 100644 index bdf4a56..0000000 --- a/src/main/kotlin/net/chariskar/breakthemod/client/objects/Town.kt +++ /dev/null @@ -1,124 +0,0 @@ -/* - * This file is part of breakthemod. - * - * breakthemod is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * breakthemod is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with breakthemod. If not, see . - */ -package net.chariskar.breakthemod.client.objects - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable -import net.chariskar.breakthemod.client.utils.serialization.SerializableUUID - -@Serializable -data class Town( - val name: String, - val uuid: SerializableUUID? = null, - val board: String? = null, - val founder: String? = null, - val wiki: String? = null, - val mayor: Reference? = null, - val nation: Reference? = null, - val timestamps: Timestamps? = null, - val status: Status? = null, - val stats: Stats? = null, - val perms: Perms? = null, - val coordinates: Coordinates? = null, - val residents: List? = null, - val trusted: List? = null, - val outlaws: List? = null, - val quarters: List? = null, - val ranks: Ranks? = null -) { - - @Serializable - data class Timestamps( - val registered: Long? = null, - val joinedNationAt: Long? = null, - val ruinedAt: Long? = null - ) - - @Serializable - data class Status( - val isPublic: Boolean? = null, - val isOpen: Boolean? = null, - val isNeutral: Boolean? = null, - val isCapital: Boolean? = null, - val isOverClaimed: Boolean? = null, - val isRuined: Boolean? = null, - val isForSale: Boolean? = null, - val hasNation: Boolean? = null, - val hasOverclaimShield: Boolean? = null, - val canOutsidersSpawn: Boolean? = null - ) - - @Serializable - data class Stats( - val numTownBlocks: Int? = null, - val maxTownBlocks: Int? = null, - val numResidents: Int? = null, - val numTrusted: Int? = null, - val numOutlaws: Int? = null, - val bonusBlocks: Int? = null, - val balance: Float? = null, - val forSalePrice: Float? = null - ) - - @Serializable - data class Perms( - val build: List? = null, - val destroy: List? = null, - val switchPerm: List? = null, - val itemUse: List? = null, - val switch: List? = null, - val flags: Flags? = null - ) - - @Serializable - data class Flags( - val pvp: Boolean? = null, - val explosion: Boolean? = null, - val fire: Boolean? = null, - val mobs: Boolean? = null - ) - - @Serializable - data class Coordinates( - val spawn: Spawn? = null, - val homeBlock: List? = null, - val townBlocks: List>? = null - ) - - @Serializable - data class Spawn( - val world: String? = null, - val x: Float? = null, - val y: Float? = null, - val z: Float? = null, - val pitch: Float? = null, - val yaw: Float? = null - ) - - @Serializable - data class Ranks( - @SerialName("Councilor") val councillor: List? = null, - @SerialName("Builder") val builder: List? = null, - @SerialName("Recruiter") val recruiter: List? = null, - @SerialName("Police") val police: List? = null, - @SerialName("Tax-Exempt") val taxExempt: List? = null, - @SerialName("Treasurer") val treasurer: List? = null, - @SerialName("Realtor") val realtor: List? = null, - @SerialName("Settler") val settler: List? = null - ) - -} \ No newline at end of file diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/utils/Config.kt b/src/main/kotlin/net/chariskar/breakthemod/client/utils/Config.kt index 4873d98..efacecc 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/utils/Config.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/utils/Config.kt @@ -34,10 +34,8 @@ object Config { var radarEnabled: Boolean = true, var debug: Boolean = false, var xaerosRdr: Boolean = false, - var mapUrl: String = "https://map.earthmc.net/", - var apiUrl: String = "https://api.earthmc.net/v3/aurora", - var staffRepoUrl: String = "https://raw.githubusercontent.com/veyronity/staff/master/staff.json", var widget: Widget = Widget(), + var mapUrl: String = "https://map.earthmc.net/", var townlessMessage: String = "Hi! I see you're new here, wanna join my Town? I can help you out! Get Free enchanted Armor, Pickaxe, Diamonds, Iron, wood, food, stone, house, and ability to teleport! Type /t join TOWN", ) @@ -91,10 +89,6 @@ object Config { fun getMapUrl(): String = formatURL(config.mapUrl) - fun getApiUrl(): String = formatURL(config.apiUrl) - - fun getStaffUrl(): String = formatURL(config.staffRepoUrl) - fun getDevMode(): Boolean = config.dev fun getRadar(): Boolean = config.radarEnabled diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/utils/Server.kt b/src/main/kotlin/net/chariskar/breakthemod/client/utils/Server.kt index 584d5f7..23ef09e 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/utils/Server.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/utils/Server.kt @@ -1,3 +1,20 @@ +/* + * This file is part of breakthemod. + * + * breakthemod is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * breakthemod is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with breakthemod. If not, see . + */ + package net.chariskar.breakthemod.client.utils import net.minecraft.client.MinecraftClient @@ -14,6 +31,6 @@ object ServerUtils { } fun getEnabled(): Boolean { - return isEarthMc() || Config.getEnabledServers() + return isEarthMc().or(Config.getEnabledServers()) } } \ No newline at end of file diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/utils/Timestamps.kt b/src/main/kotlin/net/chariskar/breakthemod/client/utils/Timestamps.kt index c3b3b51..6541366 100644 --- a/src/main/kotlin/net/chariskar/breakthemod/client/utils/Timestamps.kt +++ b/src/main/kotlin/net/chariskar/breakthemod/client/utils/Timestamps.kt @@ -1,3 +1,20 @@ +/* + * This file is part of breakthemod. + * + * breakthemod is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * breakthemod is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with breakthemod. If not, see . + */ + package net.chariskar.breakthemod.client.utils import java.time.Duration diff --git a/src/main/kotlin/net/chariskar/breakthemod/client/utils/serialization/SerializableUUID.kt b/src/main/kotlin/net/chariskar/breakthemod/client/utils/serialization/SerializableUUID.kt deleted file mode 100644 index eb33486..0000000 --- a/src/main/kotlin/net/chariskar/breakthemod/client/utils/serialization/SerializableUUID.kt +++ /dev/null @@ -1,34 +0,0 @@ -package net.chariskar.breakthemod.client.utils.serialization - -import kotlinx.serialization.KSerializer -import kotlinx.serialization.Serializable -import kotlinx.serialization.descriptors.PrimitiveKind -import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor -import kotlinx.serialization.descriptors.SerialDescriptor -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder -import java.util.UUID - -object SerializableUUIDSerializer : KSerializer { - override val descriptor: SerialDescriptor = - PrimitiveSerialDescriptor("SerializableUUID", PrimitiveKind.STRING) - - override fun serialize(encoder: Encoder, value: SerializableUUID) { - encoder.encodeString(value.value.toString()) - } - - override fun deserialize(decoder: Decoder): SerializableUUID { - return SerializableUUID(UUID.fromString(decoder.decodeString())) - } -} - -@Serializable(with = SerializableUUIDSerializer::class) -data class SerializableUUID(val value: UUID) { - fun toUUID(): UUID { - return value - } - - override fun toString(): String { - return value.toString() - } -} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index c3bebc5..3083a6f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -23,7 +23,6 @@ ] }, "mixins": [ - "breakthemod.mixins.json" ], "custom": { "modmenu": { @@ -37,9 +36,12 @@ } }, "depends": { + "minecraft": "~${minecraft_version}", "fabricloader": ">=${loader_version}", "fabric-language-kotlin": ">=${kotlin_loader_version}", - "fabric": "*", - "minecraft": "~1.21.8" + "fabric-api": "*", + "modmenu": ">=${modmenu}", + "placeholder-api": ">=${placeholder_api}", + "cloth-config2": ">=${cloth_config}" } } diff --git a/src/test/kotlin/net/chariskar/breakthemod/Main.kt b/src/test/kotlin/net/chariskar/breakthemod/Main.kt deleted file mode 100644 index b8ab476..0000000 --- a/src/test/kotlin/net/chariskar/breakthemod/Main.kt +++ /dev/null @@ -1,19 +0,0 @@ -package net.chariskar.breakthemod - -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.SupervisorJob -import kotlinx.coroutines.cancel -import net.chariskar.breakthemod.client.utils.Config - -object TestScope { - val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default) - fun shutdown() { - scope.cancel() - } -} - -object Main { - val config = Config.ConfigData() - -} \ No newline at end of file diff --git a/src/test/kotlin/net/chariskar/breakthemod/apiTest/EarthmcApiTest.kt b/src/test/kotlin/net/chariskar/breakthemod/apiTest/EarthmcApiTest.kt deleted file mode 100644 index fe73126..0000000 --- a/src/test/kotlin/net/chariskar/breakthemod/apiTest/EarthmcApiTest.kt +++ /dev/null @@ -1,58 +0,0 @@ -package net.chariskar.breakthemod.apiTest; - -import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking -import net.chariskar.breakthemod.Main -import net.chariskar.breakthemod.TestScope -import net.chariskar.breakthemod.client.api.Fetch -import net.chariskar.breakthemod.client.objects.Nation -import net.chariskar.breakthemod.client.objects.Resident -import net.chariskar.breakthemod.client.objects.StaffList -import net.chariskar.breakthemod.client.objects.Town -import org.junit.jupiter.api.Test -import kotlin.test.assertNotNull -import kotlin.test.assertIs - -/** - * Test class for [net.chariskar.breakthemod.client.api.Fetch] - * */ -class EarthmcApiTest { - val scope = TestScope.scope - - @Test - fun `test GET request`() { - scope.launch { - val result = Fetch.getRequest(Main.config.staffRepoUrl) - assertNotNull(result) - assertIs(result) - } - } - - @Test - fun `test towns`() { - scope.launch { - val result = Fetch.getTown("paris") - assertNotNull(result) - assertIs(result) - } - } - - @Test - fun `test nations`() { - scope.launch { - val result = Fetch.getNation("france") - assertNotNull(result) - assertIs(result) - } - } - - @Test - fun `test players`() { - scope.launch { - val result = Fetch.getResident("charis_k") - assertNotNull(result) - assertIs(result) - } - } - -} \ No newline at end of file