Skip to content

Commit

Permalink
Merge pull request #54 from ItsEmpa/contributor-nametag
Browse files Browse the repository at this point in the history
:3
  • Loading branch information
j10a1n15 authored May 24, 2024
2 parents cefdd7e + 3cea1d9 commit 649638d
Show file tree
Hide file tree
Showing 32 changed files with 451 additions and 188 deletions.
6 changes: 6 additions & 0 deletions pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<!-- remove all unused parts -->

## PR Reviews

When your PR is marked as ready for review, some of our maintainers will look through your code to make sure everything is good to go. In order to do this, they may request some changes you will need to do, **or fix smaller stuff (like merge conflicts) for you**. If a maintainer has reviewed your PR, make sure to **pull any of their changes** into your local project before doing more work on your code. Having maintainers fix small stuff for you helps us speed up the process of merging your PR, so if some of your systems warrant further care, be sure to let us know (preferably with a code comment).

Make sure to only mark your PR as "Ready to review" when it is. If you still want to do major changes, you can keep a draft PR open until then.

## Dependencies
- pr_number_or_link_here

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ import at.hannibal2.skyhanni.features.dungeon.TerracottaPhase
import at.hannibal2.skyhanni.features.event.UniqueGiftingOpportunitiesFeatures
import at.hannibal2.skyhanni.features.event.diana.AllBurrowsList
import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper
import at.hannibal2.skyhanni.features.event.diana.DianaFixChat
import at.hannibal2.skyhanni.features.event.diana.DianaProfitTracker
import at.hannibal2.skyhanni.features.event.diana.GriffinBurrowHelper
import at.hannibal2.skyhanni.features.event.diana.GriffinBurrowParticleFinder
Expand Down Expand Up @@ -508,7 +509,7 @@ class SkyHanniMod {
loadModule(ScoreboardData())
loadModule(SeaCreatureFeatures())
loadModule(SeaCreatureManager())
loadModule(EntityData())
loadModule(EntityData)
loadModule(MobData())
loadModule(MobDetection())
loadModule(EntityMovementData)
Expand Down Expand Up @@ -705,6 +706,7 @@ class SkyHanniMod {
loadModule(NonGodPotEffectDisplay())
loadModule(SoopyGuessBurrow())
loadModule(DianaProfitTracker)
loadModule(DianaFixChat())
loadModule(MythologicalCreatureTracker)
loadModule(ShiftClickNPCSell)
loadModule(HighlightJerries())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@
public class DevConfig {

@Expose
@ConfigOption(name = "Repo Auto Update", desc = "Update the repository on every startup.\n" +
"§cOnly disable this if you know what you are doing!")
@ConfigEditorBoolean
public boolean repoAutoUpdate = true;

@Expose
@ConfigOption(name = "Log Expiry Time", desc = "Deletes your SkyHanni logs after this time period in days.")
@ConfigEditorSlider(minValue = 1, maxValue = 30, minStep = 1)
public int logExpiryTime = 14;
@ConfigOption(name = "Repository", desc = "")
@Accordion
public RepositoryConfig repo = new RepositoryConfig();

@Expose
@ConfigOption(name = "Debug", desc = "")
Expand All @@ -34,6 +28,11 @@ public class DevConfig {
@Accordion
public RepoPatternConfig repoPattern = new RepoPatternConfig();

@Expose
@ConfigOption(name = "Log Expiry Time", desc = "Deletes your SkyHanni logs after this time period in days.")
@ConfigEditorSlider(minValue = 1, maxValue = 30, minStep = 1)
public int logExpiryTime = 14;

@Expose
@ConfigOption(name = "Slot Number", desc = "Show slot number in inventory while pressing this key.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE)
Expand Down Expand Up @@ -64,12 +63,20 @@ public class DevConfig {
@Expose
@ConfigOption(
name = "Fancy Contributors",
desc = "Marks §cSkyHanni's contributors §7fancy in the tab list. " +
desc = "Marks §cSkyHanni's contributors §7fancy in the tab list and nametags. " +
"§eThose are the folks that coded the mod for you for free :)"
)
@ConfigEditorBoolean
public boolean fancyContributors = true;

@Expose
@ConfigOption(
name = "Contributor Nametags",
desc = "Makes SkyHanni contributors' nametags fancy too. "
)
@ConfigEditorBoolean
public boolean contributorNametags = false;

@Expose
@ConfigOption(
name = "Flip Contributors",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package at.hannibal2.skyhanni.config.features.dev;

import at.hannibal2.skyhanni.data.repo.RepoUtils;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.Accordion;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorButton;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorText;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;

public class RepositoryConfig {

@Expose
@ConfigOption(name = "Repo Auto Update", desc = "Update the repository on every startup.\n" +
"§cOnly disable this if you know what you are doing!")
@ConfigEditorBoolean
public boolean repoAutoUpdate = true;

@ConfigOption(name = "Update Repo Now", desc = "Update your repository to the latest version")
@ConfigEditorButton(buttonText = "Update")
public Runnable updateRepo = RepoUtils::updateRepo;

@Expose
@ConfigOption(name = "Repository Location", desc = "")
@Accordion
public RepositoryLocation location = new RepositoryLocation();

public static class RepositoryLocation {

@ConfigOption(name = "Reset Repository Location", desc = "Reset your repository location to the default.")
@ConfigEditorButton(buttonText = "Reset")
public Runnable resetRepoLocation = RepoUtils::resetRepoLocation;

@Expose
@ConfigOption(name = "Repository User", desc = "The Repository Branch, default: hannibal002")
@ConfigEditorText
public String user = "hannibal002";

@Expose
@ConfigOption(name = "Repository Name", desc = "The Repository Name, default: SkyHanni-Repo")
@ConfigEditorText
public String name = "SkyHanni-REPO";

@Expose
@ConfigOption(name = "Repository Branch", desc = "The Repository Branch, default: main")
@ConfigEditorText
public String branch = "main";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,10 @@ public class HoppityEggsConfig {
@ConfigEditorBoolean
@FeatureToggle
public boolean timeInChat = true;

@Expose
@ConfigOption(name = "Compact Chat", desc = "Compact chat events when finding a Hoppity Egg.")
@ConfigEditorBoolean
@FeatureToggle
public boolean compactChat = false;
}
16 changes: 15 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/EntityData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,29 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.PacketEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.events.entity.EntityDisplayNameEvent
import at.hannibal2.skyhanni.utils.EntityUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth
import at.hannibal2.skyhanni.utils.LorenzUtils.derpy
import at.hannibal2.skyhanni.utils.TimeLimitedCache
import net.minecraft.client.entity.EntityOtherPlayerMP
import net.minecraft.client.entity.EntityPlayerSP
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.boss.EntityWither
import net.minecraft.entity.item.EntityArmorStand
import net.minecraft.entity.item.EntityItem
import net.minecraft.entity.item.EntityItemFrame
import net.minecraft.entity.item.EntityXPOrb
import net.minecraft.network.play.server.S1CPacketEntityMetadata
import net.minecraft.util.IChatComponent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.milliseconds

class EntityData {
object EntityData {

private val maxHealthMap = mutableMapOf<EntityLivingBase, Int>()
private val nametagCache = TimeLimitedCache<Entity, IChatComponent>(50.milliseconds)

@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
Expand Down Expand Up @@ -83,4 +89,12 @@ class EntityData {
}
}
}

fun postRenderNametag(entity: Entity, chatComponent: IChatComponent): IChatComponent {
return nametagCache.getOrPut(entity) {
val event = EntityDisplayNameEvent(entity, chatComponent)
event.postAndCatch()
event.chatComponent
}
}
}
21 changes: 12 additions & 9 deletions src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ class HypixelData {
}

@SubscribeEvent
// TODO rewrite everything in here
fun onTick(event: LorenzTickEvent) {
if (!LorenzUtils.inSkyBlock) {
// Modified from NEU.
Expand All @@ -302,17 +303,19 @@ class HypixelData {
}
}

if (LorenzUtils.inSkyBlock) {
loop@ for (line in ScoreboardData.sidebarLinesFormatted) {
skyblockAreaPattern.matchMatcher(line) {
val originalLocation = group("area")
skyBlockArea = LocationFixData.fixLocation(skyBlockIsland) ?: originalLocation
skyBlockAreaWithSymbol = line.trim()
break@loop
if (LorenzUtils.onHypixel) {
if (LorenzUtils.inSkyBlock) {
loop@ for (line in ScoreboardData.sidebarLinesFormatted) {
skyblockAreaPattern.matchMatcher(line) {
val originalLocation = group("area")
skyBlockArea = LocationFixData.fixLocation(skyBlockIsland) ?: originalLocation
skyBlockAreaWithSymbol = line.trim()
break@loop
}
}
}

checkProfileName()
checkProfileName()
}
}

if (!event.isMod(5)) return
Expand Down
30 changes: 12 additions & 18 deletions src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,21 @@ object SlayerAPI {
System.currentTimeMillis()
} else latestProgressChangeTime

fun getItemNameAndPrice(internalName: NEUInternalName, amount: Int): Pair<String, Double> {
val key = internalName to amount
nameCache.getOrNull(key)?.let {
return it
}

val amountFormat = if (amount != 1) "§7${amount}x §r" else ""
val displayName = internalName.itemName
fun getItemNameAndPrice(internalName: NEUInternalName, amount: Int): Pair<String, Double> =
nameCache.getOrPut(internalName to amount) {
val amountFormat = if (amount != 1) "§7${amount}x §r" else ""
val displayName = internalName.itemName

val price = internalName.getPrice()
val npcPrice = internalName.getNpcPriceOrNull() ?: 0.0
val maxPrice = npcPrice.coerceAtLeast(price)
val totalPrice = maxPrice * amount
val price = internalName.getPrice()
val npcPrice = internalName.getNpcPriceOrNull() ?: 0.0
val maxPrice = npcPrice.coerceAtLeast(price)
val totalPrice = maxPrice * amount

val format = NumberUtil.format(totalPrice)
val priceFormat = " §7(§6$format coins§7)"
val format = NumberUtil.format(totalPrice)
val priceFormat = " §7(§6$format coins§7)"

val result = "$amountFormat$displayName$priceFormat" to totalPrice
nameCache.put(key, result)
return result
}
"$amountFormat$displayName$priceFormat" to totalPrice
}

@SubscribeEvent
fun onDebugDataCollect(event: DebugDataCollectEvent) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/mob/MobFilter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ object MobFilter {
* REGEX-TEST: ﴾ [Lv500] Arachne 100k/100k❤ ﴿
* REGEX-TEST: ﴾ [Lv200] Barbarian Duke X 70M/70M❤ ﴿
* REGEX-TEST: ﴾ [Lv100] Endstone Protector 4.6M/5M❤ ﴿
* REGEX-TEST: ﴾ [Lv400] Thunder 29M/35M❤ ﴿
* */
val bossMobNameFilter by repoGroup.pattern(
"filter.boss",
"^. (?:\\[Lv(?<level>\\d+)\\] )?(?<name>[^ᛤ\n]*)(?: ᛤ)?(?: [\\d\\/BMk.,❤]+|█+)? .$"
"^. (?:\\[Lv(?<level>\\d+)\\] )?(?<name>[^ᛤ\n]*?)(?: ᛤ)?(?: [\\d\\/BMk.,❤]+| █+)? .$"
)
val dungeonNameFilter by repoGroup.pattern(
"filter.dungeon",
Expand Down
56 changes: 48 additions & 8 deletions src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,28 @@ class RepoManager(private val configLocation: File) {

companion object {

private val config get() = SkyHanniMod.feature.dev.repo

val successfulConstants = mutableListOf<String>()
val unsuccessfulConstants = mutableListOf<String>()

private var lastConstant: String? = null

fun setlastConstant(constant: String) {
fun setLastConstant(constant: String) {
lastConstant?.let {
successfulConstants.add(it)
}
lastConstant = constant
}

fun getRepoLocation(): String {
return "${config.location.user}/${config.location.name}/${config.location.branch}"
}
}

fun loadRepoInformation() {
atomicShouldManuallyReload.set(true)
if (SkyHanniMod.feature.dev.repoAutoUpdate) {
if (config.repoAutoUpdate) {
fetchRepository(false).thenRun(this::reloadRepository)
} else {
reloadRepository()
Expand All @@ -62,6 +68,7 @@ class RepoManager(private val configLocation: File) {

fun updateRepo() {
atomicShouldManuallyReload.set(true)
checkRepoLocation()
fetchRepository(true).thenRun { this.reloadRepository("Repo updated successfully.") }
}

Expand Down Expand Up @@ -219,7 +226,7 @@ class RepoManager(private val configLocation: File) {
if (unsuccessfulConstants.isNotEmpty()) {
ChatUtils.error(
"§7Repo Issue! Some features may not work. Please report this error on the Discord!\n"
+ "§7Repo Auto Update Value: §c${SkyHanniMod.feature.dev.repoAutoUpdate}\n"
+ "§7Repo Auto Update Value: §c${config.repoAutoUpdate}\n"
+ "§7If you have Repo Auto Update turned off, please try turning that on.\n"
+ "§cUnsuccessful Constants §7(${unsuccessfulConstants.size}):"
)
Expand Down Expand Up @@ -266,15 +273,15 @@ class RepoManager(private val configLocation: File) {
}

private fun getCommitApiUrl(): String {
val repoUser = "hannibal002"
val repoName = "SkyHanni-REPO"
val repoBranch = "main"
val repoUser = config.location.user
val repoName = config.location.name
val repoBranch = config.location.branch
return String.format("https://api.github.com/repos/%s/%s/commits/%s", repoUser, repoName, repoBranch)
}

private fun getDownloadUrl(commitId: String?): String {
val repoUser = "hannibal002"
val repoName = "SkyHanni-REPO"
val repoUser = config.location.user
val repoName = config.location.name
return String.format("https://github.com/%s/%s/archive/%s.zip", repoUser, repoName, commitId)
}

Expand All @@ -293,4 +300,37 @@ class RepoManager(private val configLocation: File) {
fun onNeuRepoReload(event: io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent) {
NeuRepositoryReloadEvent().postAndCatch()
}

fun resetRepositoryLocation(manual: Boolean = false) {
val defaultUser = "hannibal002"
val defaultName = "SkyHanni-Repo"
val defaultBranch = "main"

with(config.location) {
if (user == defaultUser && name == defaultName && branch == defaultBranch) {
if (manual) {
ChatUtils.chat("Repo settings are already on default!")
}
return
}

user = defaultUser
name = defaultName
branch = defaultBranch
if (manual) {
ChatUtils.clickableChat("Reset Repo settings to default. " +
"Click §aUpdate Repo Now §ein config or run /shupdaterepo to update!",
onClick = {
updateRepo()
})
}
}
}

private fun checkRepoLocation() {
if (config.location.user.isEmpty() || config.location.name.isEmpty() || config.location.branch.isEmpty()) {
ChatUtils.userError("Invalid Repo settings detected, resetting default settings.")
resetRepositoryLocation()
}
}
}
Loading

0 comments on commit 649638d

Please sign in to comment.