Skip to content

Commit 786331a

Browse files
committed
update online staff command
1 parent 8b2324c commit 786331a

4 files changed

Lines changed: 45 additions & 79 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,5 @@ runs/
116116

117117
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
118118
!gradle-wrapper.jar
119+
120+
logs/**

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ yarn_mappings=1.21.8+build.1
77
loader_version=0.16.13
88
kotlin_loader_version=1.13.1+kotlin.2.1.10
99
# Mod Properties
10-
mod_version=1.4.4
10+
mod_version=1.4.5
1111
maven_group=net.chariskar
1212
archives_base_name=breakthemod
1313
# Dependencies

logs/2026-02-07-1.log.gz

-190 Bytes
Binary file not shown.

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

Lines changed: 42 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder
2525
import com.mojang.brigadier.context.CommandContext
2626
import kotlinx.coroutines.launch
2727
import net.chariskar.breakthemod.client.api.Fetch
28+
import net.chariskar.breakthemod.client.api.Fetch.Items
2829
import net.chariskar.breakthemod.client.objects.Resident
2930
import net.chariskar.breakthemod.client.objects.StaffList
3031
import net.chariskar.breakthemod.client.utils.ServerUtils.getEnabled
32+
import net.chariskar.breakthemod.client.utils.serialization.SerializableUUID
3133
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
3234
import net.minecraft.text.MutableText
3335
import net.minecraft.text.Style
@@ -52,107 +54,69 @@ class onlineStaff : command() {
5254
if (!getEnabled()) {return@Command 0}
5355
val arg: String = context.getArgument("api", String::class.java)
5456

55-
if (arg == "api") return@Command execAPI(context)
56-
return@Command execNormal(context)
57+
return@Command exec(context, arg == "api")
5758
}))
5859
.executes(Command { context: CommandContext<FabricClientCommandSource> ->
5960
if (!getEnabled()) {return@Command 0}
6061

61-
return@Command execNormal(context)
62+
return@Command exec(context, null)
6263
})
6364
)
6465
}
6566

66-
fun execNormal(ctx: CommandContext<FabricClientCommandSource>): Int {
67-
scope.launch {
68-
val staff: StaffList = Fetch.getRequest<StaffList>(Fetch.Items.STAFF.url)!!
69-
val uuids: List<UUID> = staff.allStaff().map { uid-> uid.toUUID() }
7067

71-
val onlinePlayers: List<UUID> = client.networkHandler!!.playerList.stream().map { pl -> pl.profile.id }.toList()
72-
val onlineStaff: MutableList<UUID> = mutableListOf()
73-
onlinePlayers.forEach { pl ->
74-
if (pl in uuids) onlineStaff.add(pl)
75-
}
76-
val staffNames: List<String> = onlineStaff.mapNotNull { uuid ->
77-
client.networkHandler!!.playerList.firstOrNull {
78-
it.profile.id == uuid
79-
}?.profile?.name
80-
}
81-
var onlineStaffText: MutableText = Text.empty()
68+
suspend fun onlineStaff(api: Boolean): Text {
69+
val staff: List<SerializableUUID>? = fetch.getRequest<StaffList>(Items.STAFF.url)?.allStaff()
8270

83-
for (i in 0..<staffNames.size) {
84-
onlineStaffText = onlineStaffText.append(
85-
Text.literal(staffNames.get(i)).setStyle(Style.EMPTY.withColor(Formatting.AQUA))
86-
)
71+
if (staff.isNullOrEmpty()) return Text.literal("Received invalid staff list.").setStyle(Style.EMPTY.withColor(Formatting.RED))
8772

88-
if (i < staffNames.size - 1) {
89-
onlineStaffText = onlineStaffText.append(
90-
Text.literal(", ").setStyle(Style.EMPTY.withColor(Formatting.WHITE))
91-
)
92-
}
93-
}
73+
var onlineStaffText: MutableText = Text.empty()
74+
var message: MutableText
9475

95-
var message: Text
96-
if (staffNames.isNotEmpty()) {
97-
message = Text.literal("")
98-
.append(onlineStaffText)
99-
.append(Text.literal(" [").setStyle(Style.EMPTY.withColor(Formatting.GRAY)))
100-
.append(
101-
Text.literal(java.lang.String.valueOf(staffNames.size))
102-
.setStyle(Style.EMPTY.withColor(Formatting.WHITE))
103-
)
104-
.append(Text.literal("]").setStyle(Style.EMPTY.withColor(Formatting.GRAY)))
105-
} else {
106-
message = Text.empty()
107-
.append("No online staff").setStyle(Style.EMPTY.withColor(Formatting.AQUA))
108-
}
109-
sendMessage(message)
110-
}
111-
112-
return 0
113-
}
114-
115-
fun execAPI(ctx: CommandContext<FabricClientCommandSource>): Int {
116-
scope.launch {
117-
val staff: StaffList = Fetch.getRequest<StaffList>(Fetch.Items.STAFF.url)!!
118-
119-
val staffNames: List<String> = fetch.getObjects<Resident>(Fetch.Items.PLAYER, staff.allStaff().map { v->v.toUUID() }.toString() )!!
76+
val staffNames: List<String> = if (api) {
77+
fetch.getObjects<Resident>(Items.PLAYER, staff.map { v->v.toUUID() }.toString() )!!
12078
.filter { r -> r.status!!.isOnline == true }
12179
.map { r -> r.name }
80+
} else {
81+
staff.mapNotNull { uuid ->
82+
client.networkHandler!!.playerList.firstOrNull {
83+
it.profile.id == uuid.toUUID()
84+
}?.profile?.name
85+
}
86+
}
12287

12388

124-
var onlineStaffText: MutableText = Text.empty()
89+
for (i in staffNames.indices) {
90+
onlineStaffText = onlineStaffText.append(
91+
Text.literal(staffNames[i]).setStyle(Style.EMPTY.withColor(Formatting.AQUA))
92+
)
12593

126-
for (i in 0..<staffNames.size) {
94+
if (i < staffNames.size - 1) {
12795
onlineStaffText = onlineStaffText.append(
128-
Text.literal(staffNames[i]).setStyle(Style.EMPTY.withColor(Formatting.AQUA))
96+
Text.literal(", ").setStyle(Style.EMPTY.withColor(Formatting.WHITE))
12997
)
130-
131-
if (i < staffNames.size - 1) {
132-
onlineStaffText = onlineStaffText.append(
133-
Text.literal(", ").setStyle(Style.EMPTY.withColor(Formatting.WHITE))
134-
)
135-
}
13698
}
137-
var message: Text
138-
139-
if (staffNames.isNotEmpty()) {
140-
message = Text.literal("")
141-
.append(onlineStaffText)
142-
.append(Text.literal(" [").setStyle(Style.EMPTY.withColor(Formatting.GRAY)))
143-
.append(
144-
Text.literal(java.lang.String.valueOf(staffNames.size))
145-
.setStyle(Style.EMPTY.withColor(Formatting.WHITE))
146-
)
147-
.append(Text.literal("]").setStyle(Style.EMPTY.withColor(Formatting.GRAY)))
148-
} else {
149-
message = Text.empty()
150-
.append("No online staff").setStyle(Style.EMPTY.withColor(Formatting.AQUA))
151-
}
152-
sendMessage( message)
15399
}
154100

101+
if (staffNames.isNotEmpty()) {
102+
message = Text.literal("")
103+
.append(onlineStaffText)
104+
.append(Text.literal(" [").setStyle(Style.EMPTY.withColor(Formatting.GRAY)))
105+
.append(
106+
Text.literal(java.lang.String.valueOf(staffNames.size))
107+
.setStyle(Style.EMPTY.withColor(Formatting.WHITE))
108+
)
109+
.append(Text.literal("]").setStyle(Style.EMPTY.withColor(Formatting.GRAY)))
110+
} else {
111+
message = Text.empty()
112+
.append("No online staff").setStyle(Style.EMPTY.withColor(Formatting.AQUA))
113+
}
114+
115+
return message
116+
}
155117

118+
fun exec(ctx: CommandContext<FabricClientCommandSource>, api: Boolean?): Int {
119+
scope.launch { sendMessage(onlineStaff(api ?: false)) }
156120
return 0
157121
}
158122
}

0 commit comments

Comments
 (0)