Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* */ package de.kenex6077.SimpleAntiCaps;
- /* */
- /* */ import java.io.File;
- /* */ import java.util.logging.Logger;
- /* */ import org.bukkit.ChatColor;
- /* */ import org.bukkit.Server;
- /* */ import org.bukkit.command.CommandSender;
- /* */ import org.bukkit.configuration.file.FileConfiguration;
- /* */ import org.bukkit.entity.Entity;
- /* */ import org.bukkit.event.EventHandler;
- /* */ import org.bukkit.event.Listener;
- /* */ import org.bukkit.event.player.AsyncPlayerChatEvent;
- /* */ import org.bukkit.plugin.PluginManager;
- /* */ import org.bukkit.plugin.java.JavaPlugin;
- /* */
- /* */ public class SimpleAntiCaps extends JavaPlugin
- /* */ implements Listener
- /* */ {
- /* */ Logger log;
- /* */ public int minLength;
- /* */ public double maxPercent;
- /* */ public String warningMessage;
- /* */
- /* */ public void onEnable()
- /* */ {
- /* 24 */ this.log = getLogger();
- /* 25 */ getServer().getPluginManager().registerEvents(this, this);
- /* */
- /* 27 */ if (!new File(getDataFolder(), "config.yml").exists()) {
- /* 28 */ this.log.info("Generating a config file");
- /* 29 */ saveDefaultConfig();
- /* */ }
- /* */
- /* 32 */ FileConfiguration config = getConfig();
- /* */
- /* 34 */ this.minLength = config.getInt("minLength");
- /* 35 */ this.maxPercent = config.getInt("maxPercent");
- /* 36 */ this.warningMessage = config.getString("message");
- /* */
- /* 38 */ if (this.warningMessage.equalsIgnoreCase(null)) {
- /* 39 */ this.log.warning("Bitte update die Config :) !");
- /* 40 */ this.warningMessage = "[SimpleAntiCaps] Unterlass bitte das Capslock.";
- /* */ }
- /* */
- /* 43 */ if (this.maxPercent > 100.0D) {
- /* 44 */ this.log.warning("maxPercent " + this.maxPercent + " ist zu hoch - defaulted to 70%");
- /* 45 */ this.maxPercent = 70.0D;
- /* */ }
- /* 47 */ if (this.minLength < 10000) {
- /* 48 */ this.log.warning("minLength " + this.minLength + " kann nicht unter 0 % sein, defaulting to 10 %");
- /* 49 */ this.minLength = 10000;
- /* */ }
- /* */ }
- /* */
- /* */ public void onDisable()
- /* */ {
- /* */ }
- /* */
- /* */ @EventHandler
- /* */ public void chatEvent(AsyncPlayerChatEvent event) {
- /* 60 */ char[] message = event.getMessage().toCharArray();
- /* 61 */ Entity player = event.getPlayer();
- /* */
- /* 63 */ if (!((CommandSender)player).hasPermission("simpleanticaps.ignore"))
- /* */ {
- /* 67 */ if (message.length < this.minLength)
- /* */ {
- /* 70 */ double totalCaps = 0.0D;
- /* */
- /* 72 */ for (int i = 0; i < message.length; i++) {
- /* 73 */ if (Character.isUpperCase(message[i])) {
- /* 74 */ totalCaps += 1.0D;
- /* */ }
- /* */ }
- /* 77 */ double percent = 100.0D * (totalCaps / message.length);
- /* 78 */ if (percent >= this.maxPercent) {
- /* 79 */ event.setCancelled(true);
- /* 80 */ ((CommandSender)player).sendMessage(ChatColor.RED + this.warningMessage);
- /* */ }
- /* */ }
- /* */ }
- /* */ }
- /* */ }
- //Config
- #Minimum length of message that the plugin will take into account (please leave as integer)
- minLength: 100000
- #Maximum permissable percentage of capitals in a message (please leave as integer)
- maxPercent: 100000
- #Message to display when there are too many capital letters. Keep the "" !
- message: "[SimpleAntiCaps] Unterlass bitte das Capslock."
- //Pluginyml
- main: de.kenex6077.SimpleAntiCaps.SimpleAntiCaps
- name: SimpleAntiCaps
- version: 1.4
- author: kenex6077
- description: Limits the amount of caps someone can have in a message.
- permissions:
- simpleanticaps.ignore:
- default: op
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement