From 8a695ae9090064d5261b0d9d37d0aeae1793f30f Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Sun, 24 Feb 2019 16:03:56 +0300 Subject: [PATCH] crlf -> lf --- .../ru/prisonlife/PrisonAPI/PrisonAPI.java | 116 +++---- .../prisonlife/PrisonAPI/template/Level.java | 114 +++---- .../PrisonAPI/template/Prisoner.java | 306 +++++++++--------- .../prisonlife/PrisonAPI/template/Score.java | 86 ++--- .../prisonlife/PrisonAPI/template/Wallet.java | 94 +++--- 5 files changed, 358 insertions(+), 358 deletions(-) diff --git a/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java b/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java index fa629cf..6dd553f 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/PrisonAPI.java @@ -1,58 +1,58 @@ -package ru.prisonlife.prisonapi; - -import org.bukkit.plugin.java.JavaPlugin; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; - -public class PrisonAPI extends JavaPlugin { - - public static final String PLUGIN_PATH = "plugins/PrisonManager"; - - public enum Factions { - 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; - - public void onEnable() { - try { - CONN = DriverManager.getConnection( - "jdbc:mysql://localhost:3306/prison4life", - "root", "root"); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public void onDisable() { - try { - if (!CONN.isClosed()) { - CONN.close(); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } -} +package ru.prisonlife.prisonapi; + +import org.bukkit.plugin.java.JavaPlugin; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class PrisonAPI extends JavaPlugin { + + public static final String PLUGIN_PATH = "plugins/PrisonManager"; + + public enum Factions { + 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; + + public void onEnable() { + try { + CONN = DriverManager.getConnection( + "jdbc:mysql://localhost:3306/prison4life", + "root", "root"); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void onDisable() { + try { + if (!CONN.isClosed()) { + CONN.close(); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java index 87a3f1b..950cc39 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Level.java @@ -1,57 +1,57 @@ -package ru.prisonlife.prisonapi.template; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import static ru.prisonlife.prisonapi.PrisonAPI.CONN; - -public class Level { - - private Prisoner me; - private Score score; - - Level(Prisoner prisoner) { - me = prisoner; - score = new Score(me); - } - - public Score getScore() throws SQLException { - //FIXME приведи в порядок метод - /* - connect(); - if (resultSet.first()) { - return this.score; - } - disconnect(); - */ - return null; - } - - public double getLevel() throws SQLException, NullPointerException { - 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 - } - } - } - } - - public void addLevel(double value) throws SQLException, NullPointerException { - setLevel(getLevel() + value); - } - - public void setLevel(double value) throws SQLException, NullPointerException { - 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(); - } - } -} +package ru.prisonlife.prisonapi.template; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import static ru.prisonlife.prisonapi.PrisonAPI.CONN; + +public class Level { + + private Prisoner me; + private Score score; + + Level(Prisoner prisoner) { + me = prisoner; + score = new Score(me); + } + + public Score getScore() throws SQLException { + //FIXME приведи в порядок метод + /* + connect(); + if (resultSet.first()) { + return this.score; + } + disconnect(); + */ + return null; + } + + public double getLevel() throws SQLException, NullPointerException { + 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 + } + } + } + } + + public void addLevel(double value) throws SQLException, NullPointerException { + setLevel(getLevel() + value); + } + + public void setLevel(double value) throws SQLException, NullPointerException { + 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(); + } + } +} diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java index 5b2bd9c..39aec0f 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Prisoner.java @@ -1,154 +1,154 @@ -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 java.io.File; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -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 { - - private Player me; - private Level level; - private Faction faction; - private Wallet wallet; - private Stats stats; - - public Prisoner(Player player) { - me = player; - level = new Level(this); - wallet = new Wallet(this); - faction = new Faction(this); - stats = new Stats(this); - } - - public Player getPlayer() { - return me; - } - - 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())) { - FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file); - List> data = new ArrayList<>(); - List fromConfig = fileConfiguration.getIntegerList("DIAGONAL_POINTS"), - min = new ArrayList<>(), max = new ArrayList<>(); - int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()}; - 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))); - } - int c = 0; - 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) { - return file.getName().replace("PRISON_", "").replace(".yml", ""); - } - } - return "Not Prison"; - } - - public String getTerritory(String type) { - String prison = getPrison(); - if (!prison.equals("Not Prison") && (type.equals("name") || type.equals("owner"))) { - Location loc = me.getLocation(); - FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(new File(PLUGIN_PATH, "PRISON_" + prison + ".yml")); - try { - if (fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false).size() != 0) { - for (String terr : fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false)) { - List> data = new ArrayList<>(); - 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(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))); - } - int c = 0; - 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) { - return type.equals("name") ? fileConfiguration.getString("TERRITORIES." + terr + ".NAME") : - (type.equals("owner") ? fileConfiguration.getString("TERRITORIES." + terr + ".OWNER") : null); - } - } - } - } catch (NullPointerException z) { - } - } - return "Not Territory"; - } - - public Faction getFaction() { - return faction; - } - - public Wallet getWallet() { - return wallet; - } - - public Stats getStats() { - return stats; - } - - public void register() throws SQLException { - 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); - } - } - statement.close(); - } +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 java.io.File; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +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 { + + private Player me; + private Level level; + private Faction faction; + private Wallet wallet; + private Stats stats; + + public Prisoner(Player player) { + me = player; + level = new Level(this); + wallet = new Wallet(this); + faction = new Faction(this); + stats = new Stats(this); + } + + public Player getPlayer() { + return me; + } + + 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())) { + FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file); + List> data = new ArrayList<>(); + List fromConfig = fileConfiguration.getIntegerList("DIAGONAL_POINTS"), + min = new ArrayList<>(), max = new ArrayList<>(); + int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()}; + 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))); + } + int c = 0; + 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) { + return file.getName().replace("PRISON_", "").replace(".yml", ""); + } + } + return "Not Prison"; + } + + public String getTerritory(String type) { + String prison = getPrison(); + if (!prison.equals("Not Prison") && (type.equals("name") || type.equals("owner"))) { + Location loc = me.getLocation(); + FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(new File(PLUGIN_PATH, "PRISON_" + prison + ".yml")); + try { + if (fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false).size() != 0) { + for (String terr : fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false)) { + List> data = new ArrayList<>(); + 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(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))); + } + int c = 0; + 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) { + return type.equals("name") ? fileConfiguration.getString("TERRITORIES." + terr + ".NAME") : + (type.equals("owner") ? fileConfiguration.getString("TERRITORIES." + terr + ".OWNER") : null); + } + } + } + } catch (NullPointerException z) { + } + } + return "Not Territory"; + } + + public Faction getFaction() { + return faction; + } + + public Wallet getWallet() { + return wallet; + } + + public Stats getStats() { + return stats; + } + + public void register() throws SQLException { + 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); + } + } + 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 59ebf47..2f4e525 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Score.java @@ -1,43 +1,43 @@ -package ru.prisonlife.prisonapi.template; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import static ru.prisonlife.prisonapi.PrisonAPI.CONN; - -public class Score { - - private Prisoner me; - - Score(Prisoner prisoner) { - me = prisoner; - } - - public double getPoints() throws SQLException { - 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 - } - } - } - } - - public void setPoints(double value) throws SQLException { - 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(); - } - } - - public void addPoints(double value) throws SQLException { - setPoints(getPoints() + value); - } -} +package ru.prisonlife.prisonapi.template; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import static ru.prisonlife.prisonapi.PrisonAPI.CONN; + +public class Score { + + private Prisoner me; + + Score(Prisoner prisoner) { + me = prisoner; + } + + public double getPoints() throws SQLException { + 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 + } + } + } + } + + public void setPoints(double value) throws SQLException { + 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(); + } + } + + public void addPoints(double value) throws SQLException { + setPoints(getPoints() + value); + } +} diff --git a/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java b/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java index cc9fd9d..2ee483c 100644 --- a/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java +++ b/src/main/java/ru/prisonlife/PrisonAPI/template/Wallet.java @@ -1,47 +1,47 @@ -package ru.prisonlife.prisonapi.template; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import static ru.prisonlife.prisonapi.PrisonAPI.CONN; - -public class Wallet { - - private Prisoner me; - - Wallet(Prisoner prisoner) { - me = prisoner; - } - - public int getBalance() throws SQLException { - 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 - } - } - } - } - - public void addBalance(int value) throws SQLException { - setBalance(getBalance() + value); - } - - public void deposit(int value) throws SQLException { - setBalance(getBalance() - value); - } - - public void setBalance(int value) throws SQLException { - try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET WALLET = ? WHERE UUID = ?")) { - statement.setDouble(1, value); - statement.setString(2, me.getPlayer().getUniqueId().toString()); - - statement.executeUpdate(); - } - } -} +package ru.prisonlife.prisonapi.template; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import static ru.prisonlife.prisonapi.PrisonAPI.CONN; + +public class Wallet { + + private Prisoner me; + + Wallet(Prisoner prisoner) { + me = prisoner; + } + + public int getBalance() throws SQLException { + 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 + } + } + } + } + + public void addBalance(int value) throws SQLException { + setBalance(getBalance() + value); + } + + public void deposit(int value) throws SQLException { + setBalance(getBalance() - value); + } + + public void setBalance(int value) throws SQLException { + try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET WALLET = ? WHERE UUID = ?")) { + statement.setDouble(1, value); + statement.setString(2, me.getPlayer().getUniqueId().toString()); + + statement.executeUpdate(); + } + } +}