From d4fcfd12c25abf6714995d17412774af1141a843 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Wed, 20 Feb 2019 22:39:20 +0300 Subject: [PATCH 01/11] =?UTF-8?q?=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D1=83=D0=B5=D0=BC=20=D0=BD=D0=B0=D0=B8=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=BA=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit именовать пакеты заглавными буквами - не принято (cherry picked from commit 1011064dab2ac050eacd87332a615a9ec12c1b53) --- src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java | 2 +- src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java | 4 ++-- src/main/java/ru/prisonlife/PrisonAPI/template/Level.java | 4 ++-- src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java | 4 ++-- src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java | 4 ++-- src/main/java/ru/prisonlife/PrisonAPI/template/Score.java | 4 ++-- src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java | 4 ++-- src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java | 4 ++-- src/main/resources/plugin.yml | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java b/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java index e45bf41..2d3eae1 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java @@ -1,4 +1,4 @@ -package ru.prisonlife.PrisonAPI; +package ru.prisonlife.prisonapi; import org.bukkit.plugin.java.JavaPlugin; diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java index 6e7c610..873f137 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java @@ -1,8 +1,8 @@ -package ru.prisonlife.PrisonAPI.template; +package ru.prisonlife.prisonapi.template; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import ru.prisonlife.PrisonAPI.PrisonAPI; +import ru.prisonlife.prisonapi.PrisonAPI; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java index f3c1d72..6c7df06 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java @@ -1,6 +1,6 @@ -package ru.prisonlife.PrisonAPI.template; +package ru.prisonlife.prisonapi.template; -import ru.prisonlife.PrisonAPI.PrisonAPI; +import ru.prisonlife.prisonapi.PrisonAPI; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java index 5dc64f5..3934c20 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java @@ -1,9 +1,9 @@ -package ru.prisonlife.PrisonAPI.template; +package ru.prisonlife.prisonapi.template; import com.sun.media.sound.InvalidDataException; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; -import ru.prisonlife.PrisonAPI.PrisonAPI; +import ru.prisonlife.prisonapi.PrisonAPI; import java.io.File; import java.io.IOException; diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java index c15cb04..024c04e 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java @@ -1,10 +1,10 @@ -package ru.prisonlife.PrisonAPI.template; +package ru.prisonlife.prisonapi.template; import org.bukkit.Location; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; -import ru.prisonlife.PrisonAPI.PrisonAPI; +import ru.prisonlife.prisonapi.PrisonAPI; import java.io.File; import java.sql.PreparedStatement; diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java index 3a7edf6..362944b 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java @@ -1,6 +1,6 @@ -package ru.prisonlife.PrisonAPI.template; +package ru.prisonlife.prisonapi.template; -import ru.prisonlife.PrisonAPI.PrisonAPI; +import ru.prisonlife.prisonapi.PrisonAPI; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java index a9816bc..a073a5c 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java @@ -1,6 +1,6 @@ -package ru.prisonlife.PrisonAPI.template; +package ru.prisonlife.prisonapi.template; -import ru.prisonlife.PrisonAPI.PrisonAPI; +import ru.prisonlife.prisonapi.PrisonAPI; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java index 4836a6d..c8e0b1b 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java @@ -1,6 +1,6 @@ -package ru.prisonlife.PrisonAPI.template; +package ru.prisonlife.prisonapi.template; -import ru.prisonlife.PrisonAPI.PrisonAPI; +import ru.prisonlife.prisonapi.PrisonAPI; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4f61709..6cdec58 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,4 +1,4 @@ name: PrisonAPI version: 0.1.0.4 authors: [Overlord_S, Prot_CN, Wani4ka] -main: ru.prisonlife.PrisonAPI.PrisonAPI \ No newline at end of file +main: ru.prisonlife.prisonapi.PrisonAPI \ No newline at end of file From f4b470e75b8b7000782abfa80733dcfe24c5130a Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Wed, 20 Feb 2019 22:41:36 +0300 Subject: [PATCH 02/11] =?UTF-8?q?=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D1=83=D0=B5=D0=BC=20pom.xml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 9c743bf2b69e2c7a31aac0ae84274a4ba86671f8) --- pom.xml | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 095c64b..fea9f77 100644 --- a/pom.xml +++ b/pom.xml @@ -5,21 +5,51 @@ 4.0.0 ru.prisonlife - PrisonAPI + prison-api 0.0.4 + + UTF-8 + 1.8 + 1.12-R0.1 + + spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + org.spigotmc spigot-api - 1.12-R0.1-SNAPSHOT + ${bukkit.version}-SNAPSHOT provided + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + ${java.version} + ${java.version} + ${java.encoding} + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.0 + + -Dfile.encoding=${java.encoding} + + + + \ No newline at end of file From 29a453bbf1ba3fd5dcd51806e4d237eb46819e29 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Wed, 20 Feb 2019 22:42:59 +0300 Subject: [PATCH 03/11] =?UTF-8?q?=D1=81=D0=B8=D0=BD=D1=85=D1=80=D0=BE?= =?UTF-8?q?=D0=BD=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=81=D0=B8=D0=B9=20=D0=B2=20pom.xml=20=D0=B8=20plugin.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 4ed69ed72ea43229b3b698817b84f5122d12ee41) --- pom.xml | 9 ++++++++- src/main/resources/plugin.yml | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index fea9f77..f3681f5 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ ru.prisonlife prison-api - 0.0.4 + 0.1.0.4 UTF-8 @@ -31,6 +31,13 @@ + + + src/main/resources + true + + + org.apache.maven.plugins diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6cdec58..ac4901f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,4 +1,4 @@ name: PrisonAPI -version: 0.1.0.4 -authors: [Overlord_S, Prot_CN, Wani4ka] +version: ${project.version} +authors: [Overlord_S, Prot_CN, Wani4ka, DmitriyMX] main: ru.prisonlife.prisonapi.PrisonAPI \ No newline at end of file From b187c25b9b6f02fc7093082940aa788a5f466e17 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Wed, 20 Feb 2019 22:49:40 +0300 Subject: [PATCH 04/11] =?UTF-8?q?=D0=BC=D0=BE=D0=B4=D0=B5=D1=80=D0=BD?= =?UTF-8?q?=D0=B8=D0=B7=D0=B8=D1=80=D1=83=D0=B5=D0=BC=20.gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 4bfa550..4b82ef1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,10 @@ +## IDEA ## .idea/ +out/ *.iml +*.ipr +*.iws +*.ids + +## MAVEN ## target/ From fe6ae0830777cf861835f0d70e300f0c6f4c9325 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Wed, 20 Feb 2019 22:54:51 +0300 Subject: [PATCH 05/11] format code --- .../ru/prisonlife/PrisonAPI/PrisonAPI.java | 14 +++-- .../PrisonAPI/template/Faction.java | 46 ++++++++-------- .../prisonlife/PrisonAPI/template/Level.java | 17 +++--- .../PrisonAPI/template/Manager.java | 6 +-- .../PrisonAPI/template/Prisoner.java | 54 +++++++++++-------- .../prisonlife/PrisonAPI/template/Score.java | 14 +++-- .../prisonlife/PrisonAPI/template/Stats.java | 46 ++++++++-------- .../prisonlife/PrisonAPI/template/Wallet.java | 16 +++--- 8 files changed, 125 insertions(+), 88 deletions(-) diff --git a/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java b/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java index 2d3eae1..259f068 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java @@ -7,23 +7,29 @@ import java.sql.DriverManager; import java.sql.SQLException; public class PrisonAPI extends JavaPlugin { - public static Connection CONN; + public enum Factions { NONE, ASIANS, LATINOS, NIGGAZ, POLICE } + public static Connection CONN; + public void onEnable() { try { CONN = DriverManager.getConnection( "jdbc:mysql://localhost:3306/prison4life", "root", "root"); - } catch (SQLException e) { e.printStackTrace(); } + } catch (SQLException e) { + e.printStackTrace(); + } } public void onDisable() { try { - if(!CONN.isClosed()) + if (!CONN.isClosed()) CONN.close(); - } catch (SQLException e) { e.printStackTrace(); } + } 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 873f137..13af921 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java @@ -12,18 +12,20 @@ import java.util.Iterator; import java.util.List; public class Faction { + private PreparedStatement state; private ResultSet r_set; private Prisoner me; + Faction(Prisoner prisoner) { me = prisoner; } public String getType() throws SQLException { con_t(); - if(r_set.first()) { + if (r_set.first()) { r_set = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if(r_set.first()) + if (r_set.first()) return r_set.getString(1); } dis_t(); @@ -32,11 +34,11 @@ public class Faction { public int getId() throws SQLException { con_t(); - if(r_set.first()) { + if (r_set.first()) { r_set = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if(r_set.first()) - for(int i = 0; i < PrisonAPI.Factions.values().length; i++) - if(PrisonAPI.Factions.values()[i].name().equals(r_set.getString(1))) + if (r_set.first()) + for (int i = 0; i < PrisonAPI.Factions.values().length; i++) + if (PrisonAPI.Factions.values()[i].name().equals(r_set.getString(1))) return i; } dis_t(); @@ -45,9 +47,9 @@ public class Faction { public int getRangId() throws SQLException { con_t(); - if(r_set.first()) { + if (r_set.first()) { r_set = state.executeQuery("SELECT F_RANG FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if(r_set.first()) + if (r_set.first()) return r_set.getInt(1); } dis_t(); @@ -65,30 +67,30 @@ public class Faction { public void addRang(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET F_RANG = " + (getRangId() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public void setRang(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET F_RANG = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public void setFaction(int id) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET FACTION = '" + PrisonAPI.Factions.values()[id].name() + "' WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public int getRespect() throws SQLException { con_t(); - if(r_set.first()) { + if (r_set.first()) { r_set = state.executeQuery("SELECT RESPECT FROM prison4life.player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if(r_set.first()) + if (r_set.first()) return r_set.getInt(1); } dis_t(); @@ -97,47 +99,47 @@ public class Faction { public void addRespect(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET RESPECT = " + (getRespect() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public void setRespect(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET RESPECT = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public int getRespectDailyCooldown() throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) r_set = state.executeQuery("SELECT COOLDOWN FROM daily_respect_task WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if(r_set.first()) - return r_set.getInt(1); + if (r_set.first()) + return r_set.getInt(1); dis_t(); return 0; } public void addRespectDailyCooldown(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE daily_respect_task SET COOLDOWN = " + (getRespectDailyCooldown() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); } public void setRespectDailyCooldown(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE daily_respect_task SET COOLDOWN = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); } public List getOnlineList() throws SQLException { List list = new ArrayList<>(); Iterator itr = Bukkit.getOnlinePlayers().iterator(); - while(itr.hasNext()) { + 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 6c7df06..b6d4bab 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java @@ -7,15 +7,20 @@ import java.sql.ResultSet; import java.sql.SQLException; public class Level { + private PreparedStatement state; private ResultSet r_set; private Prisoner me; private Score score; - Level(Prisoner prisoner) { me = prisoner; score = new Score(me); } + + Level(Prisoner prisoner) { + me = prisoner; + score = new Score(me); + } public Score getScore() throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) return this.score; dis_t(); return null; @@ -23,9 +28,9 @@ public class Level { public double getLevel() throws SQLException, NullPointerException { con_t(); - if(r_set.first()) { + if (r_set.first()) { r_set = state.executeQuery("SELECT LEVEL FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if(r_set.first()) + if (r_set.first()) return r_set.getDouble(1); } dis_t(); @@ -34,14 +39,14 @@ public class Level { public void addLevel(double value) throws SQLException, NullPointerException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET LEVEL = " + (getLevel() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public void setLevel(double value) throws SQLException, NullPointerException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET LEVEL = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java index 3934c20..98ad5dc 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java @@ -12,10 +12,10 @@ import java.util.List; import java.util.Objects; public class Manager { + private File fi; private FileConfiguration cf; - public Manager(String id) { fi = new File("plugins/PrisonManager/", id); cf = YamlConfiguration.loadConfiguration(fi); @@ -73,7 +73,7 @@ public class Manager { } public void setDiagonal(List data) { - if(data.size() == 6) { + if (data.size() == 6) { String dp = "DIAGONAL_POINTS"; cf.set(dp, null); cf.set(dp, data); @@ -93,7 +93,7 @@ public class Manager { public int getGlobalNumTerr(int faction) { int num = 0; - for(File prison : Objects.requireNonNull(fi.getParentFile().listFiles())) { + for (File prison : Objects.requireNonNull(fi.getParentFile().listFiles())) { Manager mng = new Manager(prison.getName()); num += mng.getNumTerr(faction); } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java index 024c04e..749a88d 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.Objects; public class Prisoner { + private static final String PLUGIN_PATH = "plugins/PrisonManager"; private Player me; private Level level; @@ -32,13 +33,17 @@ public class Prisoner { stats = new Stats(this); } - public Player getPlayer() { return me; } + public Player getPlayer() { + return me; + } - public Level getPrisonLevel() throws SQLException { return this.level; } + public Level getPrisonLevel() throws SQLException { + return this.level; + } public String getPrison() { 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); List> data = new ArrayList<>(); List from_cfg = c_ti.getIntegerList("DIAGONAL_POINTS"), @@ -46,17 +51,17 @@ public class Prisoner { int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()}; data.add(from_cfg.subList(0, 3)); data.add(from_cfg.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))); max.add(Math.max(data.get(0).get(i), data.get(1).get(i))); } 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 k : loc_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"; @@ -64,53 +69,60 @@ public class Prisoner { public String getTerritory(String type) { String prs = getPrison(); - if(!prs.equals("Not Prison") && (type.equals("name") || type.equals("owner"))) { + if (!prs.equals("Not Prison") && (type.equals("name") || type.equals("owner"))) { Location loc = me.getLocation(); FileConfiguration c_ti = YamlConfiguration.loadConfiguration(new File(PLUGIN_PATH, "PRISON_" + prs + ".yml")); try { - if(c_ti.getConfigurationSection("TERRITORIES").getKeys(false).size() != 0) { - for(String terr : c_ti.getConfigurationSection("TERRITORIES").getKeys(false)) { + if (c_ti.getConfigurationSection("TERRITORIES").getKeys(false).size() != 0) { + for (String terr : c_ti.getConfigurationSection("TERRITORIES").getKeys(false)) { List> data = new ArrayList<>(); List from_cfg = c_ti.getIntegerList("TERRITORIES." + terr + ".DIAGONAL_POINTS"), min = new ArrayList<>(), max = new ArrayList<>(); int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()}; data.add(from_cfg.subList(0, 3)); data.add(from_cfg.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))); max.add(Math.max(data.get(0).get(i), data.get(1).get(i))); } int c = 0; - for(int k : loc_n) { + for (int k : loc_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") ? c_ti.getString("TERRITORIES." + terr + ".NAME") : (type.equals("owner") ? c_ti.getString("TERRITORIES." + terr + ".OWNER") : null); } } - } catch(NullPointerException z) {} + } catch (NullPointerException z) { + } } return "Not Territory"; } - public Faction getFaction() { return faction; } + public Faction getFaction() { + return faction; + } - public Wallet getWallet() { return wallet; } + public Wallet getWallet() { + return wallet; + } - public Stats getStats() { return stats; } + public Stats getStats() { + return stats; + } public void register() throws SQLException { state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;"); state.setString(1, me.getUniqueId().toString()); r_set = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getUniqueId() + "'"); - if(!r_set.next()) { + if (!r_set.next()) { state.execute( "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() - + "', '" + me.getUniqueId() + "', 1, 0, 'NONE', 0, 0, 0, 0, 0, 0, 0, 0);"); + "K_PLAYERS, K_MOBS, DEATHS) VALUES (" + "'" + getPlayer().getName() + + "', '" + me.getUniqueId() + "', 1, 0, 'NONE', 0, 0, 0, 0, 0, 0, 0, 0);"); state.execute("INSERT INTO daily_respect_task(NAME, UUID, COOLDOWN) VALUES ('" + me.getName() + "', '" + me.getUniqueId() + "', (3600 * 24));"); level = new Level(this); stats = new Stats(this); diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java index 362944b..077d068 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java @@ -7,16 +7,20 @@ import java.sql.ResultSet; import java.sql.SQLException; public class Score { + private PreparedStatement state; private ResultSet r_set; private Prisoner me; - Score(Prisoner prisoner) { me = prisoner; } + + Score(Prisoner prisoner) { + me = prisoner; + } public double getPoints() throws SQLException { con_t(); - if(r_set.first()) { + if (r_set.first()) { r_set = state.executeQuery("SELECT POINTS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if(r_set.first()) { + if (r_set.first()) { return r_set.getDouble(1); } } @@ -26,14 +30,14 @@ public class Score { public void setPoints(double value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET POINTS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public void addPoints(double value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET POINTS = " + (getPoints() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java index a073a5c..8ff2128 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java @@ -7,23 +7,27 @@ import java.sql.ResultSet; import java.sql.SQLException; public class Stats { + private PreparedStatement state; private ResultSet r_set; private Prisoner me; - Stats(Prisoner prisoner) { me = prisoner;} + + Stats(Prisoner prisoner) { + me = prisoner; + } public void setServerTime(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET G_TIME = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public int getServerTime() throws SQLException { con_t(); - if(r_set.first()) { + if (r_set.first()) { r_set = state.executeQuery("SELECT G_TIME FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if(r_set.first()) + if (r_set.first()) return r_set.getInt(1); } dis_t(); @@ -32,23 +36,23 @@ public class Stats { public void addServerTime(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET G_TIME = " + (getServerTime() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public void setBlocks(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET B = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public int getBlocks() throws SQLException { con_t(); - if(r_set.first()) { + if (r_set.first()) { r_set = state.executeQuery("SELECT D_BLOCKS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if(r_set.first()) + if (r_set.first()) return r_set.getInt(1); } dis_t(); @@ -57,23 +61,23 @@ public class Stats { public void addBlocks(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET D_BLOCKS = " + (getBlocks() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public void setPlayers(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET K_PLAYERS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public int getPlayers() throws SQLException { con_t(); - if(r_set.first()) { + if (r_set.first()) { r_set = state.executeQuery("SELECT K_PLAYERS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if(r_set.first()) + if (r_set.first()) return r_set.getInt(1); } dis_t(); @@ -82,23 +86,23 @@ public class Stats { public void addPlayers(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET K_PLAYERS = " + (getPlayers() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public void setMobs(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET K_MOBS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public int getMobs() throws SQLException { con_t(); - if(r_set.first()) { + if (r_set.first()) { r_set = state.executeQuery("SELECT K_MOBS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if(r_set.first()) + if (r_set.first()) return r_set.getInt(1); } dis_t(); @@ -107,23 +111,23 @@ public class Stats { public void addMobs(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET K_MOBS = " + (getMobs() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public void setDeaths(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET DEATHS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public int getDeaths() throws SQLException { con_t(); - if(r_set.first()) { + if (r_set.first()) { r_set = state.executeQuery("SELECT DEATHS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if(r_set.first()) + if (r_set.first()) return r_set.getInt(1); } dis_t(); @@ -132,7 +136,7 @@ public class Stats { public void addDeaths(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET DEATHS = " + (getDeaths() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java index c8e0b1b..cffdd96 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java @@ -7,16 +7,20 @@ import java.sql.ResultSet; import java.sql.SQLException; public class Wallet { + private PreparedStatement state; private ResultSet r_set; private Prisoner me; - Wallet(Prisoner prisoner) { me = prisoner; } + + Wallet(Prisoner prisoner) { + me = prisoner; + } public int getBalance() throws SQLException { con_t(); - if(r_set.first()) { + if (r_set.first()) { r_set = state.executeQuery("SELECT WALLET FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if(r_set.first()) + if (r_set.first()) return r_set.getInt(1); } dis_t(); @@ -25,21 +29,21 @@ public class Wallet { public void addBalance(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET WALLET = " + (getBalance() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public void deposit(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET WALLET = " + (getBalance() - value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } public void setBalance(int value) throws SQLException { con_t(); - if(r_set.first()) + if (r_set.first()) state.execute("UPDATE player_stats SET WALLET = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); dis_t(); } From 1a96a4569339e615a65755ce849e0027398715ac Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Wed, 20 Feb 2019 23:06:10 +0300 Subject: [PATCH 06/11] =?UTF-8?q?=D0=BD=D0=B0=D0=B8=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE?= =?UTF-8?q?=D0=B4=D0=BE=D0=B2=20=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PrisonAPI/template/Faction.java | 108 +++++++-------- .../prisonlife/PrisonAPI/template/Level.java | 40 +++--- .../PrisonAPI/template/Manager.java | 72 +++++----- .../PrisonAPI/template/Prisoner.java | 36 ++--- .../prisonlife/PrisonAPI/template/Score.java | 34 ++--- .../prisonlife/PrisonAPI/template/Stats.java | 130 +++++++++--------- .../prisonlife/PrisonAPI/template/Wallet.java | 40 +++--- 7 files changed, 230 insertions(+), 230 deletions(-) diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java index 13af921..083d43d 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java @@ -14,7 +14,7 @@ import java.util.List; public class Faction { private PreparedStatement state; - private ResultSet r_set; + private ResultSet resultSet; private Prisoner me; Faction(Prisoner prisoner) { @@ -22,37 +22,37 @@ public class Faction { } public String getType() throws SQLException { - con_t(); - if (r_set.first()) { - r_set = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (r_set.first()) - return r_set.getString(1); + connect(); + if (resultSet.first()) { + resultSet = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + if (resultSet.first()) + return resultSet.getString(1); } - dis_t(); + disconnect(); return "null"; } public int getId() throws SQLException { - con_t(); - if (r_set.first()) { - r_set = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (r_set.first()) + 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(r_set.getString(1))) + if (PrisonAPI.Factions.values()[i].name().equals(resultSet.getString(1))) return i; } - dis_t(); + disconnect(); return 0; } public int getRangId() throws SQLException { - con_t(); - if (r_set.first()) { - r_set = state.executeQuery("SELECT F_RANG FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (r_set.first()) - return r_set.getInt(1); + connect(); + if (resultSet.first()) { + resultSet = state.executeQuery("SELECT F_RANG FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + if (resultSet.first()) + return resultSet.getInt(1); } - dis_t(); + disconnect(); return 0; } @@ -66,71 +66,71 @@ public class Faction { } public void addRang(int value) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) 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 { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) state.execute("UPDATE player_stats SET F_RANG = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - dis_t(); + disconnect(); } public void setFaction(int id) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) 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 { - con_t(); - if (r_set.first()) { - r_set = state.executeQuery("SELECT RESPECT FROM prison4life.player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (r_set.first()) - return r_set.getInt(1); + connect(); + if (resultSet.first()) { + resultSet = state.executeQuery("SELECT RESPECT FROM prison4life.player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + if (resultSet.first()) + return resultSet.getInt(1); } - dis_t(); + disconnect(); return 0; } public void addRespect(int value) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) state.execute("UPDATE player_stats SET RESPECT = " + (getRespect() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - dis_t(); + disconnect(); } public void setRespect(int value) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) state.execute("UPDATE player_stats SET RESPECT = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - dis_t(); + disconnect(); } public int getRespectDailyCooldown() throws SQLException { - con_t(); - if (r_set.first()) - r_set = state.executeQuery("SELECT COOLDOWN FROM daily_respect_task WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (r_set.first()) - return r_set.getInt(1); - dis_t(); + connect(); + if (resultSet.first()) + resultSet = state.executeQuery("SELECT COOLDOWN FROM daily_respect_task WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + if (resultSet.first()) + return resultSet.getInt(1); + disconnect(); return 0; } public void addRespectDailyCooldown(int value) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + 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 { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) state.execute("UPDATE daily_respect_task SET COOLDOWN = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); } @@ -145,14 +145,14 @@ public class Faction { 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.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 { - r_set.close(); + private void disconnect() throws SQLException { + resultSet.close(); state.close(); } } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java index b6d4bab..4d59f26 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java @@ -9,7 +9,7 @@ import java.sql.SQLException; public class Level { private PreparedStatement state; - private ResultSet r_set; + private ResultSet resultSet; private Prisoner me; private Score score; @@ -19,46 +19,46 @@ public class Level { } public Score getScore() throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) return this.score; - dis_t(); + disconnect(); return null; } public double getLevel() throws SQLException, NullPointerException { - con_t(); - if (r_set.first()) { - r_set = state.executeQuery("SELECT LEVEL FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (r_set.first()) - return r_set.getDouble(1); + connect(); + if (resultSet.first()) { + resultSet = state.executeQuery("SELECT LEVEL FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + if (resultSet.first()) + return resultSet.getDouble(1); } - dis_t(); + disconnect(); return NullPointerException.class.hashCode(); } public void addLevel(double value) throws SQLException, NullPointerException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) 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 { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) 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.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 { - r_set.close(); + private void disconnect() throws SQLException { + resultSet.close(); state.close(); } } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java index 98ad5dc..e880157 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java @@ -13,72 +13,72 @@ import java.util.Objects; public class Manager { - private File fi; - private FileConfiguration cf; + private File file; + private FileConfiguration fileConfiguration; public Manager(String id) { - fi = new File("plugins/PrisonManager/", id); - cf = YamlConfiguration.loadConfiguration(fi); + file = new File("plugins/PrisonManager/", id); + fileConfiguration = YamlConfiguration.loadConfiguration(file); } public boolean contains() { - return fi.exists(); + return file.exists(); } public String getWorld() { - return cf.getString("WORLD"); + return fileConfiguration.getString("WORLD"); } public void setWorld(String name) { String p = "WORLD"; - cf.set(p, null); - cf.set(p, name); + fileConfiguration.set(p, null); + fileConfiguration.set(p, name); try { - cf.save(fi); + fileConfiguration.save(file); } catch (IOException e) { e.printStackTrace(); } } public boolean getRebootStatus() { - return cf.getBoolean("REBOOT_STATUS"); + return fileConfiguration.getBoolean("REBOOT_STATUS"); } public void setRebootStatus(boolean status) { - cf.set("REBOOT_STATUS", status); + fileConfiguration.set("REBOOT_STATUS", status); try { - cf.save(fi); + fileConfiguration.save(file); } catch (IOException e) { e.printStackTrace(); } } public List getSpawnCords(int faction) { - return cf.getIntegerList("FACTIONS." + __selectFactType__(faction) + ".CORDS"); + return fileConfiguration.getIntegerList("FACTIONS." + selectFactType(faction) + ".CORDS"); } public void setSpawnCords(int faction, List data) { - String p = "FACTIONS." + __selectFactType__(faction) + ".CORDS"; - cf.set(p, null); - cf.set(p, data); + String p = "FACTIONS." + selectFactType(faction) + ".CORDS"; + fileConfiguration.set(p, null); + fileConfiguration.set(p, data); try { - cf.save(fi); + fileConfiguration.save(file); } catch (IOException e) { e.printStackTrace(); } } public List getDiagonal() { - return cf.getIntegerList("DIAGONAL_POINTS"); + return fileConfiguration.getIntegerList("DIAGONAL_POINTS"); } public void setDiagonal(List data) { if (data.size() == 6) { String dp = "DIAGONAL_POINTS"; - cf.set(dp, null); - cf.set(dp, data); + fileConfiguration.set(dp, null); + fileConfiguration.set(dp, data); try { - cf.save(fi); + fileConfiguration.save(file); } catch (IOException e) { e.printStackTrace(); } @@ -93,7 +93,7 @@ public class Manager { public int getGlobalNumTerr(int faction) { 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()); num += mng.getNumTerr(faction); } @@ -101,55 +101,55 @@ public class Manager { } 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) { - String p = "FACTIONS." + __selectFactType__(faction) + ".NUM_TERR"; - cf.set(p, null); - cf.set(p, value); + String p = "FACTIONS." + selectFactType(faction) + ".NUM_TERR"; + fileConfiguration.set(p, null); + fileConfiguration.set(p, value); try { - cf.save(fi); + fileConfiguration.save(file); } catch (IOException e) { e.printStackTrace(); } } public String getTerrOwner(String name) { - return cf.getString("TERRITORIES." + name + ".OWNER"); + return fileConfiguration.getString("TERRITORIES." + name + ".OWNER"); } public void setTerrOwner(String name, String owner) { - cf.set("TERRITORIES." + name + ".OWNER", owner); + fileConfiguration.set("TERRITORIES." + name + ".OWNER", owner); try { - cf.save(fi); + fileConfiguration.save(file); } catch (IOException e) { e.printStackTrace(); } } public String getTerrConqurer(String name) { - return cf.getString("TERRITORIES." + name + ".CAPTURED"); + return fileConfiguration.getString("TERRITORIES." + name + ".CAPTURED"); } public void setTerrConqurer(String name, String status) { - cf.set("TERRITORIES." + name + ".CAPTURED", status); + fileConfiguration.set("TERRITORIES." + name + ".CAPTURED", status); try { - cf.save(fi); + fileConfiguration.save(file); } catch (IOException e) { e.printStackTrace(); } } public List 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(); } - public int __selectFactId__(String faction) { + public int selectFactId(String faction) { return PrisonAPI.Factions.valueOf(faction).ordinal(); } } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java index 749a88d..2894721 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java @@ -23,7 +23,7 @@ public class Prisoner { private Wallet wallet; private Stats stats; private PreparedStatement state; - private ResultSet r_set; + private ResultSet resultSet; public Prisoner(Player player) { me = player; @@ -44,13 +44,13 @@ public class Prisoner { public String getPrison() { Location loc = me.getLocation(); for (File file : Objects.requireNonNull(new File(PLUGIN_PATH).listFiles())) { - FileConfiguration c_ti = YamlConfiguration.loadConfiguration(file); + FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file); List> data = new ArrayList<>(); - List from_cfg = c_ti.getIntegerList("DIAGONAL_POINTS"), + List fromConfig = fileConfiguration.getIntegerList("DIAGONAL_POINTS"), min = new ArrayList<>(), max = new ArrayList<>(); int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()}; - data.add(from_cfg.subList(0, 3)); - data.add(from_cfg.subList(3, 6)); + data.add(fromConfig.subList(0, 3)); + data.add(fromConfig.subList(3, 6)); for (int i = 0; i < 3; 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))); @@ -68,19 +68,19 @@ public class Prisoner { } public String getTerritory(String type) { - String prs = getPrison(); - if (!prs.equals("Not Prison") && (type.equals("name") || type.equals("owner"))) { + String prison = getPrison(); + if (!prison.equals("Not Prison") && (type.equals("name") || type.equals("owner"))) { 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 { - if (c_ti.getConfigurationSection("TERRITORIES").getKeys(false).size() != 0) { - for (String terr : c_ti.getConfigurationSection("TERRITORIES").getKeys(false)) { + if (fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false).size() != 0) { + for (String terr : fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false)) { List> data = new ArrayList<>(); - List from_cfg = c_ti.getIntegerList("TERRITORIES." + terr + ".DIAGONAL_POINTS"), + List fromConfig = fileConfiguration.getIntegerList("TERRITORIES." + terr + ".DIAGONAL_POINTS"), min = new ArrayList<>(), max = new ArrayList<>(); int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()}; - data.add(from_cfg.subList(0, 3)); - data.add(from_cfg.subList(3, 6)); + data.add(fromConfig.subList(0, 3)); + data.add(fromConfig.subList(3, 6)); for (int i = 0; i < 3; 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))); @@ -92,8 +92,8 @@ public class Prisoner { ++c; } if (c == 3) - return type.equals("name") ? c_ti.getString("TERRITORIES." + terr + ".NAME") : - (type.equals("owner") ? c_ti.getString("TERRITORIES." + terr + ".OWNER") : null); + return type.equals("name") ? fileConfiguration.getString("TERRITORIES." + terr + ".NAME") : + (type.equals("owner") ? fileConfiguration.getString("TERRITORIES." + terr + ".OWNER") : null); } } } catch (NullPointerException z) { @@ -117,8 +117,8 @@ public class Prisoner { public void register() throws SQLException { state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;"); state.setString(1, me.getUniqueId().toString()); - r_set = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getUniqueId() + "'"); - if (!r_set.next()) { + resultSet = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getUniqueId() + "'"); + if (!resultSet.next()) { state.execute( "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() @@ -128,7 +128,7 @@ public class Prisoner { stats = new Stats(this); wallet = new Wallet(this); } - r_set.close(); + resultSet.close(); state.close(); } } \ No newline at end of file diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java index 077d068..338ba34 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java @@ -9,7 +9,7 @@ import java.sql.SQLException; public class Score { private PreparedStatement state; - private ResultSet r_set; + private ResultSet resultSet; private Prisoner me; Score(Prisoner prisoner) { @@ -17,39 +17,39 @@ public class Score { } public double getPoints() throws SQLException { - con_t(); - if (r_set.first()) { - r_set = state.executeQuery("SELECT POINTS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (r_set.first()) { - return r_set.getDouble(1); + connect(); + if (resultSet.first()) { + resultSet = state.executeQuery("SELECT POINTS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + if (resultSet.first()) { + return resultSet.getDouble(1); } } - dis_t(); + disconnect(); return NullPointerException.class.hashCode(); } public void setPoints(double value) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) state.execute("UPDATE player_stats SET POINTS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - dis_t(); + disconnect(); } public void addPoints(double value) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) 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.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 { - r_set.close(); + private void disconnect() throws SQLException { + resultSet.close(); state.close(); } } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java index 8ff2128..bf9ddc3 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java @@ -9,7 +9,7 @@ import java.sql.SQLException; public class Stats { private PreparedStatement state; - private ResultSet r_set; + private ResultSet resultSet; private Prisoner me; Stats(Prisoner prisoner) { @@ -17,138 +17,138 @@ public class Stats { } public void setServerTime(int value) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) state.execute("UPDATE player_stats SET G_TIME = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - dis_t(); + disconnect(); } public int getServerTime() throws SQLException { - con_t(); - if (r_set.first()) { - r_set = state.executeQuery("SELECT G_TIME FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (r_set.first()) - return r_set.getInt(1); + connect(); + if (resultSet.first()) { + resultSet = state.executeQuery("SELECT G_TIME FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + if (resultSet.first()) + return resultSet.getInt(1); } - dis_t(); + disconnect(); return NullPointerException.class.hashCode(); } public void addServerTime(int value) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) 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 { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) state.execute("UPDATE player_stats SET B = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - dis_t(); + disconnect(); } public int getBlocks() throws SQLException { - con_t(); - if (r_set.first()) { - r_set = state.executeQuery("SELECT D_BLOCKS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (r_set.first()) - return r_set.getInt(1); + connect(); + if (resultSet.first()) { + resultSet = state.executeQuery("SELECT D_BLOCKS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + if (resultSet.first()) + return resultSet.getInt(1); } - dis_t(); + disconnect(); return NullPointerException.class.hashCode(); } public void addBlocks(int value) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) 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 { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) state.execute("UPDATE player_stats SET K_PLAYERS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - dis_t(); + disconnect(); } public int getPlayers() throws SQLException { - con_t(); - if (r_set.first()) { - r_set = state.executeQuery("SELECT K_PLAYERS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (r_set.first()) - return r_set.getInt(1); + connect(); + if (resultSet.first()) { + resultSet = state.executeQuery("SELECT K_PLAYERS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + if (resultSet.first()) + return resultSet.getInt(1); } - dis_t(); + disconnect(); return NullPointerException.class.hashCode(); } public void addPlayers(int value) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) 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 { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) state.execute("UPDATE player_stats SET K_MOBS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - dis_t(); + disconnect(); } public int getMobs() throws SQLException { - con_t(); - if (r_set.first()) { - r_set = state.executeQuery("SELECT K_MOBS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (r_set.first()) - return r_set.getInt(1); + connect(); + if (resultSet.first()) { + resultSet = state.executeQuery("SELECT K_MOBS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + if (resultSet.first()) + return resultSet.getInt(1); } - dis_t(); + disconnect(); return NullPointerException.class.hashCode(); } public void addMobs(int value) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) 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 { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) state.execute("UPDATE player_stats SET DEATHS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - dis_t(); + disconnect(); } public int getDeaths() throws SQLException { - con_t(); - if (r_set.first()) { - r_set = state.executeQuery("SELECT DEATHS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (r_set.first()) - return r_set.getInt(1); + connect(); + if (resultSet.first()) { + resultSet = state.executeQuery("SELECT DEATHS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + if (resultSet.first()) + return resultSet.getInt(1); } - dis_t(); + disconnect(); return NullPointerException.class.hashCode(); } public void addDeaths(int value) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) 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.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 { - r_set.close(); + private void disconnect() throws SQLException { + resultSet.close(); state.close(); } } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java index cffdd96..ee854ae 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java @@ -9,7 +9,7 @@ import java.sql.SQLException; public class Wallet { private PreparedStatement state; - private ResultSet r_set; + private ResultSet resultSet; private Prisoner me; Wallet(Prisoner prisoner) { @@ -17,45 +17,45 @@ public class Wallet { } public int getBalance() throws SQLException { - con_t(); - if (r_set.first()) { - r_set = state.executeQuery("SELECT WALLET FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (r_set.first()) - return r_set.getInt(1); + connect(); + if (resultSet.first()) { + resultSet = state.executeQuery("SELECT WALLET FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + if (resultSet.first()) + return resultSet.getInt(1); } - dis_t(); + disconnect(); return NullPointerException.class.hashCode(); } public void addBalance(int value) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) state.execute("UPDATE player_stats SET WALLET = " + (getBalance() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - dis_t(); + disconnect(); } public void deposit(int value) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) state.execute("UPDATE player_stats SET WALLET = " + (getBalance() - value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - dis_t(); + disconnect(); } public void setBalance(int value) throws SQLException { - con_t(); - if (r_set.first()) + connect(); + if (resultSet.first()) 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.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 { - r_set.close(); + private void disconnect() throws SQLException { + resultSet.close(); state.close(); } } From be5e3e87b63b5eb7a7e26e21cb2b51ef9f06abd7 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Wed, 20 Feb 2019 23:13:39 +0300 Subject: [PATCH 07/11] code style --- .../ru/prisonlife/PrisonAPI/PrisonAPI.java | 3 +- .../PrisonAPI/template/Faction.java | 48 ++++++++++++------- .../prisonlife/PrisonAPI/template/Level.java | 12 +++-- .../PrisonAPI/template/Prisoner.java | 18 ++++--- .../prisonlife/PrisonAPI/template/Score.java | 6 ++- .../prisonlife/PrisonAPI/template/Stats.java | 33 ++++++++----- .../prisonlife/PrisonAPI/template/Wallet.java | 12 +++-- 7 files changed, 88 insertions(+), 44 deletions(-) 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(); } From ec21577586b2e53ebafa08b11987af28a45ca262 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Thu, 21 Feb 2019 00:02:53 +0300 Subject: [PATCH 08/11] fix: global constant --- src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java | 2 ++ src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java | 4 +++- src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java b/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java index f144212..4946035 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java @@ -8,6 +8,8 @@ import java.sql.SQLException; public class PrisonAPI extends JavaPlugin { + public static final String PLUGIN_PATH = "plugins/PrisonManager"; + public enum Factions { NONE, ASIANS, LATINOS, NIGGAZ, POLICE } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java index e880157..fcdf9ee 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java @@ -11,13 +11,15 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import static ru.prisonlife.prisonapi.PrisonAPI.PLUGIN_PATH; + public class Manager { private File file; private FileConfiguration fileConfiguration; public Manager(String id) { - file = new File("plugins/PrisonManager/", id); + file = new File(PLUGIN_PATH + "/", id); fileConfiguration = YamlConfiguration.loadConfiguration(file); } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java index afc7104..85d0ca1 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java @@ -14,9 +14,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import static ru.prisonlife.prisonapi.PrisonAPI.PLUGIN_PATH; + public class Prisoner { - private static final String PLUGIN_PATH = "plugins/PrisonManager"; private Player me; private Level level; private Faction faction; From 0fff60d08663b9026e5a722224158c47ef4f4f42 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Thu, 21 Feb 2019 00:22:52 +0300 Subject: [PATCH 09/11] fix stream --- .../PrisonAPI/template/Faction.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java index 5b0dd2a..2f981ac 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java @@ -10,6 +10,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.stream.Collectors; public class Faction { @@ -149,16 +150,18 @@ public class Faction { } } - public List getOnlineList() throws SQLException { - List list = new ArrayList<>(); - Iterator itr = Bukkit.getOnlinePlayers().iterator(); - while (itr.hasNext()) { - Prisoner m = new Prisoner((Player) itr.next()); - if (m.getFaction().getType().equals(me.getFaction().getType())) { - list.add(m); - } - } - return list; + public List getOnlineList() { + return Bukkit.getOnlinePlayers().stream() + .map(Prisoner::new) + .filter(prisoner -> { + try { + return prisoner.getFaction().getType().equals(me.getFaction().getType()); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + }) + .collect(Collectors.toList()); } private void connect() throws SQLException { From a364998a7988720bd93c4fcb38c324c293977e0f Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Wed, 20 Feb 2019 23:47:40 +0300 Subject: [PATCH 10/11] fix: PrepareStatement + enum Factions --- .../ru/prisonlife/PrisonAPI/PrisonAPI.java | 22 ++- .../PrisonAPI/template/Faction.java | 163 ++++++++--------- .../prisonlife/PrisonAPI/template/Level.java | 51 ++---- .../PrisonAPI/template/Prisoner.java | 47 +++-- .../prisonlife/PrisonAPI/template/Score.java | 48 ++--- .../prisonlife/PrisonAPI/template/Stats.java | 172 ++++++++---------- .../prisonlife/PrisonAPI/template/Wallet.java | 54 ++---- 7 files changed, 259 insertions(+), 298 deletions(-) diff --git a/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java b/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java index 4946035..fa629cf 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java @@ -11,7 +11,27 @@ public class PrisonAPI extends JavaPlugin { public static final String PLUGIN_PATH = "plugins/PrisonManager"; public enum Factions { - NONE, ASIANS, LATINOS, NIGGAZ, POLICE + NONE(0), ASIANS(1), LATINOS(2), NIGGAZ(3), POLICE(4); + + public static Factions valueOf(int id) { + for (Factions factions : Factions.values()) { + if (factions.id == id) { + return factions; + } + } + + throw new IllegalArgumentException("Factions id " + id + " not defined!"); + } + + private int id; + + Factions(int id) { + this.id = id; + } + + public int getId() { + return id; + } } public static Connection CONN; diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java index 2f981ac..78d4dbb 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Faction.java @@ -1,21 +1,18 @@ package ru.prisonlife.prisonapi.template; import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import ru.prisonlife.prisonapi.PrisonAPI; +import ru.prisonlife.prisonapi.PrisonAPI.Factions; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; +import static ru.prisonlife.prisonapi.PrisonAPI.CONN; + public class Faction { - private PreparedStatement state; - private ResultSet resultSet; private Prisoner me; Faction(Prisoner prisoner) { @@ -23,43 +20,45 @@ public class Faction { } public String getType() throws SQLException { - connect(); - if (resultSet.first()) { - resultSet = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) { - return resultSet.getString(1); - } - } - disconnect(); - return "null"; - } + try (PreparedStatement statement = CONN.prepareStatement("SELECT FACTION FROM player_stats WHERE UUID = ?")) { + statement.setString(1, me.getPlayer().getUniqueId().toString()); - public int getId() throws SQLException { - 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))) { - return i; - } + try (ResultSet resultSet = statement.executeQuery()) { + if (resultSet.next()) { + return resultSet.getString(1); + } else { + return "null"; } } } - disconnect(); + } + + public int getId() throws SQLException { + try (PreparedStatement statement = CONN.prepareStatement("SELECT FACTION FROM player_stats WHERE UUID = ?")) { + statement.setString(1, me.getPlayer().getUniqueId().toString()); + + try (ResultSet resultSet = statement.executeQuery()) { + if (resultSet.next()) { + return Factions.valueOf(resultSet.getString(1)).getId(); + } + } + } + return 0; } public int getRangId() throws SQLException { - connect(); - if (resultSet.first()) { - resultSet = state.executeQuery("SELECT F_RANG FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) { - return resultSet.getInt(1); + try (PreparedStatement statement = CONN.prepareStatement("SELECT F_RANG 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; + } } } - disconnect(); - return 0; } public String getRangType() throws SQLException { @@ -72,81 +71,78 @@ public class Faction { } public void addRang(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET F_RANG = " + (getRangId() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - } - disconnect(); + setRang(getRangId() + value); } public void setRang(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET F_RANG = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET F_RANG = ? WHERE UUID = ?")) { + statement.setInt(1, value); + statement.setString(2, me.getPlayer().getUniqueId().toString()); + + statement.executeUpdate(); } - disconnect(); } public void setFaction(int id) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET FACTION = '" + PrisonAPI.Factions.values()[id].name() + "' WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET FACTION = ? WHERE UUID = ?")) { + statement.setInt(1, Factions.valueOf(id).getId()); + statement.setString(2, me.getPlayer().getUniqueId().toString()); + + statement.executeUpdate(); } - disconnect(); } public int getRespect() throws SQLException { - connect(); - if (resultSet.first()) { - resultSet = state.executeQuery("SELECT RESPECT FROM prison4life.player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) { - return resultSet.getInt(1); + try (PreparedStatement statement = CONN.prepareStatement("SELECT RESPECT FROM prison4life.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; + } } } - disconnect(); - return 0; } public void addRespect(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET RESPECT = " + (getRespect() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - } - disconnect(); + setRespect(getRespect() + value); } public void setRespect(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET RESPECT = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET RESPECT = ? WHERE UUID = ?")) { + statement.setInt(1, value); + statement.setString(2, me.getPlayer().getUniqueId().toString()); + + statement.executeUpdate(); } - disconnect(); } public int getRespectDailyCooldown() throws SQLException { - connect(); - if (resultSet.first()) { - resultSet = state.executeQuery("SELECT COOLDOWN FROM daily_respect_task WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + try (PreparedStatement statement = CONN.prepareStatement("SELECT COOLDOWN FROM daily_respect_task WHERE UUID = ?")) { + statement.setString(1, me.getPlayer().getUniqueId().toString()); + + try (ResultSet resultSet = statement.executeQuery()) { + if (resultSet.next()) { + return resultSet.getInt(1); + } else { + return 0; + } + } } - if (resultSet.first()) { - return resultSet.getInt(1); - } - disconnect(); - return 0; } public void addRespectDailyCooldown(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE daily_respect_task SET COOLDOWN = " + (getRespectDailyCooldown() + value) - + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - } + setRespectDailyCooldown(getRespectDailyCooldown() + value); } public void setRespectDailyCooldown(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE daily_respect_task SET COOLDOWN = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + try (PreparedStatement statement = CONN.prepareStatement("UPDATE daily_respect_task SET COOLDOWN = ? WHERE UUID = ?")) { + statement.setInt(1, value); + statement.setString(2, me.getPlayer().getUniqueId().toString()); + + statement.executeUpdate(); } } @@ -163,15 +159,4 @@ public class Faction { }) .collect(Collectors.toList()); } - - private void connect() throws SQLException { - state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;"); - state.setString(1, me.getPlayer().getUniqueId().toString()); - resultSet = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - } - - private void disconnect() throws SQLException { - resultSet.close(); - state.close(); - } } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java index 7f40bee..87a3f1b 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java @@ -1,15 +1,13 @@ package ru.prisonlife.prisonapi.template; -import ru.prisonlife.prisonapi.PrisonAPI; - import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import static ru.prisonlife.prisonapi.PrisonAPI.CONN; + public class Level { - private PreparedStatement state; - private ResultSet resultSet; private Prisoner me; private Score score; @@ -19,50 +17,41 @@ public class Level { } public Score getScore() throws SQLException { + //FIXME приведи в порядок метод + /* connect(); if (resultSet.first()) { return this.score; } disconnect(); + */ return null; } public double getLevel() throws SQLException, NullPointerException { - connect(); - if (resultSet.first()) { - resultSet = state.executeQuery("SELECT LEVEL FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) { - return resultSet.getDouble(1); + try (PreparedStatement statement = 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 + } } } - disconnect(); - return NullPointerException.class.hashCode(); } public void addLevel(double value) throws SQLException, NullPointerException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET LEVEL = " + (getLevel() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - } - disconnect(); + setLevel(getLevel() + value); } public void setLevel(double value) throws SQLException, NullPointerException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET LEVEL = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET LEVEL = ? WHERE UUID = ?")) { + statement.setDouble(1, getLevel() + value); + statement.setString(2, me.getPlayer().getUniqueId().toString()); + + statement.executeUpdate(); } - disconnect(); - } - - private void connect() throws SQLException { - state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;"); - state.setString(1, me.getPlayer().getUniqueId().toString()); - resultSet = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - } - - private void disconnect() throws SQLException { - resultSet.close(); - state.close(); } } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java index 85d0ca1..5b2bd9c 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java @@ -4,7 +4,6 @@ import org.bukkit.Location; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; -import ru.prisonlife.prisonapi.PrisonAPI; import java.io.File; import java.sql.PreparedStatement; @@ -14,6 +13,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import static ru.prisonlife.prisonapi.PrisonAPI.CONN; import static ru.prisonlife.prisonapi.PrisonAPI.PLUGIN_PATH; public class Prisoner { @@ -23,8 +23,6 @@ public class Prisoner { private Faction faction; private Wallet wallet; private Stats stats; - private PreparedStatement state; - private ResultSet resultSet; public Prisoner(Player player) { me = player; @@ -122,20 +120,35 @@ public class Prisoner { } public void register() throws SQLException { - state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;"); - state.setString(1, me.getUniqueId().toString()); - resultSet = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getUniqueId() + "'"); - if (!resultSet.next()) { - state.execute( - "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() - + "', '" + me.getUniqueId() + "', 1, 0, 'NONE', 0, 0, 0, 0, 0, 0, 0, 0);"); - state.execute("INSERT INTO daily_respect_task(NAME, UUID, COOLDOWN) VALUES ('" + me.getName() + "', '" + me.getUniqueId() + "', (3600 * 24));"); - level = new Level(this); - stats = new Stats(this); - wallet = new Wallet(this); + PreparedStatement statement = CONN.prepareStatement("SELECT UUID FROM player_stats WHERE UUID = ?"); + statement.setString(1, me.getUniqueId().toString()); + + try (ResultSet resultSet = statement.executeQuery()) { + if (!resultSet.next()) { + statement.close(); + + statement = CONN.prepareStatement( + "INSERT INTO player_stats(NAME, UUID, LEVEL, POINTS, FACTION, RESPECT, F_RANG, WALLET, " + + "G_TIME, D_BLOCKS, K_PLAYERS, K_MOBS, DEATHS) " + + "VALUES (?, ?, 1, 0, 'NONE', 0, 0, 0, 0, 0, 0, 0, 0)"); + statement.setString(1, getPlayer().getName()); + statement.setString(2, me.getUniqueId().toString()); + statement.executeUpdate(); + statement.close(); + + statement = CONN.prepareStatement( + "INSERT INTO daily_respect_task(NAME, UUID, COOLDOWN) " + + "VALUES (?, ?, ?)"); + statement.setString(1, getPlayer().getName()); + statement.setString(2, me.getUniqueId().toString()); + statement.setInt(3, (3600 * 24)); + statement.executeUpdate(); + + level = new Level(this); + stats = new Stats(this); + wallet = new Wallet(this); + } } - resultSet.close(); - state.close(); + statement.close(); } } \ No newline at end of file diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java index 6b14375..59ebf47 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java @@ -1,15 +1,13 @@ package ru.prisonlife.prisonapi.template; -import ru.prisonlife.prisonapi.PrisonAPI; - import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import static ru.prisonlife.prisonapi.PrisonAPI.CONN; + public class Score { - private PreparedStatement state; - private ResultSet resultSet; private Prisoner me; Score(Prisoner prisoner) { @@ -17,41 +15,29 @@ public class Score { } public double getPoints() throws SQLException { - connect(); - if (resultSet.first()) { - resultSet = state.executeQuery("SELECT POINTS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) { - return resultSet.getDouble(1); + try (PreparedStatement statement = CONN.prepareStatement("SELECT POINTS 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 0d; //TODO нужно или default значение, или exception + } } } - disconnect(); - return NullPointerException.class.hashCode(); } public void setPoints(double value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET POINTS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET POINTS = ? WHERE UUID = ?")) { + statement.setDouble(1, value); + statement.setString(2, me.getPlayer().getUniqueId().toString()); + + statement.executeUpdate(); } - disconnect(); } public void addPoints(double value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET POINTS = " + (getPoints() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - } - disconnect(); - } - - private void connect() throws SQLException { - state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;"); - state.setString(1, me.getPlayer().getUniqueId().toString()); - resultSet = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - } - - private void disconnect() throws SQLException { - resultSet.close(); - state.close(); + setPoints(getPoints() + value); } } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java index fbbc84d..cad3e4b 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Stats.java @@ -1,15 +1,13 @@ package ru.prisonlife.prisonapi.template; -import ru.prisonlife.prisonapi.PrisonAPI; - import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import static ru.prisonlife.prisonapi.PrisonAPI.CONN; + public class Stats { - private PreparedStatement state; - private ResultSet resultSet; private Prisoner me; Stats(Prisoner prisoner) { @@ -17,149 +15,137 @@ public class Stats { } public void setServerTime(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET G_TIME = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET G_TIME = ? WHERE UUID = ?")) { + statement.setDouble(1, value); + statement.setString(2, me.getPlayer().getUniqueId().toString()); + + statement.executeUpdate(); } - disconnect(); } public int getServerTime() throws SQLException { - connect(); - if (resultSet.first()) { - resultSet = state.executeQuery("SELECT G_TIME FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) { - return resultSet.getInt(1); + try (PreparedStatement statement = CONN.prepareStatement("SELECT G_TIME 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 + } } } - disconnect(); - return NullPointerException.class.hashCode(); } public void addServerTime(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET G_TIME = " + (getServerTime() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - } - disconnect(); + setServerTime(getServerTime() + value); } public void setBlocks(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET B = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET B = ? WHERE UUID = ?")) { + statement.setDouble(1, value); + statement.setString(2, me.getPlayer().getUniqueId().toString()); + + statement.executeUpdate(); } - disconnect(); } public int getBlocks() throws SQLException { - connect(); - if (resultSet.first()) { - resultSet = state.executeQuery("SELECT D_BLOCKS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) { - return resultSet.getInt(1); + try (PreparedStatement statement = CONN.prepareStatement("SELECT D_BLOCKS 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 + } } } - disconnect(); - return NullPointerException.class.hashCode(); } public void addBlocks(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET D_BLOCKS = " + (getBlocks() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - } - disconnect(); + setBlocks(getBlocks() + value); } public void setPlayers(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET K_PLAYERS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET K_PLAYERS = ? WHERE UUID = ?")) { + statement.setDouble(1, value); + statement.setString(2, me.getPlayer().getUniqueId().toString()); + + statement.executeUpdate(); } - disconnect(); } public int getPlayers() throws SQLException { - connect(); - if (resultSet.first()) { - resultSet = state.executeQuery("SELECT K_PLAYERS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) { - return resultSet.getInt(1); + try (PreparedStatement statement = CONN.prepareStatement("SELECT K_PLAYERS 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 + } } } - disconnect(); - return NullPointerException.class.hashCode(); } public void addPlayers(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET K_PLAYERS = " + (getPlayers() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - } - disconnect(); + setPlayers(getPlayers() + value); } public void setMobs(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET K_MOBS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET K_MOBS = ? WHERE UUID = ?")) { + statement.setDouble(1, value); + statement.setString(2, me.getPlayer().getUniqueId().toString()); + + statement.executeUpdate(); } - disconnect(); } public int getMobs() throws SQLException { - connect(); - if (resultSet.first()) { - resultSet = state.executeQuery("SELECT K_MOBS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) { - return resultSet.getInt(1); + try (PreparedStatement statement = CONN.prepareStatement("SELECT K_MOBS 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 + } } } - disconnect(); - return NullPointerException.class.hashCode(); } public void addMobs(int value) throws SQLException { - connect(); - if (resultSet.first()) - state.execute("UPDATE player_stats SET K_MOBS = " + (getMobs() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - disconnect(); + setMobs(getMobs() + value); } public void setDeaths(int value) throws SQLException { - connect(); - if (resultSet.first()) - state.execute("UPDATE player_stats SET DEATHS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - disconnect(); + try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET DEATHS = ? WHERE UUID = ?")) { + statement.setDouble(1, value); + statement.setString(2, me.getPlayer().getUniqueId().toString()); + + statement.executeUpdate(); + } } public int getDeaths() throws SQLException { - connect(); - if (resultSet.first()) { - resultSet = state.executeQuery("SELECT DEATHS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) - return resultSet.getInt(1); + try (PreparedStatement statement = CONN.prepareStatement("SELECT DEATHS 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 + } + } } - disconnect(); - return NullPointerException.class.hashCode(); } public void addDeaths(int value) throws SQLException { - connect(); - if (resultSet.first()) - state.execute("UPDATE player_stats SET DEATHS = " + (getDeaths() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - disconnect(); - } - - private void connect() throws SQLException { - state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;"); - state.setString(1, me.getPlayer().getUniqueId().toString()); - resultSet = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - } - - private void disconnect() throws SQLException { - resultSet.close(); - state.close(); + setDeaths(getDeaths() + value); } } diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java index aeb320a..cc9fd9d 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java @@ -1,15 +1,13 @@ package ru.prisonlife.prisonapi.template; -import ru.prisonlife.prisonapi.PrisonAPI; - import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import static ru.prisonlife.prisonapi.PrisonAPI.CONN; + public class Wallet { - private PreparedStatement state; - private ResultSet resultSet; private Prisoner me; Wallet(Prisoner prisoner) { @@ -17,49 +15,33 @@ public class Wallet { } public int getBalance() throws SQLException { - connect(); - if (resultSet.first()) { - resultSet = state.executeQuery("SELECT WALLET FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - if (resultSet.first()) { - return resultSet.getInt(1); + try (PreparedStatement statement = 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 + } } } - disconnect(); - return NullPointerException.class.hashCode(); } public void addBalance(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET WALLET = " + (getBalance() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - } - disconnect(); + setBalance(getBalance() + value); } public void deposit(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET WALLET = " + (getBalance() - value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - } - disconnect(); + setBalance(getBalance() - value); } public void setBalance(int value) throws SQLException { - connect(); - if (resultSet.first()) { - state.execute("UPDATE player_stats SET WALLET = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); + try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET WALLET = ? WHERE UUID = ?")) { + statement.setDouble(1, value); + statement.setString(2, me.getPlayer().getUniqueId().toString()); + + statement.executeUpdate(); } - disconnect(); - } - - private void connect() throws SQLException { - state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;"); - state.setString(1, me.getPlayer().getUniqueId().toString()); - resultSet = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'"); - } - - private void disconnect() throws SQLException { - resultSet.close(); - state.close(); } } From 26a463fbd502d73daaeb2f41ce1c98db513d2731 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Thu, 21 Feb 2019 00:49:41 +0300 Subject: [PATCH 11/11] fix throws --- .../java/ru/prisonlife/PrisonAPI/template/Manager.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java index fcdf9ee..5d314f0 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java @@ -1,6 +1,5 @@ package ru.prisonlife.prisonapi.template; -import com.sun.media.sound.InvalidDataException; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import ru.prisonlife.prisonapi.PrisonAPI; @@ -85,11 +84,7 @@ public class Manager { e.printStackTrace(); } } else { - try { - throw new InvalidDataException(); - } catch (InvalidDataException e) { - e.printStackTrace(); - } + throw new RuntimeException("data.size() != 6"); } }