mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Add caps protection
This commit is contained in:
1 parent
5f201c3e62
commit
33bf1414ee
3 files changed
+55
No files matched your search
@@ -94,6 +94,7 @@ public final class SimpleChat extends JavaPlugin {
|
||||
pluginManager.registerEvents(new PlaceholderHandler(this), this);
|
||||
pluginManager.registerEvents(new ShadowMuteHandler(), this);
|
||||
pluginManager.registerEvents(new EmptyChatHandler(this), this);
|
||||
pluginManager.registerEvents(new CapsHandler(this), this);
|
||||
}
|
||||
|
||||
public void reloadPatterns() {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package net.draycia.simplechat.listeners;
|
||||
|
||||
import net.draycia.simplechat.SimpleChat;
|
||||
import net.draycia.simplechat.events.ChatFormatEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class CapsHandler implements Listener {
|
||||
|
||||
private SimpleChat simpleChat;
|
||||
|
||||
public CapsHandler(SimpleChat simpleChat) {
|
||||
this.simpleChat = simpleChat;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onMessage(ChatFormatEvent event) {
|
||||
if (!simpleChat.getConfig().getBoolean("caps-protection.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getMessage().length() >= simpleChat.getConfig().getInt("caps-protection.minimum-length"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
int amountOfCaps = 0;
|
||||
|
||||
for (char letter : event.getMessage().toCharArray()) {
|
||||
if (Character.isUpperCase(letter)) {
|
||||
amountOfCaps++;
|
||||
}
|
||||
}
|
||||
|
||||
double capsPercentage = (amountOfCaps * 100.0) / event.getMessage().length();
|
||||
|
||||
if (!(capsPercentage >= simpleChat.getConfig().getDouble("caps-protection.percent-caps"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (simpleChat.getConfig().getBoolean("block-message")) {
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
event.setMessage(event.getMessage().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user