-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly handled command aliases for PM checks, NCP 3.16.0
- Loading branch information
Showing
12 changed files
with
1,404 additions
and
1,344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 77 additions & 79 deletions
156
src/main/java/ru/Den_Abr/ChatGuard/ChatFilters/CapsFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
55
src/main/java/ru/Den_Abr/ChatGuard/ChatFilters/Filter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", ""))); | ||
} | ||
|
||
} |
Oops, something went wrong.