наименование методов и переменных
This commit is contained in:
@@ -14,7 +14,7 @@ import java.util.List;
|
|||||||
public class Faction {
|
public class Faction {
|
||||||
|
|
||||||
private PreparedStatement state;
|
private PreparedStatement state;
|
||||||
private ResultSet r_set;
|
private ResultSet resultSet;
|
||||||
private Prisoner me;
|
private Prisoner me;
|
||||||
|
|
||||||
Faction(Prisoner prisoner) {
|
Faction(Prisoner prisoner) {
|
||||||
@@ -22,37 +22,37 @@ public class Faction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getType() throws SQLException {
|
public String getType() throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first()) {
|
if (resultSet.first()) {
|
||||||
r_set = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
return r_set.getString(1);
|
return resultSet.getString(1);
|
||||||
}
|
}
|
||||||
dis_t();
|
disconnect();
|
||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() throws SQLException {
|
public int getId() throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first()) {
|
if (resultSet.first()) {
|
||||||
r_set = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
for (int i = 0; i < PrisonAPI.Factions.values().length; i++)
|
for (int i = 0; i < PrisonAPI.Factions.values().length; i++)
|
||||||
if (PrisonAPI.Factions.values()[i].name().equals(r_set.getString(1)))
|
if (PrisonAPI.Factions.values()[i].name().equals(resultSet.getString(1)))
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
dis_t();
|
disconnect();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRangId() throws SQLException {
|
public int getRangId() throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first()) {
|
if (resultSet.first()) {
|
||||||
r_set = state.executeQuery("SELECT F_RANG FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT F_RANG FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
return r_set.getInt(1);
|
return resultSet.getInt(1);
|
||||||
}
|
}
|
||||||
dis_t();
|
disconnect();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,71 +66,71 @@ public class Faction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addRang(int value) throws SQLException {
|
public void addRang(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET F_RANG = " + (getRangId() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET F_RANG = " + (getRangId() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRang(int value) throws SQLException {
|
public void setRang(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET F_RANG = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET F_RANG = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFaction(int id) throws SQLException {
|
public void setFaction(int id) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET FACTION = '" + PrisonAPI.Factions.values()[id].name() + "' WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET FACTION = '" + PrisonAPI.Factions.values()[id].name() + "' WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRespect() throws SQLException {
|
public int getRespect() throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first()) {
|
if (resultSet.first()) {
|
||||||
r_set = state.executeQuery("SELECT RESPECT FROM prison4life.player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT RESPECT FROM prison4life.player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
return r_set.getInt(1);
|
return resultSet.getInt(1);
|
||||||
}
|
}
|
||||||
dis_t();
|
disconnect();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRespect(int value) throws SQLException {
|
public void addRespect(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET RESPECT = " + (getRespect() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET RESPECT = " + (getRespect() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRespect(int value) throws SQLException {
|
public void setRespect(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET RESPECT = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET RESPECT = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRespectDailyCooldown() throws SQLException {
|
public int getRespectDailyCooldown() throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
r_set = state.executeQuery("SELECT COOLDOWN FROM daily_respect_task WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT COOLDOWN FROM daily_respect_task WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
return r_set.getInt(1);
|
return resultSet.getInt(1);
|
||||||
dis_t();
|
disconnect();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRespectDailyCooldown(int value) throws SQLException {
|
public void addRespectDailyCooldown(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE daily_respect_task SET COOLDOWN = " + (getRespectDailyCooldown() + value)
|
state.execute("UPDATE daily_respect_task SET COOLDOWN = " + (getRespectDailyCooldown() + value)
|
||||||
+ " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
+ " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRespectDailyCooldown(int value) throws SQLException {
|
public void setRespectDailyCooldown(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE daily_respect_task SET COOLDOWN = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE daily_respect_task SET COOLDOWN = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,14 +145,14 @@ public class Faction {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void con_t() throws SQLException {
|
private void connect() throws SQLException {
|
||||||
state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;");
|
state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;");
|
||||||
state.setString(1, me.getPlayer().getUniqueId().toString());
|
state.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dis_t() throws SQLException {
|
private void disconnect() throws SQLException {
|
||||||
r_set.close();
|
resultSet.close();
|
||||||
state.close();
|
state.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.sql.SQLException;
|
|||||||
public class Level {
|
public class Level {
|
||||||
|
|
||||||
private PreparedStatement state;
|
private PreparedStatement state;
|
||||||
private ResultSet r_set;
|
private ResultSet resultSet;
|
||||||
private Prisoner me;
|
private Prisoner me;
|
||||||
private Score score;
|
private Score score;
|
||||||
|
|
||||||
@@ -19,46 +19,46 @@ public class Level {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Score getScore() throws SQLException {
|
public Score getScore() throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
return this.score;
|
return this.score;
|
||||||
dis_t();
|
disconnect();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getLevel() throws SQLException, NullPointerException {
|
public double getLevel() throws SQLException, NullPointerException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first()) {
|
if (resultSet.first()) {
|
||||||
r_set = state.executeQuery("SELECT LEVEL FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT LEVEL FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
return r_set.getDouble(1);
|
return resultSet.getDouble(1);
|
||||||
}
|
}
|
||||||
dis_t();
|
disconnect();
|
||||||
return NullPointerException.class.hashCode();
|
return NullPointerException.class.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLevel(double value) throws SQLException, NullPointerException {
|
public void addLevel(double value) throws SQLException, NullPointerException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET LEVEL = " + (getLevel() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET LEVEL = " + (getLevel() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLevel(double value) throws SQLException, NullPointerException {
|
public void setLevel(double value) throws SQLException, NullPointerException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET LEVEL = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET LEVEL = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void con_t() throws SQLException {
|
private void connect() throws SQLException {
|
||||||
state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;");
|
state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;");
|
||||||
state.setString(1, me.getPlayer().getUniqueId().toString());
|
state.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dis_t() throws SQLException {
|
private void disconnect() throws SQLException {
|
||||||
r_set.close();
|
resultSet.close();
|
||||||
state.close();
|
state.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,72 +13,72 @@ import java.util.Objects;
|
|||||||
|
|
||||||
public class Manager {
|
public class Manager {
|
||||||
|
|
||||||
private File fi;
|
private File file;
|
||||||
private FileConfiguration cf;
|
private FileConfiguration fileConfiguration;
|
||||||
|
|
||||||
public Manager(String id) {
|
public Manager(String id) {
|
||||||
fi = new File("plugins/PrisonManager/", id);
|
file = new File("plugins/PrisonManager/", id);
|
||||||
cf = YamlConfiguration.loadConfiguration(fi);
|
fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains() {
|
public boolean contains() {
|
||||||
return fi.exists();
|
return file.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWorld() {
|
public String getWorld() {
|
||||||
return cf.getString("WORLD");
|
return fileConfiguration.getString("WORLD");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWorld(String name) {
|
public void setWorld(String name) {
|
||||||
String p = "WORLD";
|
String p = "WORLD";
|
||||||
cf.set(p, null);
|
fileConfiguration.set(p, null);
|
||||||
cf.set(p, name);
|
fileConfiguration.set(p, name);
|
||||||
try {
|
try {
|
||||||
cf.save(fi);
|
fileConfiguration.save(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getRebootStatus() {
|
public boolean getRebootStatus() {
|
||||||
return cf.getBoolean("REBOOT_STATUS");
|
return fileConfiguration.getBoolean("REBOOT_STATUS");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRebootStatus(boolean status) {
|
public void setRebootStatus(boolean status) {
|
||||||
cf.set("REBOOT_STATUS", status);
|
fileConfiguration.set("REBOOT_STATUS", status);
|
||||||
try {
|
try {
|
||||||
cf.save(fi);
|
fileConfiguration.save(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getSpawnCords(int faction) {
|
public List<Integer> getSpawnCords(int faction) {
|
||||||
return cf.getIntegerList("FACTIONS." + __selectFactType__(faction) + ".CORDS");
|
return fileConfiguration.getIntegerList("FACTIONS." + selectFactType(faction) + ".CORDS");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpawnCords(int faction, List<Integer> data) {
|
public void setSpawnCords(int faction, List<Integer> data) {
|
||||||
String p = "FACTIONS." + __selectFactType__(faction) + ".CORDS";
|
String p = "FACTIONS." + selectFactType(faction) + ".CORDS";
|
||||||
cf.set(p, null);
|
fileConfiguration.set(p, null);
|
||||||
cf.set(p, data);
|
fileConfiguration.set(p, data);
|
||||||
try {
|
try {
|
||||||
cf.save(fi);
|
fileConfiguration.save(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getDiagonal() {
|
public List<Integer> getDiagonal() {
|
||||||
return cf.getIntegerList("DIAGONAL_POINTS");
|
return fileConfiguration.getIntegerList("DIAGONAL_POINTS");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDiagonal(List<Integer> data) {
|
public void setDiagonal(List<Integer> data) {
|
||||||
if (data.size() == 6) {
|
if (data.size() == 6) {
|
||||||
String dp = "DIAGONAL_POINTS";
|
String dp = "DIAGONAL_POINTS";
|
||||||
cf.set(dp, null);
|
fileConfiguration.set(dp, null);
|
||||||
cf.set(dp, data);
|
fileConfiguration.set(dp, data);
|
||||||
try {
|
try {
|
||||||
cf.save(fi);
|
fileConfiguration.save(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ public class Manager {
|
|||||||
|
|
||||||
public int getGlobalNumTerr(int faction) {
|
public int getGlobalNumTerr(int faction) {
|
||||||
int num = 0;
|
int num = 0;
|
||||||
for (File prison : Objects.requireNonNull(fi.getParentFile().listFiles())) {
|
for (File prison : Objects.requireNonNull(file.getParentFile().listFiles())) {
|
||||||
Manager mng = new Manager(prison.getName());
|
Manager mng = new Manager(prison.getName());
|
||||||
num += mng.getNumTerr(faction);
|
num += mng.getNumTerr(faction);
|
||||||
}
|
}
|
||||||
@@ -101,55 +101,55 @@ public class Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getNumTerr(int faction) {
|
public int getNumTerr(int faction) {
|
||||||
return cf.getInt("FACTIONS." + __selectFactType__(faction) + ".NUM_TERR");
|
return fileConfiguration.getInt("FACTIONS." + selectFactType(faction) + ".NUM_TERR");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNumTerr(int faction, int value) {
|
public void setNumTerr(int faction, int value) {
|
||||||
String p = "FACTIONS." + __selectFactType__(faction) + ".NUM_TERR";
|
String p = "FACTIONS." + selectFactType(faction) + ".NUM_TERR";
|
||||||
cf.set(p, null);
|
fileConfiguration.set(p, null);
|
||||||
cf.set(p, value);
|
fileConfiguration.set(p, value);
|
||||||
try {
|
try {
|
||||||
cf.save(fi);
|
fileConfiguration.save(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTerrOwner(String name) {
|
public String getTerrOwner(String name) {
|
||||||
return cf.getString("TERRITORIES." + name + ".OWNER");
|
return fileConfiguration.getString("TERRITORIES." + name + ".OWNER");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTerrOwner(String name, String owner) {
|
public void setTerrOwner(String name, String owner) {
|
||||||
cf.set("TERRITORIES." + name + ".OWNER", owner);
|
fileConfiguration.set("TERRITORIES." + name + ".OWNER", owner);
|
||||||
try {
|
try {
|
||||||
cf.save(fi);
|
fileConfiguration.save(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTerrConqurer(String name) {
|
public String getTerrConqurer(String name) {
|
||||||
return cf.getString("TERRITORIES." + name + ".CAPTURED");
|
return fileConfiguration.getString("TERRITORIES." + name + ".CAPTURED");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTerrConqurer(String name, String status) {
|
public void setTerrConqurer(String name, String status) {
|
||||||
cf.set("TERRITORIES." + name + ".CAPTURED", status);
|
fileConfiguration.set("TERRITORIES." + name + ".CAPTURED", status);
|
||||||
try {
|
try {
|
||||||
cf.save(fi);
|
fileConfiguration.save(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getAllTerrs() {
|
public List<String> getAllTerrs() {
|
||||||
return new ArrayList<>(cf.getConfigurationSection("TERRITORIES").getKeys(false));
|
return new ArrayList<>(fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String __selectFactType__(int id) {
|
public String selectFactType(int id) {
|
||||||
return PrisonAPI.Factions.values()[id].name();
|
return PrisonAPI.Factions.values()[id].name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int __selectFactId__(String faction) {
|
public int selectFactId(String faction) {
|
||||||
return PrisonAPI.Factions.valueOf(faction).ordinal();
|
return PrisonAPI.Factions.valueOf(faction).ordinal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class Prisoner {
|
|||||||
private Wallet wallet;
|
private Wallet wallet;
|
||||||
private Stats stats;
|
private Stats stats;
|
||||||
private PreparedStatement state;
|
private PreparedStatement state;
|
||||||
private ResultSet r_set;
|
private ResultSet resultSet;
|
||||||
|
|
||||||
public Prisoner(Player player) {
|
public Prisoner(Player player) {
|
||||||
me = player;
|
me = player;
|
||||||
@@ -44,13 +44,13 @@ public class Prisoner {
|
|||||||
public String getPrison() {
|
public String getPrison() {
|
||||||
Location loc = me.getLocation();
|
Location loc = me.getLocation();
|
||||||
for (File file : Objects.requireNonNull(new File(PLUGIN_PATH).listFiles())) {
|
for (File file : Objects.requireNonNull(new File(PLUGIN_PATH).listFiles())) {
|
||||||
FileConfiguration c_ti = YamlConfiguration.loadConfiguration(file);
|
FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||||
List<List<Integer>> data = new ArrayList<>();
|
List<List<Integer>> data = new ArrayList<>();
|
||||||
List<Integer> from_cfg = c_ti.getIntegerList("DIAGONAL_POINTS"),
|
List<Integer> fromConfig = fileConfiguration.getIntegerList("DIAGONAL_POINTS"),
|
||||||
min = new ArrayList<>(), max = new ArrayList<>();
|
min = new ArrayList<>(), max = new ArrayList<>();
|
||||||
int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()};
|
int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()};
|
||||||
data.add(from_cfg.subList(0, 3));
|
data.add(fromConfig.subList(0, 3));
|
||||||
data.add(from_cfg.subList(3, 6));
|
data.add(fromConfig.subList(3, 6));
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
min.add(Math.min(data.get(0).get(i), data.get(1).get(i)));
|
min.add(Math.min(data.get(0).get(i), data.get(1).get(i)));
|
||||||
max.add(Math.max(data.get(0).get(i), data.get(1).get(i)));
|
max.add(Math.max(data.get(0).get(i), data.get(1).get(i)));
|
||||||
@@ -68,19 +68,19 @@ public class Prisoner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getTerritory(String type) {
|
public String getTerritory(String type) {
|
||||||
String prs = getPrison();
|
String prison = getPrison();
|
||||||
if (!prs.equals("Not Prison") && (type.equals("name") || type.equals("owner"))) {
|
if (!prison.equals("Not Prison") && (type.equals("name") || type.equals("owner"))) {
|
||||||
Location loc = me.getLocation();
|
Location loc = me.getLocation();
|
||||||
FileConfiguration c_ti = YamlConfiguration.loadConfiguration(new File(PLUGIN_PATH, "PRISON_" + prs + ".yml"));
|
FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(new File(PLUGIN_PATH, "PRISON_" + prison + ".yml"));
|
||||||
try {
|
try {
|
||||||
if (c_ti.getConfigurationSection("TERRITORIES").getKeys(false).size() != 0) {
|
if (fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false).size() != 0) {
|
||||||
for (String terr : c_ti.getConfigurationSection("TERRITORIES").getKeys(false)) {
|
for (String terr : fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false)) {
|
||||||
List<List<Integer>> data = new ArrayList<>();
|
List<List<Integer>> data = new ArrayList<>();
|
||||||
List<Integer> from_cfg = c_ti.getIntegerList("TERRITORIES." + terr + ".DIAGONAL_POINTS"),
|
List<Integer> fromConfig = fileConfiguration.getIntegerList("TERRITORIES." + terr + ".DIAGONAL_POINTS"),
|
||||||
min = new ArrayList<>(), max = new ArrayList<>();
|
min = new ArrayList<>(), max = new ArrayList<>();
|
||||||
int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()};
|
int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()};
|
||||||
data.add(from_cfg.subList(0, 3));
|
data.add(fromConfig.subList(0, 3));
|
||||||
data.add(from_cfg.subList(3, 6));
|
data.add(fromConfig.subList(3, 6));
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
min.add(Math.min(data.get(0).get(i), data.get(1).get(i)));
|
min.add(Math.min(data.get(0).get(i), data.get(1).get(i)));
|
||||||
max.add(Math.max(data.get(0).get(i), data.get(1).get(i)));
|
max.add(Math.max(data.get(0).get(i), data.get(1).get(i)));
|
||||||
@@ -92,8 +92,8 @@ public class Prisoner {
|
|||||||
++c;
|
++c;
|
||||||
}
|
}
|
||||||
if (c == 3)
|
if (c == 3)
|
||||||
return type.equals("name") ? c_ti.getString("TERRITORIES." + terr + ".NAME") :
|
return type.equals("name") ? fileConfiguration.getString("TERRITORIES." + terr + ".NAME") :
|
||||||
(type.equals("owner") ? c_ti.getString("TERRITORIES." + terr + ".OWNER") : null);
|
(type.equals("owner") ? fileConfiguration.getString("TERRITORIES." + terr + ".OWNER") : null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NullPointerException z) {
|
} catch (NullPointerException z) {
|
||||||
@@ -117,8 +117,8 @@ public class Prisoner {
|
|||||||
public void register() throws SQLException {
|
public void register() throws SQLException {
|
||||||
state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;");
|
state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;");
|
||||||
state.setString(1, me.getUniqueId().toString());
|
state.setString(1, me.getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getUniqueId() + "'");
|
||||||
if (!r_set.next()) {
|
if (!resultSet.next()) {
|
||||||
state.execute(
|
state.execute(
|
||||||
"INSERT INTO player_stats(NAME, UUID, LEVEL, POINTS, FACTION, RESPECT, F_RANG, WALLET, G_TIME, D_BLOCKS, " +
|
"INSERT INTO player_stats(NAME, UUID, LEVEL, POINTS, FACTION, RESPECT, F_RANG, WALLET, G_TIME, D_BLOCKS, " +
|
||||||
"K_PLAYERS, K_MOBS, DEATHS) VALUES (" + "'" + getPlayer().getName()
|
"K_PLAYERS, K_MOBS, DEATHS) VALUES (" + "'" + getPlayer().getName()
|
||||||
@@ -128,7 +128,7 @@ public class Prisoner {
|
|||||||
stats = new Stats(this);
|
stats = new Stats(this);
|
||||||
wallet = new Wallet(this);
|
wallet = new Wallet(this);
|
||||||
}
|
}
|
||||||
r_set.close();
|
resultSet.close();
|
||||||
state.close();
|
state.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ import java.sql.SQLException;
|
|||||||
public class Score {
|
public class Score {
|
||||||
|
|
||||||
private PreparedStatement state;
|
private PreparedStatement state;
|
||||||
private ResultSet r_set;
|
private ResultSet resultSet;
|
||||||
private Prisoner me;
|
private Prisoner me;
|
||||||
|
|
||||||
Score(Prisoner prisoner) {
|
Score(Prisoner prisoner) {
|
||||||
@@ -17,39 +17,39 @@ public class Score {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getPoints() throws SQLException {
|
public double getPoints() throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first()) {
|
if (resultSet.first()) {
|
||||||
r_set = state.executeQuery("SELECT POINTS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT POINTS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
if (r_set.first()) {
|
if (resultSet.first()) {
|
||||||
return r_set.getDouble(1);
|
return resultSet.getDouble(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dis_t();
|
disconnect();
|
||||||
return NullPointerException.class.hashCode();
|
return NullPointerException.class.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPoints(double value) throws SQLException {
|
public void setPoints(double value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET POINTS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET POINTS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPoints(double value) throws SQLException {
|
public void addPoints(double value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET POINTS = " + (getPoints() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET POINTS = " + (getPoints() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void con_t() throws SQLException {
|
private void connect() throws SQLException {
|
||||||
state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;");
|
state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;");
|
||||||
state.setString(1, me.getPlayer().getUniqueId().toString());
|
state.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dis_t() throws SQLException {
|
private void disconnect() throws SQLException {
|
||||||
r_set.close();
|
resultSet.close();
|
||||||
state.close();
|
state.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.sql.SQLException;
|
|||||||
public class Stats {
|
public class Stats {
|
||||||
|
|
||||||
private PreparedStatement state;
|
private PreparedStatement state;
|
||||||
private ResultSet r_set;
|
private ResultSet resultSet;
|
||||||
private Prisoner me;
|
private Prisoner me;
|
||||||
|
|
||||||
Stats(Prisoner prisoner) {
|
Stats(Prisoner prisoner) {
|
||||||
@@ -17,138 +17,138 @@ public class Stats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setServerTime(int value) throws SQLException {
|
public void setServerTime(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET G_TIME = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET G_TIME = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getServerTime() throws SQLException {
|
public int getServerTime() throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first()) {
|
if (resultSet.first()) {
|
||||||
r_set = state.executeQuery("SELECT G_TIME FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT G_TIME FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
return r_set.getInt(1);
|
return resultSet.getInt(1);
|
||||||
}
|
}
|
||||||
dis_t();
|
disconnect();
|
||||||
return NullPointerException.class.hashCode();
|
return NullPointerException.class.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addServerTime(int value) throws SQLException {
|
public void addServerTime(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET G_TIME = " + (getServerTime() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET G_TIME = " + (getServerTime() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBlocks(int value) throws SQLException {
|
public void setBlocks(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET B = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET B = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBlocks() throws SQLException {
|
public int getBlocks() throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first()) {
|
if (resultSet.first()) {
|
||||||
r_set = state.executeQuery("SELECT D_BLOCKS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT D_BLOCKS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
return r_set.getInt(1);
|
return resultSet.getInt(1);
|
||||||
}
|
}
|
||||||
dis_t();
|
disconnect();
|
||||||
return NullPointerException.class.hashCode();
|
return NullPointerException.class.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBlocks(int value) throws SQLException {
|
public void addBlocks(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET D_BLOCKS = " + (getBlocks() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET D_BLOCKS = " + (getBlocks() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayers(int value) throws SQLException {
|
public void setPlayers(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET K_PLAYERS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET K_PLAYERS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPlayers() throws SQLException {
|
public int getPlayers() throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first()) {
|
if (resultSet.first()) {
|
||||||
r_set = state.executeQuery("SELECT K_PLAYERS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT K_PLAYERS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
return r_set.getInt(1);
|
return resultSet.getInt(1);
|
||||||
}
|
}
|
||||||
dis_t();
|
disconnect();
|
||||||
return NullPointerException.class.hashCode();
|
return NullPointerException.class.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayers(int value) throws SQLException {
|
public void addPlayers(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET K_PLAYERS = " + (getPlayers() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET K_PLAYERS = " + (getPlayers() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMobs(int value) throws SQLException {
|
public void setMobs(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET K_MOBS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET K_MOBS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMobs() throws SQLException {
|
public int getMobs() throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first()) {
|
if (resultSet.first()) {
|
||||||
r_set = state.executeQuery("SELECT K_MOBS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT K_MOBS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
return r_set.getInt(1);
|
return resultSet.getInt(1);
|
||||||
}
|
}
|
||||||
dis_t();
|
disconnect();
|
||||||
return NullPointerException.class.hashCode();
|
return NullPointerException.class.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMobs(int value) throws SQLException {
|
public void addMobs(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET K_MOBS = " + (getMobs() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET K_MOBS = " + (getMobs() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeaths(int value) throws SQLException {
|
public void setDeaths(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET DEATHS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET DEATHS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDeaths() throws SQLException {
|
public int getDeaths() throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first()) {
|
if (resultSet.first()) {
|
||||||
r_set = state.executeQuery("SELECT DEATHS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT DEATHS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
return r_set.getInt(1);
|
return resultSet.getInt(1);
|
||||||
}
|
}
|
||||||
dis_t();
|
disconnect();
|
||||||
return NullPointerException.class.hashCode();
|
return NullPointerException.class.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDeaths(int value) throws SQLException {
|
public void addDeaths(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET DEATHS = " + (getDeaths() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET DEATHS = " + (getDeaths() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void con_t() throws SQLException {
|
private void connect() throws SQLException {
|
||||||
state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;");
|
state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;");
|
||||||
state.setString(1, me.getPlayer().getUniqueId().toString());
|
state.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dis_t() throws SQLException {
|
private void disconnect() throws SQLException {
|
||||||
r_set.close();
|
resultSet.close();
|
||||||
state.close();
|
state.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.sql.SQLException;
|
|||||||
public class Wallet {
|
public class Wallet {
|
||||||
|
|
||||||
private PreparedStatement state;
|
private PreparedStatement state;
|
||||||
private ResultSet r_set;
|
private ResultSet resultSet;
|
||||||
private Prisoner me;
|
private Prisoner me;
|
||||||
|
|
||||||
Wallet(Prisoner prisoner) {
|
Wallet(Prisoner prisoner) {
|
||||||
@@ -17,45 +17,45 @@ public class Wallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getBalance() throws SQLException {
|
public int getBalance() throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first()) {
|
if (resultSet.first()) {
|
||||||
r_set = state.executeQuery("SELECT WALLET FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT WALLET FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
return r_set.getInt(1);
|
return resultSet.getInt(1);
|
||||||
}
|
}
|
||||||
dis_t();
|
disconnect();
|
||||||
return NullPointerException.class.hashCode();
|
return NullPointerException.class.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBalance(int value) throws SQLException {
|
public void addBalance(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET WALLET = " + (getBalance() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET WALLET = " + (getBalance() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deposit(int value) throws SQLException {
|
public void deposit(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET WALLET = " + (getBalance() - value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET WALLET = " + (getBalance() - value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBalance(int value) throws SQLException {
|
public void setBalance(int value) throws SQLException {
|
||||||
con_t();
|
connect();
|
||||||
if (r_set.first())
|
if (resultSet.first())
|
||||||
state.execute("UPDATE player_stats SET WALLET = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
state.execute("UPDATE player_stats SET WALLET = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
dis_t();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void con_t() throws SQLException {
|
private void connect() throws SQLException {
|
||||||
state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;");
|
state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;");
|
||||||
state.setString(1, me.getPlayer().getUniqueId().toString());
|
state.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
resultSet = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dis_t() throws SQLException {
|
private void disconnect() throws SQLException {
|
||||||
r_set.close();
|
resultSet.close();
|
||||||
state.close();
|
state.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user