Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Connection connection;
- private String host, database, username, password;
- private int port;
- public void onEnable(){
- host = "192.99.143.93";
- port = 3306;
- database = "nodecloud_8844";
- username = "nodecloud_8844";
- password = "ce6e5f6d6f";
- try {
- openConnection();
- Statement statement = connection.createStatement();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException ee) {
- ee.printStackTrace();
- }
- try {
- createTable();
- Statement statement = connection.createStatement();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- getServer().getPluginManager().registerEvents(this, this);
- }
- public void onDisable(){
- }
- public void openConnection() throws SQLException, ClassNotFoundException {
- if (connection != null && !connection.isClosed()) {
- return;
- }
- synchronized (this) {
- if (connection != null && !connection.isClosed()) {
- return;
- }
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection("jdbc:mysql://" + this.host+ ":" + this.port + "/" + this.database, this.username, this.password);
- }
- }
- public void createTable(){
- try{
- openConnection();
- Statement statement = connection.createStatement();
- statement.executeUpdate("CREATE TABLE IF NOT EXISTS Coins(UUID varchar(36), name VARCHAR(16), COINS int)");
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException ee){
- ee.printStackTrace();
- }
- }
- public void addPlayer(){
- try{
- openConnection();
- Statement statement = connection.createStatement();
- statement.executeUpdate("INSERT INTO Coins(UUID varchar(36), name VARCHAR(16), COINS int)");
- statement.executeUpdate("INSERT INTO Coins(UUID varchar(36), name VARCHAR(16), COINS int)");
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException ee){
- ee.printStackTrace();
- }
- }
- @EventHandler
- public void onPlayerJoin(PlayerJoinEvent event){
- Player p = event.getPlayer();
- String UUID = p.getUniqueId().toString();
- String name = p.getPlayerListName();
- int coins = 0;
- try{
- addPlayer();
- Statement statement = connection.createStatement();
- statement.executeUpdate("CREATE TABLE IF NOT EXISTS Coins(UUID varchar(36), name VARCHAR(16), COINS int)");
- statement.executeUpdate("VALUES ('" + UUID + "','" + name + "','" + coins + "')");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- Player p = (Player) sender;
- if(command.getName().equalsIgnoreCase("gui")){
- mainGUI.main(p);
- }
- return super.onCommand(sender, command, label, args);
- }
- @EventHandler
- public void onInventoryClick(InventoryClickEvent e){
- if(e.getInventory().getName().equalsIgnoreCase(ChatColor.RED + "Belongings menu")){
- e.setCancelled(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement