diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java | 8 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListReader.kt | 21 |
2 files changed, 24 insertions, 5 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java index 1dd24fc44..ddc3fafde 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java @@ -554,13 +554,13 @@ public class MiscConfig { public boolean hideAdverts = false; @Expose - @ConfigOption(name = "Player Sort", desc = "Change what the player list is sorted by.") - @ConfigEditorDropdown(values = {"Rank (Default)", "SB Level", "Name (Abc)", "Ironman/Bingo", "Party/Friends/Guild"}) + @ConfigOption(name = "Player Sort", desc = "Change the sort order of player names in the tab list.") + @ConfigEditorDropdown(values = {"Rank (Default)", "SB Level", "Name (Abc)", "Ironman/Bingo", "Party/Friends/Guild", "Random"}) @ConfigAccordionId(id = 1) - public int playerSort = 0; + public int playerSortOrder = 0; @Expose - @ConfigOption(name = "Invert Sort", desc = "Flip the player list on its head (also works with default rank).") + @ConfigOption(name = "Invert Sort", desc = "Flip the player list order on its head (also works with default rank).") @ConfigEditorBoolean public boolean reverseSort = false; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListReader.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListReader.kt index a9e9d2ad6..d4268a39f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListReader.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListReader.kt @@ -12,8 +12,11 @@ import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.StringUtils.removeResets import at.hannibal2.skyhanni.utils.StringUtils.trimWhiteSpaceAndResets import at.hannibal2.skyhanni.utils.TabListData +import com.google.common.cache.CacheBuilder import net.minecraft.client.Minecraft import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.concurrent.TimeUnit +import kotlin.random.Random // heavily inspired by SBA code object TabListReader { @@ -124,7 +127,7 @@ object TabListReader { } val prepare = playerDatas.entries - val sorted = when (config.playerSort) { + val sorted = when (config.playerSortOrder) { // Rank (Default) 1 -> prepare.sortedBy { -(it.value.sbLevel) } @@ -138,6 +141,9 @@ object TabListReader { // Party/Friends/Guild First 4 -> prepare.sortedBy { -socialScore(it.value.name) } + // Random + 5 -> prepare.sortedBy { getRandomOrder(it.value.name) } + else -> prepare } @@ -155,6 +161,19 @@ object TabListReader { return newList } + private var randomOrderCache = + CacheBuilder.newBuilder().expireAfterWrite(20, TimeUnit.MINUTES).build<String, Int>() + + private fun getRandomOrder(name: String): Int { + val saved = randomOrderCache.getIfPresent(name) + if (saved != null) { + return saved + } + val r = (Random.nextDouble() * 500).toInt() + randomOrderCache.put(name, r) + return r + } + private fun socialScore(name: String) = when { LorenzUtils.getPlayerName() == name -> 5 MarkedPlayerManager.isMarkedPlayer(name) -> 4 |