aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java32
1 files changed, 32 insertions, 0 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 7a8214cb..34cc6352 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java
@@ -3,13 +3,33 @@ package de.hysky.skyblocker.skyblock.chat;
import de.hysky.skyblocker.utils.Utils;
import net.minecraft.sound.SoundEvent;
+import java.util.List;
import java.util.Objects;
+import java.util.Optional;
import java.util.regex.Pattern;
+import com.mojang.serialization.Codec;
+import com.mojang.serialization.codecs.RecordCodecBuilder;
+
/**
* Data class to contain all the settings for a chat rule
*/
public class ChatRule {
+ private static final Codec<ChatRule> CODEC = RecordCodecBuilder.create(instance -> instance.group(
+ Codec.STRING.fieldOf("name").forGetter(ChatRule::getName),
+ Codec.BOOL.fieldOf("enabled").forGetter(ChatRule::getEnabled),
+ Codec.BOOL.fieldOf("isPartialMatch").forGetter(ChatRule::getPartialMatch),
+ Codec.BOOL.fieldOf("isRegex").forGetter(ChatRule::getRegex),
+ Codec.BOOL.fieldOf("isIgnoreCase").forGetter(ChatRule::getIgnoreCase),
+ Codec.STRING.fieldOf("filter").forGetter(ChatRule::getFilter),
+ Codec.STRING.fieldOf("validLocations").forGetter(ChatRule::getValidLocations),
+ Codec.BOOL.fieldOf("hideMessage").forGetter(ChatRule::getHideMessage),
+ Codec.BOOL.fieldOf("showActionBar").forGetter(ChatRule::getShowActionBar),
+ Codec.BOOL.fieldOf("showAnnouncement").forGetter(ChatRule::getShowAnnouncement),
+ Codec.STRING.optionalFieldOf("replaceMessage").forGetter(ChatRule::getReplaceMessageOpt),
+ SoundEvent.CODEC.optionalFieldOf("customSound").forGetter(ChatRule::getCustomSoundOpt))
+ .apply(instance, ChatRule::new));
+ public static final Codec<List<ChatRule>> LIST_CODEC = CODEC.listOf();
private String name;
@@ -62,6 +82,10 @@ public class ChatRule {
this.customSound = customSound;
}
+ private ChatRule(String name, Boolean enabled, Boolean isPartialMatch, Boolean isRegex, Boolean isIgnoreCase, String filter, String validLocations, Boolean hideMessage, Boolean showActionBar, Boolean showAnnouncement, Optional<String> replaceMessage, Optional<SoundEvent> customSound) {
+ this(name, enabled, isPartialMatch, isRegex, isIgnoreCase, filter, validLocations, hideMessage, showActionBar, showAnnouncement, replaceMessage.orElse(null), customSound.orElse(null));
+ }
+
protected String getName() {
return name;
}
@@ -138,6 +162,10 @@ public class ChatRule {
return replaceMessage;
}
+ private Optional<String> getReplaceMessageOpt() {
+ return replaceMessage == null ? Optional.empty() : Optional.of(replaceMessage);
+ }
+
protected void setReplaceMessage(String replaceMessage) {
this.replaceMessage = replaceMessage;
}
@@ -146,6 +174,10 @@ public class ChatRule {
return customSound;
}
+ private Optional<SoundEvent> getCustomSoundOpt() {
+ return customSound == null ? Optional.empty() : Optional.of(customSound);
+ }
+
protected void setCustomSound(SoundEvent customSound) {
this.customSound = customSound;
}