From b3e4dabf7ffce74c8cd137d1ea7418c4ca1026dd Mon Sep 17 00:00:00 2001 From: olim Date: Sun, 18 Feb 2024 21:56:45 +0000 Subject: fix most formatting issues tried to find all of the formatting problems left in my code --- .../hysky/skyblocker/skyblock/chat/ChatRule.java | 20 ++---------- .../skyblock/chat/ChatRuleAnnouncementScreen.java | 6 +--- .../skyblock/chat/ChatRuleConfigScreen.java | 30 ++++++------------ .../skyblock/chat/ChatRulesConfigListWidget.java | 36 ++++++---------------- .../skyblock/chat/ChatRulesConfigScreen.java | 12 ++------ .../skyblocker/skyblock/chat/ChatRulesHandler.java | 3 -- 6 files changed, 26 insertions(+), 81 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java index 60a64fad..4877fdb6 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java @@ -1,12 +1,8 @@ package de.hysky.skyblocker.skyblock.chat; import de.hysky.skyblocker.utils.Utils; -import net.minecraft.client.sound.Sound; -import net.minecraft.item.ItemStack; import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; -import java.util.List; import java.util.Objects; import java.util.regex.Pattern; @@ -16,8 +12,8 @@ import java.util.regex.Pattern; public class ChatRule { private String name; - //inputs + //inputs private Boolean enabled; private Boolean isPartialMatch; private Boolean isRegex; @@ -29,7 +25,7 @@ public class ChatRule { private Boolean hideMessage; private Boolean showActionBar; private Boolean showAnnouncement; - private String replaceMessage; //todo extract parts of original message + private String replaceMessage; private SoundEvent customSound; /** * Creates a chat rule with default options. @@ -51,7 +47,7 @@ public class ChatRule { this.customSound = null; } - public Boolean getEnabled() { //todo remove unused getters and set + public Boolean getEnabled() { return enabled; } @@ -211,16 +207,6 @@ public class ChatRule { public void setName(String name) { this.name = name; } - - public enum LocationOption { - None, - Island, - Hub, - Garden; //todo add more - - } - - } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleAnnouncementScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleAnnouncementScreen.java index 0ee3c2c5..2cb6ca5c 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleAnnouncementScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleAnnouncementScreen.java @@ -9,10 +9,8 @@ import net.minecraft.text.Text; public class ChatRuleAnnouncementScreen { - private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); private static float timer; - private static Text text = null; public static void init() { @@ -22,11 +20,8 @@ public class ChatRuleAnnouncementScreen { } render(context, tickDelta); }); - } - - /** * renders {@link ChatRuleAnnouncementScreen#text} to the middle of the top of the screen. * @param context render context @@ -46,6 +41,7 @@ public class ChatRuleAnnouncementScreen { matrices.pop(); } + protected static void setText(Text newText) { text = newText; timer = SkyblockerConfigManager.get().messages.chatRuleConfig.announcementLength; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleConfigScreen.java index cb9a2da6..31611991 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleConfigScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleConfigScreen.java @@ -19,7 +19,6 @@ import java.util.Map; import static java.util.Map.entry; public class ChatRuleConfigScreen extends Screen { - private static final int SPACER_X = 5; private static final int SPACER_Y = 25; @@ -35,17 +34,12 @@ public class ChatRuleConfigScreen extends Screen { private final int chatRuleIndex; private final ChatRule chatRule; - - //widgets - private ButtonWidget finishButton; - private TextFieldWidget nameInput; private TextFieldWidget filterInput; private ButtonWidget partialMatchToggle; private ButtonWidget regexToggle; private ButtonWidget ignoreCaseToggle; private TextFieldWidget locationsInput; - private ButtonWidget hideMessageToggle; private ButtonWidget actionBarToggle; private ButtonWidget announcementToggle; @@ -55,16 +49,12 @@ public class ChatRuleConfigScreen extends Screen { //textLocations private IntIntPair nameLabelTextPos; private IntIntPair inputsLabelTextPos; - private IntIntPair filterLabelTextPos; private IntIntPair partialMatchTextPos; private IntIntPair regexTextPos; private IntIntPair ignoreCaseTextPos; - private IntIntPair locationLabelTextPos; - private IntIntPair outputsLabelTextPos; - private IntIntPair hideMessageTextPos; private IntIntPair actionBarTextPos; private IntIntPair announcementTextPos; @@ -75,8 +65,6 @@ public class ChatRuleConfigScreen extends Screen { private final Screen parent; - - public ChatRuleConfigScreen(Screen parent, int chatRuleIndex) { super(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen")); this.chatRuleIndex = chatRuleIndex; @@ -91,7 +79,7 @@ public class ChatRuleConfigScreen extends Screen { if (client == null) return; //start centered on the X and 1/3 down on the Y IntIntPair currentPos = IntIntPair.of((this.width - getMaxUsedWidth()) / 2,(int)((this.height -getMaxUsedHeight()) * 0.33)); - int lineXOffset = 0; + int lineXOffset; nameLabelTextPos = currentPos; lineXOffset = client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.name")) + SPACER_X; @@ -221,11 +209,9 @@ public class ChatRuleConfigScreen extends Screen { replaceMessageInput.setTooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.replace.@Tooltip"))); replaceMessageInput.setText(chatRule.getReplaceMessage()); - finishButton = ButtonWidget.builder(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.finish"), a -> { - close(); - }) + ButtonWidget finishButton = ButtonWidget.builder(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.finish"), a -> close()) .position(this.width - 75 - SPACER_Y, this.height - SPACER_Y) - .size(75,20) + .size(75, 20) .build(); addDrawableChild(nameInput); @@ -243,7 +229,7 @@ public class ChatRuleConfigScreen extends Screen { } /** - * works out the width of the maximum line + * Works out the width of the maximum line * @return the max used width */ private int getMaxUsedWidth() { @@ -259,8 +245,12 @@ public class ChatRuleConfigScreen extends Screen { return total; } + /** + * Works out the height used + * @return height used by the gui + */ private int getMaxUsedHeight() { - //there are 7 rows so just times the spacer by 7 + //there are 8 rows so just times the spacer by 8 return SPACER_Y * 8; } @@ -318,6 +308,4 @@ public class ChatRuleConfigScreen extends Screen { } return soundsLookup.keySet().stream().toList().get(currentSoundIndex); } - - } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigListWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigListWidget.java index 87455a2b..c5d7fcc8 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigListWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigListWidget.java @@ -17,8 +17,6 @@ import java.awt.*; import java.util.List; public class ChatRulesConfigListWidget extends ElementListWidget { - - private final ChatRulesConfigScreen screen; private Boolean hasChanged; @@ -45,7 +43,6 @@ public class ChatRulesConfigListWidget extends ElementListWidget children; - - - //widgets + //widgets private final ButtonWidget enabledButton; private final ButtonWidget openConfigButton; private final ButtonWidget deleteButton; - - //text locations + //text location private final int nameX = width / 2 - 125; - //saved data private double oldScrollAmount = 0; @@ -118,15 +109,10 @@ public class ChatRulesConfigListWidget extends ElementListWidget { - toggleEnabled(); - }) + enabledButton = ButtonWidget.builder(enabledButtonText() , a -> toggleEnabled()) .size(50,20) .position(width / 2 - 25,5) - .build() - ; + .build(); openConfigButton = ButtonWidget.builder(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.editRule"), a -> { client.setScreen(new ChatRuleConfigScreen(screen, chatRuleIndex)); @@ -134,17 +120,15 @@ public class ChatRulesConfigListWidget extends ElementListWidget { oldScrollAmount = getScrollAmount(); client.setScreen(new ConfirmScreen(this::deleteEntry, Text.translatable("skyblocker.shortcuts.deleteQuestion"), Text.translatable("skyblocker.shortcuts.deleteWarning", chatRule.getName()), Text.translatable("selectServer.deleteButton"), ScreenTexts.CANCEL)); }) .size(50,20) .position(width / 2 + 105,5) - .build() - ; - + .build(); children = List.of(enabledButton, openConfigButton, deleteButton); } @@ -182,7 +166,7 @@ public class ChatRulesConfigListWidget extends ElementListWidget chatRulesConfigListWidget.addRuleAfterSelected()).build(); - adder.add(buttonNew); - buttonDone = ButtonWidget.builder(ScreenTexts.DONE, button -> { + ButtonWidget buttonNew1 = ButtonWidget.builder(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.new"), buttonNew -> chatRulesConfigListWidget.addRuleAfterSelected()).build(); + adder.add(buttonNew1); + ButtonWidget buttonDone = ButtonWidget.builder(ScreenTexts.DONE, button -> { chatRulesConfigListWidget.saveRules(); if (client != null) { close(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java index c9efe749..bde55aed 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java @@ -81,7 +81,6 @@ public class ChatRulesHandler { catch (Exception e) { LOGGER.error("[Skyblocker] Failed to load locations!", e); } - System.out.println(locations); } protected static void saveChatRules() { @@ -146,7 +145,6 @@ public class ChatRulesHandler { * @param codedString the string with color codes in * @return formatted text */ - protected static MutableText formatText(String codedString) { if (codedString.contains(String.valueOf(Formatting.FORMATTING_CODE_PREFIX)) || codedString.contains("&")){ MutableText newText = Text.literal(""); @@ -166,5 +164,4 @@ public class ChatRulesHandler { } return Text.literal(codedString); } - } -- cgit