Skip to content

Commit

Permalink
Fix Uppercase Issue with Usernames. Closes DragonTechMC#39
Browse files Browse the repository at this point in the history
  • Loading branch information
hsyyid committed Sep 18, 2018
1 parent 4927d2c commit bb47e44
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 19 deletions.
110 changes: 107 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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

27 changes: 11 additions & 16 deletions src/main/java/me/morpheus/dtpunishment/WordChecker.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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) {
Expand Down

0 comments on commit bb47e44

Please sign in to comment.