From da452cdcbdb573f431c72bfb8035a7f3ce999009 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Tue, 28 Nov 2023 22:01:15 +0100 Subject: code cleanup, and used SkyHanni framework at more spots --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 4 +- .../event/winter/GiftingOpportunities.java | 26 ------- .../event/winter/GiftingOpportunitiesConfig.java | 27 +++++++ .../config/features/event/winter/WinterConfig.java | 2 +- .../SkyhanniPlayersWhenTheySeeUngiftedPlayers.kt | 84 ---------------------- .../event/UniqueGiftingOpportnitiesFeatures.kt | 79 ++++++++++++++++++++ 6 files changed, 109 insertions(+), 113 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/event/winter/GiftingOpportunities.java create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/event/winter/GiftingOpportunitiesConfig.java delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/event/SkyhanniPlayersWhenTheySeeUngiftedPlayers.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/event/UniqueGiftingOpportnitiesFeatures.kt (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 9c95c0d08..60816beb1 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -102,7 +102,7 @@ import at.hannibal2.skyhanni.features.dungeon.DungeonMilestonesDisplay import at.hannibal2.skyhanni.features.dungeon.DungeonRankTabListColor import at.hannibal2.skyhanni.features.dungeon.DungeonTeammateOutlines import at.hannibal2.skyhanni.features.dungeon.HighlightDungeonDeathmite -import at.hannibal2.skyhanni.features.event.SkyhanniPlayersWhenTheySeeUngiftedPlayers +import at.hannibal2.skyhanni.features.event.UniqueGiftingOpportnitiesFeatures import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper import at.hannibal2.skyhanni.features.event.diana.GriffinBurrowHelper import at.hannibal2.skyhanni.features.event.diana.GriffinBurrowParticleFinder @@ -435,7 +435,7 @@ class SkyHanniMod { loadModule(DungeonCleanEnd()) loadModule(DungeonBossMessages()) loadModule(DungeonBossHideDamageSplash()) - loadModule(SkyhanniPlayersWhenTheySeeUngiftedPlayers) + loadModule(UniqueGiftingOpportnitiesFeatures) loadModule(TrophyFishManager) loadModule(TrophyFishFillet()) loadModule(TrophyFishMessages()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/event/winter/GiftingOpportunities.java b/src/main/java/at/hannibal2/skyhanni/config/features/event/winter/GiftingOpportunities.java deleted file mode 100644 index 751017942..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/features/event/winter/GiftingOpportunities.java +++ /dev/null @@ -1,26 +0,0 @@ -package at.hannibal2.skyhanni.config.features.event.winter; - -import at.hannibal2.skyhanni.config.FeatureToggle; -import com.google.gson.annotations.Expose; -import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; -import io.github.moulberry.moulconfig.annotations.ConfigOption; - -public class GiftingOpportunities { - @Expose - @ConfigOption(name = "Highlight unique gift opportunities", desc = "Highlight players who you haven't given gifts to yet") - @ConfigEditorBoolean - @FeatureToggle - public boolean highlightSpecialNeedsPlayers = true; - - @Expose - @ConfigOption(name = "Display only while holding a gift", desc = "Only highlight ungifted players while holding a gift.") - @ConfigEditorBoolean - public boolean highlighWithGiftOnly = true; - - - @Expose - @ConfigOption(name = "Use armor stands", desc = "Make use of armor stands to stop highlighting players. A bit inaccurate, but can help with people you gifted before this feature was used.") - @ConfigEditorBoolean - public boolean useArmorStandDetection = false; - -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/event/winter/GiftingOpportunitiesConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/event/winter/GiftingOpportunitiesConfig.java new file mode 100644 index 000000000..f303099b4 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/event/winter/GiftingOpportunitiesConfig.java @@ -0,0 +1,27 @@ +package at.hannibal2.skyhanni.config.features.event.winter; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import com.google.gson.annotations.Expose; +import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; +import io.github.moulberry.moulconfig.annotations.ConfigOption; + +public class GiftingOpportunitiesConfig { + @Expose + @ConfigOption(name = "Enabled", desc = "Highlight players who you haven't given gifts to yet.") + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = true; + + @Expose + @ConfigOption(name = "Only While Holding Gift", desc = "Only highlight ungifted players while holding a gift.") + @ConfigEditorBoolean + public boolean highlighWithGiftOnly = true; + + + @Expose + @ConfigOption(name = "Use Armor Stands", desc = "Make use of armor stands to stop highlighting players. " + + "This is a bit inaccurate, but it can help with people you gifted before this feature was used.") + @ConfigEditorBoolean + public boolean useArmorStandDetection = false; + +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/event/winter/WinterConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/event/winter/WinterConfig.java index 2548558dc..4cb15cb19 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/event/winter/WinterConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/event/winter/WinterConfig.java @@ -23,7 +23,7 @@ public class WinterConfig { @Accordion @Expose @ConfigOption(name = "Unique Gifting Opportunities", desc = "Highlight players who you haven't given gifts to yet") - public GiftingOpportunities giftingOpportunities = new GiftingOpportunities(); + public GiftingOpportunitiesConfig giftingOpportunities = new GiftingOpportunitiesConfig(); @Expose public Position islandCloseTimePosition = new Position(10, 10, false, true); diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/SkyhanniPlayersWhenTheySeeUngiftedPlayers.kt b/src/main/java/at/hannibal2/skyhanni/features/event/SkyhanniPlayersWhenTheySeeUngiftedPlayers.kt deleted file mode 100644 index e720e3e30..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/event/SkyhanniPlayersWhenTheySeeUngiftedPlayers.kt +++ /dev/null @@ -1,84 +0,0 @@ -package at.hannibal2.skyhanni.features.event - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.ProfileStorageData -import at.hannibal2.skyhanni.events.EntityCustomNameUpdateEvent -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.RenderMobColoredEvent -import at.hannibal2.skyhanni.events.withAlpha -import at.hannibal2.skyhanni.utils.EntityUtils.isNPC -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.LorenzColor -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.getLorenzVec -import net.minecraft.client.Minecraft -import net.minecraft.entity.item.EntityArmorStand -import net.minecraft.entity.player.EntityPlayer -import net.minecraftforge.event.entity.EntityJoinWorldEvent -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -object SkyhanniPlayersWhenTheySeeUngiftedPlayers { - val playerList: MutableSet? - get() = ProfileStorageData.playerSpecific?.playersThatHaveBeenGifted - - val pattern = "§6\\+1 Unique Gift given! To ([^§]+)§r§6!".toPattern() - fun hasGiftedPlayer(player: EntityPlayer): Boolean = - playerList?.contains(player.name) == true - - fun addGiftedPlayer(playerName: String): Unit { - playerList?.add(playerName) - } - - val config get() = SkyHanniMod.feature.event.winter.giftingOpportunities - - fun isEnabled(): Boolean { - return LorenzUtils.inSkyBlock && config.highlightSpecialNeedsPlayers && - (Minecraft.getMinecraft().thePlayer?.heldItem?.getInternalName()?.endsWith("_GIFT") == true - || (!config.highlighWithGiftOnly)) - } - - val hasNotGiftedNametag = "§a§lꤥ" - val hasGiftedNametag = "§c§lꤥ" - - fun analyzeArmorStand(entity: EntityArmorStand) { - if (!config.useArmorStandDetection) return - val world = Minecraft.getMinecraft().theWorld ?: return - if (entity.name != hasGiftedNametag) return - val matchedPlayer = - world.playerEntities.singleOrNull { - !it.isNPC() && it.getLorenzVec().distance(entity.getLorenzVec()) < 2 - } ?: return - addGiftedPlayer(matchedPlayer.name) - - } - - @SubscribeEvent - fun onEntityChangeName(event: EntityCustomNameUpdateEvent) { - val entity = event.entity as? EntityArmorStand ?: return - analyzeArmorStand(entity) - } - - @SubscribeEvent - fun onEntityJoinWorldEvent(event: EntityJoinWorldEvent) { - val entity = event.entity as? EntityArmorStand ?: return - analyzeArmorStand(entity) - } - - @SubscribeEvent - fun onRenderMobColored(event: RenderMobColoredEvent) { - if (!isEnabled()) return - val entity = event.entity - if (entity is EntityPlayer && !entity.isNPC() && !hasGiftedPlayer(entity)) - event.color = LorenzColor.DARK_GREEN.toColor().withAlpha(127) - } - - - @SubscribeEvent - fun onChat(event: LorenzChatEvent) { - pattern.matchMatcher(event.message) { - addGiftedPlayer(group(1)) - } - } - -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/UniqueGiftingOpportnitiesFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/event/UniqueGiftingOpportnitiesFeatures.kt new file mode 100644 index 000000000..6679f402c --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/event/UniqueGiftingOpportnitiesFeatures.kt @@ -0,0 +1,79 @@ +package at.hannibal2.skyhanni.features.event + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.events.EntityCustomNameUpdateEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.RenderMobColoredEvent +import at.hannibal2.skyhanni.events.withAlpha +import at.hannibal2.skyhanni.utils.EntityUtils +import at.hannibal2.skyhanni.utils.EntityUtils.isNPC +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.getLorenzVec +import net.minecraft.entity.item.EntityArmorStand +import net.minecraft.entity.player.EntityPlayer +import net.minecraftforge.event.entity.EntityJoinWorldEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object UniqueGiftingOpportnitiesFeatures { + private val playerList: MutableSet? + get() = ProfileStorageData.playerSpecific?.playersThatHaveBeenGifted + + private val pattern = "§6\\+1 Unique Gift given! To ([^§]+)§r§6!".toPattern() + + private fun hasGiftedPlayer(player: EntityPlayer) = playerList?.contains(player.name) == true + + private fun addGiftedPlayer(playerName: String) { + playerList?.add(playerName) + } + + private val config get() = SkyHanniMod.feature.event.winter.giftingOpportunities + + private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled && + (InventoryUtils.itemInHandId.endsWith("_GIFT") + || !config.highlighWithGiftOnly) + + private val hasNotGiftedNametag = "§a§lꤥ" + private val hasGiftedNametag = "§c§lꤥ" + + private fun analyzeArmorStand(entity: EntityArmorStand) { + if (!config.useArmorStandDetection) return + if (entity.name != hasGiftedNametag) return + + val matchedPlayer = EntityUtils.getEntitiesNearby(entity.getLorenzVec(), 2.0) + .singleOrNull { !it.isNPC() } ?: return + addGiftedPlayer(matchedPlayer.name) + + } + + @SubscribeEvent + fun onEntityChangeName(event: EntityCustomNameUpdateEvent) { + val entity = event.entity as? EntityArmorStand ?: return + analyzeArmorStand(entity) + } + + @SubscribeEvent + fun onEntityJoinWorldEvent(event: EntityJoinWorldEvent) { + val entity = event.entity as? EntityArmorStand ?: return + analyzeArmorStand(entity) + } + + @SubscribeEvent + fun onRenderMobColored(event: RenderMobColoredEvent) { + if (!isEnabled()) return + val entity = event.entity + if (entity is EntityPlayer && !entity.isNPC() && !hasGiftedPlayer(entity)) + event.color = LorenzColor.DARK_GREEN.toColor().withAlpha(127) + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + pattern.matchMatcher(event.message) { + addGiftedPlayer(group(1)) + } + } + +} -- cgit