blob: a81675f7440ed422d48c81aa526fdb3a82f9fd67 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package at.hannibal2.skyhanni.utils
import com.google.common.collect.ComparisonChain
import com.google.common.collect.Ordering
import net.minecraft.client.Minecraft
import net.minecraft.client.network.NetworkPlayerInfo
import net.minecraft.world.WorldSettings
import net.minecraftforge.fml.relauncher.Side
import net.minecraftforge.fml.relauncher.SideOnly
object TabListUtils {
private val playerOrdering = Ordering.from(PlayerComparator())
@SideOnly(Side.CLIENT)
internal class PlayerComparator : Comparator<NetworkPlayerInfo> {
override fun compare(o1: NetworkPlayerInfo, o2: NetworkPlayerInfo): Int {
val team1 = o1.playerTeam
val team2 = o2.playerTeam
return ComparisonChain.start().compareTrueFirst(
o1.gameType != WorldSettings.GameType.SPECTATOR,
o2.gameType != WorldSettings.GameType.SPECTATOR
)
.compare(
if (team1 != null) team1.registeredName else "",
if (team2 != null) team2.registeredName else ""
)
.compare(o1.gameProfile.name, o2.gameProfile.name).result()
}
}
fun getTabList(): List<String> {
val players = playerOrdering.sortedCopy(Minecraft.getMinecraft().thePlayer.sendQueue.playerInfoMap)
val result: MutableList<String> = ArrayList()
for (info in players) {
val name = Minecraft.getMinecraft().ingameGUI.tabList.getPlayerName(info)
result.add(LorenzUtils.stripVanillaMessage(name))
}
return result
}
}
|