Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.quiabo.qcash;
- import org.bukkit.entity.Player;
- import java.sql.*;
- public class MySQL {
- public Connection openConnection() {
- try {
- String pass = Main.getInstance().getConfig().getString("MySQL" + ".senha");
- String user = Main.getInstance().getConfig().getString("MySQL" + ".user");
- String host = Main.getInstance().getConfig().getString("MySQL" + ".host");
- String port = Main.getInstance().getConfig().getString("MySQL" + ".port");
- String database = Main.getInstance().getConfig().getString("MySQL" + ".database");
- String type = Main.getInstance().getConfig().getString("MySQL" + ".type");
- String url = type + host + ":" + port + "/" + database;
- return DriverManager.getConnection(url, user, pass);
- } catch (SQLException e) {
- }
- return null;
- }
- public void addPlayer(Player p) {
- try {
- Connection con = openConnection();
- PreparedStatement st = con.prepareStatement("INSERT INTO cash VALUES (" + p.getName() + ",0);");
- st.executeUpdate();
- con.close();
- } catch (SQLException e) {
- }
- }
- public double getMoney(Player p){
- double value = 0;
- try {
- Connection con = openConnection();
- PreparedStatement st = con.prepareStatement("SELECT cash FROM qcash WHERE nome = " + p.getName() + ";");
- ResultSet rs = st.executeQuery();
- if(rs.next()){
- value = rs.getDouble("cash");
- }
- con.close();
- return value;
- } catch (SQLException e) {
- }
- return value;
- }
- public boolean hasPlayer(Player p) {
- try {
- Connection con = openConnection();
- PreparedStatement st = con.prepareStatement("SELECT cash FROM qcash WHERE nome = " + p.getName() + ";");
- ResultSet rs = st.executeQuery();
- boolean result = rs.next();
- con.close();
- return result;
- } catch (SQLException e) {
- }
- return false;
- }
- public void setPlayer(Player p, double cash) {
- try {
- Connection con = openConnection();
- PreparedStatement st = con.prepareStatement("UPDATE qcash SET cash = " + cash + " WHERE nome = " + p.getName() +";");
- st.executeUpdate();
- con.close();
- } catch (SQLException e) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement