/src/com/bukkit/systexpro/blockpatrol/settings/BlockPatrolSettings.java

https://github.com/SystexPro/BlockPatrol · Java · 149 lines · 112 code · 16 blank · 21 comment · 16 complexity · 64a5d5151d9a76ddbae5bbd7138a7f04 MD5 · raw file

  1. package com.bukkit.systexpro.blockpatrol.settings;
  2. import java.awt.List;
  3. import java.io.File;
  4. import java.net.MalformedURLException;
  5. import java.util.Iterator;
  6. import java.util.logging.Logger;
  7. import org.bukkit.util.config.Configuration;
  8. import com.bukkit.systexpro.blockpatrol.BlockPatrolPlugin;
  9. import com.minecraft.bukkit.util.SQLTools;
  10. import com.alta189.sqlLibrary.MySQL.*;
  11. import com.alta189.sqlLibrary.SQLite.*;
  12. public class BlockPatrolSettings {
  13. public BlockPatrolPlugin plugin;
  14. @SuppressWarnings("deprecation")
  15. public Configuration config;
  16. public String fileSaveType = "SQL";
  17. public String hostname = "localhost";
  18. public int hostport = 3306;
  19. public String username = "minecraft";
  20. public String password = "";
  21. public String prefix = "bp_";
  22. public String database_name_mysql = "blockpatrol";
  23. public String database_name_sql = "blockpatrol";
  24. //SQL Shtuff
  25. public File dbFolder = new File("plugins" + File.separator + "BlockPatrol");
  26. public String logPrefix = "[BlockPatrol]";
  27. public Logger log = Logger.getLogger("Minecraft");
  28. //Blacklist
  29. public String bannedBlocks = "TNT, BEDROCK";
  30. //Nerfs :p
  31. public boolean fireNerfed = false;
  32. public boolean tntNerfed = false;
  33. public boolean fireSpreadNerfed = false;
  34. public boolean liquidSpreadNerfed = false;
  35. //Cores
  36. public mysqlCore mysqlCore;
  37. public sqlCore sqlCore;
  38. //Extensions
  39. public SQLTools tools = new SQLTools(plugin);
  40. //etc
  41. public String build = "#1240";
  42. public BlockPatrolSettings(BlockPatrolPlugin core) {
  43. config = new Configuration(new File("plugins/BlockPatrol/config.yml"));
  44. plugin = core;
  45. }
  46. /**
  47. * Load Configuration File
  48. */
  49. public void loadConfig() {
  50. config.load();
  51. fileSaveType = config.getString("connection.Save Type", fileSaveType);
  52. database_name_sql = config.getString("connection.sql.SQL Database", database_name_sql);
  53. hostname = config.getString("connection.mysql.MySQL Hostname", hostname);
  54. hostport = config.getInt("connection.mysql.MySQL Port", hostport);
  55. username = config.getString("connection.mysql.MySQL Username", username);
  56. password = config.getString("connection.mysql.MySQL Password", password);
  57. database_name_mysql = config.getString("connection.mysql.MySQL Databse", database_name_mysql);
  58. prefix = config.getString("connection.mysql.MySQL Database Prefix", prefix);
  59. bannedBlocks = config.getString("blacklist.banneditems", bannedBlocks);
  60. loadBannedBlocks();
  61. config.save();
  62. }
  63. public void setupFileSaver() {
  64. if(this.fileSaveType.equalsIgnoreCase("SQL")) {
  65. this.createSQLDatabase();
  66. } else if(fileSaveType.equalsIgnoreCase("MySql")) {
  67. try {
  68. this.createMySQLDatabase();
  69. } catch (MalformedURLException e) {
  70. e.printStackTrace();
  71. } catch (InstantiationException e) {
  72. e.printStackTrace();
  73. } catch (IllegalAccessException e) {
  74. e.printStackTrace();
  75. }
  76. } else {
  77. plugin.sendConsoleMessage("Error!!! Can't find out save type for: " + this.fileSaveType);
  78. plugin.getPluginLoader().disablePlugin(plugin);
  79. }
  80. }
  81. /**
  82. * Send the list to the BannedBlocks Class
  83. */
  84. private void loadBannedBlocks() {
  85. BannedBlocks bb = new BannedBlocks();
  86. bb.setItemsToHandle(bannedBlocks);
  87. }
  88. public String getAuthors() {
  89. String s = "";
  90. Iterator<String> itr = plugin.getDescription().getAuthors().iterator();
  91. while(itr.hasNext()) {
  92. if(!itr.hasNext()) {
  93. s += ".";
  94. } else {
  95. Object element = itr.next();
  96. s += element + ", ";
  97. }
  98. }
  99. return s;
  100. }
  101. /**
  102. * Create SQL
  103. */
  104. public void createSQLDatabase() {
  105. sqlCore = new sqlCore(log, logPrefix, database_name_sql, dbFolder.getAbsolutePath());
  106. sqlCore.initialize();
  107. if(!sqlCore.checkTable("blocks")) {
  108. String query = "CREATE TABLE blocks (id INT AUTO_INCREMENT PRIMARY_KEY, owner VARCHAR(255), x INT, y INT, z INT, rb INT, type VARCHAR(255), block VARCHAR(255), time TEXT);";
  109. sqlCore.createTable(query);
  110. plugin.sendConsoleMessage("SQL Table: blocks, has been created.");
  111. }
  112. }
  113. /**
  114. * Create MySQL
  115. * @throws MalformedURLException
  116. * @throws InstantiationException
  117. * @throws IllegalAccessException
  118. */
  119. public void createMySQLDatabase() throws MalformedURLException, InstantiationException, IllegalAccessException {
  120. mysqlCore = new mysqlCore(log, logPrefix, hostname, database_name_mysql, username, password);
  121. mysqlCore.initialize();
  122. if(mysqlCore.checkConnection()) {
  123. if(mysqlCore.checkTable("blocks")) {
  124. String query = "";
  125. } else if(mysqlCore.checkTable("chat")) {
  126. } else if(mysqlCore.checkTable("teleports")) {
  127. } else if(mysqlCore.checkTable("connect")) {
  128. }
  129. } else {
  130. plugin.sendConsoleMessage("Error connecting to MySQL Server. Please check your settings.");
  131. }
  132. }
  133. }