diff options
author | Brady <thatgravyboat@gmail.com> | 2024-04-23 10:03:24 -0230 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-23 14:33:24 +0200 |
commit | d12548c5f8235fec8b9563adb25f052c9b678874 (patch) | |
tree | ae732016323b1637003ecbc047b128f8b605beb2 /src/main/java/at/hannibal2 | |
parent | 2c08c30523ece6190e301742b780fb85e6979077 (diff) | |
download | skyhanni-d12548c5f8235fec8b9563adb25f052c9b678874.tar.gz skyhanni-d12548c5f8235fec8b9563adb25f052c9b678874.tar.bz2 skyhanni-d12548c5f8235fec8b9563adb25f052c9b678874.zip |
Backend: Add ContributorManager (#1519)
Diffstat (limited to 'src/main/java/at/hannibal2')
6 files changed, 63 insertions, 53 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 841f024dd..07e1268aa 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -301,6 +301,7 @@ import at.hannibal2.skyhanni.features.misc.BetterWikiFromMenus import at.hannibal2.skyhanni.features.misc.BrewingStandOverlay import at.hannibal2.skyhanni.features.misc.ButtonOnPause import at.hannibal2.skyhanni.features.misc.CollectionTracker +import at.hannibal2.skyhanni.features.misc.ContributorManager import at.hannibal2.skyhanni.features.misc.CurrentPetDisplay import at.hannibal2.skyhanni.features.misc.CustomTextBox import at.hannibal2.skyhanni.features.misc.ExpOrbsOnGroundHider @@ -528,6 +529,7 @@ class SkyHanniMod { loadModule(ChatUtils) loadModule(FixedRateTimerManager()) loadModule(ChromaManager) + loadModule(ContributorManager) // APIs loadModule(BazaarApi()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/AdvancedPlayerListConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/AdvancedPlayerListConfig.java index be8cfe340..a7652967e 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/AdvancedPlayerListConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/AdvancedPlayerListConfig.java @@ -94,13 +94,4 @@ public class AdvancedPlayerListConfig { @ConfigOption(name = "Mark Special Persons", desc = "Show special icons behind the name of guild members, party members, friends, and marked players.") @ConfigEditorBoolean public boolean markSpecialPersons = false; - - @Expose - @ConfigOption( - name = "Mark SkyHanni Devs", - desc = "Adds a §c:O §7behind the tablist name of §cSkyHanni's contributors§7. " + - "§eThose are the folks that coded the mod for you for free :)" - ) - @ConfigEditorBoolean - public boolean markSkyHanniDevs = true; } diff --git a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/ContributorListJson.java b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/ContributorListJson.java deleted file mode 100644 index 8ea6d8ef6..000000000 --- a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/ContributorListJson.java +++ /dev/null @@ -1,10 +0,0 @@ -package at.hannibal2.skyhanni.data.jsonobjects.repo; - -import com.google.gson.annotations.Expose; - -import java.util.List; - -public class ContributorListJson { - @Expose - public List<String> usernames; -} diff --git a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/ContributorsJson.kt b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/ContributorsJson.kt new file mode 100644 index 000000000..7857da85a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/ContributorsJson.kt @@ -0,0 +1,12 @@ +package at.hannibal2.skyhanni.data.jsonobjects.repo + +import com.google.gson.annotations.Expose + +data class ContributorsJson( + @Expose val contributors: Map<String, ContributorJsonEntry> +) + +data class ContributorJsonEntry( + @Expose val suffix: String = "§c:O", + @Expose val spinny: Boolean = false +) diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ContributorManager.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ContributorManager.kt new file mode 100644 index 000000000..16d1088c8 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ContributorManager.kt @@ -0,0 +1,24 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.data.jsonobjects.repo.ContributorJsonEntry +import at.hannibal2.skyhanni.data.jsonobjects.repo.ContributorsJson +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object ContributorManager { + + private var contributors: Map<String, ContributorJsonEntry> = emptyMap() + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + contributors = event.getConstant<ContributorsJson>("Contributors").contributors.mapKeys { it.key.lowercase() } + } + + fun getTabListSuffix(username: String): String? { + return contributors[username.lowercase()]?.suffix + } + + fun canSpin(username: String): Boolean { + return contributors[username.lowercase()]?.spinny ?: false + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt index 273942287..76a5decd8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt @@ -7,10 +7,9 @@ import at.hannibal2.skyhanni.data.FriendAPI import at.hannibal2.skyhanni.data.GuildAPI import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.PartyAPI -import at.hannibal2.skyhanni.data.jsonobjects.repo.ContributorListJson -import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.features.bingo.BingoAPI import at.hannibal2.skyhanni.features.dungeon.DungeonAPI +import at.hannibal2.skyhanni.features.misc.ContributorManager import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests import at.hannibal2.skyhanni.test.command.ErrorManager @@ -73,7 +72,7 @@ object AdvancedPlayerList { readPlayerData(sbLevel, levelText, line) } catch (e: NumberFormatException) { ErrorManager.logErrorWithData( - e, "Advanced Player List failed to parse user name", + e, "Advanced Player List failed to parse username", "line" to line, "i" to i, "original" to original, @@ -108,7 +107,7 @@ object AdvancedPlayerList { } // Party/Friends/Guild First - PlayerSortEntry.SOCIAL_STATUS -> prepare.sortedBy { -socialScore(it.value.name) } + PlayerSortEntry.SOCIAL_STATUS -> prepare.sortedBy { -getSocialIcon(it.value.name).score } // Random PlayerSortEntry.RANDOM -> prepare.sortedBy { getRandomOrder(it.value.name) } @@ -180,13 +179,6 @@ object AdvancedPlayerList { return denyKeyPressed || !SkyHanniDebugsAndTests.globalRender } - private var contributors: List<String> = emptyList() - - @SubscribeEvent - fun onRepoReload(event: RepositoryReloadEvent) { - contributors = event.getConstant<ContributorListJson>("ContributorList").usernames - } - private fun createCustomName(data: PlayerData): String { val playerName = if (config.useLevelColorForName) { @@ -203,11 +195,10 @@ object AdvancedPlayerList { } else data.nameSuffix if (config.markSpecialPersons) { - val score = socialScore(data.name) - suffix += " " + getSocialScoreIcon(score) + suffix += " ${getSocialIcon(data.name).icon()}" } - if (config.markSkyHanniDevs && data.name in contributors) { - suffix += "§c:O" + ContributorManager.getTabListSuffix(data.name)?.let { + suffix += " $it" } if (IslandType.CRIMSON_ISLE.isInIsland() && !config.hideFactions) { @@ -229,25 +220,13 @@ object AdvancedPlayerList { return r } - private fun socialScore(name: String) = when { - LorenzUtils.getPlayerName() == name -> 10 - MarkedPlayerManager.isMarkedPlayer(name) -> 8 - PartyAPI.partyMembers.contains(name) -> 5 - FriendAPI.getAllFriends().any { it.name.contains(name) } -> 4 - GuildAPI.isInGuild(name) -> 3 - - else -> 1 - } - - private fun getSocialScoreIcon(score: Int) = when (score) { -// 10 -> "§c§lME" - 10 -> "" - 8 -> "${MarkedPlayerManager.config.chatColor.getChatColor()}§lMARKED" - 5 -> "§9§lP" - 4 -> "§d§lF" - 3 -> "§2§lG" - - else -> "" + private fun getSocialIcon(name: String) = when { + LorenzUtils.getPlayerName() == name -> SocialIcon.ME + MarkedPlayerManager.isMarkedPlayer(name) -> SocialIcon.MARKED + PartyAPI.partyMembers.contains(name) -> SocialIcon.PARTY + FriendAPI.getAllFriends().any { it.name.contains(name) } -> SocialIcon.FRIEND + GuildAPI.isInGuild(name) -> SocialIcon.GUILD + else -> SocialIcon.OTHER } class PlayerData(val sbLevel: Int) { @@ -267,6 +246,18 @@ object AdvancedPlayerList { NONE("") } + enum class SocialIcon(val icon: () -> String, val score: Int) { + ME("", 10), + MARKED({ "${MarkedPlayerManager.config.chatColor.getChatColor()}§lMARKED" }, 8), + PARTY("§9§lP", 5), + FRIEND("§d§lF", 4), + GUILD("§2§lG", 3), + OTHER("", 1) + ; + + constructor(icon: String, score: Int) : this({ icon }, score) + } + @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { event.transform(15, "misc.compactTabList.advancedPlayerList.playerSortOrder") { element -> |