Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.jkl1234.JKLChat;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.logging.Logger;
- import org.bukkit.ChatColor;
- import org.bukkit.Server;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.InvalidConfigurationException;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerChatEvent;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- public class JKLChat extends JavaPlugin
- {
- private static final Logger mclog = Logger.getLogger("minecraft");
- protected FileConfiguration config;
- File confFile;
- protected FileConfiguration mysql;
- File mysqlFile;
- int nums;
- private final JChatPlayerListener blockListener = new JChatPlayerListener(this);
- public void onDisable() {
- try {
- this.config.save(this.confFile);
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- mclog.info("[JKL-Chat] Stop");
- }
- public void onEnable() {
- mclog.info("[JKL-Chat] Start");
- getServer().getPluginManager().registerEvents(this.blockListener, this);
- this.config = getConfig();
- this.confFile = new File(getDataFolder(), "config.yml");
- try {
- this.config.load(this.confFile);
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- } catch (IOException e1) {
- mclog.severe("Unable to load JKL-Chat configuration");
- } catch (InvalidConfigurationException e1) {
- mclog.severe("Unable to load JKL-Chat configuration");
- }
- }
- public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
- Player player = null;
- if ((sender instanceof Player)) {
- player = (Player)sender;
- }
- if (cmd.getName().equalsIgnoreCase("addword")) {
- if ((player == null) || (sender.hasPermission("JKLChat.add"))) {
- if (args.length > 1) {
- this.config.set(args[0], args[1]);
- try {
- this.config.save(this.confFile);
- } catch (IOException e) {
- e.printStackTrace();
- }
- sender.sendMessage("Слово '" + args[0] + "' теперь будет заменяться словом '" + args[1] + "'");
- return true;
- }
- return false;
- }
- sender.sendMessage(ChatColor.DARK_RED + "У вас нет прав для выполнения этой команды!"); return true;
- }
- if (cmd.getName().equalsIgnoreCase("deleteword")) {
- if ((player == null) || (sender.hasPermission("JKLChat.delete"))) {
- if (args.length > 0) {
- if (this.config.contains(args[0])) this.config.set(args[0], "0"); try
- {
- this.config.save(this.confFile);
- } catch (IOException e) {
- e.printStackTrace();
- }
- sender.sendMessage("Слово '" + args[0] + "' больше не будет заменяться");
- return true;
- }
- return false;
- }
- sender.sendMessage(ChatColor.DARK_RED + "У вас нет прав для выполнения этой команды!"); return true;
- }
- return false;
- }
- boolean isSpace(char ch) {
- 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 == '`');
- }
- boolean Ravno(char a, char b, char c, char d) {
- this.nums = 0;
- if ((a == 'а') && ((b == '@') || (b == 'a') || (b == 'а') || (b == 'A') || (b == 'А'))) return true;
- if ((a == 'б') && ((b == 'б') || (b == 'Б') || (b == 'b') || (b == 'B') || (b == '6'))) return true;
- if ((a == 'в') && ((b == 'v') || (b == 'V') || (b == 'B') || (b == 'в') || (b == 'В') || ((b == '|') && (c == '3')))) return true;
- if ((a == 'г') && ((b == 'г') || (b == 'Г') || (b == 'g') || (b == 'G') || (b == 'r'))) return true;
- if ((a == 'д') && ((b == 'д') || (b == 'Д') || (b == 'd') || (b == 'D') || (b == 'g'))) return true;
- if (((a == 'е') || (a == 'ё')) && ((b == 'е') || (b == 'Е') || (b == 'e') || (b == 'E') || (b == 'Ё') || (b == 'ё'))) return true;
- if ((a == 'ж') && ((b == 'ж') || (b == 'Ж') || (b == '*') || ((b == '}') && (c == '|') && (d == '{')) || ((b == ')') && (c == '|') && (d == '(')))) {
- if (((b == '}') && (c == '|') && (d == '{')) || ((b == ')') && (c == '|') && (d == '('))) this.nums = 2;
- return true;
- }
- if ((a == 'з') && ((b == 'z') || (b == 'Z') || (b == 'з') || (b == 'З') || (b == '3'))) return true;
- if (((a == 'и') || (a == 'й')) && ((b == 'И') || (b == 'и') || (b == 'u') || (b == 'i') || (b == 'I') || (b == '1') || (b == 'й') || (b == 'Й'))) return true;
- if ((a == 'к') && ((b == 'k') || (b == 'K') || (b == 'к') || (b == 'К') || ((b == '|') && (c == '{')) || ((b == 'I') && (c == '{')) || ((b == 'i') && (c == '{')))) {
- if (((b == '|') && (c == '{')) || ((b == 'I') && (c == '{')) || ((b == 'i') && (c == '{'))) this.nums = 1;
- return true;
- }
- if ((a == 'л') && ((b == 'l') || (b == 'L') || (b == 'л') || (b == 'Л') || (b == '^') || ((b == '/') && (c == '\\')) || ((b == 'j') && (c == 'i')))) {
- if (((b == '/') && (c == '\\')) || ((b == 'j') && (c == 'i'))) this.nums = 1;
- return true;
- }
- if ((a == 'м') && ((b == 'm') || (b == 'M') || (b == 'м') || (b == 'М'))) return true;
- if ((a == 'н') && ((b == 'н') || (b == 'Н') || (b == 'n') || (b == 'N') || (b == 'H'))) return true;
- if ((a == 'о') && ((b == '0') || (b == 'О') || (b == 'о') || (b == 'O') || (b == 'o'))) return true;
- if ((a == 'п') && ((b == 'n') || (b == 'p') || (b == 'P') || (b == 'п') || (b == 'П') || (b == 'р') || (b == 'Р'))) return true;
- if ((a == 'р') && ((b == 'p') || (b == 'P') || (b == 'r') || (b == 'R') || (b == 'р') || (b == 'Р'))) return true;
- if ((a == 'с') && ((b == 'с') || (b == 'С') || (b == 'c') || (b == 'C') || (b == 's') || (b == 'S') || (b == '('))) return true;
- if ((a == 'т') && ((b == 't') || (b == 'T') || (b == 'т') || (b == 'Т') || (b == 'm'))) return true;
- if ((a == 'у') && ((b == 'u') || (b == 'U') || (b == 'у') || (b == 'У') || (b == 'Y') || (b == 'y'))) return true;
- if ((a == 'ф') && ((b == 'ф') || (b == 'Ф') || (b == 'f') || (b == 'F') || (b == 'А'))) return true;
- if ((a == 'х') && ((b == 'x') || (b == 'X') || (b == 'х') || (b == 'Х') || ((b == '}') && (c == '{')) || (b == 'h') || (b == 'H') || ((b == ')') && (c == '(')))) {
- if (((b == '}') && (c == '{')) || ((b == ')') && (c == '('))) this.nums = 1;
- return true;
- }
- if ((a == 'ц') && ((b == 'c') || (b == 'C') || (b == 'с') || (b == 'С') || (b == 'ц') || (b == 'Ц') || (b == 'u'))) return true;
- if ((a == 'ч') && ((b == '4') || (b == 'ч') || (b == 'Ч') || ((b == 'c') && (c == 'h')))) {
- if ((b == 'c') && (c == 'h')) this.nums = 1;
- return true;
- }
- if ((a == 'ш') && ((b == 'ш') || (b == 'Ш') || ((b == 's') && (c == 'h')))) {
- if ((b == 's') && (c == 'h')) this.nums = 1;
- return true;
- }
- if ((a == 'щ') && ((b == 'щ') || (b == 'Щ') || ((b == 's') && (c == 'c') && (d == 'h')))) {
- if ((b == 's') && (c == 'c') && (d == 'h')) this.nums = 2;
- return true;
- }
- if ((a == 'ъ') && ((b == 'ъ') || (b == 'Ъ') || (b == 'ь') || (b == 'Ь') || (b == 'b'))) return true;
- 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 == '|')))) {
- if (((b == 'b') && (c == '|')) || ((b == 'b') && (c == 'l')) || ((b == 'ь') && (c == 'l')) || ((b == 'Ь') && (c == 'l')) || ((b == 'ь') && (c == '|')) || ((b == 'Ь') && (c == '|'))) this.nums = 1;
- return true;
- }
- if ((a == 'ь') && ((b == 'ь') || (b == 'Ь') || (b == 'Ъ') || (b == 'ъ') || (b == 'b'))) return true;
- if ((a == 'э') && ((b == 'э') || (b == 'Э') || (b == 'e') || (b == 'E') || (b == 'е') || (b == 'Е'))) return true;
- if ((a == 'ю') && ((b == 'ю') || (b == 'Ю') || (b == 'u') || (b == 'U'))) return true;
- return (a == 'я') && ((b == 'я') || (b == 'Я'));
- }
- class JChatPlayerListener implements Listener {
- public JKLChat plugin;
- public JChatPlayerListener(JKLChat instance) { this.plugin = instance; }
- @EventHandler
- public void onPlayerChat(PlayerChatEvent event) {
- if (event.isCancelled()) return;
- for (String s : JKLChat.this.config.getKeys(false))
- if (!JKLChat.this.config.get(s).equals("0")) {
- int position = 0;
- String message = event.getMessage();
- int start = 0;
- s = s.toLowerCase();
- for (int i = 0; i < message.length(); i++) {
- message = event.getMessage();
- char sch = ' ';
- char cc = ' ';
- char dd = ' ';
- if (message.length() - i > 1) cc = message.charAt(i + 1);
- if (message.length() - i > 2) dd = message.charAt(i + 2);
- if (i > 0) sch = message.charAt(i - 1);
- if ((JKLChat.this.Ravno(s.charAt(position), message.charAt(i), cc, dd)) || ((JKLChat.this.isSpace(message.charAt(i))) && (position > 0))) {
- if (((position == 0) && (JKLChat.this.isSpace(sch))) || ((position == s.length() - 1) && (JKLChat.this.isSpace(cc))) || ((position > 0) && (position < s.length()))) {
- if (position == 0) start = i;
- if (JKLChat.this.Ravno(s.charAt(position), message.charAt(i), cc, dd)) position++;
- i += JKLChat.this.nums;
- JKLChat.this.nums = 0;
- if (position == s.length()) {
- position = 0;
- event.setMessage(message.substring(0, start) + JKLChat.this.config.get(s) + message.substring(i + 1));
- i = 0;
- }
- }
- }
- else position = 0;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement