По просьбе Димона + mini-update 0.1.2
This commit is contained in:
3
src/main/java/META-INF/MANIFEST.MF
Normal file
3
src/main/java/META-INF/MANIFEST.MF
Normal file
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: ru.prisonlife.api.PrisonAPI
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
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<List<Integer>> data = new ArrayList<>();
|
||||
List<Integer> 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<List<Integer>> data = new ArrayList<>();
|
||||
List<Integer> 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();
|
||||
}
|
||||
}
|
||||
@@ -1,58 +1,62 @@
|
||||
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.api;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
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 static final Plugin plugin = Bukkit.getPluginManager().getPlugin("PrisonAPI");
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package ru.prisonlife.prisonapi.template;
|
||||
package ru.prisonlife.api.template;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import ru.prisonlife.prisonapi.PrisonAPI.Factions;
|
||||
import ru.prisonlife.api.PrisonAPI;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@@ -9,8 +9,6 @@ import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static ru.prisonlife.prisonapi.PrisonAPI.CONN;
|
||||
|
||||
public class Faction {
|
||||
|
||||
private Prisoner me;
|
||||
@@ -20,7 +18,7 @@ public class Faction {
|
||||
}
|
||||
|
||||
public String getType() throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("SELECT FACTION FROM player_stats WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT FACTION FROM player_stats WHERE UUID = ?")) {
|
||||
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
try (ResultSet resultSet = statement.executeQuery()) {
|
||||
@@ -34,12 +32,12 @@ public class Faction {
|
||||
}
|
||||
|
||||
public int getId() throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("SELECT FACTION FROM player_stats WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.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 PrisonAPI.Factions.valueOf(resultSet.getString(1)).getId();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,7 +46,7 @@ public class Faction {
|
||||
}
|
||||
|
||||
public int getRangId() throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("SELECT F_RANG FROM player_stats WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT F_RANG FROM player_stats WHERE UUID = ?")) {
|
||||
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
try (ResultSet resultSet = statement.executeQuery()) {
|
||||
@@ -75,7 +73,7 @@ public class Faction {
|
||||
}
|
||||
|
||||
public void setRang(int value) throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET F_RANG = ? WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("UPDATE player_stats SET F_RANG = ? WHERE UUID = ?")) {
|
||||
statement.setInt(1, value);
|
||||
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
@@ -84,8 +82,8 @@ public class Faction {
|
||||
}
|
||||
|
||||
public void setFaction(int id) throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET FACTION = ? WHERE UUID = ?")) {
|
||||
statement.setInt(1, Factions.valueOf(id).getId());
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("UPDATE player_stats SET FACTION = ? WHERE UUID = ?")) {
|
||||
statement.setString(1, PrisonAPI.Factions.valueOf(id).name());
|
||||
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
statement.executeUpdate();
|
||||
@@ -93,7 +91,7 @@ public class Faction {
|
||||
}
|
||||
|
||||
public int getRespect() throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("SELECT RESPECT FROM prison4life.player_stats WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT RESPECT FROM prison4life.player_stats WHERE UUID = ?")) {
|
||||
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
try (ResultSet resultSet = statement.executeQuery()) {
|
||||
@@ -111,7 +109,7 @@ public class Faction {
|
||||
}
|
||||
|
||||
public void setRespect(int value) throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET RESPECT = ? WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("UPDATE player_stats SET RESPECT = ? WHERE UUID = ?")) {
|
||||
statement.setInt(1, value);
|
||||
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
@@ -120,7 +118,7 @@ public class Faction {
|
||||
}
|
||||
|
||||
public int getRespectDailyCooldown() throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("SELECT COOLDOWN FROM daily_respect_task WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT COOLDOWN FROM daily_respect_task WHERE UUID = ?")) {
|
||||
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
try (ResultSet resultSet = statement.executeQuery()) {
|
||||
@@ -138,7 +136,7 @@ public class Faction {
|
||||
}
|
||||
|
||||
public void setRespectDailyCooldown(int value) throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("UPDATE daily_respect_task SET COOLDOWN = ? WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("UPDATE daily_respect_task SET COOLDOWN = ? WHERE UUID = ?")) {
|
||||
statement.setInt(1, value);
|
||||
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
@@ -1,57 +1,49 @@
|
||||
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.api.template;
|
||||
|
||||
import ru.prisonlife.api.PrisonAPI;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Level {
|
||||
|
||||
private Prisoner me;
|
||||
private Score score;
|
||||
|
||||
Level(Prisoner prisoner) {
|
||||
me = prisoner;
|
||||
score = new Score(me);
|
||||
}
|
||||
|
||||
public Score getScore() throws SQLException {
|
||||
return score;
|
||||
}
|
||||
|
||||
public double getLevel() throws SQLException, NullPointerException {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT LEVEL FROM player_stats WHERE UUID = ?")) {
|
||||
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
try (ResultSet resultSet = statement.executeQuery()) {
|
||||
if (resultSet.next()) {
|
||||
return resultSet.getDouble(1);
|
||||
} else {
|
||||
return 1d; //TODO нужно или default значение, или exception
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addLevel(double value) throws SQLException, NullPointerException {
|
||||
setLevel(getLevel() + value);
|
||||
}
|
||||
|
||||
public void setLevel(double value) throws SQLException, NullPointerException {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("UPDATE player_stats SET LEVEL = ? WHERE UUID = ?")) {
|
||||
statement.setDouble(1, getLevel() + value);
|
||||
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
statement.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package ru.prisonlife.prisonapi.template;
|
||||
package ru.prisonlife.api.template;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import ru.prisonlife.prisonapi.PrisonAPI;
|
||||
import ru.prisonlife.api.PrisonAPI;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -10,15 +12,13 @@ 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(PLUGIN_PATH + "/", id);
|
||||
file = new File(PrisonAPI.PLUGIN_PATH + "/", "PRISON_" + id + ".yml");
|
||||
fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
@@ -139,7 +139,28 @@ public class Manager {
|
||||
}
|
||||
|
||||
public List<String> getAllTerrs() {
|
||||
return new ArrayList<>(fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false));
|
||||
List<String> terrs = new ArrayList<>();
|
||||
for(String t : fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false))
|
||||
terrs.add(t);
|
||||
return terrs;
|
||||
}
|
||||
|
||||
public List<String> getCages() {
|
||||
List<String> cages = new ArrayList<>();
|
||||
for(String c : fileConfiguration.getConfigurationSection("CAGES").getKeys(false))
|
||||
cages.add(c);
|
||||
return cages;
|
||||
}
|
||||
|
||||
public List<Integer> getPointCage(String cage) {
|
||||
return new ArrayList<>(fileConfiguration.getIntegerList("CAGES." + cage));
|
||||
}
|
||||
|
||||
public void teleportInToCage(Prisoner prs, String cage) {
|
||||
List<Integer> data =fileConfiguration.getIntegerList("CAGES." + cage);
|
||||
Location loc = new Location(Bukkit.getWorld(fileConfiguration.getString("WORLD")),
|
||||
data.get(0) + 0.5, data.get(1), data.get(2) + 0.5);
|
||||
prs.getPlayer().teleport(loc);
|
||||
}
|
||||
|
||||
public String selectFactType(int id) {
|
||||
101
src/main/java/ru/prisonlife/api/template/Policeman.java
Normal file
101
src/main/java/ru/prisonlife/api/template/Policeman.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package ru.prisonlife.api.template;
|
||||
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import ru.prisonlife.api.PrisonAPI;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class Policeman extends Prisoner {
|
||||
|
||||
private Map<Prisoner, BukkitRunnable> timeInCage = new HashMap<>();
|
||||
|
||||
public Policeman(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
public void arrestPrisoner(Prisoner prs) throws SQLException {
|
||||
if(prs.getPlayer().isOnline()) {
|
||||
Manager mng = new Manager(super.getPrison());
|
||||
List<String> all_cages = mng.getCages();
|
||||
PreparedStatement st = PrisonAPI.CONN.prepareStatement("SELECT UUID FROM player_stats WHERE UUID = ?");
|
||||
st.setString(1, me.getUniqueId().toString());
|
||||
try(ResultSet resultSet = st.executeQuery()) {
|
||||
if(!resultSet.next()) {
|
||||
int su = prs.getSuspect();
|
||||
st.close();
|
||||
st = PrisonAPI.CONN.prepareStatement(
|
||||
"INSERT INTO players_in_cages(NAME, UUID, TIME_IN_CAGE, BLOCKS_LEFT) " +
|
||||
"VALUES (?, ?, ?, ?)");
|
||||
st.setString(1, getPlayer().getName());
|
||||
st.setString(2, me.getUniqueId().toString());
|
||||
st.setInt(3, (su * 6));
|
||||
st.setInt(4, (su * 100));
|
||||
st.executeUpdate();
|
||||
}
|
||||
}
|
||||
st.close();
|
||||
prs.setSuspect(0);
|
||||
mng.teleportInToCage(prs, all_cages.get(new Random().nextInt(all_cages.size())));
|
||||
FileConfiguration configurationSuspect = YamlConfiguration.loadConfiguration(new File("plugins/PrisonSuspect/", "parameters.yml"));
|
||||
String actionMessage = ChatColor.translateAlternateColorCodes('&',
|
||||
configurationSuspect.getString("MESSAGES.ACTION_BAR_PROGRESS"));
|
||||
BukkitRunnable actionBar = new BukkitRunnable() {//"MESSAGES.WHEN_PRISONER_CAN_EXIT_FROM_CAGE"
|
||||
@Override
|
||||
public void run() {
|
||||
prs.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionMessage));
|
||||
}
|
||||
};
|
||||
timeInCage.put(prs, new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() { // Future = Пометить, что когда in Cage и вышел, то удалить поток, а если зашёл и in Cage - запустить ~ Optimize
|
||||
try {
|
||||
int time = 0;
|
||||
String uuid = prs.getPlayer().getUniqueId().toString();
|
||||
PreparedStatement st = PrisonAPI.CONN.prepareStatement(
|
||||
"SELECT TIME_IN_CAGE FROM players_in_cages WHERE UUID = ?");
|
||||
st.setString(1, uuid);
|
||||
try(ResultSet resultSet = st.executeQuery()) {
|
||||
if(resultSet.next())
|
||||
time = resultSet.getInt(1);
|
||||
}
|
||||
if(time == 0) {
|
||||
prs.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
configurationSuspect.getString("MESSAGES.WHEN_PRISONER_CAN_EXIT_FROM_CAGE")));
|
||||
actionBar.cancel();
|
||||
cancel();
|
||||
timeInCage.remove(prs);
|
||||
st = PrisonAPI.CONN.prepareStatement("DELETE FROM players_in_cages WHERE UUID = ?");
|
||||
st.setString(1, uuid);
|
||||
st.execute();
|
||||
} else {
|
||||
if(prs.getPlayer().isOnline()) {
|
||||
st = PrisonAPI.CONN.prepareStatement("UPDATE players_in_cages SET TIME_IN_CAGE = " + (time - 1) + " WHERE UUID = ?");
|
||||
st.setString(1, uuid);
|
||||
st.execute();
|
||||
}
|
||||
}
|
||||
st.close();
|
||||
} catch(SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
int m = 20 * 60;
|
||||
actionBar.runTaskTimer(PrisonAPI.plugin, 5, 5);
|
||||
timeInCage.get(prs).runTaskTimer(PrisonAPI.plugin, m, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
259
src/main/java/ru/prisonlife/api/template/Prisoner.java
Normal file
259
src/main/java/ru/prisonlife/api/template/Prisoner.java
Normal file
@@ -0,0 +1,259 @@
|
||||
package ru.prisonlife.api.template;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import ru.prisonlife.api.PrisonAPI;
|
||||
|
||||
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;
|
||||
|
||||
public class Prisoner {
|
||||
|
||||
protected Player me;
|
||||
protected Level level;
|
||||
protected Faction faction;
|
||||
protected Wallet wallet;
|
||||
protected 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(PrisonAPI.PLUGIN_PATH).listFiles())) {
|
||||
FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||
List<List<Integer>> data = new ArrayList<>();
|
||||
List<Integer> 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 prison = getPrison();
|
||||
if(!prison.equals("Not Prison")) {
|
||||
Location loc = me.getLocation();
|
||||
FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(new File(PrisonAPI.PLUGIN_PATH, "PRISON_" + prison + ".yml"));
|
||||
try {
|
||||
if(fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false).size() != 0) {
|
||||
for(String terr : fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false)) {
|
||||
List<List<Integer>> data = new ArrayList<>();
|
||||
List<Integer> 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 fileConfiguration.getString("TERRITORIES." + terr + ".NAME");
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException z) {
|
||||
}
|
||||
}
|
||||
return "Not Territory";
|
||||
}
|
||||
|
||||
public void teleportToFactionSpawn() {
|
||||
try {
|
||||
Prisoner ps = new Prisoner(me);
|
||||
Manager mng = new Manager(getPrison());
|
||||
String f = ps.getFaction().getType();
|
||||
List<Integer> c = mng.getSpawnCords(ps.getFaction().getId());
|
||||
if(!f.equals("NONE") && c.size() != 0)
|
||||
me.teleport(new Location(Bukkit.getWorld(mng.getWorld()), c.get(0) + 0.5, c.get(1), c.get(2) + 0.5));
|
||||
} catch(SQLException z) {
|
||||
z.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public int getSuspect() {
|
||||
try {
|
||||
try(PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT SUSPECT FROM player_stats WHERE UUID = ?")) {
|
||||
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
try(ResultSet resultSet = statement.executeQuery()) {
|
||||
if(resultSet.next())
|
||||
return resultSet.getInt(1);
|
||||
}
|
||||
}
|
||||
} catch(SQLException z) {
|
||||
z.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setSuspect(int value) {
|
||||
try {
|
||||
try(PreparedStatement statement = PrisonAPI.CONN.prepareStatement("UPDATE player_stats SET SUSPECT = ? WHERE UUID = ?")) {
|
||||
statement.setInt(1, value);
|
||||
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
statement.executeUpdate();
|
||||
}
|
||||
} catch(SQLException z) {
|
||||
z.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void addSuspect(int value) {
|
||||
int su = getSuspect() + value;
|
||||
setSuspect(su);
|
||||
if(su > 6)
|
||||
setSuspect(su - (su - 6));
|
||||
}
|
||||
|
||||
public int getTimeLeftInCage() {
|
||||
try {
|
||||
PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT TIME_IN_CAGE FROM players_in_cages WHERE UUID = ?");
|
||||
statement.setString(1, me.getUniqueId().toString());
|
||||
try(ResultSet resultSet = statement.executeQuery()) {
|
||||
if(resultSet.next())
|
||||
return resultSet.getInt(1);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setTimeLeftInCage(int value) {
|
||||
try {
|
||||
PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT TIME_IN_CAGE FROM players_in_cages WHERE UUID = ?");
|
||||
statement.setString(1, me.getUniqueId().toString());
|
||||
try(ResultSet resultSet = statement.executeQuery()) {
|
||||
if(resultSet.next()) {
|
||||
statement = PrisonAPI.CONN.prepareStatement("UPDATE players_in_cages SET TIME_IN_CAGE = ? WHERE UUID = ?");
|
||||
statement.setInt(1, value);
|
||||
statement.setString(2, me.getUniqueId().toString());
|
||||
statement.execute();
|
||||
}
|
||||
}
|
||||
} catch(SQLException z) {
|
||||
z.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public int getBlocksLeftToBreak() {
|
||||
try {
|
||||
PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT BLOCKS_LEFT FROM players_in_cages WHERE UUID = ?");
|
||||
statement.setString(1, me.getUniqueId().toString());
|
||||
try(ResultSet resultSet = statement.executeQuery()) {
|
||||
if(resultSet.next())
|
||||
return resultSet.getInt(1);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isLocateInCage() {
|
||||
try {
|
||||
PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT UUID FROM players_in_cages WHERE UUID = ?");
|
||||
statement.setString(1, me.getUniqueId().toString());
|
||||
try(ResultSet resultSet = statement.executeQuery()) {
|
||||
if(resultSet.next())
|
||||
return true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Faction getFaction() {
|
||||
return faction;
|
||||
}
|
||||
|
||||
public Wallet getWallet() {
|
||||
return wallet;
|
||||
}
|
||||
|
||||
public Stats getStats() {
|
||||
return stats;
|
||||
}
|
||||
|
||||
public void register() throws SQLException {
|
||||
PreparedStatement statement = PrisonAPI.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 = PrisonAPI.CONN.prepareStatement(
|
||||
"INSERT INTO player_stats(NAME, UUID, LEVEL, POINTS, FACTION, RESPECT, F_RANG, SUSPECT, WALLET, " +
|
||||
"G_TIME, D_BLOCKS, K_PLAYERS, K_MOBS, DEATHS) "
|
||||
+ "VALUES (?, ?, 1, 0, 'NONE', 0, 0, 0, 0, 0, 0, 0, 0, 0)");
|
||||
statement.setString(1, getPlayer().getName());
|
||||
statement.setString(2, me.getUniqueId().toString());
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
|
||||
statement = PrisonAPI.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();
|
||||
}
|
||||
}
|
||||
@@ -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.api.template;
|
||||
|
||||
import ru.prisonlife.api.PrisonAPI;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Score {
|
||||
|
||||
private Prisoner me;
|
||||
|
||||
Score(Prisoner prisoner) {
|
||||
me = prisoner;
|
||||
}
|
||||
|
||||
public double getPoints() throws SQLException {
|
||||
try (PreparedStatement statement = PrisonAPI.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 = PrisonAPI.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);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package ru.prisonlife.prisonapi.template;
|
||||
package ru.prisonlife.api.template;
|
||||
|
||||
import ru.prisonlife.api.PrisonAPI;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static ru.prisonlife.prisonapi.PrisonAPI.CONN;
|
||||
|
||||
public class Stats {
|
||||
|
||||
private Prisoner me;
|
||||
@@ -15,7 +15,7 @@ public class Stats {
|
||||
}
|
||||
|
||||
public void setServerTime(int value) throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET G_TIME = ? WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("UPDATE player_stats SET G_TIME = ? WHERE UUID = ?")) {
|
||||
statement.setDouble(1, value);
|
||||
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Stats {
|
||||
}
|
||||
|
||||
public int getServerTime() throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("SELECT G_TIME FROM player_stats WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT G_TIME FROM player_stats WHERE UUID = ?")) {
|
||||
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
try (ResultSet resultSet = statement.executeQuery()) {
|
||||
@@ -42,7 +42,7 @@ public class Stats {
|
||||
}
|
||||
|
||||
public void setBlocks(int value) throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET B = ? WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("UPDATE player_stats SET B = ? WHERE UUID = ?")) {
|
||||
statement.setDouble(1, value);
|
||||
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
@@ -51,7 +51,7 @@ public class Stats {
|
||||
}
|
||||
|
||||
public int getBlocks() throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("SELECT D_BLOCKS FROM player_stats WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT D_BLOCKS FROM player_stats WHERE UUID = ?")) {
|
||||
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
try (ResultSet resultSet = statement.executeQuery()) {
|
||||
@@ -69,7 +69,7 @@ public class Stats {
|
||||
}
|
||||
|
||||
public void setPlayers(int value) throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET K_PLAYERS = ? WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("UPDATE player_stats SET K_PLAYERS = ? WHERE UUID = ?")) {
|
||||
statement.setDouble(1, value);
|
||||
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
@@ -78,7 +78,7 @@ public class Stats {
|
||||
}
|
||||
|
||||
public int getPlayers() throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("SELECT K_PLAYERS FROM player_stats WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT K_PLAYERS FROM player_stats WHERE UUID = ?")) {
|
||||
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
try (ResultSet resultSet = statement.executeQuery()) {
|
||||
@@ -96,7 +96,7 @@ public class Stats {
|
||||
}
|
||||
|
||||
public void setMobs(int value) throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET K_MOBS = ? WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("UPDATE player_stats SET K_MOBS = ? WHERE UUID = ?")) {
|
||||
statement.setDouble(1, value);
|
||||
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
@@ -105,7 +105,7 @@ public class Stats {
|
||||
}
|
||||
|
||||
public int getMobs() throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("SELECT K_MOBS FROM player_stats WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT K_MOBS FROM player_stats WHERE UUID = ?")) {
|
||||
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
try (ResultSet resultSet = statement.executeQuery()) {
|
||||
@@ -123,7 +123,7 @@ public class Stats {
|
||||
}
|
||||
|
||||
public void setDeaths(int value) throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET DEATHS = ? WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("UPDATE player_stats SET DEATHS = ? WHERE UUID = ?")) {
|
||||
statement.setDouble(1, value);
|
||||
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
@@ -132,7 +132,7 @@ public class Stats {
|
||||
}
|
||||
|
||||
public int getDeaths() throws SQLException {
|
||||
try (PreparedStatement statement = CONN.prepareStatement("SELECT DEATHS FROM player_stats WHERE UUID = ?")) {
|
||||
try (PreparedStatement statement = PrisonAPI.CONN.prepareStatement("SELECT DEATHS FROM player_stats WHERE UUID = ?")) {
|
||||
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
try (ResultSet resultSet = statement.executeQuery()) {
|
||||
@@ -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.api.template;
|
||||
|
||||
import ru.prisonlife.api.PrisonAPI;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Wallet {
|
||||
|
||||
private Prisoner me;
|
||||
|
||||
Wallet(Prisoner prisoner) {
|
||||
me = prisoner;
|
||||
}
|
||||
|
||||
public int getBalance() throws SQLException {
|
||||
try (PreparedStatement statement = PrisonAPI.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 = PrisonAPI.CONN.prepareStatement("UPDATE player_stats SET WALLET = ? WHERE UUID = ?")) {
|
||||
statement.setDouble(1, value);
|
||||
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||
|
||||
statement.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
name: PrisonAPI
|
||||
version: ${project.version}
|
||||
authors: [Overlord_S, Prot_CN, Wani4ka, DmitriyMX]
|
||||
main: ru.prisonlife.prisonapi.PrisonAPI
|
||||
main: ru.prisonlife.api.PrisonAPI
|
||||
Reference in New Issue
Block a user