Skip to content

Commit 2ac02dd

Browse files
committed
fixes are reduced jar size
1 parent 4b64c64 commit 2ac02dd

7 files changed

Lines changed: 46 additions & 76 deletions

File tree

src/main/kotlin/net/chariskar/breakthemod/client/api/Fetch.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import java.net.http.HttpResponse
3636
object Fetch {
3737
val logger: Logger = LoggerFactory.getLogger("breakthemod")
3838

39-
val json: Json = Json {
39+
val json: Json = Json {
4040
ignoreUnknownKeys = true
4141
}
4242

@@ -89,6 +89,7 @@ object Fetch {
8989
.header("Content-Type", "application/json")
9090
.POST(HttpRequest.BodyPublishers.ofString(body))
9191
.build()
92+
9293
val response = client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).await()
9394
var body = response.body()
9495
if (body.startsWith("[[") && body.endsWith("]]")) {

src/main/kotlin/net/chariskar/breakthemod/client/commands/findPlayer.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder
88
import com.mojang.brigadier.context.CommandContext
99
import kotlinx.coroutines.launch
1010
import kotlinx.serialization.Serializable
11+
import kotlinx.serialization.encodeToString
1112
import kotlinx.serialization.json.Json
1213
import net.chariskar.breakthemod.client.api.Command
1314
import net.chariskar.breakthemod.client.api.Fetch
@@ -32,16 +33,24 @@ class findPlayer : Command() {
3233
val query: List<List<Double>>
3334
)
3435

36+
@Serializable
37+
data class MapResponse(
38+
val name: String? = null,
39+
val x: Double,
40+
val z: Double
41+
)
42+
3543
@Serializable
3644
data class ApiResponse(
3745
val max: Int? = null,
38-
val players: MutableList<Location>? = null
46+
val players: MutableList<MapResponse>? = null
3947
)
4048

4149
override fun execute(ctx: CommandContext<FabricClientCommandSource>): Int {
4250
val name: String = ctx.getArgument("name", String::class.java)
4351
scope.launch {
44-
val players: MutableList<Location>? = Fetch.getRequest<ApiResponse>(Config.getMapUrl() + "tiles/players.json")!!.players
52+
val players: MutableList<MapResponse>? = Fetch.getRequest<ApiResponse>(Config.getMapUrl() + "tiles/players.json")!!.players
53+
4554
if (players.isNullOrEmpty()) {
4655
sendMessage(Text.literal("Received empty player list from map."), Formatting.RED)
4756
return@launch
@@ -51,12 +60,15 @@ class findPlayer : Command() {
5160
for (player in players) {
5261
if (player.name.equals(name, ignoreCase = true)) {
5362
playerData.found = true
54-
playerData.x = player.location?.x!!
55-
playerData.z = player.location.z!!
63+
playerData.x = player.x
64+
playerData.z = player.z
5665

57-
val coords = listOf(player.location.x, player.location.z)
66+
val coords = listOf(player.x, player.z)
5867
val payload = Payload(listOf(coords))
59-
val locationData: Location? = Fetch.postRequest<Location>(Fetch.ItemTypes.LOCATION.url, Json.encodeToString(payload))
68+
val payloadJson = Json.encodeToString(payload)
69+
70+
val locationData: Location? = Fetch.postRequest<List<Location>>(Fetch.ItemTypes.LOCATION.url, Json.encodeToString(payload))?.first()
71+
6072
if (locationData != null && locationData.isWilderness == false) {
6173
playerData.townName = locationData.town?.name
6274
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package net.chariskar.breakthemod.client.objects
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class Coordinates(
7+
val x: Double? = null,
8+
val y: Double? = null,
9+
val z: Double? = null
10+
)

src/main/kotlin/net/chariskar/breakthemod/client/objects/Location.kt

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,6 @@ data class Location (
88
val name: String? = null,
99
val location: Coordinates? = null,
1010
val isWilderness: Boolean? = null,
11-
val town: Town? = null,
12-
val nation: Nation? = null
13-
) {
14-
@Serializable
15-
data class Coordinates(
16-
val x: Double? = null,
17-
val z: Double? = null
18-
)
19-
20-
@Serializable
21-
data class Town (
22-
val name: String? = null,
23-
val uuid: SerializableUUID? = null
24-
)
25-
26-
@Serializable
27-
data class Nation (
28-
val name: String? = null,
29-
val uuid: SerializableUUID? = null
30-
)
31-
}
11+
val town: Reference? = null,
12+
val nation: Reference? = null
13+
)

src/main/kotlin/net/chariskar/breakthemod/client/objects/Nation.kt

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,19 @@ class Nation(val name: String) {
2828
var dynmapColour: String? = null
2929
var dynmapOutline: String? = null
3030
var wiki: String? = null
31-
var king: Leader? = null
32-
var capital: Capital? = null
31+
var king: Reference? = null
32+
var capital: Reference? = null
3333
var timestamps: Timestamps? = null
3434
var status: Status? = null
3535
var stats: Stats? = null
3636
var coordinates: Coordinates? = null
37-
var residents: List<Resident>? = null
38-
var towns: List<Resident>? = null
39-
var allies: List<Resident>? = null
40-
var enemies: List<Resident>? = null
41-
var sanctioned: List<Resident>? = null
37+
var residents: List<Reference>? = null
38+
var towns: List<Reference>? = null
39+
var allies: List<Reference>? = null
40+
var enemies: List<Reference>? = null
41+
var sanctioned: List<Reference>? = null
4242
var ranks: Ranks? = null
4343

44-
@Serializable
45-
data class Leader(
46-
var name: String? = null,
47-
val uuid: SerializableUUID? = null
48-
)
49-
50-
@Serializable
51-
data class Capital(
52-
var name: String? = null,
53-
val uuid: SerializableUUID? = null
54-
)
55-
5644
@Serializable
5745
data class Timestamps(
5846
var registered: Long? = null
@@ -89,12 +77,6 @@ class Nation(val name: String) {
8977
var yaw: Float? = null
9078
)
9179

92-
@Serializable
93-
data class Resident(
94-
var name: String? = null,
95-
val uuid: SerializableUUID? = null
96-
)
97-
9880
@Serializable
9981
data class Ranks(
10082
var Chancellor: List<Resident>? = null,

src/main/kotlin/net/chariskar/breakthemod/client/objects/PlayerLocationInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ data class PlayerLocationInfo(
1919
override fun toString(): String {
2020
return if (!found) {
2121
"$username is either offline or not showing up on the map."
22-
} else if (isWilderness) {
22+
} else if (townName == null) {
2323
"$username at x: $x, z: $z is in wilderness."
2424
} else {
2525
"$username at x: $x, z: $z is in town: $townName."

src/main/kotlin/net/chariskar/breakthemod/client/objects/Town.kt

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,19 @@ data class Town(
2727
val board: String? = null,
2828
val founder: String? = null,
2929
val wiki: String? = null,
30-
val mayor: Mayor? = null,
31-
val nation: Nation? = null,
30+
val mayor: Reference? = null,
31+
val nation: Reference? = null,
3232
val timestamps: Timestamps? = null,
3333
val status: Status? = null,
3434
val stats: Stats? = null,
3535
val perms: Perms? = null,
3636
val coordinates: Coordinates? = null,
37-
val residents: List<Resident>? = null,
38-
val trusted: List<Resident>? = null,
39-
val outlaws: List<Resident>? = null,
37+
val residents: List<Reference>? = null,
38+
val trusted: List<Reference>? = null,
39+
val outlaws: List<Reference>? = null,
4040
val quarters: List<Reference>? = null,
4141
val ranks: Ranks? = null
4242
) {
43-
@Serializable
44-
data class Mayor(
45-
val name: String? = null,
46-
val uuid: SerializableUUID? = null
47-
)
48-
49-
@Serializable
50-
data class Nation(
51-
val name: String? = null,
52-
val uuid: SerializableUUID? = null
53-
)
5443

5544
@Serializable
5645
data class Timestamps(
@@ -120,12 +109,6 @@ data class Town(
120109
val yaw: Float? = null
121110
)
122111

123-
@Serializable
124-
data class Resident(
125-
val name: String? = null,
126-
val uuid: SerializableUUID? = null
127-
)
128-
129112
@Serializable
130113
data class Ranks(
131114
@SerialName("Councilor") val councillor: List<Resident>? = null,

0 commit comments

Comments
 (0)