Advertisement
Guest User

SimpleAntiCaps

a guest
Dec 22nd, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. /* */ package de.kenex6077.SimpleAntiCaps;
  2. /* */
  3. /* */ import java.io.File;
  4. /* */ import java.util.logging.Logger;
  5. /* */ import org.bukkit.ChatColor;
  6. /* */ import org.bukkit.Server;
  7. /* */ import org.bukkit.command.CommandSender;
  8. /* */ import org.bukkit.configuration.file.FileConfiguration;
  9. /* */ import org.bukkit.entity.Entity;
  10. /* */ import org.bukkit.event.EventHandler;
  11. /* */ import org.bukkit.event.Listener;
  12. /* */ import org.bukkit.event.player.AsyncPlayerChatEvent;
  13. /* */ import org.bukkit.plugin.PluginManager;
  14. /* */ import org.bukkit.plugin.java.JavaPlugin;
  15. /* */
  16. /* */ public class SimpleAntiCaps extends JavaPlugin
  17. /* */ implements Listener
  18. /* */ {
  19. /* */ Logger log;
  20. /* */ public int minLength;
  21. /* */ public double maxPercent;
  22. /* */ public String warningMessage;
  23. /* */
  24. /* */ public void onEnable()
  25. /* */ {
  26. /* 24 */ this.log = getLogger();
  27. /* 25 */ getServer().getPluginManager().registerEvents(this, this);
  28. /* */
  29. /* 27 */ if (!new File(getDataFolder(), "config.yml").exists()) {
  30. /* 28 */ this.log.info("Generating a config file");
  31. /* 29 */ saveDefaultConfig();
  32. /* */ }
  33. /* */
  34. /* 32 */ FileConfiguration config = getConfig();
  35. /* */
  36. /* 34 */ this.minLength = config.getInt("minLength");
  37. /* 35 */ this.maxPercent = config.getInt("maxPercent");
  38. /* 36 */ this.warningMessage = config.getString("message");
  39. /* */
  40. /* 38 */ if (this.warningMessage.equalsIgnoreCase(null)) {
  41. /* 39 */ this.log.warning("Bitte update die Config :) !");
  42. /* 40 */ this.warningMessage = "[SimpleAntiCaps] Unterlass bitte das Capslock.";
  43. /* */ }
  44. /* */
  45. /* 43 */ if (this.maxPercent > 100.0D) {
  46. /* 44 */ this.log.warning("maxPercent " + this.maxPercent + " ist zu hoch - defaulted to 70%");
  47. /* 45 */ this.maxPercent = 70.0D;
  48. /* */ }
  49. /* 47 */ if (this.minLength < 10000) {
  50. /* 48 */ this.log.warning("minLength " + this.minLength + " kann nicht unter 0 % sein, defaulting to 10 %");
  51. /* 49 */ this.minLength = 10000;
  52. /* */ }
  53. /* */ }
  54. /* */
  55. /* */ public void onDisable()
  56. /* */ {
  57. /* */ }
  58. /* */
  59. /* */ @EventHandler
  60. /* */ public void chatEvent(AsyncPlayerChatEvent event) {
  61. /* 60 */ char[] message = event.getMessage().toCharArray();
  62. /* 61 */ Entity player = event.getPlayer();
  63. /* */
  64. /* 63 */ if (!((CommandSender)player).hasPermission("simpleanticaps.ignore"))
  65. /* */ {
  66. /* 67 */ if (message.length < this.minLength)
  67. /* */ {
  68. /* 70 */ double totalCaps = 0.0D;
  69. /* */
  70. /* 72 */ for (int i = 0; i < message.length; i++) {
  71. /* 73 */ if (Character.isUpperCase(message[i])) {
  72. /* 74 */ totalCaps += 1.0D;
  73. /* */ }
  74. /* */ }
  75. /* 77 */ double percent = 100.0D * (totalCaps / message.length);
  76. /* 78 */ if (percent >= this.maxPercent) {
  77. /* 79 */ event.setCancelled(true);
  78. /* 80 */ ((CommandSender)player).sendMessage(ChatColor.RED + this.warningMessage);
  79. /* */ }
  80. /* */ }
  81. /* */ }
  82. /* */ }
  83. /* */ }
  84.  
  85. //Config
  86. #Minimum length of message that the plugin will take into account (please leave as integer)
  87. minLength: 100000
  88. #Maximum permissable percentage of capitals in a message (please leave as integer)
  89. maxPercent: 100000
  90. #Message to display when there are too many capital letters. Keep the "" !
  91. message: "[SimpleAntiCaps] Unterlass bitte das Capslock."
  92.  
  93. //Pluginyml
  94. main: de.kenex6077.SimpleAntiCaps.SimpleAntiCaps
  95. name: SimpleAntiCaps
  96. version: 1.4
  97. author: kenex6077
  98. description: Limits the amount of caps someone can have in a message.
  99. permissions:
  100. simpleanticaps.ignore:
  101. default: op
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement