По просьбе Димона + mini-update 0.1.2
This commit is contained in:
47
src/main/java/ru/prisonlife/api/template/Wallet.java
Normal file
47
src/main/java/ru/prisonlife/api/template/Wallet.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package ru.prisonlife.api.template;
|
||||
|
||||
import ru.prisonlife.api.PrisonAPI;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Wallet {
|
||||
|
||||
private Prisoner me;
|
||||
|
||||
Wallet(Prisoner prisoner) {
|
||||
me = prisoner;
|
||||
}
|
||||
|
||||
public int getBalance() throws SQLException {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT WALLET FROM player_stats WHERE UUID = ?")) {
|
||||
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
try (ResultSet resultSet = statement.executeQuery()) {
|
||||
if (resultSet.next()) {
|
||||
return resultSet.getInt(1);
|
||||
} else {
|
||||
return 0; //TODO нужно или default значение, или exception
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addBalance(int value) throws SQLException {
|
||||
setBalance(getBalance() + value);
|
||||
}
|
||||
|
||||
public void deposit(int value) throws SQLException {
|
||||
setBalance(getBalance() - value);
|
||||
}
|
||||
|
||||
public void setBalance(int value) throws SQLException {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("UPDATE player_stats SET WALLET = ? WHERE UUID = ?")) {
|
||||
statement.setDouble(1, value);
|
||||
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
statement.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user