aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock
diff options
context:
space:
mode:
authorAaron <51387595+AzureAaron@users.noreply.github.com>2024-02-21 00:00:31 -0500
committerAaron <51387595+AzureAaron@users.noreply.github.com>2024-02-21 00:00:31 -0500
commit980e91c202c7e015e959f30752b69d7818afd715 (patch)
tree2beb6022a7ecc39b48ed8f4e977f436724d42a27 /src/main/java/de/hysky/skyblocker/skyblock
parentc4b5fbc8fdbfe708a4925e901aeca011237cf736 (diff)
downloadSkyblocker-980e91c202c7e015e959f30752b69d7818afd715.tar.gz
Skyblocker-980e91c202c7e015e959f30752b69d7818afd715.tar.bz2
Skyblocker-980e91c202c7e015e959f30752b69d7818afd715.zip
Fix formatting
The text rendering methods use AARRGGBB not RRGGBB so I fixed that too.
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java30
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleAnnouncementScreen.java3
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleConfigScreen.java109
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigListWidget.java62
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigScreen.java2
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java28
6 files changed, 120 insertions, 114 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 93897988..7a8214cb 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java
@@ -30,7 +30,7 @@ public class ChatRule {
/**
* Creates a chat rule with default options.
*/
- protected ChatRule(){
+ protected ChatRule() {
this.name = "New Rule";
this.enabled = true;
@@ -163,43 +163,46 @@ public class ChatRule {
* @param inputString the chat message to check if fits
* @return if the inputs are all true and the outputs should be performed
*/
- protected Boolean isMatch(String inputString){
+ protected Boolean isMatch(String inputString) {
//enabled
if (!enabled) return false;
//ignore case
String testString;
String testFilter;
- if (isIgnoreCase){
+
+ if (isIgnoreCase) {
testString = inputString.toLowerCase();
testFilter = filter.toLowerCase();
- }else {
+ } else {
testString = inputString;
testFilter = filter;
}
//filter
if (testFilter.isBlank()) return false;
- if(isRegex) {
+ if (isRegex) {
if (isPartialMatch) {
- if (! Pattern.compile(testFilter).matcher(testString).find()) return false;
- }else {
+ if (!Pattern.compile(testFilter).matcher(testString).find()) return false;
+ } else {
if (!testString.matches(testFilter)) return false;
}
- } else{
+ } else {
if (isPartialMatch) {
if (!testString.contains(testFilter)) return false;
- }else {
+ } else {
if (!testFilter.equals(testString)) return false;
}
}
//location
- if (validLocations.isBlank()){ //if no locations do not check
+ if (validLocations.isBlank()) { //if no locations do not check
return true;
}
+
String rawLocation = Utils.getLocationRaw();
Boolean isLocationValid = null;
+
for (String validLocation : validLocations.replace(" ", "").toLowerCase().split(",")) {//the locations are raw locations split by "," and start with ! if not locations
String rawValidLocation = ChatRulesHandler.locations.get(validLocation.replace("!",""));
if (rawValidLocation == null) continue;
@@ -208,15 +211,16 @@ public class ChatRule {
isLocationValid = false;
break;
}
- }
- else {
+ } else {
if (Objects.equals(rawValidLocation, rawLocation.toLowerCase())) { //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
+
+ //if location is not in the list at all and is a not a "!" location or and is a normal location
+ if (isLocationValid != null && isLocationValid) {
return true;
}
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 2cb6ca5c..bafada27 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleAnnouncementScreen.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleAnnouncementScreen.java
@@ -7,7 +7,6 @@ import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
-
public class ChatRuleAnnouncementScreen {
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
private static float timer;
@@ -37,7 +36,7 @@ public class ChatRuleAnnouncementScreen {
matrices.translate(context.getScaledWindowWidth() / 2f, context.getScaledWindowHeight() * 0.3, 0f);
matrices.scale(scale, scale, 0f);
//render text
- context.drawCenteredTextWithShadow(CLIENT.textRenderer,text,0, 0, 0xFFFFFF);
+ context.drawCenteredTextWithShadow(CLIENT.textRenderer, text, 0, 0, 0xFFFFFFFF);
matrices.pop();
}
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 92cd72d7..9b91d4a8 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleConfigScreen.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleConfigScreen.java
@@ -1,7 +1,6 @@
package de.hysky.skyblocker.skyblock.chat;
import it.unimi.dsi.fastutil.ints.IntIntPair;
-import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.tooltip.Tooltip;
@@ -17,7 +16,6 @@ import net.minecraft.util.Identifier;
import java.awt.*;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
import static java.util.Map.entry;
@@ -55,7 +53,7 @@ public class ChatRuleConfigScreen extends Screen {
private IntIntPair filterLabelTextPos;
private IntIntPair partialMatchTextPos;
private IntIntPair regexTextPos;
- private IntIntPair ignoreCaseTextPos;
+ private IntIntPair ignoreCaseTextPos;
private IntIntPair locationLabelTextPos;
private IntIntPair outputsLabelTextPos;
private IntIntPair hideMessageTextPos;
@@ -78,8 +76,10 @@ public class ChatRuleConfigScreen extends Screen {
private int getCurrentSoundIndex() {
if (chatRule.getCustomSound() == null) return -1; //if no sound just return -1
+
List<SoundEvent> soundOptions = soundsLookup.values().stream().toList();
Identifier ruleSoundId = chatRule.getCustomSound().getId();
+
for (int i = 0; i < soundOptions.size(); i++) {
if (soundOptions.get(i).getId().compareTo(ruleSoundId) == 0) {
return i;
@@ -94,74 +94,74 @@ public class ChatRuleConfigScreen extends Screen {
super.init();
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));
+ IntIntPair currentPos = IntIntPair.of((this.width - getMaxUsedWidth()) / 2, (int)((this.height -getMaxUsedHeight()) * 0.33));
int lineXOffset;
nameLabelTextPos = currentPos;
lineXOffset = client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.name")) + SPACER_X;
- nameInput = new TextFieldWidget(MinecraftClient.getInstance().textRenderer, currentPos.leftInt() + lineXOffset, currentPos.rightInt(), 100, 20, Text.of(""));
+ nameInput = new TextFieldWidget(client.textRenderer, currentPos.leftInt() + lineXOffset, currentPos.rightInt(), 100, 20, Text.of(""));
nameInput.setText(chatRule.getName());
nameInput.setTooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.name.@Tooltip")));
- currentPos = IntIntPair.of(currentPos.leftInt(),currentPos.rightInt() + SPACER_Y);
+ currentPos = IntIntPair.of(currentPos.leftInt(), currentPos.rightInt() + SPACER_Y);
inputsLabelTextPos = currentPos;
- currentPos = IntIntPair.of(currentPos.leftInt() + 10 ,currentPos.rightInt() + SPACER_Y);
+ currentPos = IntIntPair.of(currentPos.leftInt() + 10, currentPos.rightInt() + SPACER_Y);
filterLabelTextPos = currentPos;
lineXOffset = client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.filter")) + SPACER_X;
- filterInput = new TextFieldWidget(MinecraftClient.getInstance().textRenderer, currentPos.leftInt() + lineXOffset, currentPos.rightInt(), 200, 20, Text.of(""));
+ filterInput = new TextFieldWidget(client.textRenderer, currentPos.leftInt() + lineXOffset, currentPos.rightInt(), 200, 20, Text.of(""));
filterInput.setMaxLength(96);
filterInput.setText(chatRule.getFilter());
filterInput.setTooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.filter.@Tooltip")));
currentPos = IntIntPair.of(currentPos.leftInt(),currentPos.rightInt() + SPACER_Y);
lineXOffset = 0;
- partialMatchTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset,currentPos.rightInt());
+ partialMatchTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset, currentPos.rightInt());
lineXOffset += client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.partialMatch")) + SPACER_X;
partialMatchToggle = ButtonWidget.builder(enabledButtonText(chatRule.getPartialMatch()), a -> {
chatRule.setPartialMatch(!chatRule.getPartialMatch());
partialMatchToggle.setMessage(enabledButtonText(chatRule.getPartialMatch()));
})
.position(currentPos.leftInt() + lineXOffset, currentPos.rightInt())
- .size(75,20)
+ .size(75, 20)
.tooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.partialMatch.@Tooltip")))
.build();
lineXOffset += 75 + SPACER_X;
- regexTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset,currentPos.rightInt());
+ regexTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset, currentPos.rightInt());
lineXOffset += client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.regex")) + SPACER_X;
regexToggle = ButtonWidget.builder(enabledButtonText(chatRule.getRegex()), a -> {
chatRule.setRegex(!chatRule.getRegex());
regexToggle.setMessage(enabledButtonText(chatRule.getRegex()));
})
.position(currentPos.leftInt() + lineXOffset, currentPos.rightInt())
- .size(75,20)
+ .size(75, 20)
.tooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.regex.@Tooltip")))
.build();
lineXOffset += 75 + SPACER_X;
- ignoreCaseTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset,currentPos.rightInt());
+ 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)
+ .size(75, 20)
.tooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.ignoreCase.@Tooltip")))
.build();
- currentPos = IntIntPair.of(currentPos.leftInt(),currentPos.rightInt() + SPACER_Y);
+ 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 = new TextFieldWidget(client.textRenderer, currentPos.leftInt() + lineXOffset, currentPos.rightInt(), 200, 20, Text.of(""));
locationsInput.setText(chatRule.getValidLocations());
MutableText locationToolTip = Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.locations.@Tooltip");
locationToolTip.append("\n");
ChatRulesHandler.locationsList.forEach(location -> locationToolTip.append(" " + location + ",\n"));
locationsInput.setTooltip(Tooltip.of(locationToolTip));
- currentPos = IntIntPair.of(currentPos.leftInt(),currentPos.rightInt() + SPACER_Y);
+ 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);
+ currentPos = IntIntPair.of(currentPos.leftInt(), currentPos.rightInt() + SPACER_Y);
hideMessageTextPos = currentPos;
lineXOffset = client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.hideMessage")) + SPACER_X;
@@ -170,35 +170,35 @@ public class ChatRuleConfigScreen extends Screen {
hideMessageToggle.setMessage(enabledButtonText(chatRule.getHideMessage()));
})
.position(currentPos.leftInt() + lineXOffset, currentPos.rightInt())
- .size(75,20)
+ .size(75, 20)
.tooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.hideMessage.@Tooltip")))
.build();
lineXOffset += 75 + SPACER_X;
- actionBarTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset,currentPos.rightInt());
+ actionBarTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset, currentPos.rightInt());
lineXOffset += client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.actionBar")) + SPACER_X;
actionBarToggle = ButtonWidget.builder(enabledButtonText(chatRule.getShowActionBar()), a -> {
chatRule.setShowActionBar(!chatRule.getShowActionBar());
actionBarToggle.setMessage(enabledButtonText(chatRule.getShowActionBar()));
})
.position(currentPos.leftInt() + lineXOffset, currentPos.rightInt())
- .size(75,20)
+ .size(75, 20)
.tooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.actionBar.@Tooltip")))
.build();
lineXOffset = 0;
- currentPos = IntIntPair.of(currentPos.leftInt(),currentPos.rightInt() + SPACER_Y);
+ currentPos = IntIntPair.of(currentPos.leftInt(), currentPos.rightInt() + SPACER_Y);
- announcementTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset,currentPos.rightInt());
+ announcementTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset, currentPos.rightInt());
lineXOffset += client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.announcement")) + SPACER_X;
announcementToggle = ButtonWidget.builder(enabledButtonText(chatRule.getShowAnnouncement()), a -> {
chatRule.setShowAnnouncement(!chatRule.getShowAnnouncement());
announcementToggle.setMessage(enabledButtonText(chatRule.getShowAnnouncement()));
})
.position(currentPos.leftInt() + lineXOffset, currentPos.rightInt())
- .size(75,20)
+ .size(75, 20)
.tooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.announcement.@Tooltip")))
.build();
lineXOffset += 75 + SPACER_X;
- customSoundLabelTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset,currentPos.rightInt());
+ customSoundLabelTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset, currentPos.rightInt());
lineXOffset += client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.sounds")) + SPACER_X;
soundsToggle = ButtonWidget.builder(getSoundName(), a -> {
currentSoundIndex += 1;
@@ -211,17 +211,16 @@ public class ChatRuleConfigScreen extends Screen {
chatRule.setCustomSound(sound);
if (client.player != null && sound != null) {
client.player.playSound(sound, 100f, 0.1f);
- }
- })
+ }})
.position(currentPos.leftInt() + lineXOffset, currentPos.rightInt())
- .size(100,20)
+ .size(100, 20)
.tooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.sounds.@Tooltip")))
.build();
- currentPos = IntIntPair.of(currentPos.leftInt(),currentPos.rightInt() + SPACER_Y);
+ currentPos = IntIntPair.of(currentPos.leftInt(), currentPos.rightInt() + SPACER_Y);
replaceMessageLabelTextPos = currentPos;
lineXOffset = client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.replace")) + SPACER_X;
- replaceMessageInput = new TextFieldWidget(MinecraftClient.getInstance().textRenderer, currentPos.leftInt() + lineXOffset, currentPos.rightInt(), 200, 20, Text.of(""));
+ replaceMessageInput = new TextFieldWidget(client.textRenderer, currentPos.leftInt() + lineXOffset, currentPos.rightInt(), 200, 20, Text.of(""));
replaceMessageInput.setMaxLength(96);
replaceMessageInput.setTooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.replace.@Tooltip")));
replaceMessageInput.setText(chatRule.getReplaceMessage());
@@ -259,6 +258,7 @@ public class ChatRuleConfigScreen extends Screen {
total += SPACER_X * 6;
//button width
total += 75 * 3;
+
return total;
}
@@ -272,33 +272,33 @@ public class ChatRuleConfigScreen extends Screen {
}
private Text enabledButtonText(boolean enabled) {
- if (enabled){
- return Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.true").withColor(Color.green.getRGB());
- }else {
- return Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.false").withColor(Color.red.getRGB());
+ if (enabled) {
+ return Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.true").withColor(Color.GREEN.getRGB());
+ } else {
+ return Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.false").withColor(Color.RED.getRGB());
}
}
@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);
- context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 16, 0xFFFFFF);
+ context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 16, 0xFFFFFFFF);
//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,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.sounds"), customSoundLabelTextPos.leftInt(), customSoundLabelTextPos.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.inputs"), inputsLabelTextPos.leftInt(), inputsLabelTextPos.rightInt() + yOffset, 0xFFFFFFFF);
+ context.drawTextWithShadow(this.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.name"), nameLabelTextPos.leftInt(), nameLabelTextPos.rightInt() + yOffset, 0xFFFFFFFF);
+ context.drawTextWithShadow(this.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.filter"), filterLabelTextPos.leftInt(), filterLabelTextPos.rightInt() + yOffset, 0xFFFFFFFF);
+ context.drawTextWithShadow(this.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.partialMatch"), partialMatchTextPos.leftInt(), partialMatchTextPos.rightInt() + yOffset, 0xFFFFFFFF);
+ context.drawTextWithShadow(this.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.regex"), regexTextPos.leftInt(), regexTextPos.rightInt() + yOffset, 0xFFFFFFFF);
+ context.drawTextWithShadow(this.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.ignoreCase"), ignoreCaseTextPos.leftInt(), ignoreCaseTextPos.rightInt() + yOffset, 0xFFFFFFFF);
+ context.drawTextWithShadow(this.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.locations"), locationLabelTextPos.leftInt(), locationLabelTextPos.rightInt() + yOffset, 0xFFFFFFFF);
+ context.drawTextWithShadow(this.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.outputs"), outputsLabelTextPos.leftInt(), outputsLabelTextPos.rightInt() + yOffset, 0xFFFFFFFF);
+ context.drawTextWithShadow(this.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.hideMessage"), hideMessageTextPos.leftInt(), hideMessageTextPos.rightInt() + yOffset, 0xFFFFFFFF);
+ context.drawTextWithShadow(this.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.actionBar"), actionBarTextPos.leftInt(), actionBarTextPos.rightInt() + yOffset, 0xFFFFFFFF);
+ context.drawTextWithShadow(this.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.announcement"), announcementTextPos.leftInt(), announcementTextPos.rightInt() + yOffset, 0xFFFFFFFF);
+ context.drawTextWithShadow(this.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.sounds"), customSoundLabelTextPos.leftInt(), customSoundLabelTextPos.rightInt() + yOffset, 0xFFFFFFFF);
+ context.drawTextWithShadow(this.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.replace"), replaceMessageLabelTextPos.leftInt(), replaceMessageLabelTextPos.rightInt() + yOffset, 0xFFFFFFFF);
}
/**
@@ -306,25 +306,26 @@ public class ChatRuleConfigScreen extends Screen {
*/
@Override
public void close() {
-
- if (client != null ) {
+ if (client != null) {
save();
client.setScreen(parent);
}
}
- private void save(){
+
+ private void save() {
chatRule.setName(nameInput.getText());
chatRule.setFilter(filterInput.getText());
chatRule.setReplaceMessage(replaceMessageInput.getText());
chatRule.setValidLocations(locationsInput.getText());
- ChatRulesHandler.chatRuleList.set(chatRuleIndex,chatRule);
+ ChatRulesHandler.chatRuleList.set(chatRuleIndex, chatRule);
}
private MutableText getSoundName() {
- if (currentSoundIndex == -1){
- return Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.sounds.none");
+ if (currentSoundIndex == -1) {
+ return Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.sounds.none");
}
+
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 c5d7fcc8..aecfa88d 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigListWidget.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigListWidget.java
@@ -18,18 +18,18 @@ import java.util.List;
public class ChatRulesConfigListWidget extends ElementListWidget<ChatRulesConfigListWidget.AbstractChatRuleEntry> {
private final ChatRulesConfigScreen screen;
-
private Boolean hasChanged;
- public ChatRulesConfigListWidget(MinecraftClient minecraftClient, ChatRulesConfigScreen screen, int width, int height, int y, int itemHeight) {
- super(minecraftClient, width, height, y, itemHeight);
+ public ChatRulesConfigListWidget(MinecraftClient client, ChatRulesConfigScreen screen, int width, int height, int y, int itemHeight) {
+ super(client, width, height, y, itemHeight);
this.screen = screen;
this.hasChanged = false;
+
//add labels
- addEntry(new chatRuleLabelsEntry());
+ addEntry(new ChatRuleLabelsEntry());
//add entry fall all existing rules
- for (int i = 0; i < (long) ChatRulesHandler.chatRuleList.size(); i++){
- addEntry(new chatRuleConfigEntry(i));
+ for (int i = 0; i < ChatRulesHandler.chatRuleList.size(); i++){
+ addEntry(new ChatRuleConfigEntry(i));
}
}
@@ -46,8 +46,9 @@ public class ChatRulesConfigListWidget extends ElementListWidget<ChatRulesConfig
protected void addRuleAfterSelected() {
hasChanged = true;
int newIndex = children().indexOf(getSelectedOrNull()) + 1;
+
ChatRulesHandler.chatRuleList.add(newIndex, new ChatRule());
- children().add(newIndex + 1, new chatRuleConfigEntry(newIndex));
+ children().add(newIndex + 1, new ChatRuleConfigEntry(newIndex));
}
protected boolean removeEntry(AbstractChatRuleEntry entry) {
@@ -60,14 +61,14 @@ public class ChatRulesConfigListWidget extends ElementListWidget<ChatRulesConfig
ChatRulesHandler.saveChatRules();
}
- protected boolean hasChanges(){
- return (hasChanged || children().stream().filter(chatRuleConfigEntry.class::isInstance).map(chatRuleConfigEntry.class::cast).anyMatch(chatRuleConfigEntry::isChange));
+ protected boolean hasChanges() {
+ return (hasChanged || children().stream().filter(ChatRuleConfigEntry.class::isInstance).map(ChatRuleConfigEntry.class::cast).anyMatch(ChatRuleConfigEntry::isChange));
}
- protected static abstract class AbstractChatRuleEntry extends Entry<ChatRulesConfigListWidget.AbstractChatRuleEntry> {
+ protected static abstract class AbstractChatRuleEntry extends ElementListWidget.Entry<ChatRulesConfigListWidget.AbstractChatRuleEntry> {
}
- private class chatRuleLabelsEntry extends AbstractChatRuleEntry {
+ private class ChatRuleLabelsEntry extends AbstractChatRuleEntry {
@Override
public List<? extends Selectable> selectableChildren() {
@@ -81,13 +82,13 @@ public class ChatRulesConfigListWidget extends ElementListWidget<ChatRulesConfig
@Override
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
- context.drawCenteredTextWithShadow(client.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleName"), width / 2 - 125, y + 5, 0xFFFFFF);
- context.drawCenteredTextWithShadow(client.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleEnabled"), width / 2, y + 5, 0xFFFFFF);
- context.drawCenteredTextWithShadow(client.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.modify"), width / 2 + 100, y + 5, 0xFFFFFF);
+ context.drawCenteredTextWithShadow(client.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleName"), width / 2 - 125, y + 5, 0xFFFFFFFF);
+ context.drawCenteredTextWithShadow(client.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleEnabled"), width / 2, y + 5, 0xFFFFFFFF);
+ context.drawCenteredTextWithShadow(client.textRenderer, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.modify"), width / 2 + 100, y + 5, 0xFFFFFFFF);
}
}
- private class chatRuleConfigEntry extends AbstractChatRuleEntry {
+ private class ChatRuleConfigEntry extends AbstractChatRuleEntry {
//data
private final int chatRuleIndex;
private final ChatRule chatRule;
@@ -105,20 +106,20 @@ public class ChatRulesConfigListWidget extends ElementListWidget<ChatRulesConfig
private double oldScrollAmount = 0;
- public chatRuleConfigEntry(int chatRuleIndex) {
+ public ChatRuleConfigEntry(int chatRuleIndex) {
this.chatRuleIndex = chatRuleIndex;
this.chatRule = ChatRulesHandler.chatRuleList.get(chatRuleIndex);
- enabledButton = ButtonWidget.builder(enabledButtonText() , a -> toggleEnabled())
- .size(50,20)
- .position(width / 2 - 25,5)
+ enabledButton = ButtonWidget.builder(enabledButtonText(), a -> toggleEnabled())
+ .size(50, 20)
+ .position(width / 2 - 25, 5)
.build();
openConfigButton = ButtonWidget.builder(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.editRule"), a -> {
client.setScreen(new ChatRuleConfigScreen(screen, chatRuleIndex));
- })
- .size(50,20)
- .position(width / 2 + 45,5)
+ })
+ .size(50, 20)
+ .position(width / 2 + 45, 5)
.tooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.editRule.@Tooltip")))
.build();
@@ -126,18 +127,18 @@ public class ChatRulesConfigListWidget extends ElementListWidget<ChatRulesConfig
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)
+ .size(50, 20)
+ .position(width / 2 + 105, 5)
.build();
children = List.of(enabledButton, openConfigButton, deleteButton);
}
private Text enabledButtonText() {
- if (chatRule.getEnabled()){
- return Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.true").withColor(Color.green.getRGB());
- }else {
- return Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.false").withColor(Color.red.getRGB());
+ if (chatRule.getEnabled()) {
+ return Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.true").withColor(Color.GREEN.getRGB());
+ } else {
+ return Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.false").withColor(Color.RED.getRGB());
}
}
private void toggleEnabled() {
@@ -147,11 +148,12 @@ public class ChatRulesConfigListWidget extends ElementListWidget<ChatRulesConfig
}
private void deleteEntry(boolean confirmedAction) {
- if (confirmedAction){
+ if (confirmedAction) {
//delete this
ChatRulesHandler.chatRuleList.remove(chatRuleIndex);
removeEntry(this);
}
+
client.setScreen(screen);
setScrollAmount(oldScrollAmount);
}
@@ -186,7 +188,7 @@ public class ChatRulesConfigListWidget extends ElementListWidget<ChatRulesConfig
deleteButton.setY(y);
deleteButton.render(context, mouseX, mouseY, tickDelta);
//text
- context.drawCenteredTextWithShadow(client.textRenderer, chatRule.getName(), nameX, y + 5, 0xFFFFFF);
+ context.drawCenteredTextWithShadow(client.textRenderer, chatRule.getName(), nameX, y + 5, 0xFFFFFFFF);
}
public boolean isChange() {
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigScreen.java
index 1a6815dc..49ef735d 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigScreen.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigScreen.java
@@ -55,7 +55,7 @@ public class ChatRulesConfigScreen extends Screen {
@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);
- context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 16, 0xFFFFFF);
+ context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 16, 0xFFFFFFFF);
}
@Override
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 aa9343d8..ef44e670 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java
@@ -49,8 +49,7 @@ public class ChatRulesHandler {
private static void loadChatRules() {
try (BufferedReader reader = Files.newBufferedReader(CHAT_RULE_FILE)) {
- Type chatRulesType = new TypeToken<Map<String, List<ChatRule>>>() {
- }.getType();
+ Type chatRulesType = new TypeToken<Map<String, List<ChatRule>>>() {}.getType();
Map<String, List<ChatRule>> chatRules = SkyblockerMod.GSON.fromJson(reader,chatRulesType);
chatRuleList.addAll(chatRules.get("rules"));
@@ -74,7 +73,7 @@ public class ChatRulesHandler {
}
private static void loadLocations() {
- try {
+ try {
String response = Http.sendGetRequest("https://api.hypixel.net/v2/resources/games");
JsonObject locationsJson = JsonParser.parseString(response).getAsJsonObject().get("games").getAsJsonObject().get("SKYBLOCK").getAsJsonObject().get("modeNames").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : locationsJson.entrySet()) {
@@ -86,10 +85,9 @@ public class ChatRulesHandler {
}
locationsList.add(entry.getValue().getAsString());
//add to list in a simplified for so more lenient for user input
- locations.put(entry.getValue().getAsString().replace(" ", "").toLowerCase(),entry.getKey());
+ locations.put(entry.getValue().getAsString().replace(" ", "").toLowerCase(), entry.getKey());
}
- }
- catch (Exception e) {
+ } catch (Exception e) {
LOGGER.error("[Skyblocker] Failed to load locations!", e);
}
}
@@ -110,18 +108,18 @@ public class ChatRulesHandler {
* @param message the chat message
* @param overlay if its overlay
*/
- private static boolean checkMessage(Text message, Boolean overlay) {
+ private static boolean checkMessage(Text message, boolean overlay) {
if (!Utils.isOnSkyblock()) return true; //do not work not on skyblock
if (overlay) return true; //ignore messages in overlay
String plain = Formatting.strip(message.getString());
+
for (ChatRule rule : chatRuleList) {
if (rule.isMatch(plain)) {
//get a replacement message
Text newMessage;
if (!rule.getReplaceMessage().isBlank()) {
newMessage = formatText(rule.getReplaceMessage());
- }
- else {
+ } else {
newMessage = message;
}
@@ -135,7 +133,7 @@ public class ChatRulesHandler {
}
//hide message
- if (!rule.getHideMessage() && CLIENT.player != null) {
+ if (!rule.getHideMessage() && CLIENT.player != null) {
CLIENT.player.sendMessage(newMessage, false);
}
@@ -157,22 +155,24 @@ public class ChatRulesHandler {
* @return formatted text
*/
protected static MutableText formatText(String codedString) {
- if (codedString.contains(String.valueOf(Formatting.FORMATTING_CODE_PREFIX)) || codedString.contains("&")){
+ if (codedString.contains(String.valueOf(Formatting.FORMATTING_CODE_PREFIX)) || codedString.contains("&")) {
MutableText newText = Text.literal("");
String[] parts = codedString.split("[" + Formatting.FORMATTING_CODE_PREFIX +"&]");
Style style = Style.EMPTY;
+
for (String part : parts) {
if (part.isEmpty()) continue;
Formatting formatting = Formatting.byCode(part.charAt(0));
- if (formatting != null){
+
+ if (formatting != null) {
style = style.withFormatting(formatting);
Text.literal(part.substring(1)).getWithStyle(style).forEach(newText::append);
} else {
newText.append(Text.of(part));
}
}
- return newText;
+ return newText;
}
- return Text.literal(codedString);
+ return Text.literal(codedString);
}
}