PageRenderTime 165ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/src/fr/pluginmakers/login/Main.java

https://bitbucket.org/pluginmakers/mysqlilogin
Java | 213 lines | 197 code | 13 blank | 3 comment | 22 complexity | 62e53c2f4441000b3c8a40b7eda04976 MD5 | raw file
  1. package fr.pluginmakers.login;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.sql.SQLException;
  5. import java.util.HashSet;
  6. import java.util.Set;
  7. import java.util.logging.Logger;
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.Location;
  10. import org.bukkit.World;
  11. import org.bukkit.configuration.file.FileConfiguration;
  12. import org.bukkit.configuration.file.YamlConfiguration;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15. public class Main extends JavaPlugin {
  16. public static Set<String> logging = new HashSet<String>();
  17. public static Set<String> moving = new HashSet<String>();
  18. public String locale = "en";
  19. static Logger log = Logger.getLogger("minecraft");
  20. File configfile;
  21. FileConfiguration config;
  22. public static String mysql_server = null;
  23. public static String mysql_port = null;
  24. public static String mysql_database = null;
  25. public static String mysql_user = null;
  26. public static String mysql_password = null;
  27. public static String database_table = null;
  28. public static String database_id = null;
  29. public static String database_nick = null;
  30. public static String database_password = null;
  31. public static String hashs_crypt = null; // plain/md5/sha1
  32. public static String name = null;
  33. public static String data_loading = null;
  34. public static String data_loading_error = null;
  35. public static String mysqli_loading = null;
  36. public static String mysqli_loading_error = null;
  37. public static String player_login = null;
  38. public static String player_loginweb = null;
  39. public static String player_action = null;
  40. public static String player_serveur = null;
  41. public static String player_cmd = null;
  42. public static String player_log = null;
  43. public static String player_pass = null;
  44. public static String player_passerror = null;
  45. public void onEnable(){
  46. //_______________________________________________________________conf
  47. if(setupConf()) {
  48. log.info(name + " " + data_loading);
  49. } else {
  50. log.info(name + " " + data_loading_error);
  51. setEnabled(false);
  52. return;
  53. }
  54. //_______________________________________________________________mysqli
  55. String mysql = null;
  56. try { mysql = Mysqli.Verif_Mysqli(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); }
  57. if (!mysql.equals("0")) {
  58. log.info(name + " " + mysqli_loading);
  59. } else {
  60. log.info(name + " " + mysqli_loading_error);
  61. setEnabled(false);
  62. return;
  63. }
  64. //_____________________________________________________________cmds&events
  65. getServer().getPluginManager().registerEvents(new PlayerListener(), this);
  66. getCommand("login").setExecutor(new LoginCommand());
  67. }
  68. public void onDisable(){
  69. for(Player p : Bukkit.getOnlinePlayers()){
  70. int x = p.getLocation().getBlockX();
  71. int z = p.getLocation().getBlockZ();
  72. World w = p.getLocation().getWorld();
  73. Location loc = new Location(w, x, p.getLocation().getWorld().getHighestBlockYAt(x, z), z);
  74. p.teleport(loc);
  75. }
  76. }
  77. private boolean setupConf() {
  78. if (!getDataFolder().exists()) {
  79. getDataFolder().mkdir();
  80. }
  81. configfile = new File(getDataFolder() + File.separator + "config.yml");
  82. if(!configfile.exists()) {
  83. config = YamlConfiguration.loadConfiguration(configfile);
  84. config.set("mysql.server", "localhost");
  85. config.set("mysql.port", "3306");
  86. config.set("mysql.database", "base");
  87. config.set("mysql.user", "username");
  88. config.set("mysql.password", "password");
  89. config.set("database.table", "mumber");
  90. config.set("database.id", "id");
  91. config.set("database.nick", "nick");
  92. config.set("database.password", "pass");
  93. config.set("hashs.crypt", "plain");
  94. config.set("language.lang", "en");
  95. config.set("language.name", "[PMLogin]");
  96. config.set("language.english.data-loading", "Configuration loaded successfully !");
  97. config.set("language.english.data-loadingerror", "Unable to load the configuration !");
  98. config.set("language.english.mysqli-loading", "Mysqli configuration loaded successfully !");
  99. config.set("language.english.mysqli-loadingerror", "Unable to load configuration Mysqli !");
  100. config.set("language.english.player-login", "Please login with /login password");
  101. config.set("language.english.player-loginweb", "Please register on the website www.*******. com !");
  102. config.set("language.english.player-action", "Not possible, please login !");
  103. config.set("language.english.player-serveur", "This command can only be used in the game !");
  104. config.set("language.english.player-cmd", "Please use: /login password");
  105. config.set("language.english.player-log", "You are already connected to the server !");
  106. config.set("language.english.player-pass", "You are now connected. Good game !");
  107. config.set("language.english.player-passerror", "Incorrect password");
  108. config.set("language.french.data-loading", "Configuration chargé avec succés !");
  109. config.set("language.french.data-loadingerror", "Impossible de charger la configuration !");
  110. config.set("language.french.mysqli-loading", "Configuration Mysqli chargé avec succés !");
  111. config.set("language.french.mysqli-loadingerror", "Impossible de charger la configuration Mysqli !");
  112. config.set("language.french.player-login", "Veuillez vous connecter avec /login password");
  113. config.set("language.french.player-loginweb", "Veuillez vous inscrire sur le site www.*******.com !");
  114. config.set("language.french.player-action", "Action impossible, veuillez vous connecter !");
  115. config.set("language.french.player-serveur", "Cette commande est uniquement utilisable en jeu !");
  116. config.set("language.french.player-cmd", "Veuillez utilisez : /login password");
  117. config.set("language.french.player-log", "Vous êtes déjà connecté sur le serveur !");
  118. config.set("language.french.player-pass", "Vous êtes désormais connecté. Bon jeu !");
  119. config.set("language.french.player-passerror", "Mot de passe incorrect");
  120. try {
  121. config.save(configfile);
  122. } catch (IOException e) {
  123. e.printStackTrace();
  124. return false;
  125. }
  126. }
  127. config = YamlConfiguration.loadConfiguration(configfile);
  128. loadConf();
  129. return true;
  130. }
  131. private void loadConf() {
  132. try {
  133. mysql_server = config.getString("mysql.server");
  134. mysql_port = config.getString("mysql.port");
  135. mysql_database = config.getString("mysql.database");
  136. mysql_user = config.getString("mysql.user");
  137. mysql_password = config.getString("mysql.password");
  138. database_table = config.getString("database.table");
  139. database_id = config.getString("database.id");
  140. database_nick = config.getString("database.nick");
  141. database_password = config.getString("database.password");
  142. hashs_crypt = config.getString("hashs.crypt");
  143. locale = config.getString("language.lang");
  144. name = config.getString("language.name");
  145. if (locale.equalsIgnoreCase("en")) {
  146. data_loading = config.getString("language.english.data-loading");
  147. data_loading_error = config.getString("language.english.data-loadingerror");
  148. mysqli_loading = config.getString("language.english.mysqli-loading");
  149. mysqli_loading_error = config.getString("language.english.mysqli-loadingerror");
  150. player_login = config.getString("language.english.player-login");
  151. player_loginweb = config.getString("language.english.player-loginweb");
  152. player_action = config.getString("language.english.player-action");
  153. player_serveur = config.getString("language.english.player-serveur");
  154. player_cmd = config.getString("language.english.player-cmd");
  155. player_log = config.getString("language.english.player-log");
  156. player_pass = config.getString("language.english.player-pass");
  157. player_passerror = config.getString("language.english.player-passerror");
  158. } else if (locale.equalsIgnoreCase("fr")) {
  159. data_loading = config.getString("language.french.data-loading");
  160. data_loading_error = config.getString("language.french.data-loadingerror");
  161. mysqli_loading = config.getString("language.french.mysqli-loading");
  162. mysqli_loading_error = config.getString("language.french.mysqli-loadingerror");
  163. player_login = config.getString("language.french.player-login");
  164. player_loginweb = config.getString("language.french.player-loginweb");
  165. player_action = config.getString("language.french.player-action");
  166. player_serveur = config.getString("language.french.player-serveur");
  167. player_cmd = config.getString("language.french.player-cmd");
  168. player_log = config.getString("language.french.player-log");
  169. player_pass = config.getString("language.french.player-pass");
  170. player_passerror = config.getString("language.french.player-passerror");
  171. } else {
  172. data_loading = config.getString("language.english.data-loading");
  173. data_loading_error = config.getString("language.english.data-loadingerror");
  174. mysqli_loading = config.getString("language.english.mysqli-loading");
  175. mysqli_loading_error = config.getString("language.english.mysqli-loadingerror");
  176. player_login = config.getString("language.english.player-login");
  177. player_loginweb = config.getString("language.english.player-loginweb");
  178. player_action = config.getString("language.english.player-action");
  179. player_serveur = config.getString("language.english.player-serveur");
  180. player_cmd = config.getString("language.english.player-cmd");
  181. player_log = config.getString("language.english.player-log");
  182. player_pass = config.getString("language.english.player-pass");
  183. player_passerror = config.getString("language.english.player-passerror");
  184. }
  185. } catch(Exception e) {
  186. config = null;
  187. configfile.delete();
  188. setupConf();
  189. return;
  190. }
  191. if (!config.contains("mysql.server") || !config.contains("mysql.port") || !config.contains("mysql.database") || !config.contains("mysql.user") || !config.contains("mysql.password") ||
  192. !config.contains("database.table") || !config.contains("database.id") || !config.contains("database.nick") || !config.contains("database.password") ||
  193. !config.contains("hashs.crypt") || !config.contains("language.lang") || !config.contains("language.name")) {
  194. config = null;
  195. configfile.delete();
  196. setupConf();
  197. return;
  198. }
  199. }
  200. }