diff options
28 files changed, 233 insertions, 168 deletions
diff --git a/src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java b/src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java index aaa182e..4db0b51 100644 --- a/src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java +++ b/src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java @@ -6,11 +6,16 @@ import java.awt.datatransfer.Transferable; public interface GuiNewChatHook { int getRight(); + boolean shouldCopy(); + Transferable getStratusChatComponent(int mouseY); + default ChatLine getFullMessage(ChatLine line) { throw new AssertionError("getFullMessage not overridden on GuiNewChat"); } + String getPrevText(); + void setPrevText(String prevText); } diff --git a/src/main/java/com/raeids/stratus/mixin/ClientCommandHandlerMixin.java b/src/main/java/com/raeids/stratus/mixin/ClientCommandHandlerMixin.java index 3082b88..ecdef69 100644 --- a/src/main/java/com/raeids/stratus/mixin/ClientCommandHandlerMixin.java +++ b/src/main/java/com/raeids/stratus/mixin/ClientCommandHandlerMixin.java @@ -1,7 +1,7 @@ package com.raeids.stratus.mixin; import com.raeids.stratus.config.StratusConfig; -import com.raeids.stratus.hook.ChatShortcuts; +import com.raeids.stratus.chat.ChatShortcuts; import kotlin.Pair; import net.minecraft.client.Minecraft; import net.minecraft.command.CommandHandler; diff --git a/src/main/java/com/raeids/stratus/mixin/EntityPlayerSPMixin.java b/src/main/java/com/raeids/stratus/mixin/EntityPlayerSPMixin.java index 44ef05d..c605511 100644 --- a/src/main/java/com/raeids/stratus/mixin/EntityPlayerSPMixin.java +++ b/src/main/java/com/raeids/stratus/mixin/EntityPlayerSPMixin.java @@ -1,7 +1,7 @@ package com.raeids.stratus.mixin; import com.raeids.stratus.config.StratusConfig; -import com.raeids.stratus.hook.ChatTabs; +import com.raeids.stratus.chat.ChatTabs; import net.minecraft.client.entity.EntityPlayerSP; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java index 37fb0f3..bf0ac79 100644 --- a/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java +++ b/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java @@ -1,9 +1,12 @@ package com.raeids.stratus.mixin; import com.google.common.collect.Lists; -import com.raeids.stratus.Stratus; +import com.raeids.stratus.chat.*; import com.raeids.stratus.config.StratusConfig; +import com.raeids.stratus.gui.components.ScreenshotButton; +import com.raeids.stratus.gui.components.SearchButton; import com.raeids.stratus.hook.*; +import com.raeids.stratus.utils.ModCompatHooks; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiChat; import net.minecraft.client.gui.GuiScreen; @@ -36,17 +39,15 @@ public abstract class GuiChatMixin extends GuiScreen { "\u00A73\u00A7l\u00A7nModifiers", "\u00A7lALT\u00A7r - Formatting Codes"); - private CleanSearchButton searchButton; - private ScreenshotButton screenshotButton; + private SearchButton searchButton; @Inject(method = "initGui", at = @At("TAIL")) private void init(CallbackInfo ci) { if (StratusConfig.INSTANCE.getChatSearch()) { - searchButton = new CleanSearchButton(); + searchButton = new SearchButton(); buttonList.add(searchButton); } - screenshotButton = new ScreenshotButton(); - buttonList.add(screenshotButton); + buttonList.add(new ScreenshotButton()); if (StratusConfig.INSTANCE.getChatTabs()) { for (ChatTab chatTab : ChatTabs.INSTANCE.getTabs()) { buttonList.add(chatTab.getButton()); @@ -70,7 +71,7 @@ public abstract class GuiChatMixin extends GuiScreen { return; } searchButton.getInputField().textboxKeyTyped(typedChar, keyCode); - ChatSearchingKt.setPrevText(searchButton.getInputField().getText()); + ChatSearchingManager.setPrevText(searchButton.getInputField().getText()); } } @@ -79,7 +80,7 @@ public abstract class GuiChatMixin extends GuiScreen { GuiNewChatHook hook = ((GuiNewChatHook) Minecraft.getMinecraft().ingameGUI.getChatGUI()); float f = mc.ingameGUI.getChatGUI().getChatScale(); int x = MathHelper.floor_float((float) mouseX / f); - if (hook.shouldCopy() && (hook.getRight() + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getXOffset() : 0)) <= x && (hook.getRight() + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getXOffset() : 0)) + 9 > x) { + if (hook.shouldCopy() && (hook.getRight() + ModCompatHooks.getXOffset()) <= x && (hook.getRight() + ModCompatHooks.getXOffset()) + 9 > x) { GuiUtils.drawHoveringText(COPY_TOOLTIP, mouseX, mouseY, width, height, -1, fontRendererObj); GlStateManager.disableLighting(); } @@ -90,7 +91,7 @@ public abstract class GuiChatMixin extends GuiScreen { GuiNewChatHook hook = ((GuiNewChatHook) Minecraft.getMinecraft().ingameGUI.getChatGUI()); float f = mc.ingameGUI.getChatGUI().getChatScale(); int x = MathHelper.floor_float((float) mouseX / f); - if (hook.shouldCopy() && (hook.getRight() + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getXOffset() : 0)) <= x && (hook.getRight() + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getXOffset() : 0)) + 9 > x) { + if (hook.shouldCopy() && (hook.getRight() + ModCompatHooks.getXOffset()) <= x && (hook.getRight() + ModCompatHooks.getXOffset()) + 9 > x) { Transferable message = hook.getStratusChatComponent(Mouse.getY()); if (message == null) return; try { diff --git a/src/main/java/com/raeids/stratus/mixin/GuiNewChatAccessor.java b/src/main/java/com/raeids/stratus/mixin/GuiNewChatAccessor.java index 9b68d48..43d4288 100644 --- a/src/main/java/com/raeids/stratus/mixin/GuiNewChatAccessor.java +++ b/src/main/java/com/raeids/stratus/mixin/GuiNewChatAccessor.java @@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.gen.Accessor; import java.util.List; -@Mixin (GuiNewChat.class) +@Mixin(GuiNewChat.class) public interface GuiNewChatAccessor { @Accessor List<ChatLine> getDrawnChatLines(); diff --git a/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java index 09c464b..06e25be 100644 --- a/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java +++ b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java @@ -1,11 +1,11 @@ package com.raeids.stratus.mixin; import com.raeids.stratus.Stratus; +import com.raeids.stratus.chat.ChatSearchingManager; +import com.raeids.stratus.chat.ChatTabs; +import com.raeids.stratus.utils.ModCompatHooks; import com.raeids.stratus.config.StratusConfig; -import com.raeids.stratus.hook.ChatSearchingKt; -import com.raeids.stratus.hook.ChatTabs; import com.raeids.stratus.hook.GuiNewChatHook; -import com.raeids.stratus.hook.ModCompatHooks; import com.raeids.stratus.utils.RenderHelper; import gg.essential.universal.UMouse; import net.minecraft.client.Minecraft; @@ -28,6 +28,7 @@ import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; import java.awt.image.BufferedImage; import java.util.List; +import java.util.Locale; @Mixin(value = GuiNewChat.class, priority = Integer.MIN_VALUE) public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @@ -56,11 +57,14 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @Inject(method = "printChatMessageWithOptionalDeletion", at = @At("HEAD"), cancellable = true) private void handlePrintChatMessage(IChatComponent chatComponent, int chatLineId, CallbackInfo ci) { handleChatTabMessage(chatComponent, chatLineId, mc.ingameGUI.getUpdateCounter(), false, ci); + if (!EnumChatFormatting.getTextWithoutFormattingCodes(chatComponent.getUnformattedText()).toLowerCase(Locale.ENGLISH).contains(stratus$previousText.toLowerCase(Locale.ENGLISH))) { + percentComplete = 1.0F; + } } @Inject(method = "setChatLine", at = @At("HEAD"), cancellable = true) private void handleSetChatLine(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { - ChatSearchingKt.getCache().invalidateAll(); + ChatSearchingManager.getCache().invalidateAll(); handleChatTabMessage(chatComponent, chatLineId, updateCounter, displayOnly, ci); } @@ -93,10 +97,10 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { if (mc.currentScreen instanceof GuiChat) { float f = this.getChatScale(); int mouseX = MathHelper.floor_double(UMouse.getScaledX()) - 3; - int mouseY = MathHelper.floor_double(UMouse.getScaledY()) - 27 + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getYOffset() : 0) - (Stratus.INSTANCE.isPatcher() && ModCompatHooks.getChatPosition() ? 12 : 0); + int mouseY = MathHelper.floor_double(UMouse.getScaledY()) - 27 + ModCompatHooks.getYOffset() - ModCompatHooks.getChatPosition(); mouseX = MathHelper.floor_float((float)mouseX / f); mouseY = -(MathHelper.floor_float((float)mouseY / f)); //WHY DO I NEED TO DO THIS - if (mouseX >= (left + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getXOffset() : 0)) && mouseY < bottom && mouseX < (right + 9 + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getXOffset() : 0)) && mouseY >= top) { + if (mouseX >= (left + ModCompatHooks.getXOffset()) && mouseY < bottom && mouseX < (right + 9 + ModCompatHooks.getXOffset()) && mouseY >= top) { stratus$shouldCopy = true; drawCopyChatBox(right, top); } @@ -105,7 +109,7 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @Redirect(method = "drawChat", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/GuiNewChat;drawnChatLines:Ljava/util/List;", opcode = Opcodes.GETFIELD)) private List<ChatLine> injected(GuiNewChat instance) { - return ChatSearchingKt.filterMessages(stratus$previousText, drawnChatLines); + return ChatSearchingManager.filterMessages(stratus$previousText, drawnChatLines); } @Inject(method = "drawChat", at = @At("RETURN")) @@ -134,7 +138,7 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { } if (!displayOnly) { chatLines.add(0, new ChatLine(updateCounter, chatComponent, chatLineId)); - while (this.chatLines.size() > (Stratus.INSTANCE.isPatcher() ? 32767 : 100)) + while (this.chatLines.size() > (100 + ModCompatHooks.getExtendedChatLength())) { this.chatLines.remove(this.chatLines.size() - 1); } @@ -172,7 +176,7 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { ScaledResolution scaledresolution = new ScaledResolution(this.mc); int i = scaledresolution.getScaleFactor(); float f = this.getChatScale(); - int k = mouseY / i - 27 + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getYOffset() : 0) - (Stratus.INSTANCE.isPatcher() && ModCompatHooks.getChatPosition() ? 12 : 0); + int k = mouseY / i - 27 + ModCompatHooks.getYOffset() - ModCompatHooks.getChatPosition(); k = MathHelper.floor_float((float) k / f); if (k >= 0) { diff --git a/src/main/kotlin/com/raeids/stratus/Stratus.kt b/src/main/kotlin/com/raeids/stratus/Stratus.kt index 7588749..57ef565 100644 --- a/src/main/kotlin/com/raeids/stratus/Stratus.kt +++ b/src/main/kotlin/com/raeids/stratus/Stratus.kt @@ -1,11 +1,11 @@ package com.raeids.stratus +import com.raeids.stratus.chat.ChatSearchingManager +import com.raeids.stratus.chat.ChatShortcuts +import com.raeids.stratus.chat.ChatTabs import com.raeids.stratus.command.StratusCommand import com.raeids.stratus.config.StratusConfig -import com.raeids.stratus.hook.ChatShortcuts -import com.raeids.stratus.hook.ChatTabs import com.raeids.stratus.hook.GuiNewChatHook -import com.raeids.stratus.hook.filterMessages import com.raeids.stratus.mixin.GuiNewChatAccessor import com.raeids.stratus.updater.Updater import com.raeids.stratus.utils.RenderHelper @@ -48,9 +48,9 @@ object Stratus { lateinit var jarFile: File private set var isPatcher = false - private set + private set var isBetterChat = false - private set + private set private val fileFormatter: SimpleDateFormat = SimpleDateFormat("yyyy-MM-dd_HH.mm.ss'.png'") @@ -92,8 +92,16 @@ object Stratus { fun screenshotLine(line: ChatLine): BufferedImage? { val hud = Minecraft.getMinecraft().ingameGUI val chat = hud.chatGUI - val i = MathHelper.floor_float(chat.chatWidth/chat.chatScale) - return screenshot(GuiUtilRenderComponents.splitText(line.chatComponent, i, Minecraft.getMinecraft().fontRendererObj, false, false).map { it.formattedText }.reversed(), chat.chatWidth) + val i = MathHelper.floor_float(chat.chatWidth / chat.chatScale) + return screenshot( + GuiUtilRenderComponents.splitText( + line.chatComponent, + i, + Minecraft.getMinecraft().fontRendererObj, + false, + false + ).map { it.formattedText }.reversed(), chat.chatWidth + ) } private fun screenshotChat() { @@ -104,8 +112,15 @@ object Stratus { val hud = Minecraft.getMinecraft().ingameGUI val chat = hud.chatGUI val chatLines = ArrayList<String>() - filterMessages((chat as GuiNewChatHook).prevText, (chat as GuiNewChatAccessor).drawnChatLines)?.let { drawnLines -> - for (i in scrollPos until drawnLines.size.coerceAtMost(scrollPos+GuiNewChat.calculateChatboxHeight(Minecraft.getMinecraft().gameSettings.chatHeightFocused)/9)){ + ChatSearchingManager.filterMessages( + (chat as GuiNewChatHook).prevText, + (chat as GuiNewChatAccessor).drawnChatLines + )?.let { drawnLines -> + for (i in scrollPos until drawnLines.size.coerceAtMost( + scrollPos + GuiNewChat.calculateChatboxHeight( + Minecraft.getMinecraft().gameSettings.chatHeightFocused + ) / 9 + )) { chatLines.add(drawnLines[i].chatComponent.formattedText) } @@ -122,10 +137,10 @@ object Stratus { } val fr: FontRenderer = Minecraft.getMinecraft().fontRendererObj - val fb: Framebuffer = RenderHelper.createBindFramebuffer(width, messages.size*9) + val fb: Framebuffer = RenderHelper.createBindFramebuffer(width, messages.size * 9) val file = File(Minecraft.getMinecraft().mcDataDir, "screenshots/chat/" + fileFormatter.format(Date())) - for (i in messages.indices) fr.drawStringWithShadow(messages[i], 0f, (messages.size-1-i)*9f, 0xffffff) + for (i in messages.indices) fr.drawStringWithShadow(messages[i], 0f, (messages.size - 1 - i) * 9f, 0xffffff) val image = RenderHelper.screenshotFramebuffer(fb, file) Minecraft.getMinecraft().entityRenderer.setupOverlayRendering() diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatRegexes.kt b/src/main/kotlin/com/raeids/stratus/chat/ChatRegexes.kt index fd743ea..4737177 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/ChatRegexes.kt +++ b/src/main/kotlin/com/raeids/stratus/chat/ChatRegexes.kt @@ -1,4 +1,4 @@ -package com.raeids.stratus.hook +package com.raeids.stratus.chat data class ChatRegexes(val regexList: List<String>?) { val compiledRegexList: MutableList<Regex> = arrayListOf() diff --git a/src/main/kotlin/com/raeids/stratus/chat/ChatSearchingManager.kt b/src/main/kotlin/com/raeids/stratus/chat/ChatSearchingManager.kt new file mode 100644 index 0000000..030635b --- /dev/null +++ b/src/main/kotlin/com/raeids/stratus/chat/ChatSearchingManager.kt @@ -0,0 +1,47 @@ +package com.raeids.stratus.chat + +import com.raeids.stratus.hook.GuiNewChatHook +import gg.essential.lib.caffeine.cache.Cache +import gg.essential.lib.caffeine.cache.Caffeine +import gg.essential.universal.wrappers.message.UTextComponent +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.ChatLine +import java.util.concurrent.LinkedBlockingQueue +import java.util.concurrent.ThreadPoolExecutor +import java.util.concurrent.TimeUnit +import java.util.concurrent.atomic.AtomicInteger + +object ChatSearchingManager { + private var counter: AtomicInteger = AtomicInteger(0) + private var POOL: ThreadPoolExecutor = ThreadPoolExecutor( + 50, 50, + 0L, TimeUnit.SECONDS, + LinkedBlockingQueue() + ) { r -> + Thread( + r, + "Chat Filter Cache Thread ${counter.incrementAndGet()}" + ) + } + + @JvmStatic + val cache: Cache<String, List<ChatLine>> = Caffeine.newBuilder().executor(POOL).maximumSize(5000).build() + + @JvmStatic + fun filterMessages(text: String, list: List<ChatLine>): List<ChatLine>? { + if (text.isBlank()) return list + val cached = cache.getIfPresent(text) + return cached ?: run { + cache.put(text, list.filter { + UTextComponent.stripFormatting(it.chatComponent.unformattedText).lowercase() + .contains(text.lowercase()) + }) + cache.getIfPresent(text) + } + } + + @JvmStatic + fun setPrevText(text: String) { + (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).prevText = text + } +}
\ No newline at end of file diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatShortcuts.kt b/src/main/kotlin/com/raeids/stratus/chat/ChatShortcuts.kt index 10a2af9..68fc18e 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/ChatShortcuts.kt +++ b/src/main/kotlin/com/raeids/stratus/chat/ChatShortcuts.kt @@ -1,4 +1,4 @@ -package com.raeids.stratus.hook +package com.raeids.stratus.chat import com.google.gson.JsonObject import com.google.gson.JsonParser @@ -49,7 +49,9 @@ object ChatShortcuts { fun handleSentCommand(command: String): String { shortcuts.forEach { - if (command == it.first || (command.startsWith(it.first) && command.substringAfter(it.first).startsWith(" "))) { + if (command == it.first || (command.startsWith(it.first) && command.substringAfter(it.first) + .startsWith(" ")) + ) { return command.replaceFirst(it.first, it.second) } } diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatTab.kt b/src/main/kotlin/com/raeids/stratus/chat/ChatTab.kt index fa56a54..ed6712c 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/ChatTab.kt +++ b/src/main/kotlin/com/raeids/stratus/chat/ChatTab.kt @@ -1,6 +1,7 @@ -package com.raeids.stratus.hook +package com.raeids.stratus.chat import com.google.gson.annotations.SerializedName +import com.raeids.stratus.gui.components.TabButton import kotlinx.coroutines.runBlocking import net.minecraft.client.Minecraft import net.minecraft.util.EnumChatFormatting @@ -17,14 +18,14 @@ data class ChatTab( @SerializedName("regex") val uncompiledRegex: List<String>?, val prefix: String ) { - lateinit var button: CleanTabButton + lateinit var button: TabButton lateinit var compiledRegex: ChatRegexes //Ugly hack to make GSON not make button / regex null fun initialize() { compiledRegex = ChatRegexes(uncompiledRegex) val width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(name) - button = CleanTabButton(653452, runBlocking { + button = TabButton(653452, runBlocking { val returnValue = x - 2 x += 6 + width return@runBlocking returnValue @@ -35,7 +36,8 @@ data class ChatTab( if (startsWith == null && equals == null && endsWith == null && contains == null && uncompiledRegex == null) { return true } - val message = if (unformatted) EnumChatFormatting.getTextWithoutFormattingCodes(chatComponent.unformattedText) else chatComponent.formattedText + val message = + if (unformatted) EnumChatFormatting.getTextWithoutFormattingCodes(chatComponent.unformattedText) else chatComponent.formattedText equals?.forEach { if (message == it) { return true diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt b/src/main/kotlin/com/raeids/stratus/chat/ChatTabs.kt index 8d03ed6..68e1d23 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt +++ b/src/main/kotlin/com/raeids/stratus/chat/ChatTabs.kt @@ -1,6 +1,9 @@ -package com.raeids.stratus.hook +package com.raeids.stratus.chat -import com.google.gson.* +import com.google.gson.GsonBuilder +import com.google.gson.JsonArray +import com.google.gson.JsonObject +import com.google.gson.JsonParser import com.raeids.stratus.Stratus import net.minecraft.client.Minecraft import net.minecraft.util.IChatComponent diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatTabsJson.kt b/src/main/kotlin/com/raeids/stratus/chat/ChatTabsJson.kt index b3a5e4c..020c8fc 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/ChatTabsJson.kt +++ b/src/main/kotlin/com/raeids/stratus/chat/ChatTabsJson.kt @@ -1,4 +1,4 @@ -package com.raeids.stratus.hook +package com.raeids.stratus.chat import com.google.gson.JsonArray import com.google.gson.annotations.SerializedName diff --git a/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt b/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt index 8600416..d67bfd0 100644 --- a/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt +++ b/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt @@ -1,10 +1,10 @@ package com.raeids.stratus.config import com.raeids.stratus.Stratus +import com.raeids.stratus.chat.ChatShortcuts +import com.raeids.stratus.chat.ChatTab +import com.raeids.stratus.chat.ChatTabs import com.raeids.stratus.gui.ChatShortcutViewGui -import com.raeids.stratus.hook.ChatShortcuts -import com.raeids.stratus.hook.ChatTab -import com.raeids.stratus.hook.ChatTabs import com.raeids.stratus.updater.DownloadGui import com.raeids.stratus.updater.Updater import gg.essential.api.EssentialAPI @@ -43,14 +43,14 @@ object StratusConfig : Vigilant(File(Stratus.modDir, "${Stratus.ID}.toml"), Stra category = "Tabs" ) var chatTabs = true - get() { - if (!field) return false - return if (hypixelOnlyChatTabs) { - EssentialAPI.getMinecraftUtil().isHypixel() - } else { - true + get() { + if (!field) return false + return if (hypixelOnlyChatTabs) { + EssentialAPI.getMinecraftUtil().isHypixel() + } else { + true + } } - } @Property( type = PropertyType.SWITCH, diff --git a/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutEditGui.kt b/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutEditGui.kt index ce64c6a..351c07e 100644 --- a/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutEditGui.kt +++ b/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutEditGui.kt @@ -1,6 +1,6 @@ package com.raeids.stratus.gui -import com.raeids.stratus.hook.ChatShortcuts +import com.raeids.stratus.chat.ChatShortcuts import gg.essential.api.EssentialAPI import gg.essential.api.gui.buildConfirmationModal import gg.essential.elementa.WindowScreen @@ -15,7 +15,8 @@ import gg.essential.vigilance.gui.VigilancePalette import gg.essential.vigilance.gui.settings.ButtonComponent import gg.essential.vigilance.gui.settings.TextComponent -class ChatShortcutEditGui(private var alias: String, private var command: String, private val editing: Boolean): WindowScreen(restoreCurrentGuiOnClose = true) { +class ChatShortcutEditGui(private var alias: String, private var command: String, private val editing: Boolean) : + WindowScreen(restoreCurrentGuiOnClose = true) { private val initialAlias = alias private val initialCommand = command @@ -69,7 +70,8 @@ class ChatShortcutEditGui(private var alias: String, private var command: String } childOf window } - inner class ChatShortcutConfirmGui(private var alias: String, private var command: String): WindowScreen(restoreCurrentGuiOnClose = true) { + inner class ChatShortcutConfirmGui(private var alias: String, private var command: String) : + WindowScreen(restoreCurrentGuiOnClose = true) { override fun initScreen(width: Int, height: Int) { super.initScreen(width, height) EssentialAPI.getEssentialComponentFactory().buildConfirmationModal { diff --git a/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutViewGui.kt b/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutViewGui.kt index ba8c771..06dfcbd 100644 --- a/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutViewGui.kt +++ b/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutViewGui.kt @@ -1,20 +1,16 @@ package com.raeids.stratus.gui -import com.raeids.stratus.hook.ChatShortcuts +import com.raeids.stratus.chat.ChatShortcuts +import com.raeids.stratus.gui.components.TextBlock import gg.essential.api.EssentialAPI import gg.essential.elementa.WindowScreen import gg.essential.elementa.components.UIBlock -import gg.essential.elementa.components.UIText import gg.essential.elementa.constraints.CenterConstraint -import gg.essential.elementa.constraints.ChildBasedSizeConstraint import gg.essential.elementa.constraints.RelativeWindowConstraint import gg.essential.elementa.constraints.SiblingConstraint import gg.essential.elementa.dsl.* -import gg.essential.elementa.effects.OutlineEffect -import gg.essential.elementa.state.BasicState import gg.essential.vigilance.gui.VigilancePalette import gg.essential.vigilance.gui.settings.ButtonComponent -import gg.essential.vigilance.gui.settings.SettingComponent class ChatShortcutViewGui : WindowScreen() { override fun initScreen(width: Int, height: Int) { @@ -57,31 +53,4 @@ class ChatShortcutViewGui : WindowScreen() { y = 80.percent() } childOf window } -} - -class TextBlock( - text: String -) : SettingComponent() { - private val textHolder = UIBlock().constrain { - width = ChildBasedSizeConstraint() + 6.pixels() - height = ChildBasedSizeConstraint() + 6.pixels() - color = VigilancePalette.getDarkHighlight().toConstraint() - } childOf this effect OutlineEffect( - VigilancePalette.getDivider(), - 1f - ).bindColor(BasicState(VigilancePalette.getDivider())) - - private val textInput: UIText = UIText(text).constrain { - x = 3.pixels() - y = 3.pixels() - } - - init { - textInput childOf textHolder - - constrain { - width = ChildBasedSizeConstraint() - height = ChildBasedSizeConstraint() - } - } }
\ No newline at end of file diff --git a/src/main/kotlin/com/raeids/stratus/hook/CleanButton.kt b/src/main/kotlin/com/raeids/stratus/gui/components/CleanButton.kt index bc4db34..7ec29d4 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/CleanButton.kt +++ b/src/main/kotlin/com/raeids/stratus/gui/components/CleanButton.kt @@ -1,4 +1,4 @@ -package com.raeids.stratus.hook +package com.raeids.stratus.gui.components import club.sk1er.patcher.config.PatcherConfig import com.raeids.stratus.Stratus diff --git a/src/main/kotlin/com/raeids/stratus/hook/ScreenshotButton.kt b/src/main/kotlin/com/raeids/stratus/gui/components/ScreenshotButton.kt index 70c64c2..9e6fa1f 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/ScreenshotButton.kt +++ b/src/main/kotlin/com/raeids/stratus/gui/components/ScreenshotButton.kt @@ -1,4 +1,4 @@ -package com.raeids.stratus.hook +package com.raeids.stratus.gui.components import com.raeids.stratus.Stratus import com.raeids.stratus.mixin.GuiNewChatAccessor @@ -10,7 +10,8 @@ import net.minecraft.client.gui.GuiChat import net.minecraft.client.renderer.GlStateManager import net.minecraft.util.ResourceLocation -class ScreenshotButton: CleanButton(448318, { UResolution.scaledWidth - 28}, { UResolution.scaledHeight - 27}, 12, 12, "") { +class ScreenshotButton : + CleanButton(448318, { UResolution.scaledWidth - 28 }, { UResolution.scaledHeight - 27 }, 12, 12, "") { override fun onMousePress() { val chat = Minecraft.getMinecraft().ingameGUI.chatGUI diff --git a/src/main/kotlin/com/raeids/stratus/hook/CleanSearchButton.kt b/src/main/kotlin/com/raeids/stratus/gui/components/SearchButton.kt index 7a68c75..3180482 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/CleanSearchButton.kt +++ b/src/main/kotlin/com/raeids/stratus/gui/components/SearchButton.kt @@ -1,6 +1,7 @@ -package com.raeids.stratus.hook +package com.raeids.stratus.gui.components import com.raeids.stratus.Stratus +import com.raeids.stratus.hook.GuiNewChatHook import gg.essential.universal.UResolution import net.minecraft.client.Minecraft import net.minecraft.client.gui.Gui @@ -8,7 +9,8 @@ import net.minecraft.client.gui.GuiTextField import net.minecraft.client.renderer.GlStateManager import net.minecraft.util.ResourceLocation -class CleanSearchButton: CleanButton(3993935, {UResolution.scaledWidth - 14}, {UResolution.scaledHeight - 27}, 12, 12, "") { +class SearchButton : + CleanButton(3993935, { UResolution.scaledWidth - 14 }, { UResolution.scaledHeight - 27 }, 12, 12, "") { val inputField = SearchTextField() private var chatBox = false @@ -30,17 +32,24 @@ class CleanSearchButton: CleanButton(3993935, {UResolution.scaledWidth - 14}, {U if (visible) { mc.textureManager.bindTexture(ResourceLocation(Stratus.ID, "search.png")) if (isEnabled()) { - GlStateManager.color(224f/255f, 224f/255f, 224f/255f) + GlStateManager.color(224f / 255f, 224f / 255f, 224f / 255f) } else if (mouseX >= xPosition && mouseX <= xPosition + 10 && mouseY >= yPosition && mouseY <= yPosition + 10) { - GlStateManager.color(1f, 1f, 160f/255f) + GlStateManager.color(1f, 1f, 160f / 255f) } else { GlStateManager.color(1f, 1f, 1f) } - Gui.drawModalRectWithCustomSizedTexture(xPosition+1, yPosition+1, 0f, 0f, 10, 10, 10f, 10f) + Gui.drawModalRectWithCustomSizedTexture(xPosition + 1, yPosition + 1, 0f, 0f, 10, 10, 10f, 10f) } } - inner class SearchTextField: GuiTextField(69420, Minecraft.getMinecraft().fontRendererObj, UResolution.scaledWidth * 4 / 5 - 60, UResolution.scaledHeight - 27, UResolution.scaledWidth / 5, 12) { + inner class SearchTextField : GuiTextField( + 69420, + Minecraft.getMinecraft().fontRendererObj, + UResolution.scaledWidth * 4 / 5 - 60, + UResolution.scaledHeight - 27, + UResolution.scaledWidth / 5, + 12 + ) { init { maxStringLength = 100 diff --git a/src/main/kotlin/com/raeids/stratus/hook/CleanTabButton.kt b/src/main/kotlin/com/raeids/stratus/gui/components/TabButton.kt index 0277dd8..48c399a 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/CleanTabButton.kt +++ b/src/main/kotlin/com/raeids/stratus/gui/components/TabButton.kt @@ -1,10 +1,12 @@ -package com.raeids.stratus.hook +package com.raeids.stratus.gui.components +import com.raeids.stratus.chat.ChatTab +import com.raeids.stratus.chat.ChatTabs import gg.essential.universal.UResolution -class CleanTabButton(buttonId: Int, x: Int, widthIn: Int, heightIn: Int, private val chatTab: ChatTab) : +class TabButton(buttonId: Int, x: Int, widthIn: Int, heightIn: Int, private val chatTab: ChatTab) : CleanButton(buttonId, { x }, { - UResolution.scaledHeight - 26 + UResolution.scaledHeight - 26 }, widthIn, heightIn, chatTab.name) { override fun onMousePress() { diff --git a/src/main/kotlin/com/raeids/stratus/gui/components/TextBlock.kt b/src/main/kotlin/com/raeids/stratus/gui/components/TextBlock.kt new file mode 100644 index 0000000..9b36fa4 --- /dev/null +++ b/src/main/kotlin/com/raeids/stratus/gui/components/TextBlock.kt @@ -0,0 +1,37 @@ +package com.raeids.stratus.gui.components + +import gg.essential.elementa.components.UIBlock +import gg.essential.elementa.components.UIText +import gg.essential.elementa.constraints.ChildBasedSizeConstraint +import gg.essential.elementa.dsl.* +import gg.essential.elementa.effects.OutlineEffect +import gg.essential.elementa.state.BasicState +import gg.essential.vigilance.gui.VigilancePalette +import gg.essential.vigilance.gui.settings.SettingComponent + +class TextBlock( + text: String +) : SettingComponent() { + private val textHolder = UIBlock() constrain { + width = ChildBasedSizeConstraint() + 6.pixels() + height = ChildBasedSizeConstraint() + 6.pixels() + color = VigilancePalette.getDarkHighlight().toConstraint() + } childOf this effect OutlineEffect( + VigilancePalette.getDivider(), + 1f + ).bindColor(BasicState(VigilancePalette.getDivider())) + + private val textInput: UIText = UIText(text) constrain { + x = 3.pixels() + y = 3.pixels() + } + + init { + textInput childOf textHolder + + constrain { + width = ChildBasedSizeConstraint() + height = ChildBasedSizeConstraint() + } + } +}
\ No newline at end of file diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatSearching.kt b/src/main/kotlin/com/raeids/stratus/hook/ChatSearching.kt deleted file mode 100644 index 6dd4904..0000000 --- a/src/main/kotlin/com/raeids/stratus/hook/ChatSearching.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.raeids.stratus.hook - -import gg.essential.lib.caffeine.cache.Cache -import gg.essential.lib.caffeine.cache.Caffeine -import gg.essential.universal.wrappers.message.UTextComponent -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.ChatLine -import java.util.concurrent.LinkedBlockingQueue -import java.util.concurrent.ThreadPoolExecutor -import java.util.concurrent.TimeUnit -import java.util.concurrent.atomic.AtomicInteger - -private var counter: AtomicInteger = AtomicInteger(0) -private var POOL: ThreadPoolExecutor = ThreadPoolExecutor( - 50, 50, - 0L, TimeUnit.SECONDS, - LinkedBlockingQueue() -) { r -> - Thread( - r, - "Chat Filter Cache Thread ${counter.incrementAndGet()}" - ) -} - -val cache: Cache<String, List<ChatLine>> = Caffeine.newBuilder().executor(POOL).maximumSize(5000).build() - -fun filterMessages(text: String, list: List<ChatLine>): List<ChatLine>? { - if (text.isBlank()) return list - val cached = cache.getIfPresent(text) - return cached ?: run { - cache.put(text, list.filter { - UTextComponent.stripFormatting(it.chatComponent.unformattedText).lowercase() - .contains(text.lowercase()) - }) - cache.getIfPresent(text) - } -} - -fun setPrevText(text: String) { - (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).prevText = text -}
\ No newline at end of file diff --git a/src/main/kotlin/com/raeids/stratus/hook/ModCompatHooks.kt b/src/main/kotlin/com/raeids/stratus/hook/ModCompatHooks.kt deleted file mode 100644 index e2ac629..0000000 --- a/src/main/kotlin/com/raeids/stratus/hook/ModCompatHooks.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.raeids.stratus.hook - -import club.sk1er.patcher.config.PatcherConfig -import com.llamalad7.betterchat.BetterChat - -// This exists because mixin doesn't like dummy classes -object ModCompatHooks { - @JvmStatic - val xOffset - get() = BetterChat.getSettings().xOffset - - @JvmStatic - val yOffset - get() = BetterChat.getSettings().yOffset - - @JvmStatic - val chatPosition - get() = PatcherConfig.chatPosition - -} diff --git a/src/main/kotlin/com/raeids/stratus/updater/Updater.kt b/src/main/kotlin/com/raeids/stratus/updater/Updater.kt index 2f48cdb..11368fd 100644 --- a/src/main/kotlin/com/raeids/stratus/updater/Updater.kt +++ b/src/main/kotlin/com/raeids/stratus/updater/Updater.kt @@ -27,7 +27,9 @@ object Updater { DefaultArtifactVersion(Stratus.VER.substringBefore("-")) val latestVersion = DefaultArtifactVersion(latestTag!!.substringAfter("v").substringBefore("-")) if (currentVersion >= latestVersion) { - return@runAsync + if (!Stratus.VER.contains("-")) { + return@runAsync + } } updateUrl = latestRelease["assets"].asJsonArray[0].asJsonObject["browser_download_url"] diff --git a/src/main/kotlin/com/raeids/stratus/utils/ImageTransferable.kt b/src/main/kotlin/com/raeids/stratus/utils/ImageTransferable.kt index 81571a5..a8fe9fb 100644 --- a/src/main/kotlin/com/raeids/stratus/utils/ImageTransferable.kt +++ b/src/main/kotlin/com/raeids/stratus/utils/ImageTransferable.kt @@ -5,7 +5,7 @@ import java.awt.datatransfer.DataFlavor import java.awt.datatransfer.Transferable import java.awt.datatransfer.UnsupportedFlavorException -class ImageTransferable(private val image: Image): Transferable { +data class ImageTransferable(private val image: Image) : Transferable { override fun getTransferDataFlavors(): Array<DataFlavor> { return arrayOf(DataFlavor.imageFlavor) diff --git a/src/main/kotlin/com/raeids/stratus/utils/ModCompatHooks.kt b/src/main/kotlin/com/raeids/stratus/utils/ModCompatHooks.kt new file mode 100644 index 0000000..48463a6 --- /dev/null +++ b/src/main/kotlin/com/raeids/stratus/utils/ModCompatHooks.kt @@ -0,0 +1,26 @@ +package com.raeids.stratus.utils + +import club.sk1er.patcher.config.PatcherConfig +import com.llamalad7.betterchat.BetterChat +import com.raeids.stratus.Stratus.isBetterChat +import com.raeids.stratus.Stratus.isPatcher + +// This exists because mixin doesn't like dummy classes +object ModCompatHooks { + @JvmStatic + val xOffset + get() = if (isBetterChat) BetterChat.getSettings().xOffset else 0 + + @JvmStatic + val yOffset + get() = if (isBetterChat) BetterChat.getSettings().yOffset else 0 + + @JvmStatic + val chatPosition + get() = if (isPatcher && PatcherConfig.chatPosition) 12 else 0 + + @JvmStatic + val extendedChatLength + get() = if (isPatcher) 32667 else 0 + +} diff --git a/src/main/kotlin/com/raeids/stratus/utils/RenderHelper.kt b/src/main/kotlin/com/raeids/stratus/utils/RenderHelper.kt index 664f5de..95de4d8 100644 --- a/src/main/kotlin/com/raeids/stratus/utils/RenderHelper.kt +++ b/src/main/kotlin/com/raeids/stratus/utils/RenderHelper.kt @@ -144,7 +144,8 @@ object RenderHelper { e.printStackTrace() } } - val pixels: IntArray = bufferedImage.getRGB(0, 0, bufferedImage.width, bufferedImage.height, null, 0, bufferedImage.width) + val pixels: IntArray = + bufferedImage.getRGB(0, 0, bufferedImage.width, bufferedImage.height, null, 0, bufferedImage.width) val newImage = BufferedImage(bufferedImage.width, bufferedImage.height, BufferedImage.TYPE_INT_RGB) newImage.setRGB(0, 0, newImage.width, newImage.height, pixels, 0, newImage.width) diff --git a/src/main/resources/mixins.stratus.json b/src/main/resources/mixins.stratus.json index 033e372..fc3d100 100644 --- a/src/main/resources/mixins.stratus.json +++ b/src/main/resources/mixins.stratus.json @@ -8,10 +8,8 @@ "EntityPlayerSPMixin", "GuiChatMixin", "GuiNewChatAccessor", + "GuiNewChatMapMixin", "GuiNewChatMixin" ], - "verbose": true, - "client": [ - "GuiNewChatMapMixin" - ] + "verbose": true }
\ No newline at end of file |