Advertisement
Guest User

Untitled

a guest
Jan 17th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.19 KB | None | 0 0
  1. package ru.yooxa.ultrawipe;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.Statement;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. import org.bukkit.configuration.file.FileConfiguration;
  10.  
  11. public class SqlConnect
  12. {
  13.   String url;
  14.   Log log;
  15.   FileConfiguration config;
  16.   String host;
  17.   String port;
  18.   String dbauthme;
  19.   String dbpermissions;
  20.   String username;
  21.   String password;
  22.   List<String> list;
  23.   String group;
  24.   String authmetable;
  25.   String pextable;
  26.  
  27.   public SqlConnect(Main main)
  28.   {
  29.     this.log = new Log();
  30.     this.config = main.getConfig();
  31.     this.host = this.config.getString("Mysql.host");
  32.     this.port = this.config.getString("Mysql.port");
  33.     this.username = this.config.getString("Mysql.username");
  34.     this.password = this.config.getString("Mysql.password");
  35.     this.dbauthme = this.config.getString("Mysql.database.authme");
  36.     this.dbpermissions = this.config.getString("Mysql.database.permissions");
  37.     this.group = this.config.getString("deletegroup");
  38.     this.list = new ArrayList();
  39.     this.authmetable = this.config.getString("Mysql.tables.authme");
  40.     this.pextable = this.config.getString("Mysql.tables.permissions");
  41.   }
  42.  
  43.   public void waip()
  44.   {
  45.     Start();
  46.   }
  47.  
  48.   private void Start()
  49.   {
  50.     new Thread(new Runnable()
  51.     {
  52.       public void run()
  53.       {
  54.         Connection connection;
  55.         try
  56.         {
  57.           connection = DriverManager.getConnection("jdbc:mysql://" + SqlConnect.this.host + ":" + SqlConnect.this.port + "/" + SqlConnect.this.dbauthme, SqlConnect.this.username, SqlConnect.this.password);
  58.           ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM " + SqlConnect.this.authmetable);
  59.           while (resultSet.next()) {
  60.             SqlConnect.this.list.add(resultSet.getString("name"));
  61.           }
  62.           SqlConnect.this.log.info("Добавил игроков из таблицы AuthMe");
  63.           resultSet.close();
  64.           connection.close();
  65.         }
  66.         catch (Exception e)
  67.         {
  68.           SqlConnect.this.log.info("[Error] Ошибка при запросе AuthMe! Ошибка - " + e.getMessage());
  69.           e.printStackTrace();
  70.         }
  71.         try
  72.         {
  73.           connection = DriverManager.getConnection("jdbc:mysql://" + SqlConnect.this.host + ":" + SqlConnect.this.port + "/" + SqlConnect.this.dbpermissions, SqlConnect.this.username, SqlConnect.this.password);
  74.           ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM " + SqlConnect.this.pextable);
  75.           while (resultSet.next()) {
  76.             if ((resultSet.getInt("type") == 1) && (!resultSet.getString("parent").equals(SqlConnect.this.group)))
  77.             {
  78.               SqlConnect.this.list.remove(resultSet.getString("child").toLowerCase());
  79.               SqlConnect.this.log.info("Удалил из списка игрока " + resultSet.getString("child"));
  80.             }
  81.           }
  82.           SqlConnect.this.log.info("Удалил донатеров");
  83.           resultSet.close();
  84.           connection.close();
  85.         }
  86.         catch (Exception e)
  87.         {
  88.           SqlConnect.this.log.info("[Error] Ошибка при запросе PermissionEx! Ошибка - " + e.getMessage());
  89.           e.printStackTrace();
  90.         }
  91.         try
  92.         {
  93.           connection = DriverManager.getConnection("jdbc:mysql://" + SqlConnect.this.host + ":" + SqlConnect.this.port + "/" + SqlConnect.this.dbauthme, SqlConnect.this.username, SqlConnect.this.password);
  94.           Statement state = connection.createStatement();
  95.           for (String name : SqlConnect.this.list) {
  96.             state.executeUpdate("DELETE FROM " + SqlConnect.this.authmetable + " WHERE name = '" + name + "'");
  97.           }
  98.           state.close();
  99.           connection.close();
  100.         }
  101.         catch (Exception e)
  102.         {
  103.           SqlConnect.this.log.info("[Error] Ошибка при соединении с базой данных! Ошибка - " + e.getMessage());
  104.           e.printStackTrace();
  105.         }
  106.         SqlConnect.this.log.info("Вайп завершен");
  107.       }
  108.     }).start();
  109.   }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement