Advertisement
Guest User

Untitled

a guest
Sep 12th, 2012
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.42 KB | None | 0 0
  1. package me.jkl1234.JKLChat;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6. import java.util.logging.Logger;
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.Server;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandSender;
  11. import org.bukkit.configuration.InvalidConfigurationException;
  12. import org.bukkit.configuration.file.FileConfiguration;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.player.PlayerChatEvent;
  17. import org.bukkit.plugin.PluginManager;
  18. import org.bukkit.plugin.java.JavaPlugin;
  19.  
  20. public class JKLChat extends JavaPlugin
  21. {
  22.   private static final Logger mclog = Logger.getLogger("minecraft");
  23.   protected FileConfiguration config;
  24.   File confFile;
  25.   protected FileConfiguration mysql;
  26.   File mysqlFile;
  27.   int nums;
  28.   private final JChatPlayerListener blockListener = new JChatPlayerListener(this);
  29.  
  30.   public void onDisable() {
  31.     try {
  32.       this.config.save(this.confFile);
  33.     } catch (IOException e1) {
  34.       e1.printStackTrace();
  35.     }
  36.     mclog.info("[JKL-Chat] Stop");
  37.   }
  38.  
  39.   public void onEnable() {
  40.     mclog.info("[JKL-Chat] Start");
  41.     getServer().getPluginManager().registerEvents(this.blockListener, this);
  42.     this.config = getConfig();
  43.     this.confFile = new File(getDataFolder(), "config.yml");
  44.     try {
  45.       this.config.load(this.confFile);
  46.     } catch (FileNotFoundException e1) {
  47.       e1.printStackTrace();
  48.     } catch (IOException e1) {
  49.       mclog.severe("Unable to load JKL-Chat configuration");
  50.     } catch (InvalidConfigurationException e1) {
  51.       mclog.severe("Unable to load JKL-Chat configuration");
  52.     }
  53.   }
  54.  
  55.   public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
  56.     Player player = null;
  57.     if ((sender instanceof Player)) {
  58.       player = (Player)sender;
  59.     }
  60.     if (cmd.getName().equalsIgnoreCase("addword")) {
  61.       if ((player == null) || (sender.hasPermission("JKLChat.add"))) {
  62.         if (args.length > 1) {
  63.           this.config.set(args[0], args[1]);
  64.           try {
  65.             this.config.save(this.confFile);
  66.           } catch (IOException e) {
  67.             e.printStackTrace();
  68.           }
  69.           sender.sendMessage("Слово '" + args[0] + "' теперь будет заменяться словом '" + args[1] + "'");
  70.           return true;
  71.         }
  72.         return false;
  73.       }
  74.       sender.sendMessage(ChatColor.DARK_RED + "У вас нет прав для выполнения этой команды!"); return true;
  75.     }
  76.     if (cmd.getName().equalsIgnoreCase("deleteword")) {
  77.       if ((player == null) || (sender.hasPermission("JKLChat.delete"))) {
  78.         if (args.length > 0) {
  79.           if (this.config.contains(args[0])) this.config.set(args[0], "0"); try
  80.           {
  81.             this.config.save(this.confFile);
  82.           } catch (IOException e) {
  83.             e.printStackTrace();
  84.           }
  85.           sender.sendMessage("Слово '" + args[0] + "' больше не будет заменяться");
  86.           return true;
  87.         }
  88.         return false;
  89.       }
  90.       sender.sendMessage(ChatColor.DARK_RED + "У вас нет прав для выполнения этой команды!"); return true;
  91.     }
  92.     return false;
  93.   }
  94.   boolean isSpace(char ch) {
  95.     return (ch == ' ') || (ch == '.') || (ch == ',') || (ch == '>') || (ch == '<') || (ch == '^') || (ch == '-') || (ch == '_') || (ch == '=') || (ch == '"') || (ch == '\'') || (ch == '\\') || (ch == '|') || (ch == '/') || (ch == '(') || (ch == ')') || (ch == '#') || (ch == '№') || (ch == ';') || (ch == ':') || (ch == '?') || (ch == '*') || (ch == '%') || (ch == '$') || (ch == '@') || (ch == '!') || (ch == '~') || (ch == '`');
  96.   }
  97.  
  98.   boolean Ravno(char a, char b, char c, char d) {
  99.     this.nums = 0;
  100.     if ((a == 'а') && ((b == '@') || (b == 'a') || (b == 'а') || (b == 'A') || (b == 'А'))) return true;
  101.     if ((a == 'б') && ((b == 'б') || (b == 'Б') || (b == 'b') || (b == 'B') || (b == '6'))) return true;
  102.     if ((a == 'в') && ((b == 'v') || (b == 'V') || (b == 'B') || (b == 'в') || (b == 'В') || ((b == '|') && (c == '3')))) return true;
  103.     if ((a == 'г') && ((b == 'г') || (b == 'Г') || (b == 'g') || (b == 'G') || (b == 'r'))) return true;
  104.     if ((a == 'д') && ((b == 'д') || (b == 'Д') || (b == 'd') || (b == 'D') || (b == 'g'))) return true;
  105.     if (((a == 'е') || (a == 'ё')) && ((b == 'е') || (b == 'Е') || (b == 'e') || (b == 'E') || (b == 'Ё') || (b == 'ё'))) return true;
  106.     if ((a == 'ж') && ((b == 'ж') || (b == 'Ж') || (b == '*') || ((b == '}') && (c == '|') && (d == '{')) || ((b == ')') && (c == '|') && (d == '(')))) {
  107.       if (((b == '}') && (c == '|') && (d == '{')) || ((b == ')') && (c == '|') && (d == '('))) this.nums = 2;
  108.       return true;
  109.     }
  110.     if ((a == 'з') && ((b == 'z') || (b == 'Z') || (b == 'з') || (b == 'З') || (b == '3'))) return true;
  111.     if (((a == 'и') || (a == 'й')) && ((b == 'И') || (b == 'и') || (b == 'u') || (b == 'i') || (b == 'I') || (b == '1') || (b == 'й') || (b == 'Й'))) return true;
  112.     if ((a == 'к') && ((b == 'k') || (b == 'K') || (b == 'к') || (b == 'К') || ((b == '|') && (c == '{')) || ((b == 'I') && (c == '{')) || ((b == 'i') && (c == '{')))) {
  113.       if (((b == '|') && (c == '{')) || ((b == 'I') && (c == '{')) || ((b == 'i') && (c == '{'))) this.nums = 1;
  114.       return true;
  115.     }
  116.     if ((a == 'л') && ((b == 'l') || (b == 'L') || (b == 'л') || (b == 'Л') || (b == '^') || ((b == '/') && (c == '\\')) || ((b == 'j') && (c == 'i')))) {
  117.       if (((b == '/') && (c == '\\')) || ((b == 'j') && (c == 'i'))) this.nums = 1;
  118.       return true;
  119.     }
  120.     if ((a == 'м') && ((b == 'm') || (b == 'M') || (b == 'м') || (b == 'М'))) return true;
  121.     if ((a == 'н') && ((b == 'н') || (b == 'Н') || (b == 'n') || (b == 'N') || (b == 'H'))) return true;
  122.     if ((a == 'о') && ((b == '0') || (b == 'О') || (b == 'о') || (b == 'O') || (b == 'o'))) return true;
  123.     if ((a == 'п') && ((b == 'n') || (b == 'p') || (b == 'P') || (b == 'п') || (b == 'П') || (b == 'р') || (b == 'Р'))) return true;
  124.     if ((a == 'р') && ((b == 'p') || (b == 'P') || (b == 'r') || (b == 'R') || (b == 'р') || (b == 'Р'))) return true;
  125.     if ((a == 'с') && ((b == 'с') || (b == 'С') || (b == 'c') || (b == 'C') || (b == 's') || (b == 'S') || (b == '('))) return true;
  126.     if ((a == 'т') && ((b == 't') || (b == 'T') || (b == 'т') || (b == 'Т') || (b == 'm'))) return true;
  127.     if ((a == 'у') && ((b == 'u') || (b == 'U') || (b == 'у') || (b == 'У') || (b == 'Y') || (b == 'y'))) return true;
  128.     if ((a == 'ф') && ((b == 'ф') || (b == 'Ф') || (b == 'f') || (b == 'F') || (b == 'А'))) return true;
  129.     if ((a == 'х') && ((b == 'x') || (b == 'X') || (b == 'х') || (b == 'Х') || ((b == '}') && (c == '{')) || (b == 'h') || (b == 'H') || ((b == ')') && (c == '(')))) {
  130.       if (((b == '}') && (c == '{')) || ((b == ')') && (c == '('))) this.nums = 1;
  131.       return true;
  132.     }
  133.     if ((a == 'ц') && ((b == 'c') || (b == 'C') || (b == 'с') || (b == 'С') || (b == 'ц') || (b == 'Ц') || (b == 'u'))) return true;
  134.     if ((a == 'ч') && ((b == '4') || (b == 'ч') || (b == 'Ч') || ((b == 'c') && (c == 'h')))) {
  135.       if ((b == 'c') && (c == 'h')) this.nums = 1;
  136.       return true;
  137.     }
  138.     if ((a == 'ш') && ((b == 'ш') || (b == 'Ш') || ((b == 's') && (c == 'h')))) {
  139.       if ((b == 's') && (c == 'h')) this.nums = 1;
  140.       return true;
  141.     }
  142.     if ((a == 'щ') && ((b == 'щ') || (b == 'Щ') || ((b == 's') && (c == 'c') && (d == 'h')))) {
  143.       if ((b == 's') && (c == 'c') && (d == 'h')) this.nums = 2;
  144.       return true;
  145.     }
  146.     if ((a == 'ъ') && ((b == 'ъ') || (b == 'Ъ') || (b == 'ь') || (b == 'Ь') || (b == 'b'))) return true;
  147.     if ((a == 'ы') && ((b == 'ы') || (b == 'Ы') || (b == 'а') || (b == 'A') || (b == 'А') || ((b == 'b') && (c == '|')) || ((b == 'b') && (c == 'l')) || ((b == 'ь') && (c == 'l')) || ((b == 'Ь') && (c == 'l')) || ((b == 'ь') && (c == '|')) || ((b == 'Ь') && (c == '|')))) {
  148.       if (((b == 'b') && (c == '|')) || ((b == 'b') && (c == 'l')) || ((b == 'ь') && (c == 'l')) || ((b == 'Ь') && (c == 'l')) || ((b == 'ь') && (c == '|')) || ((b == 'Ь') && (c == '|'))) this.nums = 1;
  149.       return true;
  150.     }
  151.     if ((a == 'ь') && ((b == 'ь') || (b == 'Ь') || (b == 'Ъ') || (b == 'ъ') || (b == 'b'))) return true;
  152.     if ((a == 'э') && ((b == 'э') || (b == 'Э') || (b == 'e') || (b == 'E') || (b == 'е') || (b == 'Е'))) return true;
  153.     if ((a == 'ю') && ((b == 'ю') || (b == 'Ю') || (b == 'u') || (b == 'U'))) return true;
  154.     return (a == 'я') && ((b == 'я') || (b == 'Я'));
  155.   }
  156.   class JChatPlayerListener implements Listener {
  157.     public JKLChat plugin;
  158.  
  159.     public JChatPlayerListener(JKLChat instance) { this.plugin = instance; }
  160.     @EventHandler
  161.     public void onPlayerChat(PlayerChatEvent event) {
  162.       if (event.isCancelled()) return;
  163.  
  164.       for (String s : JKLChat.this.config.getKeys(false))
  165.         if (!JKLChat.this.config.get(s).equals("0")) {
  166.           int position = 0;
  167.           String message = event.getMessage();
  168.           int start = 0;
  169.           s = s.toLowerCase();
  170.           for (int i = 0; i < message.length(); i++) {
  171.             message = event.getMessage();
  172.             char sch = ' ';
  173.             char cc = ' ';
  174.             char dd = ' ';
  175.             if (message.length() - i > 1) cc = message.charAt(i + 1);
  176.             if (message.length() - i > 2) dd = message.charAt(i + 2);
  177.             if (i > 0) sch = message.charAt(i - 1);
  178.             if ((JKLChat.this.Ravno(s.charAt(position), message.charAt(i), cc, dd)) || ((JKLChat.this.isSpace(message.charAt(i))) && (position > 0))) {
  179.               if (((position == 0) && (JKLChat.this.isSpace(sch))) || ((position == s.length() - 1) && (JKLChat.this.isSpace(cc))) || ((position > 0) && (position < s.length()))) {
  180.                 if (position == 0) start = i;
  181.                 if (JKLChat.this.Ravno(s.charAt(position), message.charAt(i), cc, dd)) position++;
  182.                 i += JKLChat.this.nums;
  183.                 JKLChat.this.nums = 0;
  184.                 if (position == s.length()) {
  185.                   position = 0;
  186.                   event.setMessage(message.substring(0, start) + JKLChat.this.config.get(s) + message.substring(i + 1));
  187.                   i = 0;
  188.                 }
  189.               }
  190.             }
  191.             else position = 0;
  192.           }
  193.         }
  194.     }
  195.   }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement