diff --git a/gradle.properties b/gradle.properties index 1d6c1c29..08a1d1da 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,6 +6,6 @@ org.gradle.jvmargs=-Xmx2G mod_name = Hytils Reborn mod_id = hytils-reborn -mod_version = 1.5.1-beta4 +mod_version = 1.6.0-beta4 loom.platform = forge \ No newline at end of file diff --git a/src/main/java/cc/woverflow/hytils/config/HytilsConfig.java b/src/main/java/cc/woverflow/hytils/config/HytilsConfig.java index 06687cfd..d81bc982 100644 --- a/src/main/java/cc/woverflow/hytils/config/HytilsConfig.java +++ b/src/main/java/cc/woverflow/hytils/config/HytilsConfig.java @@ -27,6 +27,7 @@ import cc.polyfrost.oneconfig.config.data.PageLocation; import cc.polyfrost.oneconfig.config.migration.VigilanceMigrator; import cc.woverflow.hytils.HytilsReborn; +import cc.woverflow.hytils.handlers.chat.modules.modifiers.GameStartCompactor; import cc.woverflow.hytils.util.DarkColorUtils; import com.google.common.collect.Lists; import net.minecraft.client.Minecraft; @@ -1101,6 +1102,10 @@ public HytilsConfig() { addDependency("chattingIntegration", "chatSwapper"); addDependency("hideAllChatMessage", "chatSwapper"); + addListener("cleanerGameStartAnnouncements", () -> { + if (!cleanerGameStartAnnouncements) GameStartCompactor.lastMessage = null; + }); + addDependency("playerCountBeforePlayerName", "gameStatusRestyle"); addDependency("playerCountOnPlayerLeave", "gameStatusRestyle"); addDependency("padPlayerCount", "gameStatusRestyle"); @@ -1145,6 +1150,7 @@ public void hideTabulous() { hidePlayerRanksInTab = false; hidePingInTab = false; cleanerSkyblockTabInfo = false; + hideAdsInTab = false; save(); addDependency("hideNpcsInTab", "Tabulous", () -> false); addDependency("keepImportantNpcsInTab", "Tabulous", () -> false); @@ -1152,6 +1158,7 @@ public void hideTabulous() { addDependency("hidePlayerRanksInTab", "Tabulous", () -> false); addDependency("hidePingInTab", "Tabulous", () -> false); addDependency("cleanerSkyblockTabInfo", "Tabulous", () -> false); + addDependency("hideAdsInTab", "Tabulous", () -> false); } private void setWBMessages() { diff --git a/src/main/java/cc/woverflow/hytils/handlers/chat/modules/modifiers/GameStartCompactor.java b/src/main/java/cc/woverflow/hytils/handlers/chat/modules/modifiers/GameStartCompactor.java index b519ea85..e05eb299 100644 --- a/src/main/java/cc/woverflow/hytils/handlers/chat/modules/modifiers/GameStartCompactor.java +++ b/src/main/java/cc/woverflow/hytils/handlers/chat/modules/modifiers/GameStartCompactor.java @@ -21,6 +21,7 @@ import cc.woverflow.hytils.config.HytilsConfig; import cc.woverflow.hytils.handlers.chat.ChatReceiveModule; import cc.woverflow.hytils.mixin.GuiNewChatAccessor; +import com.google.common.collect.Lists; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ChatLine; import net.minecraft.client.gui.GuiNewChat; @@ -30,6 +31,7 @@ import net.minecraftforge.client.event.ClientChatReceivedEvent; import org.jetbrains.annotations.NotNull; +import java.util.Iterator; import java.util.List; import java.util.regex.Matcher; @@ -40,9 +42,7 @@ public int getPriority() { return 7; } - // Used to determine if the property has changed. TODO: Once ModCore 2 is out, have a listener for this. - private boolean prevConfigValue = HytilsConfig.cleanerGameStartAnnouncements; - private IChatComponent lastMessage = null; + public static IChatComponent lastMessage = null; @Override public void onMessageReceived(@NotNull ClientChatReceivedEvent event) { @@ -51,32 +51,37 @@ public void onMessageReceived(@NotNull ClientChatReceivedEvent event) { if (gameStartMatcher.matches() || (HytilsConfig.gameStatusRestyle && chatRestylerMatcher.matches())) { if (lastMessage != null) { final GuiNewChat chat = Minecraft.getMinecraft().ingameGUI.getChatGUI(); - final List oldTimerLines = GuiUtilRenderComponents.splitText(lastMessage, MathHelper.floor_float((float) chat.getChatWidth() / chat.getChatScale()), Minecraft.getMinecraft().fontRendererObj, false, false); final GuiNewChatAccessor accessor = ((GuiNewChatAccessor) chat); - for (int i = accessor.getDrawnChatLines().size() - 1; i >= 0; i--) { // tries to find the last message in drawn chat lines, if found, it removes them - final ChatLine drawnLine = accessor.getDrawnChatLines().get(i); - for (IChatComponent oldTimerLine : oldTimerLines) { - if (drawnLine.getChatComponent().getFormattedText().startsWith(oldTimerLine.getFormattedText())) { - accessor.getDrawnChatLines().remove(i); - oldTimerLines.remove(oldTimerLine); - break; - } - } - } + final List oldTimerLines = GuiUtilRenderComponents.splitText(lastMessage, MathHelper.floor_float((float) chat.getChatWidth() / chat.getChatScale()), Minecraft.getMinecraft().fontRendererObj, false, false); + removeChatLines(accessor.getChatLines(), Lists.newArrayList(lastMessage)); + removeChatLines(accessor.getDrawnChatLines(), oldTimerLines); } lastMessage = event.message.createCopy(); } } - @Override - public boolean isEnabled() { - // don't affect messages sent when the config value was false (or was true and was set to false later) - if (!prevConfigValue && HytilsConfig.cleanerGameStartAnnouncements) { - prevConfigValue = true; - lastMessage = null; + private void removeChatLines(List currentLines, List oldTimerLines) { + Iterator iterator = currentLines.iterator(); + while (iterator.hasNext()) { + final ChatLine drawnLine = iterator.next(); + if (drawnLine.getChatComponent().getFormattedText().contains(lastMessage.getFormattedText())) { + iterator.remove(); + return; + } + for (IChatComponent oldTimerLine : oldTimerLines) { + if (drawnLine.getChatComponent().getFormattedText().contains(oldTimerLine.getFormattedText())) { + iterator.remove(); + oldTimerLines.remove(oldTimerLine); + break; + } + } + if (oldTimerLines.isEmpty()) return; } + } + @Override + public boolean isEnabled() { return HytilsConfig.cleanerGameStartAnnouncements; } diff --git a/src/main/java/cc/woverflow/hytils/mixin/GuiNewChatAccessor.java b/src/main/java/cc/woverflow/hytils/mixin/GuiNewChatAccessor.java index b3557d6c..a0e42979 100644 --- a/src/main/java/cc/woverflow/hytils/mixin/GuiNewChatAccessor.java +++ b/src/main/java/cc/woverflow/hytils/mixin/GuiNewChatAccessor.java @@ -27,6 +27,9 @@ @Mixin(GuiNewChat.class) public interface GuiNewChatAccessor { - @Accessor("drawnChatLines") + @Accessor + List getChatLines(); + + @Accessor List getDrawnChatLines(); }