Skip to content

Commit

Permalink
Properly handled command aliases for PM checks, NCP 3.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DenAbr committed Apr 20, 2019
1 parent b7bdd2d commit f802d39
Show file tree
Hide file tree
Showing 12 changed files with 1,404 additions and 1,344 deletions.
26 changes: 18 additions & 8 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="bin/main" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="src/main/resources">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
17 changes: 13 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ apply plugin: 'java'
apply plugin: 'maven'

group = 'ru.den_abr'
version = '7.6.1'
version = '7.6.2'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -23,7 +23,6 @@ repositories {
maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }
maven { url "https://hub.spigotmc.org/nexus/content/groups/public/" }
maven { url "http://repo.codemc.org/repository/maven-public/" }
maven { url "https://repo.md-5.net/content/repositories/snapshots/" }
maven { url "https://repo.md-5.net/content/repositories/releases/" }
maven { url "http://repo.dmulloy2.net/nexus/repository/public/" }
maven { url "http://ci.drtshock.net/plugin/repository/everything/" }
Expand All @@ -38,12 +37,22 @@ shadowJar {
relocate 'org.bstats.bukkit', 'ru.Den_Abr.ChatGuard.ThirdParty.bstats'
}

processResources {
from (sourceSets.main.resources.srcDirs) {
expand 'version': version
include 'plugin.yml'
}

from (sourceSets.main.resources.srcDirs) {
exclude 'plugin.yml'
}
}

dependencies {
compileOnly group: 'fr.xephi', name: 'authme', version:'5.4.0'
compileOnly group: 'com.comphenix.protocol', name: 'ProtocolLib', version:'4.3.0'
compileOnly group: 'com.comphenix.protocol', name: 'ProtocolLib-API', version:'4.3.0'
compileOnly group: 'org.bukkit', name: 'bukkit', version:'1.13.2-R0.1-SNAPSHOT'
compileOnly group: 'fr.neatmonster', name: 'nocheatplus', version:'3.16.1-SNAPSHOT'
compileOnly group: 'fr.neatmonster', name: 'nocheatplus', version:'3.16.0-RC'
compile group: 'org.bstats', name: 'bstats-bukkit', version:'1.4'

}
156 changes: 77 additions & 79 deletions src/main/java/ru/Den_Abr/ChatGuard/ChatFilters/CapsFilter.java
Original file line number Diff line number Diff line change
@@ -1,79 +1,77 @@
package ru.Den_Abr.ChatGuard.ChatFilters;

import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;

import ru.Den_Abr.ChatGuard.ChatGuardPlugin;
import ru.Den_Abr.ChatGuard.Violation;
import ru.Den_Abr.ChatGuard.Configuration.Messages.Message;
import ru.Den_Abr.ChatGuard.Configuration.Settings;
import ru.Den_Abr.ChatGuard.Player.CGPlayer;

public class CapsFilter extends AbstractFilter {
private boolean informAdmins;
private int maxCapsPercent;
private int minLenght;

@Override
public Violation checkMessage(String message, CGPlayer player, boolean justCheck) {
if (message.length() < minLenght)
return null;
if (player.hasPermission("chatguard.ignore.caps"))
return null;
ChatGuardPlugin.debug(2, getClass().getSimpleName() + ": Hello!");

String ws = message.replaceAll(" ", "").replaceAll("[^A-Za-zА-Яа-яà-ÿÀ-ß]", "");
if (ws.length() == 0 || ws.length() < minLenght)
return null;
int capsCount = getCapsCount(ws);
int capspercent = capsCount * 100 / ws.length();
Violation v = (capspercent > maxCapsPercent) ? Violation.CAPS : null;
if (!justCheck && v != null && informAdmins) {
informAdmins(player, message);
}
return v;
}

@Override
public Violation checkMessage(String message, CGPlayer player) {
return checkMessage(message, player, false);
}

private void informAdmins(CGPlayer player, String message) {
String complete = Message.INFORM_CAPS.get().replace("{PLAYER}", player.getName()).replace("{MESSAGE}", message);
Bukkit.getConsoleSender().sendMessage(complete);
Bukkit.broadcast(complete, "chatguard.inform.caps");
}

private int getCapsCount(String message) {
int count = 0;
for (char ch : message.toCharArray()) {
if (Character.isUpperCase(ch)) {
count++;
}
}
return count;
}

@Override
public String getClearMessage(String message, CGPlayer player) {
if (player.hasPermission("chatguard.ignore.caps"))
return message;
return message.toLowerCase();
}

@Override
public void register() {
ConfigurationSection cs = Settings.getConfig().getConfigurationSection("caps settings");
if (!cs.getBoolean("enabled"))
return;
informAdmins = cs.getBoolean("inform admins");
maxWarns = cs.getInt("max warnings");

maxCapsPercent = cs.getInt("max caps percent");
minLenght = cs.getInt("min message lenght");
addMetricsGraph();
getActiveFilters().add(this);
}

}
package ru.Den_Abr.ChatGuard.ChatFilters;

