Skip to content

Commit

Permalink
Updating readme and build
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkKronicle committed Oct 17, 2021
1 parent fb43474 commit 354a88d
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 6 deletions.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
# AdvancedChatFilters

AdvancedChat filters allows for complex
AdvancedChatFilters allows for complex manipulation of incoming chat messages.

Please submit bugs to the [issue tracker](https://github.com/DarkKronicle/AdvancedChatFilters/issues). Join the [Discord](https://discord.gg/WnaE3uZxDA) for more help!

## Dependencies

[AdvancedChatCore](https://github.com/DarkKronicle/AdvancedChatCore) is required to run the mod.

## Features

- Replace an advanced search with specified text
- Change the color of the match
- Replace the full message
- Rainbow specific text
- Convert specific text to OwO
- Convert numbers into Roman Numerals
- Child filters for complex actions
- Send a chat message to the Action Bar
- Narrate a message
- Play a sound when a match is found
- Many complex options for in complex matching and replacing

## Credits n' more

Code & Mastermind: DarkKronicle

Update to 1.16.3: lmichaelis

Language & Proofreading: Chronos22
11 changes: 9 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,15 @@ processResources {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
tasks.withType(JavaCompile).configureEach {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// If Javadoc is generated, this must be specified in that task too.
it.options.encoding = "UTF-8"

// Minecraft 1.17 (21w19a) upwards uses Java 16.
it.options.release = 16
}

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static ParentFilter createFilter(Filter filter) {
if (!filter.getActive().config.getBooleanValue()) {
return null;
}
ParentFilter filt = new ParentFilter(filter.getFind(), filter.getFindString().config.getStringValue());
ParentFilter filt = new ParentFilter(filter.getFind(), filter.getFindString().config.getStringValue(), filter.getStripColors().config.getBooleanValue());
if (filter.getReplace() != null) {
if (filter.getReplace().useChildren()) {
ReplaceFilter f = new ReplaceFilter(filter.getReplaceTo().config.getStringValue().replaceAll("&", "§"), filter.getReplace(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ private static String translate(String key) {
private ConfigStorage.SaveableConfig<ConfigBoolean> active = ConfigStorage.SaveableConfig.fromConfig("active",
new ConfigBoolean(translate("active"), false, translate("info.active")));

/**
* Whether or not it should be used to filter chat messages currently.
*/
private ConfigStorage.SaveableConfig<ConfigBoolean> stripColors = ConfigStorage.SaveableConfig.fromConfig("stripColors",
new ConfigBoolean(translate("stripcolors"), true, translate("info.stripcolors")));

/**
* The Expression to find a match. The way it is interpreted is defined by findType.
*/
Expand Down Expand Up @@ -117,6 +123,7 @@ public IMatchReplace getReplace() {
private final ImmutableList<ConfigStorage.SaveableConfig<?>> options = ImmutableList.of(
name,
active,
stripColors,
findString,
findType,
replaceType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.darkkronicle.advancedchatfilters.filters;

import io.github.darkkronicle.advancedchatcore.util.FindType;
import io.github.darkkronicle.advancedchatcore.util.RawText;
import io.github.darkkronicle.advancedchatcore.util.StringMatch;
import io.github.darkkronicle.advancedchatfilters.FiltersHandler;
import io.github.darkkronicle.advancedchatfilters.interfaces.IFilter;
import io.github.darkkronicle.advancedchatcore.util.ColorUtil;
Expand All @@ -10,6 +12,7 @@
import lombok.Value;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.text.Style;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -31,12 +34,14 @@ public static class FilterResult {
private List<ForwardFilter> forwardFilters;
private final FindType findType;
private final String findString;
private final boolean stripColors;

public ParentFilter(FindType findType, String findString) {
public ParentFilter(FindType findType, String findString, boolean stripColors) {
filters = new ArrayList<>();
forwardFilters = new ArrayList<>();
this.findString = findString;
this.findType = findType;
this.stripColors = stripColors;
}

public List<IFilter> getFilters() {
Expand All @@ -53,8 +58,44 @@ public void addForwardFilter(ForwardFilter forwardFilter) {
forwardFilters.add(forwardFilter);
}

private static String getWithColors(FluidText text) {
StringBuilder builder = new StringBuilder();
Style previous = Style.EMPTY;
for (RawText t : text.getRawTexts()) {
if (t.getStyle().getColor() != null && !t.getStyle().getColor().equals(previous.getColor())) {
previous = t.getStyle();
String hex = Integer.toHexString(previous.getColor().getRgb());
builder.append(hex);
}
builder.append(t.getMessage());
}
return builder.toString();
}

private static String getWithoutColors(String input) {
SearchResult hex = SearchResult.searchOf(input, \\[[a-fA-F0-9]{6}\\]", FindType.REGEX);
int last = -1;
StringBuilder builder = new StringBuilder();
for (StringMatch match : hex.getMatches()) {
if (last <= -1) {
last = match.end;
continue;
}
builder.append(input, last, match.start);
last = match.end;
}
builder.append(input, last, input.length());
return builder.toString();
}

public FilterResult filter(FluidText text, FluidText unfiltered) {
SearchResult search = SearchResult.searchOf(text.getString(), findString, findType);
String searchString;
if (stripColors) {
searchString = getWithColors(text);
} else {
searchString = text.getString();
}
SearchResult search = SearchResult.searchOf(searchString, findString, findType);
if (search.size() == 0) {
return FilterResult.EMPTY;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 354a88d

Please sign in to comment.