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