How to createPlayerAccount on VaultAPI while using MYSQL

Discussion in 'Spigot Plugin Development' started by Owner_jomzaza, Jul 1, 2018.

  1. bump Thanks for Reading
     
  2. This section is to help people with making something, not to help people by making something. This means that your questions have to be more specific than "How to make XXX?" Have you tried something yourself? Did you take a look at the documentation for stuff you are trying to use? What is the exact problem?

    If you want someone else to make it, there is a section specialized to hire people.
     
  3. Ok i'm really sorry for asking so many time

    I try to do it by my self but i'm still confuesed

    First
    Code (Java):
    @EventHandler
        public void onPlayerLogin(PlayerLoginEvent e) {
            Player player = e.getPlayer();
            try {
                openConnection();
                createPlayer(player.getName());
                connection.close();
            } catch (SQLException e1) {
                e1.printStackTrace();
            } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
            }
        }
        public void createPlayer(String player) {
            try {
                openConnection();
                Statement statement = connection.createStatement();
                ResultSet res = statement.executeQuery("SELECT * FROM accounts WHERE player='"+ player +"';");
                if(!res.next()) {
                    statement.executeUpdate("INSERT INTO accounts (player, balance) VALUES ('"+ player +"', '0');");
                }
                statement.close();
                res.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    and when player entry to server it created a database

    but i'm still confuesed how to get balance from player

    i'm try

    Code (Java):
    if (args.length == 0) {
                try {
                 pl.openConnection();
                 Statement statement = c.createStatement();
                 ResultSet res = statement.executeQuery("SELECT * FROM accounts WHERE player='"+ player +"';");
                 while (res.next()) {
                     double balance = res.getDouble("balance");
                     player.sendMessage(ChatColor.translateAlternateColorCodes('&', Message.balance.replace("{prefix}", Message.prefix).replace("{balance}", balance + "")));
                 }
                } catch(SQLException e1) {
                    e1.printStackTrace();
                } catch(ClassNotFoundException e1) {
                    e1.printStackTrace();
                }
                return true;
            }
    Does it correct ?
     
  4. Wait, you say you are using Vault, but you are getting the balance from a database??????????
     
  5. I want player data from Vault to mysql
     
  6. So you want to get the balance information from a vault-based plugin and store it in your database? Why would you want this? You know those money plugins already have ways of storing that information!
     
  7. Use preparedstatements. Easier, cleaner, and secure.
     
  8. Because i want to do it by myself
     
  9. Then why use another API?
     
  10. Thanks you for replies guy

    but it not my purpose, i want data from Vault-based into mysql
     
  11. i don't sure if i do it all, i think those of all plugin economy (like: Chestshop, GUI-SHOP) will not supported my plugin

    if i think wrong i'm sorry
     
  12. bumpp please give me a little suggestion
     
    • Agree Agree x 1