summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/event
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-28 22:01:15 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-28 22:01:15 +0100
commitda452cdcbdb573f431c72bfb8035a7f3ce999009 (patch)
treeb28e39f338916f22dcfdfd4e31b466281778bf08 /src/main/java/at/hannibal2/skyhanni/features/event
parent24b68dcc80cbf13f1098a0f6cf259c4bd44f4446 (diff)
downloadskyhanni-da452cdcbdb573f431c72bfb8035a7f3ce999009.tar.gz
skyhanni-da452cdcbdb573f431c72bfb8035a7f3ce999009.tar.bz2
skyhanni-da452cdcbdb573f431c72bfb8035a7f3ce999009.zip
code cleanup, and used SkyHanni framework at more spots
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/event')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/UniqueGiftingOpportnitiesFeatures.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/event/SkyhanniPlayersWhenTheySeeUngiftedPlayers.kt)41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/SkyhanniPlayersWhenTheySeeUngiftedPlayers.kt b/src/main/java/at/hannibal2/skyhanni/features/event/UniqueGiftingOpportnitiesFeatures.kt
index e720e3e30..6679f402c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/event/SkyhanniPlayersWhenTheySeeUngiftedPlayers.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/event/UniqueGiftingOpportnitiesFeatures.kt
@@ -6,49 +6,45 @@ 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.ItemUtils.getInternalName
+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.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<String>?
+object UniqueGiftingOpportnitiesFeatures {
+ private val playerList: MutableSet<String>?
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
+ private val pattern = "§6\\+1 Unique Gift given! To ([^§]+)§r§6!".toPattern()
- fun addGiftedPlayer(playerName: String): Unit {
+ private fun hasGiftedPlayer(player: EntityPlayer) = playerList?.contains(player.name) == true
+
+ private fun addGiftedPlayer(playerName: String) {
playerList?.add(playerName)
}
- val config get() = SkyHanniMod.feature.event.winter.giftingOpportunities
+ private 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))
- }
+ private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled &&
+ (InventoryUtils.itemInHandId.endsWith("_GIFT")
+ || !config.highlighWithGiftOnly)
- val hasNotGiftedNametag = "§a§lꤥ"
- val hasGiftedNametag = "§c§lꤥ"
+ private val hasNotGiftedNametag = "§a§lꤥ"
+ private val hasGiftedNametag = "§c§lꤥ"
- fun analyzeArmorStand(entity: EntityArmorStand) {
+ private 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
+
+ val matchedPlayer = EntityUtils.getEntitiesNearby<EntityPlayer>(entity.getLorenzVec(), 2.0)
+ .singleOrNull { !it.isNPC() } ?: return
addGiftedPlayer(matchedPlayer.name)
}
@@ -73,7 +69,6 @@ object SkyhanniPlayersWhenTheySeeUngiftedPlayers {
event.color = LorenzColor.DARK_GREEN.toColor().withAlpha(127)
}
-
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
pattern.matchMatcher(event.message) {