Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.brinedev.fixer;
- import java.io.File;
- import java.text.Normalizer;
- import java.util.Arrays;
- import java.util.List;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.AsyncPlayerChatEvent;
- import org.bukkit.event.player.PlayerCommandPreprocessEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Fixer extends JavaPlugin implements Listener {
- private File customYml = null;
- private FileConfiguration customConfig = null;
- public void onEnable() {
- saveDefaultConfig();
- saveResource("corretor.yml", false);
- customYml=new File(getDataFolder()+"/corretor.yml");
- customConfig=YamlConfiguration.loadConfiguration(customYml);
- Bukkit.getPluginManager().registerEvents(this, this);
- Bukkit.getConsoleSender().sendMessage("§a[BrineFixer] Plugin criado por BrineDev, não edite este plugin!");
- }
- public FileConfiguration getCorretor() {
- return customConfig;
- }
- public static String removerAcentos(String str) {
- return Normalizer.normalize(str, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "");
- }
- public boolean checa(String str1, String str2) {
- String str12=removerAcentos(str1);
- String str22=removerAcentos(str2);
- boolean igual=str12.equalsIgnoreCase(str22);
- if (igual==true)return true;
- double porcentagem=StringSimilarity.similaridade(str12, str22);
- double minimo=getConfig().getDouble("Similaridade", 75.0);
- if (porcentagem >=minimo) {
- return true;
- } else {
- return false;
- }
- }
- public char getFromUnicode(String unicode) {
- if (unicode==null) return '*';
- unicode=unicode.replace("+", "");
- if (!unicode.startsWith("\\")) {
- unicode="\\"+unicode;
- }
- try {
- return (char) Integer.parseInt(unicode.substring(2), 16);
- } catch (Exception e) {
- return '*';
- }
- }
- public String emoticonizer(String message) {
- if (!getConfig().getBoolean("Emoticons")) return message;
- if (getConfig().getStringList("EmoticonsLista")==null) return message;
- for (String s:getConfig().getStringList("EmoticonsLista")) {
- String[] dados=s.split("=");
- if (dados.length<2) continue;
- message=message.replace(dados[0], getFromUnicode(dados[1])+"");
- }
- return message;
- }
- public boolean checaDV(String mensagem) {
- if (!getConfig().getBoolean("AntiDV")) return false;
- if (getConfig().getBoolean("IngorarEspacos")) {
- mensagem=mensagem.replace(" ", "");
- }
- for (String regex:getConfig().getStringList("Avancado.ReGex")) {
- try {
- Pattern replace = Pattern.compile(regex);
- Matcher matcher = replace.matcher(mensagem);
- if (matcher.matches()) {
- return true;
- }
- } catch (Exception e){}
- } return false;
- }
- public String marcar(String mensagem, Player p, String cmd) {
- if (!getConfig().getBoolean("Marcar")) return mensagem;
- String msgnova="";
- for (String palavra:mensagem.split(" ")) {
- if (palavra==null) continue;
- if (palavra.length()>1) {
- String nome=palavra;
- if (Bukkit.getPlayer(nome)!=null) {
- nome=Bukkit.getPlayer(nome).getName();
- p.sendMessage(mensagem);
- if (msgnova.equalsIgnoreCase("")) {
- msgnova="§b"+nome+getCor(cmd);
- } else {
- msgnova=msgnova+" §b"+nome+getCor(cmd);
- }
- } else {
- if (msgnova.equalsIgnoreCase("")) {
- msgnova=palavra;
- } else {
- msgnova=msgnova+" "+palavra;
- }
- }
- } else {
- if (msgnova.equalsIgnoreCase("")) {
- msgnova=palavra;
- } else {
- msgnova=msgnova+" "+palavra;
- }
- }
- }
- return msgnova;
- }
- public String corrigir(String palavra) {
- for (String c:getCorretor().getStringList("Fix")) {
- try {
- String[] correcao=c.split("->");
- if (correcao.length>1) {
- if (checa(correcao[0], palavra)) {
- return correcao[1];
- }
- }
- } catch (Exception e) {}
- }
- return palavra;
- }
- public ChatColor getCor(String cmd) {
- ChatColor rtn=ChatColor.WHITE;
- for (String c:getConfig().getStringList("Cores")) {
- if (c.split(":")[0].equalsIgnoreCase(cmd)) {
- String cor=c.split(":")[1];
- if (ChatColor.valueOf(cor)!=null) {
- rtn=ChatColor.valueOf(cor);
- }
- }
- }
- return rtn;
- }
- protected String gerarAsterisco(int length, char charToFill) {
- if (length > 0) {
- char[] array = new char[length];
- Arrays.fill(array, charToFill);
- return new String(array);
- }
- return "";
- }
- public String block(String msg) {
- String novamsg=msg;
- for (String p:getConfig().getStringList("Palavroes")) {
- p=p.replaceAll("([\\\\\\.\\[\\{\\(\\*\\+\\?\\^\\$\\|])", "\\\\$1");
- novamsg=novamsg.replaceAll("(?i)\\b("+p+")+\\b", gerarAsterisco(p.length(), '*'));
- }
- return novamsg;
- }
- @EventHandler
- public void onChat(AsyncPlayerChatEvent event) {
- String mensagem=event.getMessage();
- String msgnova="";
- for (String palavra:mensagem.split(" ")) {
- if (msgnova.equalsIgnoreCase("")) {
- msgnova=corrigir(palavra);
- } else {
- msgnova=msgnova+" "+corrigir(palavra);
- }
- }
- if (checaDV(msgnova)) {
- event.getPlayer().sendMessage(getConfig().getString("MensagemDV").replace("&", "§"));
- event.setCancelled(true);
- return;
- }
- msgnova=marcar(msgnova,event.getPlayer(),"CHAT");
- if (getConfig().getBoolean("BlockCaps")) {
- msgnova=msgnova.toLowerCase();
- }
- if (getConfig().getBoolean("RemoverAcentos")) {
- msgnova=removerAcentos(msgnova);
- }
- if (getConfig().getBoolean("ForcePonto")) {
- if (!msgnova.endsWith(".")) msgnova=msgnova+".";
- }
- if (getConfig().getBoolean("ForceUpper")) {
- msgnova=primeiraLetra(msgnova);
- }
- msgnova=block(msgnova);
- msgnova=emoticonizer(msgnova);
- event.setMessage(msgnova);
- }
- public String primeiraLetra(String original){
- if(original.length() == 0)
- return original;
- return original.substring(0, 1).toUpperCase() + original.substring(1);
- }
- @EventHandler
- public void onCmd(PlayerCommandPreprocessEvent event) {
- boolean tem=false;
- String cmdformato="";
- for (String cmd:getConfig().getStringList("LerComandos")) {
- if (cmd.split(" ")[0].equalsIgnoreCase(event.getMessage().split(" ")[0])) {
- tem=true;
- cmdformato=cmd;
- }
- }
- if (tem) {
- String[] msg=event.getMessage().split(" ");
- String[] cmd=cmdformato.split(" ");
- int i=cmd.length;
- if (msg.length<=cmd.length) return;
- String mensagem="";
- while (i!=msg.length) {
- if (mensagem.equalsIgnoreCase("")) {
- mensagem=msg[i];
- } else {
- mensagem=mensagem+" "+msg[i];
- }
- i++;
- }
- String base="";
- i=0;
- while(i!=cmd.length) {
- if (base.equalsIgnoreCase("")) {
- base=event.getMessage().split(" ")[i];
- } else {
- base=base+" "+event.getMessage().split(" ")[i];
- }
- i++;
- }
- String msgnova="";
- for (String palavra:mensagem.split(" ")) {
- if (msgnova.equalsIgnoreCase("")) {
- msgnova=corrigir(palavra);
- } else {
- msgnova=msgnova+" "+corrigir(palavra);
- }
- }
- if (checaDV(msgnova)) {
- event.getPlayer().sendMessage(getConfig().getString("MensagemDV").replace("&", "§"));
- event.setCancelled(true);
- return;
- }
- msgnova=marcar(msgnova,event.getPlayer(),event.getMessage().split(" ")[0].toLowerCase());
- if (getConfig().getBoolean("BlockCaps")) {
- msgnova=msgnova.toLowerCase();
- }
- if (getConfig().getBoolean("ForcePonto")) {
- if (!msgnova.endsWith(".")) msgnova=msgnova+".";
- }
- if (getConfig().getBoolean("RemoverAcentos")) {
- msgnova=removerAcentos(msgnova);
- }
- if (getConfig().getBoolean("ForceUpper")) {
- msgnova=primeiraLetra(msgnova);
- }
- msgnova=block(msgnova);
- msgnova=emoticonizer(msgnova);
- event.setMessage(base+" "+msgnova);
- }
- }
- public void saveCorretor() {
- try {
- customConfig.save(customYml);
- } catch (Exception e) {
- }
- }
- public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
- if (!sender.isOp()) {
- sender.sendMessage("§cVoce nao tem permissao.");
- return false;
- }
- if (cmd.getName().equalsIgnoreCase("limparchat")) {
- int i=0;
- while (i!=200) {
- for (Player p:Bukkit.getOnlinePlayers()) {
- p.sendMessage("");
- }
- i++;
- }
- for (Player p:Bukkit.getOnlinePlayers()) {
- p.sendMessage("§9Chat limpo por §b"+sender.getName()+"§9!");
- }
- return false;
- }
- if (args.length==0) {
- sender.sendMessage("§aBrineFixer * Comandos:");
- sender.sendMessage("§a/brinefixer reload * Recarregar sistema");
- sender.sendMessage("§a/brinefixer addpalavra <original> <novo> * Adicionar nova correção");
- return false;
- }
- if (args[0].equalsIgnoreCase("reload")) {
- customYml=null;
- customConfig=null;
- customYml=new File(getDataFolder()+"/corretor.yml");
- customConfig=YamlConfiguration.loadConfiguration(customYml);
- reloadConfig();
- sender.sendMessage("§aConfig recarregada!");
- } else if (args[0].equalsIgnoreCase("addpalavra")) {
- if (args.length<3) {
- sender.sendMessage("§cUso: /brinefixer addpalavra <original> <novo>");
- return false;
- }
- String correcao=args[1]+"->"+args[2];
- if (correcao.contains("'") || correcao.contains("\"")) {
- sender.sendMessage("§cCorreção inválida!");
- return false;
- }
- List<String> correcoes=getCorretor().getStringList("Fix");
- if (!correcoes.contains(correcao)) {
- correcoes.add(correcao);
- }
- getCorretor().set("Fix", correcoes);
- saveCorretor();
- sender.sendMessage("§aCorreção adicionada!");
- sender.sendMessage("§a"+args[1]+" -> "+args[2]);
- } else {
- sender.sendMessage("§aBrineFixer * Comandos:");
- sender.sendMessage("§a/brinefixer reload * Recarregar sistema");
- sender.sendMessage("§a/brinefixer addpalavra <original> <novo> * Adicionar nova correção");
- return false;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment