diff options
author | Lorenz <ESs95s3P5z8Pheb> | 2022-07-08 10:05:47 +0200 |
---|---|---|
committer | Lorenz <ESs95s3P5z8Pheb> | 2022-07-08 10:05:47 +0200 |
commit | 697389e5a2bffdbe40be6ee9418dcf19e64ba3ce (patch) | |
tree | a75ee28dd19d85be47c635013ec601f762fb5504 /src/main/java/at/lorenz/mod/utils | |
parent | f255bd7048d1cc4a29423b7b538ee32416570700 (diff) | |
download | skyhanni-697389e5a2bffdbe40be6ee9418dcf19e64ba3ce.tar.gz skyhanni-697389e5a2bffdbe40be6ee9418dcf19e64ba3ce.tar.bz2 skyhanni-697389e5a2bffdbe40be6ee9418dcf19e64ba3ce.zip |
code cleanup
Diffstat (limited to 'src/main/java/at/lorenz/mod/utils')
-rw-r--r-- | src/main/java/at/lorenz/mod/utils/ItemUtils.kt | 68 | ||||
-rw-r--r-- | src/main/java/at/lorenz/mod/utils/LorenzLogger.kt | 2 | ||||
-rw-r--r-- | src/main/java/at/lorenz/mod/utils/LorenzUtils.kt | 106 |
3 files changed, 86 insertions, 90 deletions
diff --git a/src/main/java/at/lorenz/mod/utils/ItemUtils.kt b/src/main/java/at/lorenz/mod/utils/ItemUtils.kt index 44972fb0c..168b41ddf 100644 --- a/src/main/java/at/lorenz/mod/utils/ItemUtils.kt +++ b/src/main/java/at/lorenz/mod/utils/ItemUtils.kt @@ -1,51 +1,49 @@ package at.lorenz.mod.utils -import at.lorenz.mod.utils.LorenzUtils.Companion.matchRegex -import at.lorenz.mod.utils.LorenzUtils.Companion.removeColorCodes +import at.lorenz.mod.utils.LorenzUtils.matchRegex +import at.lorenz.mod.utils.LorenzUtils.removeColorCodes import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.item.ItemStack -class ItemUtils { - - companion object { - fun ItemStack.cleanName() = this.displayName.removeColorCodes() - - fun getItemsInOpenChest(): List<ItemStack> { - val list = mutableListOf<ItemStack>() - val guiChest = Minecraft.getMinecraft().currentScreen as GuiChest - val inventorySlots = guiChest.inventorySlots.inventorySlots - val skipAt = inventorySlots.size - 9 * 4 - var i = 0 - for (slot in inventorySlots) { - val stack = slot.stack - if (stack != null) { - list.add(stack) - } - i++ - if (i == skipAt) break +object ItemUtils { + + fun ItemStack.cleanName() = this.displayName.removeColorCodes() + + fun getItemsInOpenChest(): List<ItemStack> { + val list = mutableListOf<ItemStack>() + val guiChest = Minecraft.getMinecraft().currentScreen as GuiChest + val inventorySlots = guiChest.inventorySlots.inventorySlots + val skipAt = inventorySlots.size - 9 * 4 + var i = 0 + for (slot in inventorySlots) { + val stack = slot.stack + if (stack != null) { + list.add(stack) } - return list + i++ + if (i == skipAt) break } + return list + } - fun isSack(name: String): Boolean = name.endsWith(" Sack") + fun isSack(name: String): Boolean = name.endsWith(" Sack") - fun ItemStack.getLore() = ItemUtil.getItemLore(this) + fun ItemStack.getLore() = ItemUtil.getItemLore(this) - fun isCoOpSoulBound(stack: ItemStack): Boolean = stack.getLore().any { it.contains("Co-op Soulbound") } + fun isCoOpSoulBound(stack: ItemStack): Boolean = stack.getLore().any { it.contains("Co-op Soulbound") } - fun isRecombobulated(stack: ItemStack): Boolean = stack.getLore().any { it.contains("§k") } + fun isRecombobulated(stack: ItemStack): Boolean = stack.getLore().any { it.contains("§k") } - fun isPet(name: String): Boolean = name.matchRegex("\\[Lvl (.*)] (.*)") && !listOf( - "Archer", - "Berserk", - "Mage", - "Tank", - "Healer", - "➡", - ).any { name.contains(it) } + fun isPet(name: String): Boolean = name.matchRegex("\\[Lvl (.*)] (.*)") && !listOf( + "Archer", + "Berserk", + "Mage", + "Tank", + "Healer", + "➡", + ).any { name.contains(it) } - fun maxPetLevel(name: String) = if (name.contains("Golden Dragon")) 200 else 100 + fun maxPetLevel(name: String) = if (name.contains("Golden Dragon")) 200 else 100 - } }
\ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/utils/LorenzLogger.kt b/src/main/java/at/lorenz/mod/utils/LorenzLogger.kt index de69e7e66..48bfc6099 100644 --- a/src/main/java/at/lorenz/mod/utils/LorenzLogger.kt +++ b/src/main/java/at/lorenz/mod/utils/LorenzLogger.kt @@ -1,6 +1,6 @@ package at.lorenz.mod.utils -import at.lorenz.mod.utils.LorenzUtils.Companion.formatCurrentTime +import at.lorenz.mod.utils.LorenzUtils.formatCurrentTime import java.io.File import java.io.IOException import java.text.SimpleDateFormat diff --git a/src/main/java/at/lorenz/mod/utils/LorenzUtils.kt b/src/main/java/at/lorenz/mod/utils/LorenzUtils.kt index 3bcb630e0..e27e0f50f 100644 --- a/src/main/java/at/lorenz/mod/utils/LorenzUtils.kt +++ b/src/main/java/at/lorenz/mod/utils/LorenzUtils.kt @@ -5,63 +5,62 @@ import net.minecraft.util.ChatComponentText import org.intellij.lang.annotations.Language import java.text.SimpleDateFormat -class LorenzUtils { +object LorenzUtils { - companion object { - const val DEBUG_PREFIX = "[Debug] §7" + const val DEBUG_PREFIX = "[Debug] §7" - fun debug(message: String) { - internaChat(DEBUG_PREFIX + message) - } + fun debug(message: String) { + internaChat(DEBUG_PREFIX + message) + } - fun warning(message: String) { - internaChat("§cWarning! $message") - } + fun warning(message: String) { + internaChat("§cWarning! $message") + } - fun error(message: String) { - internaChat("§4$message") - } + fun error(message: String) { + internaChat("§4$message") + } - fun chat(message: String) { - internaChat(message) - } + fun chat(message: String) { + internaChat(message) + } - private fun internaChat(message: String) { - val thePlayer = Minecraft.getMinecraft().thePlayer - thePlayer.addChatMessage(ChatComponentText(message)) - } + private fun internaChat(message: String) { + val thePlayer = Minecraft.getMinecraft().thePlayer + thePlayer.addChatMessage(ChatComponentText(message)) + } - fun String.matchRegex(@Language("RegExp") regex: String): Boolean = regex.toRegex().matches(this) - - fun String.removeColorCodes(): String { - val builder = StringBuilder() - var skipNext = false - for (c in this.toCharArray()) { - if (c == '§') { - skipNext = true - continue - } - if (skipNext) { - skipNext = false - continue - } - builder.append(c) - } + fun String.matchRegex(@Language("RegExp") regex: String): Boolean = regex.toRegex().matches(this) - return builder.toString() + fun String.removeColorCodes(): String { + val builder = StringBuilder() + var skipNext = false + for (c in this.toCharArray()) { + if (c == '§') { + skipNext = true + continue + } + if (skipNext) { + skipNext = false + continue + } + builder.append(c) } - fun SimpleDateFormat.formatCurrentTime(): String = this.format(System.currentTimeMillis()) + return builder.toString() + } - fun stripVanillaMessage(originalMessage: String): String { - var message = originalMessage + fun SimpleDateFormat.formatCurrentTime(): String = this.format(System.currentTimeMillis()) - while (message.startsWith("§r")) { - message = message.substring(2) - } - while (message.endsWith("§r")) { - message = message.substring(0, message.length - 2) - } + fun stripVanillaMessage(originalMessage: String): String { + var message = originalMessage + + while (message.startsWith("§r")) { + message = message.substring(2) + } + while (message.endsWith("§r")) { + message = message.substring(0, message.length - 2) + } // if (!message.startsWith(LorenzUtils.DEBUG_PREFIX + "chat api got (123)")) { // if (message.matchRegex("(.*)§r§7 \\((.{1,3})\\)")) { @@ -79,15 +78,14 @@ class LorenzUtils { // } // } - return message - } - - fun Double.round(decimals: Int): Double { - var multiplier = 1.0 - repeat(decimals) { multiplier *= 10 } - return kotlin.math.round(this * multiplier) / multiplier - } + return message + } - fun String.between(start: String, end: String): String = this.split(start, end)[1] + fun Double.round(decimals: Int): Double { + var multiplier = 1.0 + repeat(decimals) { multiplier *= 10 } + return kotlin.math.round(this * multiplier) / multiplier } + + fun String.between(start: String, end: String): String = this.split(start, end)[1] }
\ No newline at end of file |