diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-02-06 10:39:36 +0700 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-02-06 10:39:36 +0700 |
commit | 6ef0b0b64522ae45bf3747b26bd6dc5f58358f82 (patch) | |
tree | 267709bb401f10f414534552a39a7697614aa4f9 /src | |
parent | 1307b6c8f8f7a4aa4d1fd9781cddb5edd0c9f349 (diff) | |
download | Chatting-6ef0b0b64522ae45bf3747b26bd6dc5f58358f82.tar.gz Chatting-6ef0b0b64522ae45bf3747b26bd6dc5f58358f82.tar.bz2 Chatting-6ef0b0b64522ae45bf3747b26bd6dc5f58358f82.zip |
1.3.0
Diffstat (limited to 'src')
11 files changed, 55 insertions, 280 deletions
diff --git a/src/main/java/cc/woverflow/chatting/mixin/RedactionNameHighlightMixin.java b/src/main/java/cc/woverflow/chatting/mixin/RedactionNameHighlightMixin.java new file mode 100644 index 0000000..eab1bfe --- /dev/null +++ b/src/main/java/cc/woverflow/chatting/mixin/RedactionNameHighlightMixin.java @@ -0,0 +1,22 @@ +package cc.woverflow.chatting.mixin; + +import cc.woverflow.chatting.utils.RenderUtils; +import org.spongepowered.asm.mixin.Dynamic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Pseudo +@Mixin(targets = "net.wyvest.redaction.features.NameHighlight") +public class RedactionNameHighlightMixin { + + @Dynamic("REDACTION") + @Inject(method = "highlightName", at = @At("HEAD"), cancellable = true) + private static void onNameHighlight(String text, CallbackInfoReturnable<String> cir) { + if (RenderUtils.getBypassNameHighlight()) { + cir.setReturnValue(text); + } + } +} diff --git a/src/main/java/cc/woverflow/chatting/mixin/WyvtilsListenerMixin.java b/src/main/java/cc/woverflow/chatting/mixin/WyvtilsListenerMixin.java index f5b7cfb..4c7448e 100644 --- a/src/main/java/cc/woverflow/chatting/mixin/WyvtilsListenerMixin.java +++ b/src/main/java/cc/woverflow/chatting/mixin/WyvtilsListenerMixin.java @@ -16,6 +16,6 @@ public class WyvtilsListenerMixin { @Dynamic("Wyvtils") @Inject(method = "onStringRendered", at = @At("HEAD"), cancellable = true, remap = false) private void cancelStringRender(@Coerce Object a, CallbackInfo ci) { - if (RenderUtils.getBypassWyvtils()) ci.cancel(); + if (RenderUtils.getBypassNameHighlight()) ci.cancel(); } } diff --git a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt index d90ba34..1f7c47d 100644 --- a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt +++ b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt @@ -3,23 +3,17 @@ package cc.woverflow.chatting import cc.woverflow.chatting.chat.ChatSearchingManager import cc.woverflow.chatting.chat.ChatShortcuts import cc.woverflow.chatting.chat.ChatTabs -import cc.woverflow.chatting.command.ChattingCommand import cc.woverflow.chatting.config.ChattingConfig import cc.woverflow.chatting.hook.GuiNewChatHook import cc.woverflow.chatting.mixin.GuiNewChatAccessor -import cc.woverflow.chatting.updater.Updater import cc.woverflow.chatting.utils.ModCompatHooks import cc.woverflow.chatting.utils.copyToClipboard import cc.woverflow.chatting.utils.createBindFramebuffer import cc.woverflow.chatting.utils.screenshot -import com.google.gson.JsonParser +import cc.woverflow.wcore.utils.Updater +import cc.woverflow.wcore.utils.command +import cc.woverflow.wcore.utils.openGUI import gg.essential.api.EssentialAPI -import gg.essential.api.gui.buildConfirmationModal -import gg.essential.api.utils.Multithreading -import gg.essential.api.utils.WebUtil -import gg.essential.elementa.ElementaVersion -import gg.essential.elementa.WindowScreen -import gg.essential.elementa.dsl.childOf import gg.essential.universal.UDesktop import gg.essential.universal.UResolution import net.minecraft.client.Minecraft @@ -33,7 +27,10 @@ import net.minecraftforge.common.MinecraftForge.EVENT_BUS import net.minecraftforge.fml.client.registry.ClientRegistry import net.minecraftforge.fml.common.Loader import net.minecraftforge.fml.common.Mod -import net.minecraftforge.fml.common.event.* +import net.minecraftforge.fml.common.event.FMLInitializationEvent +import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent +import net.minecraftforge.fml.common.event.FMLPostInitializationEvent +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent import org.lwjgl.input.Keyboard @@ -57,14 +54,10 @@ object Chatting { const val VER = "@VER@" const val ID = "@ID@" var doTheThing = false - lateinit var jarFile: File - private set var isPatcher = false private set var isBetterChat = false private set - var isSkyclientStupid = false - private set var isSkytils = false private set var isHychat = false @@ -77,18 +70,21 @@ object Chatting { @Mod.EventHandler fun onFMLPreInitialization(event: FMLPreInitializationEvent) { if (!modDir.exists()) modDir.mkdirs() - jarFile = event.sourceFile + Updater.addToUpdater(event.sourceFile, NAME, ID, VER, "W-OVERFLOW/${ID}") } @Mod.EventHandler fun onInitialization(event: FMLInitializationEvent) { ChattingConfig.preload() - ChattingCommand.register() + command("chatting", aliases = arrayListOf("stratus")) { + main { + ChattingConfig.openGUI() + } + } ClientRegistry.registerKeyBinding(keybind) EVENT_BUS.register(this) ChatTabs.initialize() ChatShortcuts.initialize() - Updater.update() } @Mod.EventHandler @@ -96,59 +92,11 @@ object Chatting { isPatcher = Loader.isModLoaded("patcher") isBetterChat = Loader.isModLoaded("betterchat") isSkytils = Loader.isModLoaded("skytils") - val date = Date(jarFile.lastModified()) - isSkyclientStupid = date.before(Date(1641985860)) && date.after(Date(1641956460)) && Loader.isModLoaded("skyblockclientupdater") && !isSkytils // between 10am gmt+7 and 6pm gmt+7 skyclient updater falsely detected skytils as chatting isHychat = Loader.isModLoaded("hychat") } @Mod.EventHandler fun onForgeLoad(event: FMLLoadCompleteEvent) { - if (ChattingConfig.firstLaunch) { - ChattingConfig.firstLaunch = false - ChattingConfig.markDirty() - ChattingConfig.writeData() - if (isSkyclientStupid) { - EssentialAPI.getGuiUtil().openScreen(object : WindowScreen(version = ElementaVersion.V1) { - override fun initScreen(width: Int, height: Int) { - super.initScreen(width, height) - EssentialAPI.getEssentialComponentFactory().buildConfirmationModal { - this.text = "You may have had Skytils accidentally update to Chatting. Do you want to install the latest version of Skytils?" - this.onConfirm = { - restorePreviousScreen() - Multithreading.runAsync { - val json = JsonParser().parse(WebUtil.fetchString( - "https://api.github.com/repos/Skytils/SkytilsMod/releases" - )).asJsonArray[0].asJsonObject - if (Updater.download( - json["assets"].asJsonArray[0].asJsonObject["browser_download_url"].asString, - File( - "mods/Skytils-${ - json["tag_name"].asString.substringAfter("v") - }.jar" - ) - ) - ) { - EssentialAPI.getNotifications() - .push( - NAME, - "The ingame updater has successfully installed Skytils." - ) - } else { - EssentialAPI.getNotifications().push( - NAME, - "The ingame updater has NOT installed Skytils as something went wrong." - ) - } - } - } - this.onDeny = { - restorePreviousScreen() - } - } childOf this.window - } - }) - } - } if (ChattingConfig.informForAlternatives) { if (isHychat) { EssentialAPI.getNotifications().push(NAME, "Hychat can be removed at it is replaced by Chatting.") @@ -230,7 +178,7 @@ object Chatting { } val fr: FontRenderer = ModCompatHooks.fontRenderer - val width = messages.maxOf { fr.getStringWidth(it) } + val width = messages.maxOf { fr.getStringWidth(it) } + 4 val fb: Framebuffer = createBindFramebuffer(width * 2, (messages.size * 9) * 2) val file = File(Minecraft.getMinecraft().mcDataDir, "screenshots/chat/" + fileFormatter.format(Date())) @@ -238,7 +186,7 @@ object Chatting { val scale = Minecraft.getMinecraft().gameSettings.chatScale GlStateManager.scale(scale, scale, 1f) for (i in messages.indices) { - fr.drawStringWithShadow(messages[i], 0f, (messages.size - 1 - i) * 9f, 0xffffff) + ModCompatHooks.redirectDrawString(messages[i], 0f, (messages.size - 1 - i) * 9f, 0xffffff) } val image = fb.screenshot(file) diff --git a/src/main/kotlin/cc/woverflow/chatting/command/ChattingCommand.kt b/src/main/kotlin/cc/woverflow/chatting/command/ChattingCommand.kt deleted file mode 100644 index ba697e1..0000000 --- a/src/main/kotlin/cc/woverflow/chatting/command/ChattingCommand.kt +++ /dev/null @@ -1,17 +0,0 @@ -package cc.woverflow.chatting.command - -import cc.woverflow.chatting.Chatting -import cc.woverflow.chatting.config.ChattingConfig -import gg.essential.api.EssentialAPI -import gg.essential.api.commands.Command -import gg.essential.api.commands.DefaultHandler - -object ChattingCommand : Command(Chatting.ID, true) { - - override val commandAliases: Set<Alias> = setOf(Alias("stratus")) - - @DefaultHandler - fun handle() { - EssentialAPI.getGuiUtil().openScreen(ChattingConfig.gui()) - } -}
\ No newline at end of file diff --git a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt index 1c70b49..ec27a4e 100644 --- a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt +++ b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt @@ -5,8 +5,6 @@ import cc.woverflow.chatting.chat.ChatShortcuts import cc.woverflow.chatting.chat.ChatTab import cc.woverflow.chatting.chat.ChatTabs import cc.woverflow.chatting.gui.ChatShortcutViewGui -import cc.woverflow.chatting.updater.DownloadGui -import cc.woverflow.chatting.updater.Updater import gg.essential.api.EssentialAPI import gg.essential.vigilance.Vigilant import gg.essential.vigilance.data.Category @@ -167,37 +165,6 @@ object ChattingConfig : Vigilant(File(Chatting.modDir, "${Chatting.ID}.toml"), C EssentialAPI.getGuiUtil().openScreen(ChatShortcutViewGui()) } - @Property( - type = PropertyType.SWITCH, - name = "Show Update Notification", - description = "Show a notification when you start Minecraft informing you of new updates.", - category = "Updater" - ) - var showUpdate = true - - @Property( - type = PropertyType.BUTTON, - name = "Update Now", - description = "Update by clicking the button.", - category = "Updater" - ) - fun update() { - if (Updater.shouldUpdate) EssentialAPI.getGuiUtil() - .openScreen(DownloadGui()) else EssentialAPI.getNotifications() - .push( - Chatting.NAME, - "No update had been detected at startup, and thus the update GUI has not been shown." - ) - } - - @Property( - type = PropertyType.SWITCH, - name = "First Launch", - category = "General", - hidden = true - ) - var firstLaunch = true - init { initialize() registerListener("chatTabs") { funny: Boolean -> diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/ChatShortcutEditGui.kt b/src/main/kotlin/cc/woverflow/chatting/gui/ChatShortcutEditGui.kt index d75339b..983e2ed 100644 --- a/src/main/kotlin/cc/woverflow/chatting/gui/ChatShortcutEditGui.kt +++ b/src/main/kotlin/cc/woverflow/chatting/gui/ChatShortcutEditGui.kt @@ -8,10 +8,7 @@ import gg.essential.elementa.WindowScreen import gg.essential.elementa.components.UIBlock import gg.essential.elementa.constraints.CenterConstraint import gg.essential.elementa.constraints.SiblingConstraint -import gg.essential.elementa.dsl.childOf -import gg.essential.elementa.dsl.constrain -import gg.essential.elementa.dsl.percent -import gg.essential.elementa.dsl.pixels +import gg.essential.elementa.dsl.* import gg.essential.vigilance.gui.VigilancePalette import gg.essential.vigilance.gui.settings.ButtonComponent import gg.essential.vigilance.gui.settings.TextComponent @@ -24,7 +21,8 @@ class ChatShortcutEditGui(private var alias: String, private var command: String override fun initScreen(width: Int, height: Int) { super.initScreen(width, height) - val block = UIBlock(VigilancePalette.getBackground()).constrain { + window.clearChildren() // make sure everything is cleared, sometimes the shortcuts duplicated + val block by UIBlock(VigilancePalette.getBackground()).constrain { this.x = CenterConstraint() this.y = CenterConstraint() this.width = 100.pixels() diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/ChatShortcutViewGui.kt b/src/main/kotlin/cc/woverflow/chatting/gui/ChatShortcutViewGui.kt index a4a9f70..0fa2ef7 100644 --- a/src/main/kotlin/cc/woverflow/chatting/gui/ChatShortcutViewGui.kt +++ b/src/main/kotlin/cc/woverflow/chatting/gui/ChatShortcutViewGui.kt @@ -5,6 +5,7 @@ import cc.woverflow.chatting.gui.components.TextBlock import gg.essential.api.EssentialAPI import gg.essential.elementa.ElementaVersion import gg.essential.elementa.WindowScreen +import gg.essential.elementa.components.ScrollComponent import gg.essential.elementa.components.UIBlock import gg.essential.elementa.constraints.CenterConstraint import gg.essential.elementa.constraints.RelativeWindowConstraint @@ -16,13 +17,20 @@ import gg.essential.vigilance.gui.settings.ButtonComponent class ChatShortcutViewGui : WindowScreen(version = ElementaVersion.V1) { override fun initScreen(width: Int, height: Int) { super.initScreen(width, height) + window.clearChildren() // make sure everything is cleared, sometimes the shortcuts duplicated + val container by ScrollComponent() constrain { + x = 0.pixels() + y = 0.pixels() + this.width = 85.percent() + this.height = 85.percent() + } childOf window for ((index, shortcut) in ChatShortcuts.shortcuts.withIndex()) { val block = UIBlock(VigilancePalette.getBackground()).constrain { x = 3.percent() y = (index * 12).percent() this.width = 94.percent() this.height = 25.pixels() - } childOf this.window + } childOf container TextBlock(shortcut.first).constrain { x = RelativeWindowConstraint(0.05F) y = CenterConstraint() @@ -51,7 +59,7 @@ class ChatShortcutViewGui : WindowScreen(version = ElementaVersion.V1) { EssentialAPI.getGuiUtil().openScreen(ChatShortcutEditGui("", "", false)) } constrain { x = CenterConstraint() - y = 80.percent() + y = 90.percent() } childOf window } }
\ No newline at end of file diff --git a/src/main/kotlin/cc/woverflow/chatting/updater/DownloadGui.kt b/src/main/kotlin/cc/woverflow/chatting/updater/DownloadGui.kt deleted file mode 100644 index 10f2f6f..0000000 --- a/src/main/kotlin/cc/woverflow/chatting/updater/DownloadGui.kt +++ /dev/null @@ -1,54 +0,0 @@ -package cc.woverflow.chatting.updater - -import cc.woverflow.chatting.Chatting -import gg.essential.api.EssentialAPI -import gg.essential.api.gui.buildConfirmationModal -import gg.essential.api.utils.Multithreading -import gg.essential.elementa.ElementaVersion -import gg.essential.elementa.WindowScreen -import gg.essential.elementa.dsl.childOf -import java.io.File - -class DownloadGui : WindowScreen(ElementaVersion.V1, true, true, true, -1) { - override fun initScreen(width: Int, height: Int) { - super.initScreen(width, height) - EssentialAPI.getEssentialComponentFactory().buildConfirmationModal { - this.text = "Are you sure you want to update?" - this.secondaryText = - "(This will update from v${Chatting.VER} to ${Updater.latestTag})" - this.onConfirm = { - restorePreviousScreen() - Multithreading.runAsync { - if (Updater.download( - Updater.updateUrl, - File( - "mods/${Chatting.NAME}-${ - Updater.latestTag!!.substringAfter("v") - }.jar" - ) - ) && Updater.download( - "https://github.com/Wyvest/Deleter/releases/download/v1.2/Deleter-1.2.jar", - File(Chatting.modDir.parentFile, "Deleter-1.2.jar") - ) - ) { - EssentialAPI.getNotifications() - .push( - Chatting.NAME, - "The ingame updater has successfully installed the newest version." - ) - Updater.addShutdownHook() - Updater.shouldUpdate = false - } else { - EssentialAPI.getNotifications().push( - Chatting.NAME, - "The ingame updater has NOT installed the newest version as something went wrong." - ) - } - } - } - this.onDeny = { - restorePreviousScreen() - } - } childOf this.window - } -}
\ No newline at end of file diff --git a/src/main/kotlin/cc/woverflow/chatting/updater/Updater.kt b/src/main/kotlin/cc/woverflow/chatting/updater/Updater.kt deleted file mode 100644 index dbd851c..0000000 --- a/src/main/kotlin/cc/woverflow/chatting/updater/Updater.kt +++ /dev/null @@ -1,98 +0,0 @@ -package cc.woverflow.chatting.updater - -import cc.woverflow.chatting.Chatting -import cc.woverflow.chatting.config.ChattingConfig -import gg.essential.api.EssentialAPI -import gg.essential.api.utils.Multithreading -import gg.essential.api.utils.WebUtil.downloadToFile -import gg.essential.api.utils.WebUtil.fetchJSON -import gg.essential.universal.UDesktop -import net.minecraft.client.Minecraft -import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion -import java.io.File -import java.io.IOException - -object Updater { - var updateUrl = "" - var latestTag: String? = null - var shouldUpdate = false - - fun update() { - Multithreading.runAsync { - try { - val latestRelease = - fetchJSON("https://api.github.com/repos/W-OVERFLOW/${Chatting.ID}/releases/latest").getObject() - latestTag = latestRelease["tag_name"].asString - val currentVersion = - DefaultArtifactVersion(Chatting.VER.substringBefore("-")) - val latestVersion = DefaultArtifactVersion(latestTag!!.substringAfter("v").substringBefore("-")) - if (currentVersion >= latestVersion) { - if (currentVersion.compareTo(latestVersion) == 0 || !Chatting.VER.contains("-")) { - return@runAsync - } - } - updateUrl = - latestRelease["assets"].asJsonArray[0].asJsonObject["browser_download_url"] - .asString - if (updateUrl.isNotEmpty()) { - if (ChattingConfig.showUpdate) { - EssentialAPI.getNotifications().push( - Chatting.NAME, - "${Chatting.NAME} has a new update ($latestTag)! Click here to download it automatically!", action = { EssentialAPI.getGuiUtil().openScreen(DownloadGui()) } - ) - } - shouldUpdate = true - } - } catch (e: Exception) { - e.printStackTrace() - } - } - } - - fun download(url: String, file: File): Boolean { - var url = url - if (file.exists()) return true - url = url.replace(" ", "%20") - try { - downloadToFile(url, file, "${Chatting.NAME}/${Chatting.VER}") - } catch (e: Exception) { - e.printStackTrace() - return false - } - return file.exists() - } - - fun addShutdownHook() { - EssentialAPI.getShutdownHookUtil().register { - println("Opening Deleter task...") - try { - val runtime = javaRuntime - if (Minecraft.isRunningOnMac) { - UDesktop.open(Chatting.jarFile.parentFile) - } - val file = File(Chatting.modDir.parentFile, "Deleter-1.2.jar") - Runtime.getRuntime() - .exec("\"" + runtime + "\" -jar \"" + file.absolutePath + "\" \"" + Chatting.jarFile.absolutePath + "\"") - } catch (e: Exception) { - e.printStackTrace() - } - } - } - - /** - * Gets the current Java runtime being used. - * - * @link https://stackoverflow.com/a/47925649 - */ - @get:Throws(IOException::class) - val javaRuntime: String - get() { - val os = System.getProperty("os.name") - val java = System.getProperty("java.home") + File.separator + "bin" + File.separator + - if (os != null && os.lowercase().startsWith("windows")) "java.exe" else "java" - if (!File(java).isFile) { - throw IOException("Unable to find suitable java runtime at $java") - } - return java - } -}
\ No newline at end of file diff --git a/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt b/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt index 0496905..07fa2d3 100644 --- a/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt +++ b/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt @@ -24,7 +24,7 @@ import java.nio.ByteBuffer import java.nio.ByteOrder import javax.imageio.ImageIO -var bypassWyvtils = false +var bypassNameHighlight = false private set private val regex = Regex("(?i)\\u00A7[0-9a-f]") @@ -226,7 +226,7 @@ fun FontRenderer.drawBorderedString(text: String, val noColors = text.replace(regex, "\u00A7r") var yes = 0 if (((Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity / 4) > 3) { - bypassWyvtils = true + bypassNameHighlight = true for (xOff in -2..2) { for (yOff in -2..2) { if (xOff * xOff != yOff * yOff) { @@ -237,7 +237,7 @@ fun FontRenderer.drawBorderedString(text: String, } } } - bypassWyvtils = false + bypassNameHighlight = false } yes += drawString(text, x, y, color) return yes diff --git a/src/main/resources/mixins.chatting.json b/src/main/resources/mixins.chatting.json index 3a488ae..814bf92 100644 --- a/src/main/resources/mixins.chatting.json +++ b/src/main/resources/mixins.chatting.json @@ -11,6 +11,7 @@ "GuiNewChatMapMixin", "GuiNewChatMixin", "GuiUtilsMixin", + "RedactionNameHighlightMixin", "WyvtilsListenerMixin" ], "verbose": true |