Advertisement
Guest User

Untitled

a guest
May 27th, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. import org.bukkit.command.Command;
  2. import org.bukkit.command.CommandExecutor;
  3. import org.bukkit.command.CommandSender;
  4. import org.bukkit.entity.Player;
  5. import org.bukkit.plugin.java.JavaPlugin;
  6.  
  7. import java.sql.*;
  8.  
  9.  
  10. public class Main extends JavaPlugin {
  11.  
  12. String host, port, database, username, password;
  13. static Connection c;
  14.  
  15. @Override
  16. public void onEnable() {
  17. this.getCommand("stats").setExecutor(new Stats());
  18. host = "localhost";
  19. port = "3306";
  20. database = "TestDatabase";
  21. username = "user";
  22. password = "pass";
  23. try {
  24. openConnection();
  25. Statement statement = c.createStatement();
  26. } catch (ClassNotFoundException e) {
  27. e.printStackTrace();
  28. } catch (SQLException e) {
  29. e.printStackTrace();
  30. }
  31. }
  32.  
  33. @Override
  34. public void onDisable() {
  35. }
  36.  
  37. public void openConnection() throws SQLException, ClassNotFoundException {
  38. if (c != null && !c.isClosed()) {
  39. return;
  40. }
  41. Class.forName("com.mysql.jdbc.Driver");
  42. c = DriverManager.getConnection("jdbc:mysql://"
  43. + this.host + ":" + this.port + "/" + this.database,
  44. this.username, this.password);
  45. }
  46.  
  47. //statement.executeUpdate("INSERT INTO SStats (PLAYERNAME, BALANCE) VALUES ('Playername', 100);");
  48.  
  49. public class Stats implements CommandExecutor {
  50.  
  51. //This method is called, when somebody uses our command
  52. @Override
  53. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  54. if (sender instanceof Player) {
  55. ResultSet result = statement.executeUpdate("INSERT INTO...blablabla");
  56. }
  57. }
  58.  
  59. // If the player (or console) uses our command correct, we can return true
  60. return true;
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement