Advertisement
WaffleMast3r

eroare

Feb 19th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. package me.wafflemaster.com;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.util.logging.Logger;
  8.  
  9. import org.bukkit.ChatColor;
  10. import org.bukkit.command.Command;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.plugin.PluginDescriptionFile;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15.  
  16. public class main extends JavaPlugin{
  17. public final Logger logger = Logger.getLogger("Minecraft");
  18. public static main plugin;
  19.  
  20. @Override
  21. public void onDisable() {
  22. PluginDescriptionFile pdfFile = this.getDescription();
  23. this.logger.info(pdfFile.getName() + " s-a dezactivat!");
  24. closeConnection();
  25. }
  26.  
  27. @Override
  28. public void onEnable() {
  29. PluginDescriptionFile pdfFile = this.getDescription();
  30. this.logger.info(pdfFile.getName() + " versiunea " + pdfFile.getVersion() + " s-a activat!");
  31. openConnection();
  32. createTable();
  33. }
  34.  
  35. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
  36. Player player = (Player) sender;
  37. if(commandLabel.equalsIgnoreCase("arena")) {
  38. if(args.length == 0){
  39. player.sendMessage("Foloseste /arena join");
  40. return true;
  41. }
  42. if(player instanceof Player){
  43. if(args[0].equalsIgnoreCase("join")) {
  44. addPlayer(player);
  45. return true;
  46. }
  47. }else{
  48. logger.info("Aceasta comanda poate fi rulata doar de jucatori!");
  49. }
  50. }
  51. return true;
  52. }
  53.  
  54. private static Connection connection;
  55. static String table = "event1";
  56.  
  57. public static void openConnection() {
  58. try
  59. {
  60. connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/ArenaEvent", "root", "");
  61. }
  62. catch(Exception e)
  63. {
  64. e.printStackTrace();
  65. }
  66. }
  67.  
  68. public static void closeConnection() {
  69. try
  70. {
  71. connection.close();
  72. }
  73. catch(Exception e)
  74. {
  75. e.printStackTrace();
  76. }
  77. }
  78.  
  79. public static void createTable() {
  80. try{
  81. PreparedStatement sql = connection.prepareStatement("CREATE TABLE IF NOT EXISTS " + table + " (ID INT(11) NOT NULL AUTO_INCREMENT, USERNAME VARCHAR(17), primary key (ID));");
  82. sql.execute();
  83. sql.close();
  84. }catch (Exception e){
  85. e.printStackTrace();
  86. }
  87. }
  88.  
  89. public void addPlayer(Player player) {
  90. if(checkPlayer(player) == false){
  91. try{
  92. PreparedStatement sql = connection.prepareStatement("INSERT INTO `" + table + "` VALUES('null'," + player.getName() + ");");
  93. sql.execute();
  94. sql.close();
  95. }catch (Exception e){
  96. e.printStackTrace();
  97. }
  98. }else{
  99. player.sendMessage(ChatColor.RED + "Esti deja inscris!");
  100. }
  101. }
  102.  
  103. public boolean checkPlayer(Player player){
  104. try{
  105. PreparedStatement sql = connection.prepareStatement("SELECT * FROM `" + table + "` WHERE USERNAME=?;");
  106. sql.setString(1, player.getName());
  107. ResultSet resultSet = sql.executeQuery();
  108. boolean containsPlayer = resultSet.next();
  109.  
  110. sql.close();
  111. resultSet.close();
  112.  
  113. if(containsPlayer){
  114. return true;
  115. }else{
  116. return false;
  117. }
  118. } catch(Exception e){
  119. e.printStackTrace();
  120. return true;
  121. }
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement