Advertisement
Guest User

Untitled

a guest
Nov 1st, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. private Connection connection;
  2. private String host, database, username, password;
  3. private int port;
  4.  
  5. public void onEnable(){
  6.  
  7. host = "192.99.143.93";
  8. port = 3306;
  9. database = "nodecloud_8844";
  10. username = "nodecloud_8844";
  11. password = "ce6e5f6d6f";
  12. try {
  13. openConnection();
  14. Statement statement = connection.createStatement();
  15. } catch (ClassNotFoundException e) {
  16. e.printStackTrace();
  17. } catch (SQLException ee) {
  18. ee.printStackTrace();
  19. }
  20. try {
  21. createTable();
  22. Statement statement = connection.createStatement();
  23. } catch (SQLException e) {
  24. e.printStackTrace();
  25. }
  26. getServer().getPluginManager().registerEvents(this, this);
  27.  
  28. }
  29. public void onDisable(){
  30.  
  31. }
  32. public void openConnection() throws SQLException, ClassNotFoundException {
  33. if (connection != null && !connection.isClosed()) {
  34. return;
  35. }
  36.  
  37. synchronized (this) {
  38. if (connection != null && !connection.isClosed()) {
  39. return;
  40. }
  41. Class.forName("com.mysql.jdbc.Driver");
  42. connection = DriverManager.getConnection("jdbc:mysql://" + this.host+ ":" + this.port + "/" + this.database, this.username, this.password);
  43. }
  44. }
  45.  
  46. public void createTable(){
  47. try{
  48. openConnection();
  49. Statement statement = connection.createStatement();
  50. statement.executeUpdate("CREATE TABLE IF NOT EXISTS Coins(UUID varchar(36), name VARCHAR(16), COINS int)");
  51. } catch (SQLException e) {
  52. e.printStackTrace();
  53. } catch (ClassNotFoundException ee){
  54. ee.printStackTrace();
  55. }
  56. }
  57. public void addPlayer(){
  58. try{
  59. openConnection();
  60. Statement statement = connection.createStatement();
  61. statement.executeUpdate("INSERT INTO Coins(UUID varchar(36), name VARCHAR(16), COINS int)");
  62. statement.executeUpdate("INSERT INTO Coins(UUID varchar(36), name VARCHAR(16), COINS int)");
  63. } catch (SQLException e) {
  64. e.printStackTrace();
  65. } catch (ClassNotFoundException ee){
  66. ee.printStackTrace();
  67. }
  68. }
  69.  
  70. @EventHandler
  71. public void onPlayerJoin(PlayerJoinEvent event){
  72. Player p = event.getPlayer();
  73. String UUID = p.getUniqueId().toString();
  74. String name = p.getPlayerListName();
  75. int coins = 0;
  76. try{
  77. addPlayer();
  78. Statement statement = connection.createStatement();
  79. statement.executeUpdate("CREATE TABLE IF NOT EXISTS Coins(UUID varchar(36), name VARCHAR(16), COINS int)");
  80. statement.executeUpdate("VALUES ('" + UUID + "','" + name + "','" + coins + "')");
  81. } catch (SQLException e) {
  82. e.printStackTrace();
  83. }
  84. }
  85.  
  86.  
  87. @Override
  88. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  89. Player p = (Player) sender;
  90. if(command.getName().equalsIgnoreCase("gui")){
  91. mainGUI.main(p);
  92. }
  93.  
  94. return super.onCommand(sender, command, label, args);
  95. }
  96.  
  97. @EventHandler
  98. public void onInventoryClick(InventoryClickEvent e){
  99. if(e.getInventory().getName().equalsIgnoreCase(ChatColor.RED + "Belongings menu")){
  100. e.setCancelled(true);
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement