Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
name: build-and-test
on:
pull_request:
branches:
- master
### COMMENTED OUT FOR NOW SINCE THIS BUILD NO LONGER USES GRADLE ###

jobs:
build-and-test:
runs-on: ubuntu-latest
# name: build-and-test
# on:
# pull_request:
# branches:
# - master

steps:
- name: Checkout
uses: actions/checkout@v4
# jobs:
# build-and-test:
# runs-on: ubuntu-latest

- name: Set up JDK 1.8
uses: actions/setup-java@v2
with:
java-version: 8
distribution: 'temurin'
# steps:
# - name: Checkout
# uses: actions/checkout@v4

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
# - name: Set up JDK 1.8
# uses: actions/setup-java@v2
# with:
# java-version: 8
# distribution: 'temurin'

- name: Build with Gradle
run: ./gradlew build
# - name: Set up Gradle
# uses: gradle/actions/setup-gradle@v3

- name: Test with Gradle
run: ./gradlew test
# - name: Build with Gradle
# run: ./gradlew build

# - name: Test with Gradle
# run: ./gradlew test
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
</properties>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>

<repository>
<id>johnymuffin-nexus-releases</id>
<url>https://repository.johnymuffin.com/repository/maven-public/</url>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.aleksandarharalanov.chatguard;

