Skip to content
This repository has been archived by the owner on Oct 12, 2024. It is now read-only.

Commit

Permalink
fix: polymorphic filter settings serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Apr 2, 2024
1 parent c0d5cd3 commit bdd25b9
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,24 +195,11 @@ default void loadLocales() {

default void loadUserCache() {
final Path cacheFile = getConfigDirectory().resolve("user_cache.yml");
updateOldCache(cacheFile);
setUserCache(cacheFile.toFile().exists()
? YamlConfigurations.load(cacheFile, UserCache.Editor.class)
: new UserCache.Editor());
}

// Old config migration (v2.x)
private void updateOldCache(@NotNull Path newFile) {
final Path oldCache = getConfigDirectory().resolve("spies.yml");
if (oldCache.toFile().exists()) {
try {
Files.move(oldCache, newFile);
} catch (Throwable e) {
getPlugin().log(Level.SEVERE, "An error occurred moving the old cache file", e);
}
}
}

default void editUserCache(@NotNull Consumer<UserCache.Editor> userCache) {
userCache.accept((UserCache.Editor) getUserCache());
YamlConfigurations.save(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package net.william278.huskchat.filter;

import de.exlll.configlib.Configuration;
import de.exlll.configlib.Polymorphic;
import de.exlll.configlib.PolymorphicTypes;
import lombok.*;
import net.william278.huskchat.user.OnlineUser;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -66,6 +68,16 @@ public abstract class ChatFilter {
@SuppressWarnings("FieldMayBeFinal")
@Getter
@Configuration
@Polymorphic
@PolymorphicTypes({
@PolymorphicTypes.Type(type = FilterSettings.class, alias = "filter"),
@PolymorphicTypes.Type(type = CapsFilter.CapsFilterSettings.class, alias = "caps"),
@PolymorphicTypes.Type(type = ProfanityFilterer.ProfanityFilterSettings.class, alias = "profanity"),
@PolymorphicTypes.Type(type = SpamFilter.SpamFilterSettings.class, alias = "spam"),
@PolymorphicTypes.Type(type = RepeatFilter.RepeatFilterSettings.class, alias = "repeat"),
@PolymorphicTypes.Type(type = RegexFilter.RegexFilterSettings.class, alias = "regex"),
@PolymorphicTypes.Type(type = EmojiReplacer.EmojiReplacerSettings.class, alias = "emoji"),
})
@NoArgsConstructor(access = AccessLevel.PACKAGE)
public static class FilterSettings {
protected boolean enabled = true;
Expand Down
77 changes: 56 additions & 21 deletions docs/Config-Files.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,55 +221,90 @@ channels:
# ┗╸ Channels Help: https://william278.net/docs/huskchat/filters-and-replacers/

filters:
REPEAT:
CAPS:
type: caps
enabled: true
channels:
- global
- local
- global
- local
private_messages: true
broadcast_messages: false
max_caps_percentage: 0.4
ADVERTISING:
type: filter
enabled: true
channels:
- global
- local
- global
- local
private_messages: true
broadcast_messages: false
CAPS:
ASCII:
type: filter
enabled: true
channels:
- global
- local
- global
- local
private_messages: true
broadcast_messages: false
SPAM:
enabled: true
PROFANITY:
type: profanity
enabled: false
channels:
- global
- local
- global
- local
private_messages: true
broadcast_messages: false
ASCII:
library_path: ''
mode: AUTOMATIC
tolerance: 0.78
REGEX:
type: regex
enabled: false
channels:
- global
- local
private_messages: true
broadcast_messages: false
patterns: []
REPEAT:
type: repeat
enabled: true
channels:
- global
- local
- global
- local
private_messages: true
broadcast_messages: false
PROFANITY:
enabled: false
previous_messages_to_check: 5
SPAM:
type: spam
enabled: true
channels:
- global
- local
- global
- local
private_messages: true
broadcast_messages: false
period_seconds: 4
messages_per_period: 3
replacers:
EMOJI:
type: emoji
enabled: true
channels:
- global
- local
- global
- local
private_messages: true
broadcast_messages: false
case_insensitive: false
emoji:
':heart:':
':smile:':
:-(:
:-):
<3:
':frown:':
':star:':
':fire:': 🔥
:(:
:):
```
</details>
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.parallel=true
org.gradle.daemon=true
javaVersion=17

plugin_version=3.0.2
plugin_version=3.0.3
plugin_archive=huskchat
plugin_description=A simple & customizable no-frills Minecraft chat system

Expand Down

0 comments on commit bdd25b9

Please sign in to comment.