diff --git a/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java b/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java index 259f068..f144212 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java @@ -26,8 +26,9 @@ public class PrisonAPI extends JavaPlugin { public void onDisable() { try { - if (!CONN.isClosed()) + if (!CONN.isClosed()) { CONN.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java index 083d43d..5b0dd2a 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java @@ -25,8 +25,9 @@ public class Faction { connect(); if (resultSet.first()) { resultSet = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) + if (resultSet.first()) { return resultSet.getString(1); + } } disconnect(); return "null"; @@ -36,10 +37,13 @@ public class Faction { connect(); if (resultSet.first()) { resultSet = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) - for (int i = 0; i < PrisonAPI.Factions.values().length; i++) - if (PrisonAPI.Factions.values()[i].name().equals(resultSet.getString(1))) + if (resultSet.first()) { + for (int i = 0; i < PrisonAPI.Factions.values().length; i++) { + if (PrisonAPI.Factions.values()[i].name().equals(resultSet.getString(1))) { return i; + } + } + } } disconnect(); return 0; @@ -49,8 +53,9 @@ public class Faction { connect(); if (resultSet.first()) { resultSet = state.executeQuery("SELECT F_RANG FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) + if (resultSet.first()) { return resultSet.getInt(1); + } } disconnect(); return 0; @@ -67,22 +72,25 @@ public class Faction { public void addRang(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET F_RANG = " + (getRangId() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } public void setRang(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET F_RANG = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } public void setFaction(int id) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET FACTION = '" + PrisonAPI.Factions.values()[id].name() + "' WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } @@ -90,8 +98,9 @@ public class Faction { connect(); if (resultSet.first()) { resultSet = state.executeQuery("SELECT RESPECT FROM prison4life.player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) + if (resultSet.first()) { return resultSet.getInt(1); + } } disconnect(); return 0; @@ -99,39 +108,45 @@ public class Faction { public void addRespect(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET RESPECT = " + (getRespect() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } public void setRespect(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET RESPECT = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } public int getRespectDailyCooldown() throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { resultSet = state.executeQuery("SELECT COOLDOWN FROM daily_respect_task WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) + } + if (resultSet.first()) { return resultSet.getInt(1); + } disconnect(); return 0; } public void addRespectDailyCooldown(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE daily_respect_task SET COOLDOWN = " + (getRespectDailyCooldown() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } } public void setRespectDailyCooldown(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE daily_respect_task SET COOLDOWN = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } } public List getOnlineList() throws SQLException { @@ -139,8 +154,9 @@ public class Faction { Iterator itr = Bukkit.getOnlinePlayers().iterator(); while (itr.hasNext()) { Prisoner m = new Prisoner((Player) itr.next()); - if (m.getFaction().getType().equals(me.getFaction().getType())) + if (m.getFaction().getType().equals(me.getFaction().getType())) { list.add(m); + } } return list; } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java index 4d59f26..7f40bee 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java @@ -20,8 +20,9 @@ public class Level { public Score getScore() throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { return this.score; + } disconnect(); return null; } @@ -30,8 +31,9 @@ public class Level { connect(); if (resultSet.first()) { resultSet = state.executeQuery("SELECT LEVEL FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) + if (resultSet.first()) { return resultSet.getDouble(1); + } } disconnect(); return NullPointerException.class.hashCode(); @@ -39,15 +41,17 @@ public class Level { public void addLevel(double value) throws SQLException, NullPointerException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET LEVEL = " + (getLevel() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } public void setLevel(double value) throws SQLException, NullPointerException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET LEVEL = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java index 2894721..afc7104 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java @@ -57,12 +57,15 @@ public class Prisoner { } int c = 0; for (int k : loc_n) { - for (int n = 0; n < 3; n++) - if (k >= min.get(n) && k <= max.get(n)) + for (int n = 0; n < 3; n++) { + if (k >= min.get(n) && k <= max.get(n)) { ++c; + } + } } - if (c == 3) + if (c == 3) { return file.getName().replace("PRISON_", "").replace(".yml", ""); + } } return "Not Prison"; } @@ -87,13 +90,16 @@ public class Prisoner { } int c = 0; for (int k : loc_n) { - for (int n = 0; n < 3; n++) - if (k >= min.get(n) && k <= max.get(n)) + for (int n = 0; n < 3; n++) { + if (k >= min.get(n) && k <= max.get(n)) { ++c; + } + } } - if (c == 3) + if (c == 3) { return type.equals("name") ? fileConfiguration.getString("TERRITORIES." + terr + ".NAME") : (type.equals("owner") ? fileConfiguration.getString("TERRITORIES." + terr + ".OWNER") : null); + } } } } catch (NullPointerException z) { diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java index 338ba34..6b14375 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java @@ -30,15 +30,17 @@ public class Score { public void setPoints(double value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET POINTS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } public void addPoints(double value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET POINTS = " + (getPoints() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java index bf9ddc3..fbbc84d 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java @@ -18,8 +18,9 @@ public class Stats { public void setServerTime(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET G_TIME = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } @@ -27,8 +28,9 @@ public class Stats { connect(); if (resultSet.first()) { resultSet = state.executeQuery("SELECT G_TIME FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) + if (resultSet.first()) { return resultSet.getInt(1); + } } disconnect(); return NullPointerException.class.hashCode(); @@ -36,15 +38,17 @@ public class Stats { public void addServerTime(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET G_TIME = " + (getServerTime() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } public void setBlocks(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET B = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } @@ -52,8 +56,9 @@ public class Stats { connect(); if (resultSet.first()) { resultSet = state.executeQuery("SELECT D_BLOCKS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) + if (resultSet.first()) { return resultSet.getInt(1); + } } disconnect(); return NullPointerException.class.hashCode(); @@ -61,15 +66,17 @@ public class Stats { public void addBlocks(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET D_BLOCKS = " + (getBlocks() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } public void setPlayers(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET K_PLAYERS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } @@ -77,8 +84,9 @@ public class Stats { connect(); if (resultSet.first()) { resultSet = state.executeQuery("SELECT K_PLAYERS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) + if (resultSet.first()) { return resultSet.getInt(1); + } } disconnect(); return NullPointerException.class.hashCode(); @@ -86,15 +94,17 @@ public class Stats { public void addPlayers(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET K_PLAYERS = " + (getPlayers() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } public void setMobs(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET K_MOBS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } @@ -102,8 +112,9 @@ public class Stats { connect(); if (resultSet.first()) { resultSet = state.executeQuery("SELECT K_MOBS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) + if (resultSet.first()) { return resultSet.getInt(1); + } } disconnect(); return NullPointerException.class.hashCode(); diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java index ee854ae..aeb320a 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java @@ -20,8 +20,9 @@ public class Wallet { connect(); if (resultSet.first()) { resultSet = state.executeQuery("SELECT WALLET FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) + if (resultSet.first()) { return resultSet.getInt(1); + } } disconnect(); return NullPointerException.class.hashCode(); @@ -29,22 +30,25 @@ public class Wallet { public void addBalance(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET WALLET = " + (getBalance() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } public void deposit(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET WALLET = " + (getBalance() - value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); } public void setBalance(int value) throws SQLException { connect(); - if (resultSet.first()) + if (resultSet.first()) { state.execute("UPDATE player_stats SET WALLET = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + } disconnect(); }