danik159

Untitled

Aug 4th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. package com.chickenstyle.report;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.SQLException;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.ChatColor;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.event.EventHandler;
  12. import org.bukkit.event.Listener;
  13. import org.bukkit.event.inventory.InventoryClickEvent;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15.  
  16. public class Main extends JavaPlugin implements Listener {
  17. private static Connection connection;
  18. private String host, database, username, password;
  19. private int port;
  20. public void onEnable() {
  21. getCommand("report").setExecutor(new Report());
  22. Bukkit.getPluginManager().registerEvents(this, this);
  23. host = "localhost";
  24. port = 3306;
  25. database = "player_report";
  26. username = "root";
  27. password = "";
  28. try {
  29. openConnection();
  30.  
  31. System.out.println(ChatColor.GREEN + "MySQL Connected!");
  32. }catch (SQLException x) {
  33. x.printStackTrace();
  34. }
  35.  
  36. }
  37.  
  38. public static PreparedStatement prepareStatement(String query) {
  39. PreparedStatement ps = null;
  40. try {
  41. ps = connection.prepareStatement(query);
  42. } catch (SQLException x) {
  43. x.printStackTrace();
  44. }
  45. return ps;
  46. }
  47. private void openConnection() throws SQLException {
  48. if (connection != null && !connection.isClosed()) {
  49. return;
  50. }
  51.  
  52. connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password);
  53. }
  54.  
  55. @EventHandler
  56. public void onClick(InventoryClickEvent e) {
  57. Player player = (Player) e.getWhoClicked();
  58. int slot = e.getSlot();
  59. if (ChatColor.translateAlternateColorCodes('&', e.getClickedInventory().getTitle()).equals(ChatColor.GOLD + "ReportMenu")) {
  60. e.setCancelled(true);
  61. if (slot >= 11 && slot <= 15) {
  62. player.closeInventory();
  63. player.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Thanks for your report!");
  64.  
  65. }
  66. }
  67.  
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment