diff options
author | olim <bobq4582@gmail.com> | 2024-02-15 21:04:20 +0000 |
---|---|---|
committer | olim <bobq4582@gmail.com> | 2024-02-15 21:04:20 +0000 |
commit | 3cdcc209a398694f212238b843e732fcd512c408 (patch) | |
tree | 0aa87f7df809e64948ce544def6e7393d810a889 /src/main | |
parent | 4d0d772537648d424631a1a932780601a642b1a5 (diff) | |
download | Skyblocker-3cdcc209a398694f212238b843e732fcd512c408.tar.gz Skyblocker-3cdcc209a398694f212238b843e732fcd512c408.tar.bz2 Skyblocker-3cdcc209a398694f212238b843e732fcd512c408.zip |
add config options for ignore case and valid locations
implemented option to ignore the case of the message. and option to make it only work when raw location = value or != value.
Diffstat (limited to 'src/main')
3 files changed, 111 insertions, 56 deletions
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 afc409ac..9643b413 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,11 @@ package de.hysky.skyblocker.skyblock.chat; import de.hysky.skyblocker.utils.Utils; -import dev.isxander.yacl3.config.v2.api.SerialEntry; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.sound.Sound; import net.minecraft.item.ItemStack; import java.util.List; +import java.util.Objects; import java.util.regex.Pattern; /** @@ -14,22 +13,22 @@ import java.util.regex.Pattern; */ public class ChatRule { - public String name; + private String name; //inputs - public Boolean enabled; - public Boolean isPartialMatch; - public Boolean isRegex; - public Boolean isIgnoreCase; - public String filter; - public LocationOption validLocation; + private Boolean enabled; + private Boolean isPartialMatch; + private Boolean isRegex; + private Boolean isIgnoreCase; + private String filter; + private String validLocations; //output - public Boolean hideMessage; - public Boolean showActionBar; - public Boolean showAnnouncement; - public String replaceMessage; //todo extract parts of original message - public Sound customSound; + private Boolean hideMessage; + private Boolean showActionBar; + private Boolean showAnnouncement; + private String replaceMessage; //todo extract parts of original message + private Sound customSound; /** * Creates a chat rule with default options. */ @@ -41,7 +40,7 @@ public class ChatRule { this.isRegex = false; this.isIgnoreCase = true; this.filter = ""; - this.validLocation = LocationOption.None; + this.validLocations = ""; this.hideMessage = true; this.showActionBar = false; @@ -51,14 +50,14 @@ public class ChatRule { } - public ChatRule(String name, Boolean enabled, Boolean isPartialMatch, Boolean isRegex, Boolean isIgnoreCase, String filter, LocationOption validLocation, List<ItemStack> validItems, Boolean hideMessage, Boolean showActionBar, Boolean showAnnouncement, String replaceMessage, Sound customSound) { + public ChatRule(String name, Boolean enabled, Boolean isPartialMatch, Boolean isRegex, Boolean isIgnoreCase, String filter, String validLocation, List<ItemStack> validItems, Boolean hideMessage, Boolean showActionBar, Boolean showAnnouncement, String replaceMessage, Sound customSound) { this.name = name; this.enabled = enabled; this.isPartialMatch = isPartialMatch; this.isRegex = isRegex; this.isIgnoreCase = isIgnoreCase; this.filter = filter; - this.validLocation = validLocation; + this.validLocations = validLocation; this.hideMessage = hideMessage; this.showActionBar = showActionBar; this.showAnnouncement = showAnnouncement; @@ -90,24 +89,22 @@ public class ChatRule { isRegex = regex; } - public String getFilter() { - return filter; + public Boolean getIgnoreCase() { + return isIgnoreCase; } - public void setFilter(String filter) { - this.filter = filter; + public void setIgnoreCase(Boolean ignoreCase) { + isIgnoreCase = ignoreCase; } - public LocationOption getValidLocation() { - return validLocation; + public String getFilter() { + return filter; } - public void setValidLocation(LocationOption validLocation) { - this.validLocation = validLocation; + public void setFilter(String filter) { + this.filter = filter; } - - public Boolean getHideMessage() { return hideMessage; } @@ -148,6 +145,14 @@ public class ChatRule { this.customSound = customSound; } + public String getValidLocations() { + return validLocations; + } + + public void setValidLocations(String validLocations) { + this.validLocations = validLocations; + } + /** * checks every input option and if the games state and the inputted str matches them returns true. * @param inputString the chat message to check if fits @@ -185,22 +190,30 @@ public class ChatRule { } //location + if (validLocations.isEmpty()){ //if no locations do not check + return true; + } String rawLocation = Utils.getLocationRaw(); - switch (validLocation){ //todo maybe add functionality straight into utils - case Island -> { - if (!rawLocation.equals("private_island")) return false; - } - case Hub -> { - if (!rawLocation.equals("hub")) return false; - } - case Garden -> { - if (!rawLocation.equals("garden")) return false; - } - default -> {} + Boolean isLocationValid = null; + for (String validLocation : validLocations.replace(" ", "").split(",")) {//the locations are raw locations split by "," and start with ! if not locations + if (validLocation.startsWith("!")) {//not location ( + if (Objects.equals(validLocation.substring(1), rawLocation)) { + isLocationValid = false; + break; + } + }else { + if (Objects.equals(validLocation, rawLocation)) { //normal location + isLocationValid = true; + break; + } + } + } + if (isLocationValid == null || !isLocationValid){//if location is not in the list at all and is a not a "!" location or and is a normal location + return true; } - return true; + return false; } public String getName() { 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 0dc912d2..e866520f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleConfigScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleConfigScreen.java @@ -26,8 +26,8 @@ public class ChatRuleConfigScreen extends Screen { private TextFieldWidget filterInput; private ButtonWidget partialMatchToggle; private ButtonWidget regexToggle; - //todo location dropdown or somthig - //todo item selection thing + private ButtonWidget ignoreCaseToggle; + private TextFieldWidget locationsInput; private ButtonWidget hideMessageToggle; private ButtonWidget actionBarToggle; @@ -42,10 +42,9 @@ public class ChatRuleConfigScreen extends Screen { private IntIntPair filterLabelTextPos; private IntIntPair partialMatchTextPos; private IntIntPair regexTextPos; + private IntIntPair ignoreCaseTextPos; - private IntIntPair validLocationLabelTextPos; - - private IntIntPair validItemLabelTextPos; + private IntIntPair locationLabelTextPos; private IntIntPair outputsLabelTextPos; @@ -73,8 +72,8 @@ public class ChatRuleConfigScreen extends Screen { protected void init() { super.init(); if (client == null) return; - - IntIntPair currentPos = IntIntPair.of(5,15); + //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; nameLabelTextPos = currentPos; @@ -112,8 +111,23 @@ public class ChatRuleConfigScreen extends Screen { .position(currentPos.leftInt() + lineXOffset, currentPos.rightInt()) .size(75,20) .build(); + lineXOffset += 75 + SPACER_X; + ignoreCaseTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset,currentPos.rightInt()); + lineXOffset += client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.ignoreCase")) + SPACER_X; + ignoreCaseToggle = ButtonWidget.builder(enabledButtonText(chatRule.getIgnoreCase()), a -> { + chatRule.setIgnoreCase(!chatRule.getIgnoreCase()); + ignoreCaseToggle.setMessage(enabledButtonText(chatRule.getIgnoreCase())); + }) + .position(currentPos.leftInt() + lineXOffset, currentPos.rightInt()) + .size(75,20) + .build(); currentPos = IntIntPair.of(currentPos.leftInt(),currentPos.rightInt() + SPACER_Y); + locationLabelTextPos = currentPos; + lineXOffset = client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.locations")) + SPACER_X; + locationsInput = new TextFieldWidget(MinecraftClient.getInstance().textRenderer, currentPos.leftInt() + lineXOffset, currentPos.rightInt(), 200, 20, Text.of("")); + locationsInput.setText(chatRule.getValidLocations()); + currentPos = IntIntPair.of(currentPos.leftInt(),currentPos.rightInt() + SPACER_Y); outputsLabelTextPos = IntIntPair.of(currentPos.leftInt() - 10,currentPos.rightInt()); currentPos = IntIntPair.of(currentPos.leftInt(),currentPos.rightInt() + SPACER_Y); @@ -166,6 +180,8 @@ public class ChatRuleConfigScreen extends Screen { addDrawableChild(filterInput); addDrawableChild(partialMatchToggle); addDrawableChild(regexToggle); + addDrawableChild(ignoreCaseToggle); + addDrawableChild(locationsInput); addDrawableChild(hideMessageToggle); addDrawableChild(actionBarToggle); addDrawableChild(announcementToggle); @@ -173,6 +189,28 @@ public class ChatRuleConfigScreen extends Screen { addDrawableChild(finishButton); } + /** + * works out the width of the maximum line + * @return + */ + private int getMaxUsedWidth() { + if (client == null) return 0; + //text + int total = client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.partialMatch")); + total += client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.regex")); + total += client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.ignoreCase")); + //space + total += SPACER_X * 6; + //button width + total += 75 * 3; + return total; + } + + private int getMaxUsedHeight() { + //there are 7 rows so just times the spacer by 7 + return SPACER_Y * 8; + } + private Text enabledButtonText(boolean enabled) { if (enabled){ return Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.true").withColor(Color.green.getRGB()); @@ -189,16 +227,17 @@ public class ChatRuleConfigScreen extends Screen { //draw labels ands text int yOffset = (SPACER_Y - this.textRenderer.fontHeight) / 2; context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.inputs"), inputsLabelTextPos.leftInt(), inputsLabelTextPos.rightInt() + yOffset, 0xFFFFFF); - context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.name"), nameLabelTextPos.leftInt(), nameLabelTextPos.rightInt()+ yOffset, 0xFFFFFF); - context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.filter"), filterLabelTextPos.leftInt(), filterLabelTextPos.rightInt()+ yOffset, 0xFFFFFF); - context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.partialMatch"), partialMatchTextPos.leftInt(), partialMatchTextPos.rightInt()+ yOffset, 0xFFFFFF); - context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.regex"), regexTextPos.leftInt(), regexTextPos.rightInt()+ yOffset, 0xFFFFFF); - //context.drawTextWithShadow(this.textRenderer,"valid", validItemLabelTextPos.leftInt(), validItemLabelTextPos.rightInt(), 0xFFFFFF); - context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.outputs"), outputsLabelTextPos.leftInt(), outputsLabelTextPos.rightInt()+ yOffset, 0xFFFFFF); - context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.hideMessage"), hideMessageTextPos.leftInt(), hideMessageTextPos.rightInt()+ yOffset, 0xFFFFFF); - context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.actionBar"), actionBarTextPos.leftInt(), actionBarTextPos.rightInt()+ yOffset, 0xFFFFFF); - context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.announcement"), announcementTextPos.leftInt(), announcementTextPos.rightInt()+ yOffset, 0xFFFFFF); - context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.replace"), replaceMessageLabelTextPos.leftInt(), replaceMessageLabelTextPos.rightInt()+ yOffset, 0xFFFFFF); + context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.name"), nameLabelTextPos.leftInt(), nameLabelTextPos.rightInt() + yOffset, 0xFFFFFF); + context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.filter"), filterLabelTextPos.leftInt(), filterLabelTextPos.rightInt() + yOffset, 0xFFFFFF); + context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.partialMatch"), partialMatchTextPos.leftInt(), partialMatchTextPos.rightInt() + yOffset, 0xFFFFFF); + context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.regex"), regexTextPos.leftInt(), regexTextPos.rightInt() + yOffset, 0xFFFFFF); + context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.ignoreCase"), ignoreCaseTextPos.leftInt(), ignoreCaseTextPos.rightInt() + yOffset, 0xFFFFFF); + context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.locations"), locationLabelTextPos.leftInt(), locationLabelTextPos.rightInt() + yOffset, 0xFFFFFF); + context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.outputs"), outputsLabelTextPos.leftInt(), outputsLabelTextPos.rightInt() + yOffset, 0xFFFFFF); + context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.hideMessage"), hideMessageTextPos.leftInt(), hideMessageTextPos.rightInt() + yOffset, 0xFFFFFF); + context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.actionBar"), actionBarTextPos.leftInt(), actionBarTextPos.rightInt() + yOffset, 0xFFFFFF); + context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.announcement"), announcementTextPos.leftInt(), announcementTextPos.rightInt() + yOffset, 0xFFFFFF); + context.drawTextWithShadow(this.textRenderer,Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.replace"), replaceMessageLabelTextPos.leftInt(), replaceMessageLabelTextPos.rightInt() + yOffset, 0xFFFFFF); } @Override @@ -214,6 +253,7 @@ public class ChatRuleConfigScreen extends Screen { chatRule.setName(nameInput.getText()); chatRule.setFilter(filterInput.getText()); chatRule.setReplaceMessage(replaceMessageInput.getText()); + chatRule.setValidLocations(locationsInput.getText()); ChatRulesHandler.chatRuleList.set(chatRuleIndex,chatRule); } diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 35759e3e..c8725dc8 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -365,6 +365,8 @@ "text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.filter": "ChatFilter:", "text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.partialMatch": "Allow Partial Match:", "text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.regex": "Is Regex:", + "text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.ignoreCase": "Ignore Case:", + "text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.locations": "Valid Locations:", "text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.outputs": "Outputs:", "text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.hideMessage": "Hide Message:", "text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.actionBar": "Show In Action Bar:", |