Advertisement
Qballl

Untitled

Sep 7th, 2018
124
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pd = connection.prepareStatement("ALTER TABLE sp_playerdata CHANGE Password Password VARCHAR(255) NOT NULL DEFAULT '';");
  2. pd.executeUpdate();
  3. pd.close();
  4. connection.close();
  5. importData();
  6. return true;
  7. } catch (SQLException e) {
  8. StaffPlus.get().message.sendConsoleMessage("Connection failed with the database! Are the details correct?",true);
  9. e.printStackTrace();
  10. return false;
  11. }
  12. }
  13.  
  14. public Connection getConnection()throws SQLException{
  15. return datasource.getConnection();
  16. }
  17.  
  18. public static void kill() {
  19. datasource.close();
  20. }
  21.  
  22. private void importData(){
  23. FileConfiguration save = StaffPlus.get().dataFile.getConfiguration();
  24. if(!StaffPlus.get().getConfig().getBoolean("storage.mysql.migrated"))
  25. {
  26. try(Connection connection = getDataSource().getConnection();
  27. PreparedStatement pd = connection.prepareStatement("INSERT INTO sp_playerdata(GlassColor, Password, Player_UUID, Name)" +
  28. "VALUES(?, ?, ?, ?) ON DUPLICATE KEY UPDATE Player_UUID=?;");
  29. PreparedStatement report = connection.prepareStatement("INSERT INTO sp_reports(Reason, Reporter_UUID, Player_UUID) " +
  30. "VALUES(?, ?, ?);");
  31. PreparedStatement warn = connection.prepareStatement("INSERT INTO sp_warnings(Reason, Warner_UUID, Player_UUID) " +
  32. "VALUES(?, ?, ?);");
  33. PreparedStatement name = connection.prepareStatement("INSERT INTO sp_alert_options(Name_Change, Player_UUID) " +
  34. "VALUES(?, ?) ON DUPLICATE KEY UPDATE Name_Change=?;");
  35. PreparedStatement xray= connection.prepareStatement("INSERT INTO sp_alert_options(Xray, Player_UUID) " +
  36. "VALUES(?, ?) ON DUPLICATE KEY UPDATE Xray=?;");
  37. PreparedStatement mention = connection.prepareStatement("INSERT INTO sp_alert_options(Mention, Player_UUID) " +
  38. "VALUES(?, ?) ON DUPLICATE KEY UPDATE Mention=?;")){
  39. for (String key : save.getConfigurationSection("").getKeys(false)) {
  40. StaffPlus.get().message.sendConsoleMessage(key +" "+save.getString(key+".name")+" "+
  41. save.getInt(key+".glass-color")+ " "+save.getString(key+".password"),false);
  42. pd.setInt(1,save.getInt(key+".glass-color"));
  43. pd.setString(2,save.getString(key+".password"));
  44. pd.setString(3,key);
  45. pd.setString(4,save.getString(key+".name"));
  46. pd.setString(5,key);
  47. StaffPlus.get().message.sendConsoleMessage("Update returned "+pd.executeUpdate(),false);
  48. pd.executeUpdate();
  49. for(String reportInfo : save.getStringList(key+".reports")){
  50. String[] info = reportInfo.split(";");
  51. report.setString(1,info[0]);
  52. report.setString(2,info[2]);
  53. report.setString(3,key);
  54. report.executeUpdate();
  55. }
  56. for(String warnInfo : save.getStringList(key+".warnings")){
  57. String[] info = warnInfo.split(";");
  58. warn.setString(1,info[0]);
  59. warn.setString(2,info[2]);
  60. warn.setString(3,key);
  61. warn.executeUpdate();
  62. }
  63. for(String alertOptions : save.getStringList(key+".alert-options")){
  64. String[] info = alertOptions.split(";");
  65. if(info[0].equalsIgnoreCase("name_change")) {
  66. name.setString(1,info[1]);
  67. name.setString(2,key);
  68. name.setString(3, info[1]);
  69. name.executeUpdate();
  70. }else if(info[0].equalsIgnoreCase("xray")){
  71. xray.setString(1,info[1]);
  72. xray.setString(2,key);
  73. xray.setString(3, info[1]);
  74. xray.executeUpdate();
  75. }else if(info[0].equalsIgnoreCase("mention")){
  76. mention.setString(1,info[1]);
  77. mention.setString(2,key);
  78. mention.setString(3, info[1]);
  79. mention.executeUpdate();
  80. }
  81. }
  82. }
  83. }catch (SQLException e){
  84. e.printStackTrace();
  85. }
  86. StaffPlus.get().message.sendConsoleMessage("Data has been imported to MySQL from flatfile",false);
  87. //StaffPlus.get().getConfig().set("storage.mysql.migrated",true);
  88. StaffPlus.get().saveConfig();
  89. }
  90. }
Advertisement
RAW Paste Data Copied
Advertisement