Archived
0

Delete Wallet.java

This commit is contained in:
Prot-CN
2019-01-30 05:18:06 +06:00
committed by GitHub
parent a5e1714afc
commit 51c107b920

View File

@@ -1,60 +0,0 @@
package ru.prisonlife.PrisonAPI.template;
import ru.prisonlife.PrisonAPI.connect.DataBasePrison4Life;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Wallet extends DataBasePrison4Life {
private PreparedStatement state;
private ResultSet r_set;
private Prisoner me;
Wallet(Prisoner prisoner) { me = prisoner; }
public int getBalance() throws SQLException {
setInResUUID();
if(r_set.first()) {
r_set = state.executeQuery("SELECT WALLET FROM ECONOMY WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
if(r_set.first()) {
return r_set.getInt(1);
}
disconnect();
}
return NullPointerException.class.hashCode();
}
public void addBalance(int value) throws SQLException {
setInResUUID();
if(r_set.first()) {
state.execute("UPDATE ECONOMY SET WALLET = " + (getBalance() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
disconnect();
}
}
public void deposit(int value) throws SQLException {
setInResUUID();
if(r_set.first()) {
state.execute("UPDATE ECONOMY SET WALLET = " + (getBalance() - value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
}
}
public void setBalance(int value) throws SQLException {
setInResUUID();
if(r_set.first()) {
state.execute("UPDATE ECONOMY SET WALLET = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
disconnect();
}
}
private void setInResUUID() throws SQLException {
state = connection.prepareStatement("SELECT * UUID FROM ECONOMY WHERE UUID = ?;");
state.setString(1, me.getPlayer().getUniqueId().toString());
r_set = state.executeQuery("SELECT UUID FROM ECONOMY WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
}
private void disconnect() throws SQLException {
r_set.close();
state.close();
}
}