mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +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 PlaceholderHandler(this), this);
|
||||||
pluginManager.registerEvents(new ShadowMuteHandler(), this);
|
pluginManager.registerEvents(new ShadowMuteHandler(), this);
|
||||||
pluginManager.registerEvents(new EmptyChatHandler(this), this);
|
pluginManager.registerEvents(new EmptyChatHandler(this), this);
|
||||||
|
pluginManager.registerEvents(new CapsHandler(this), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadPatterns() {
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -98,6 +98,12 @@ item-link-placeholders:
|
|||||||
- '[item]' # cursed placeholder do not use
|
- '[item]' # cursed placeholder do not use
|
||||||
- '%item%'
|
- '%item%'
|
||||||
|
|
||||||
|
caps-protection:
|
||||||
|
enabled: true
|
||||||
|
minimum-length: 10
|
||||||
|
percent-caps: 80
|
||||||
|
block-message: false
|
||||||
|
|
||||||
spy-prefix: '<color>[SPY] '
|
spy-prefix: '<color>[SPY] '
|
||||||
spy-prefix-nation: '<color>[SPY <nation>] '
|
spy-prefix-nation: '<color>[SPY <nation>] '
|
||||||
spy-prefix-town: '<color>[SPY <town>] '
|
spy-prefix-town: '<color>[SPY <town>] '
|
||||||
|
|||||||
Reference in new issue
Block a user