import io.github.aleksandarharalanov.chatguard.command.ChatGuardCommand;
import io.github.aleksandarharalanov.chatguard.core.config.FilterConfig;
import io.github.aleksandarharalanov.chatguard.listener.block.SignChangeListener;
import io.github.aleksandarharalanov.chatguard.listener.player.*;
import io.github.aleksandarharalanov.chatguard.util.config.ConfigUtil;
Expand Down Expand Up @@ -64,13 +65,13 @@ public void onEnable() {
final ChatGuardCommand command = new ChatGuardCommand(this);
getCommand("chatguard").setExecutor(command);

LogUtil.logConsoleInfo(String.format("[%s] v%s Enabled.",
System.out.println(String.format("[%s] v%s Enabled.",
getDescription().getName(), getDescription().getVersion()));
}

@Override
public void onDisable() {
LogUtil.logConsoleInfo(String.format("[%s] v%s Disabled.",
System.out.println(String.format("[%s] v%s Disabled.",
getDescription().getName(), getDescription().getVersion()));
}

Expand All @@ -93,4 +94,10 @@ public static ConfigUtil getStrikes() {
public static ConfigUtil getCaptchas() {
return captchas;
}

public static void reloadConfig() {
getConfig().loadAndLog();

FilterConfig.generateBlackListCache();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.github.aleksandarharalanov.chatguard.util.auth.AccessUtil;
import io.github.aleksandarharalanov.chatguard.core.misc.AudioCuePlayer;
import io.github.aleksandarharalanov.chatguard.util.misc.ColorUtil;
import io.github.aleksandarharalanov.chatguard.util.log.LogUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -49,7 +48,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
CaptchaConfig.removePlayerCaptcha(player.getName());

AudioCuePlayer.play(LogType.CAPTCHA, player, true);
LogUtil.logConsoleInfo(String.format("[ChatGuard] Player '%s' passed captcha verification.", player.getName()));
System.out.println(String.format("[ChatGuard] Player '%s' passed captcha verification.", player.getName()));

return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.aleksandarharalanov.chatguard.command.subcommand;

import io.github.aleksandarharalanov.chatguard.util.log.LogUtil;
import io.github.aleksandarharalanov.chatguard.util.misc.ColorUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand All @@ -23,7 +22,7 @@ public static void sendHelp(CommandSender sender) {
if (sender instanceof Player) {
sender.sendMessage(ColorUtil.translateColorCodes(message));
} else {
LogUtil.logConsoleInfo(message.replaceAll("&.", ""));
System.out.println(message.replaceAll("&.", ""));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.github.aleksandarharalanov.chatguard.ChatGuard;
import io.github.aleksandarharalanov.chatguard.util.auth.AccessUtil;
import io.github.aleksandarharalanov.chatguard.util.log.LogUtil;
import io.github.aleksandarharalanov.chatguard.util.misc.ColorUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand All @@ -20,9 +19,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (sender instanceof Player) {
sender.sendMessage(ColorUtil.translateColorCodes("&a[ChatGuard] Configurations reloaded."));
}
LogUtil.logConsoleInfo("[ChatGuard] Configurations reloaded.");
System.out.println("[ChatGuard] Configurations reloaded.");

ChatGuard.getConfig().loadAndLog();
ChatGuard.reloadConfig();
ChatGuard.getDiscord().loadAndLog();
ChatGuard.getStrikes().loadAndLog();
ChatGuard.getCaptchas().loadAndLog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.github.aleksandarharalanov.chatguard.core.config.PenaltyConfig;
import io.github.aleksandarharalanov.chatguard.util.auth.AccessUtil;
import io.github.aleksandarharalanov.chatguard.util.misc.ColorUtil;
import io.github.aleksandarharalanov.chatguard.util.log.LogUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -20,7 +19,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

if (args.length < 2) {
sender.sendMessage(ColorUtil.translateColorCodes("&cUsage: /cg strike <username> [0-5]"));
sender.sendMessage(ColorUtil.translateColorCodes("&cUsage: /cg strike <username> [strikes]"));
return true;
}

Expand Down Expand Up @@ -50,8 +49,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

try {
int newStrike = Integer.parseInt(args[2]);
if (newStrike < 0 || newStrike > 5) {
sender.sendMessage(ColorUtil.translateColorCodes("&c[ChatGuard] Invalid range. Choose from &e0 &cto &e5&c."));
if (newStrike < 0) {
sender.sendMessage(ColorUtil.translateColorCodes("&c[ChatGuard] Must be greater than &e0."));
return true;
}

Expand All @@ -64,12 +63,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
)));
}

LogUtil.logConsoleInfo(String.format(
System.out.println(String.format(
"[ChatGuard] Player '%s' set from strike %d to %d.",
foundKey, playerStrikeTier, newStrike
));
} catch (NumberFormatException e) {
sender.sendMessage(ColorUtil.translateColorCodes("&c[ChatGuard] Invalid input. Enter a number from &e0 &cto &e5&c."));
sender.sendMessage(ColorUtil.translateColorCodes("&c[ChatGuard] Invalid input. Enter a number."));
}

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package io.github.aleksandarharalanov.chatguard.core.config;

import io.github.aleksandarharalanov.chatguard.ChatGuard;
import io.github.aleksandarharalanov.chatguard.core.security.common.TimeFormatter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public final class FilterConfig {

private static List<FilterTerm> blacklist;

private FilterConfig() {}

public static boolean getChatEnabled() {
Expand Down Expand Up @@ -38,24 +41,79 @@ public static boolean getAutoMuteEnabled() {
return ChatGuard.getConfig().getBoolean("filter.auto-mute.enabled", true);
}

public static boolean getStrikeDecayEnabled() {
return ChatGuard.getConfig().getBoolean("filter.auto-mute.strike-decay.enabled", true);
}

public static long getStrikeDecayPeriod() {
final String configString = ChatGuard.getConfig().getString("filter.auto-mute.strike-decay.period");

try {
final long futureTime = TimeFormatter.parseDateDiff(configString, true);

return futureTime - System.currentTimeMillis();
} catch(Exception e) {
throw new RuntimeException(e);
}
}

public static int getWarningcount() {
return ChatGuard.getConfig().getInt("filter.auto-mute.warnings.warning-count", 0);
}

public static int getWarningBypassThreashold() {
return ChatGuard.getConfig().getInt("filter.auto-mute.warnings.severity-bypass-threashold", 3);
}

public static List<String> getAutoMuteDurations() {
List<String> def = Arrays.asList("30m", "1h", "2h", "4h", "8h", "24h");
return ChatGuard.getConfig().getStringList("filter.auto-mute.duration", def);
}

public static List<String> getTermsWhitelist() {
return ChatGuard.getConfig().getStringList("filter.rules.whitelist.terms", new ArrayList<>());
public static List<String> getWhitelist() {
return ChatGuard.getConfig().getStringList("filter.rules.whitelist", new ArrayList<>());
}

public static List<String> getRegexWhitelist() {
return ChatGuard.getConfig().getStringList("filter.rules.whitelist.regex", new ArrayList<>());
}
public static List<FilterTerm> getBlacklist() {
if (blacklist == null)
generateBlackListCache();

public static List<String> getTermsBlacklist() {
return ChatGuard.getConfig().getStringList("filter.rules.blacklist.terms", new ArrayList<>());
return blacklist;
}

public static List<String> getRegexBlacklist() {
return ChatGuard.getConfig().getStringList("filter.rules.blacklist.regex", new ArrayList<>());
public static void generateBlackListCache() {
List<Object> entries = ChatGuard.getConfig().getList("filter.rules.blacklist");

List<FilterTerm> newBlackList = new ArrayList<>();

try {
for (Object entry : entries) {
final FilterTerm filterTerm;

List<?> pair = (List<?>) entry;
if (pair.size() == 2) {
final String name = (String) pair.get(0);
final String filter = (String) pair.get(1);

filterTerm = new FilterTerm(name, filter);
} else {
final String name = (String) pair.get(0);
final String filter = (String) pair.get(1);

final int severity = (int) pair.get(2);

filterTerm = new FilterTerm(name, filter, severity);
}

newBlackList.add(filterTerm);
}

blacklist = newBlackList;
}
catch(
ClassCastException e
) {
throw new RuntimeException("unknown type in config for blacklist. use either (String, String, Int) or (String, String). if confused, ask RitzKid76");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.github.aleksandarharalanov.chatguard.core.config;

public class FilterTerm {
private String name;
private String filter;

private int severity = 1;

public FilterTerm(String name, String filter) {
this.name = name;
this.filter = filter;
}

public FilterTerm(String name, String filter, int severity) {
this(name, filter);

this.severity = severity;
}

public String getName() {
return name;
}

public String getFilter() {
return filter;
}

public int getSeverity() {
return severity;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;

if(o == null)
return false;

if(o instanceof String)
return equalsString((String) o);
if(o instanceof FilterTerm)
return equalsFilterTerm((FilterTerm) o);

return false;
}

private boolean equalsString(String s) {
final FilterTerm that = new FilterTerm("", s);
return equalsFilterTerm(that);
}

private boolean equalsFilterTerm(FilterTerm that) {
return filter == that.getFilter();
}
}
Loading