Skip to content

Commit 6b8a53d

Browse files
authored
feat(tab): mark party members without voice (#109)
A member of the viewer's party who has no voice connection shows the voice-off icon in the danger colour, so the party knows voice cannot reach them.
1 parent d150d3d commit 6b8a53d

3 files changed

Lines changed: 38 additions & 13 deletions

File tree

‎velocity/src/main/kotlin/gg/grounds/proxy/velocity/tab/TabList.kt‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ class TabList(
116116
isBedrock(entry.profile.id),
117117
bedrockViewer = isBedrock(viewer.uniqueId),
118118
partyMember = entry.profile.id in partyMembers,
119-
voice = voiceOf(entry.profile.id),
119+
voice =
120+
when (voiceOf(entry.profile.id)) {
121+
true -> TabVoice.ON
122+
false -> TabVoice.OFF
123+
// The party should know voice cannot reach this member.
124+
null -> TabVoice.MISSING.takeIf { entry.profile.id in partyMembers }
125+
},
120126
)
121127
if (supplied != formatted) entry.setDisplayName(formatted)
122128
}

‎velocity/src/main/kotlin/gg/grounds/proxy/velocity/tab/TabName.kt‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ import net.kyori.adventure.text.format.NamedTextColor
88
import net.kyori.adventure.text.format.TextColor
99
import net.kyori.adventure.text.format.TextDecoration
1010

11+
/** What the tab list shows about a player's voice; Java viewers only. */
12+
enum class TabVoice {
13+
ON,
14+
/** Switched off in the mod. */
15+
OFF,
16+
/** No voice at all, shown only to the player's own party: voice cannot reach them. */
17+
MISSING,
18+
}
19+
1120
object TabName {
1221
private const val GAP = 2
1322

@@ -17,8 +26,8 @@ object TabName {
1726
bedrock: Boolean = false,
1827
bedrockViewer: Boolean = false,
1928
partyMember: Boolean = false,
20-
/** True for voice on, false for voice off, null for no voice; Java viewers only. */
21-
voice: Boolean? = null,
29+
/** Null draws no voice icon. */
30+
voice: TabVoice? = null,
2231
): Component {
2332
val displayName = PlayerDisplayNames.displayName(name, bedrock)
2433
val colour = role?.colour?.let(TextColor::fromHexString) ?: Palette.TEXT
@@ -42,14 +51,14 @@ object TabName {
4251
)
4352
row.append(Component.text(TabSpaces.of(GAP)).font(TabGlyphs.FONT))
4453
}
45-
voice?.let { on ->
46-
row.append(
47-
Component.text(
48-
if (on) TabGlyphs.VOICE_ON else TabGlyphs.VOICE_OFF,
49-
if (on) Palette.SUCCESS else Palette.TEXT_FAINT,
50-
)
51-
.font(TabGlyphs.FONT)
52-
)
54+
voice?.let {
55+
val icon =
56+
when (it) {
57+
TabVoice.ON -> Component.text(TabGlyphs.VOICE_ON, Palette.SUCCESS)
58+
TabVoice.OFF -> Component.text(TabGlyphs.VOICE_OFF, Palette.TEXT_FAINT)
59+
TabVoice.MISSING -> Component.text(TabGlyphs.VOICE_OFF, Palette.DANGER)
60+
}
61+
row.append(icon.font(TabGlyphs.FONT))
5362
row.append(Component.text(TabSpaces.of(GAP)).font(TabGlyphs.FONT))
5463
}
5564
row.append(nameText)

‎velocity/src/test/kotlin/gg/grounds/proxy/velocity/tab/TabNameTest.kt‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class TabNameTest {
132132
val name = "Steve"
133133
val text =
134134
PlainTextComponentSerializer.plainText()
135-
.serialize(TabName.format(name, null, voice = false))
135+
.serialize(TabName.format(name, null, voice = TabVoice.OFF))
136136
assertTrue(text.startsWith(TabGlyphs.VOICE_OFF.toString()), text)
137137
assertTrue(
138138
text.endsWith(
@@ -147,11 +147,21 @@ class TabNameTest {
147147
)
148148
}
149149

150+
@Test
151+
fun `a party member without voice gets the voice-off icon in the danger colour`() {
152+
val icon =
153+
findText(
154+
TabName.format("Steve", null, voice = TabVoice.MISSING),
155+
TabGlyphs.VOICE_OFF.toString(),
156+
)
157+
assertEquals(gg.grounds.i18n.Palette.DANGER, icon.color())
158+
}
159+
150160
@Test
151161
fun `bedrock viewers get no voice icon`() {
152162
val text =
153163
PlainTextComponentSerializer.plainText()
154-
.serialize(TabName.format("Steve", null, bedrockViewer = true, voice = true))
164+
.serialize(TabName.format("Steve", null, bedrockViewer = true, voice = TabVoice.ON))
155165
assertEquals("Steve", text)
156166
}
157167

0 commit comments

Comments
 (0)