import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;

import ru.Den_Abr.ChatGuard.Violation;
import ru.Den_Abr.ChatGuard.Configuration.Messages.Message;
import ru.Den_Abr.ChatGuard.Configuration.Settings;
import ru.Den_Abr.ChatGuard.Player.CGPlayer;

public class CapsFilter extends AbstractFilter {
private boolean informAdmins;
private int maxCapsPercent;
private int minLenght;

@Override
public Violation checkMessage(String message, CGPlayer player, boolean justCheck) {
if (message.length() < minLenght)
return null;
if (player.hasPermission("chatguard.ignore.caps"))
return null;

String ws = message.replaceAll(" ", "").replaceAll("[^A-Za-zА-Яа-яà-ÿÀ-ß]", "");
if (ws.length() == 0 || ws.length() < minLenght)
return null;
int capsCount = getCapsCount(ws);
int capspercent = capsCount * 100 / ws.length();
Violation v = (capspercent > maxCapsPercent) ? Violation.CAPS : null;
if (!justCheck && v != null && informAdmins) {
informAdmins(player, message);
}
return v;
}

@Override
public Violation checkMessage(String message, CGPlayer player) {
return checkMessage(message, player, false);
}

private void informAdmins(CGPlayer player, String message) {
String complete = Message.INFORM_CAPS.get().replace("{PLAYER}", player.getName()).replace("{MESSAGE}", message);
Bukkit.getConsoleSender().sendMessage(complete);
Bukkit.broadcast(complete, "chatguard.inform.caps");
}

private int getCapsCount(String message) {
int count = 0;
for (char ch : message.toCharArray()) {
if (Character.isUpperCase(ch)) {
count++;
}
}
return count;
}

@Override
public String getClearMessage(String message, CGPlayer player) {
if (player.hasPermission("chatguard.ignore.caps"))
return message;
return message.toLowerCase();
}

@Override
public void register() {
ConfigurationSection cs = Settings.getConfig().getConfigurationSection("caps settings");
if (!cs.getBoolean("enabled"))
return;
informAdmins = cs.getBoolean("inform admins");
maxWarns = cs.getInt("max warnings");

maxCapsPercent = cs.getInt("max caps percent");
minLenght = cs.getInt("min message lenght");
addMetricsGraph();
getActiveFilters().add(this);
}

}
55 changes: 28 additions & 27 deletions src/main/java/ru/Den_Abr/ChatGuard/ChatFilters/Filter.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package ru.Den_Abr.ChatGuard.ChatFilters;

import org.bstats.bukkit.Metrics;

import ru.Den_Abr.ChatGuard.ChatGuardPlugin;
import ru.Den_Abr.ChatGuard.Violation;
import ru.Den_Abr.ChatGuard.Player.CGPlayer;

public interface Filter {

@Deprecated
public Violation checkMessage(String message, CGPlayer player);

public Violation checkMessage(String message, CGPlayer player, boolean justCheck);

public String getClearMessage(String message, CGPlayer player);

public int getMaxWarnings();

public void register();

default void addMetricsGraph() {
ChatGuardPlugin.metrics.addCustomChart(
new Metrics.SimplePie("filters_used", () -> getClass().getSimpleName().replace("Filter", "")));
}

}
package ru.Den_Abr.ChatGuard.ChatFilters;

import org.bstats.bukkit.Metrics;

import ru.Den_Abr.ChatGuard.ChatGuardPlugin;
import ru.Den_Abr.ChatGuard.Violation;
import ru.Den_Abr.ChatGuard.Player.CGPlayer;

public interface Filter {

@Deprecated
public Violation checkMessage(String message, CGPlayer player);

public Violation checkMessage(String message, CGPlayer player, boolean justCheck);

public String getClearMessage(String message, CGPlayer player);

public int getMaxWarnings();

public void register();

default void addMetricsGraph() {
if (ChatGuardPlugin.metrics.isEnabled())
ChatGuardPlugin.metrics.addCustomChart(
new Metrics.SimplePie("filters_used", () -> getClass().getSimpleName().replace("Filter", "")));
}

}
Loading

0 comments on commit f802d39

Please sign in to comment.