diff --git a/.gitignore b/.gitignore index ff1bdab..8f60e79 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,107 @@ -/bin/ -/.gradle/ -/build/ +# Created by .ignore support plugin (hsz.mobi) +### Eclipse template +*.pydevproject +.metadata +.gradle +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Java annotation processor (APT) +.factorypath + +# PDT-specific +.buildpath + +# sbteclipse plugin +.target + +# TeXlipse plugin +.texlipse +### NetBeans template +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +nbactions.xml +nb-configuration.xml +.nb-gradle/ +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +### Gradle template +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + diff --git a/src/main/java/me/morpheus/dtpunishment/WordChecker.java b/src/main/java/me/morpheus/dtpunishment/WordChecker.java index 4a64ec8..5d147f6 100644 --- a/src/main/java/me/morpheus/dtpunishment/WordChecker.java +++ b/src/main/java/me/morpheus/dtpunishment/WordChecker.java @@ -1,5 +1,9 @@ package me.morpheus.dtpunishment; +import me.morpheus.dtpunishment.configuration.ChatConfig; +import org.apache.commons.lang3.StringUtils; +import org.spongepowered.api.Sponge; + import java.time.Instant; import java.util.ArrayList; import java.util.Collections; @@ -10,15 +14,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.lang3.StringUtils; - -import com.google.inject.Inject; -import com.google.inject.Singleton; - -import me.morpheus.dtpunishment.configuration.ChatConfig; -import org.spongepowered.api.Sponge; -import org.spongepowered.api.entity.living.player.Player; - public class WordChecker { private ChatConfig chatConfig; @@ -92,16 +87,14 @@ public String getBannedWord(String message) { } public boolean containsUppercase(String message) { - - if (message.replaceAll("[\\W]", "").length() <= chatConfig.caps.minimum_length) - return false; - String[] words = message.split("\\s+"); int upper = 0; int total = 0; for (String word : words) { - if (Sponge.getServer().getPlayer(word).isPresent()) continue; + // Ignore player names + if (Sponge.getServer().getPlayer(word).isPresent()) continue; + String cleaned = word.replaceAll("[\\W]", ""); total += cleaned.length(); @@ -112,11 +105,13 @@ public boolean containsUppercase(String message) { if (Character.isUpperCase(cleaned.charAt(i))) upper++; } - } + + if (total <= chatConfig.caps.minimum_length) + return false; + int max = (chatConfig.caps.percentage * total) / 100; return upper > max; - } public boolean isSpam(String message, UUID author) {