Merge branch 'dmitriymx/dev' into dev
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,3 +1,10 @@
|
|||||||
|
## IDEA ##
|
||||||
.idea/
|
.idea/
|
||||||
|
out/
|
||||||
*.iml
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
*.ids
|
||||||
|
|
||||||
|
## MAVEN ##
|
||||||
target/
|
target/
|
||||||
|
|||||||
43
pom.xml
43
pom.xml
@@ -5,8 +5,14 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>ru.prisonlife</groupId>
|
<groupId>ru.prisonlife</groupId>
|
||||||
<artifactId>PrisonAPI</artifactId>
|
<artifactId>prison-api</artifactId>
|
||||||
<version>0.0.4</version>
|
<version>0.1.0.4</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.encoding>UTF-8</java.encoding>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<bukkit.version>1.12-R0.1</bukkit.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
@@ -14,12 +20,43 @@
|
|||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.12-R0.1-SNAPSHOT</version>
|
<version>${bukkit.version}-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
<encoding>${java.encoding}</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.0</version>
|
||||||
|
<configuration>
|
||||||
|
<argLine>-Dfile.encoding=${java.encoding}</argLine>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ru.prisonlife.PrisonAPI;
|
package ru.prisonlife.prisonapi;
|
||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@@ -7,23 +7,52 @@ import java.sql.DriverManager;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public class PrisonAPI extends JavaPlugin {
|
public class PrisonAPI extends JavaPlugin {
|
||||||
public static Connection CONN;
|
|
||||||
|
public static final String PLUGIN_PATH = "plugins/PrisonManager";
|
||||||
|
|
||||||
public enum Factions {
|
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;
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
try {
|
try {
|
||||||
CONN = DriverManager.getConnection(
|
CONN = DriverManager.getConnection(
|
||||||
"jdbc:mysql://localhost:3306/prison4life",
|
"jdbc:mysql://localhost:3306/prison4life",
|
||||||
"root", "root");
|
"root", "root");
|
||||||
} catch (SQLException e) { e.printStackTrace(); }
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
try {
|
try {
|
||||||
if(!CONN.isClosed())
|
if (!CONN.isClosed()) {
|
||||||
CONN.close();
|
CONN.close();
|
||||||
} catch (SQLException e) { e.printStackTrace(); }
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,58 +1,65 @@
|
|||||||
package ru.prisonlife.PrisonAPI.template;
|
package ru.prisonlife.prisonapi.template;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import ru.prisonlife.prisonapi.PrisonAPI.Factions;
|
||||||
import ru.prisonlife.PrisonAPI.PrisonAPI;
|
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static ru.prisonlife.prisonapi.PrisonAPI.CONN;
|
||||||
|
|
||||||
public class Faction {
|
public class Faction {
|
||||||
private PreparedStatement state;
|
|
||||||
private ResultSet r_set;
|
|
||||||
private Prisoner me;
|
private Prisoner me;
|
||||||
|
|
||||||
Faction(Prisoner prisoner) {
|
Faction(Prisoner prisoner) {
|
||||||
me = prisoner;
|
me = prisoner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getType() throws SQLException {
|
public String getType() throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("SELECT FACTION FROM player_stats WHERE UUID = ?")) {
|
||||||
if(r_set.first()) {
|
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
|
||||||
if(r_set.first())
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
return r_set.getString(1);
|
if (resultSet.next()) {
|
||||||
}
|
return resultSet.getString(1);
|
||||||
dis_t();
|
} else {
|
||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getId() throws SQLException {
|
public int getId() throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("SELECT FACTION FROM player_stats WHERE UUID = ?")) {
|
||||||
if(r_set.first()) {
|
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
|
||||||
if(r_set.first())
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
for(int i = 0; i < PrisonAPI.Factions.values().length; i++)
|
if (resultSet.next()) {
|
||||||
if(PrisonAPI.Factions.values()[i].name().equals(r_set.getString(1)))
|
return Factions.valueOf(resultSet.getString(1)).getId();
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
dis_t();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRangId() throws SQLException {
|
public int getRangId() throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("SELECT F_RANG FROM player_stats WHERE UUID = ?")) {
|
||||||
if(r_set.first()) {
|
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT F_RANG FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
|
||||||
if(r_set.first())
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
return r_set.getInt(1);
|
if (resultSet.next()) {
|
||||||
}
|
return resultSet.getInt(1);
|
||||||
dis_t();
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getRangType() throws SQLException {
|
public String getRangType() throws SQLException {
|
||||||
String[][] post = {
|
String[][] post = {
|
||||||
@@ -64,93 +71,92 @@ public class Faction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addRang(int value) throws SQLException {
|
public void addRang(int value) throws SQLException {
|
||||||
con_t();
|
setRang(getRangId() + value);
|
||||||
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 {
|
public void setRang(int value) throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET F_RANG = ? WHERE UUID = ?")) {
|
||||||
if(r_set.first())
|
statement.setInt(1, value);
|
||||||
state.execute("UPDATE player_stats SET F_RANG = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||||
dis_t();
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFaction(int id) throws SQLException {
|
public void setFaction(int id) throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET FACTION = ? WHERE UUID = ?")) {
|
||||||
if(r_set.first())
|
statement.setInt(1, Factions.valueOf(id).getId());
|
||||||
state.execute("UPDATE player_stats SET FACTION = '" + PrisonAPI.Factions.values()[id].name() + "' WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||||
dis_t();
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRespect() throws SQLException {
|
public int getRespect() throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("SELECT RESPECT FROM prison4life.player_stats WHERE UUID = ?")) {
|
||||||
if(r_set.first()) {
|
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT RESPECT FROM prison4life.player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
|
||||||
if(r_set.first())
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
return r_set.getInt(1);
|
if (resultSet.next()) {
|
||||||
}
|
return resultSet.getInt(1);
|
||||||
dis_t();
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void addRespect(int value) throws SQLException {
|
public void addRespect(int value) throws SQLException {
|
||||||
con_t();
|
setRespect(getRespect() + value);
|
||||||
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 {
|
public void setRespect(int value) throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET RESPECT = ? WHERE UUID = ?")) {
|
||||||
if(r_set.first())
|
statement.setInt(1, value);
|
||||||
state.execute("UPDATE player_stats SET RESPECT = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||||
dis_t();
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRespectDailyCooldown() throws SQLException {
|
public int getRespectDailyCooldown() throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("SELECT COOLDOWN FROM daily_respect_task WHERE UUID = ?")) {
|
||||||
if(r_set.first())
|
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT COOLDOWN FROM daily_respect_task WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
|
||||||
if(r_set.first())
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
return r_set.getInt(1);
|
if (resultSet.next()) {
|
||||||
dis_t();
|
return resultSet.getInt(1);
|
||||||
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void addRespectDailyCooldown(int value) throws SQLException {
|
public void addRespectDailyCooldown(int value) throws SQLException {
|
||||||
con_t();
|
setRespectDailyCooldown(getRespectDailyCooldown() + value);
|
||||||
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 {
|
public void setRespectDailyCooldown(int value) throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("UPDATE daily_respect_task SET COOLDOWN = ? WHERE UUID = ?")) {
|
||||||
if(r_set.first())
|
statement.setInt(1, value);
|
||||||
state.execute("UPDATE daily_respect_task SET COOLDOWN = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Prisoner> getOnlineList() throws SQLException {
|
public List<Prisoner> getOnlineList() {
|
||||||
List<Prisoner> list = new ArrayList<>();
|
return Bukkit.getOnlinePlayers().stream()
|
||||||
Iterator itr = Bukkit.getOnlinePlayers().iterator();
|
.map(Prisoner::new)
|
||||||
while(itr.hasNext()) {
|
.filter(prisoner -> {
|
||||||
Prisoner m = new Prisoner((Player) itr.next());
|
try {
|
||||||
if(m.getFaction().getType().equals(me.getFaction().getType()))
|
return prisoner.getFaction().getType().equals(me.getFaction().getType());
|
||||||
list.add(m);
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return list;
|
})
|
||||||
}
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
private void con_t() 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() + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dis_t() throws SQLException {
|
|
||||||
r_set.close();
|
|
||||||
state.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,59 +1,57 @@
|
|||||||
package ru.prisonlife.PrisonAPI.template;
|
package ru.prisonlife.prisonapi.template;
|
||||||
|
|
||||||
import ru.prisonlife.PrisonAPI.PrisonAPI;
|
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import static ru.prisonlife.prisonapi.PrisonAPI.CONN;
|
||||||
|
|
||||||
public class Level {
|
public class Level {
|
||||||
private PreparedStatement state;
|
|
||||||
private ResultSet r_set;
|
|
||||||
private Prisoner me;
|
private Prisoner me;
|
||||||
private Score score;
|
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 {
|
public Score getScore() throws SQLException {
|
||||||
con_t();
|
//FIXME приведи в порядок метод
|
||||||
if(r_set.first())
|
/*
|
||||||
|
connect();
|
||||||
|
if (resultSet.first()) {
|
||||||
return this.score;
|
return this.score;
|
||||||
dis_t();
|
}
|
||||||
|
disconnect();
|
||||||
|
*/
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getLevel() throws SQLException, NullPointerException {
|
public double getLevel() throws SQLException, NullPointerException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("SELECT LEVEL FROM player_stats WHERE UUID = ?")) {
|
||||||
if(r_set.first()) {
|
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT LEVEL FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
|
||||||
if(r_set.first())
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
return r_set.getDouble(1);
|
if (resultSet.next()) {
|
||||||
|
return resultSet.getDouble(1);
|
||||||
|
} else {
|
||||||
|
return 1d; //TODO нужно или default значение, или exception
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dis_t();
|
|
||||||
return NullPointerException.class.hashCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLevel(double value) throws SQLException, NullPointerException {
|
public void addLevel(double value) throws SQLException, NullPointerException {
|
||||||
con_t();
|
setLevel(getLevel() + value);
|
||||||
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 {
|
public void setLevel(double value) throws SQLException, NullPointerException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET LEVEL = ? WHERE UUID = ?")) {
|
||||||
if(r_set.first())
|
statement.setDouble(1, getLevel() + value);
|
||||||
state.execute("UPDATE player_stats SET LEVEL = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||||
dis_t();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void con_t() throws SQLException {
|
statement.executeUpdate();
|
||||||
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() + "'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dis_t() throws SQLException {
|
|
||||||
r_set.close();
|
|
||||||
state.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
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.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import ru.prisonlife.PrisonAPI.PrisonAPI;
|
import ru.prisonlife.prisonapi.PrisonAPI;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -11,89 +10,87 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Manager {
|
import static ru.prisonlife.prisonapi.PrisonAPI.PLUGIN_PATH;
|
||||||
private File fi;
|
|
||||||
private FileConfiguration cf;
|
|
||||||
|
|
||||||
|
public class Manager {
|
||||||
|
|
||||||
|
private File file;
|
||||||
|
private FileConfiguration fileConfiguration;
|
||||||
|
|
||||||
public Manager(String id) {
|
public Manager(String id) {
|
||||||
fi = new File("plugins/PrisonManager/", id);
|
file = new File(PLUGIN_PATH + "/", id);
|
||||||
cf = YamlConfiguration.loadConfiguration(fi);
|
fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains() {
|
public boolean contains() {
|
||||||
return fi.exists();
|
return file.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWorld() {
|
public String getWorld() {
|
||||||
return cf.getString("WORLD");
|
return fileConfiguration.getString("WORLD");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWorld(String name) {
|
public void setWorld(String name) {
|
||||||
String p = "WORLD";
|
String p = "WORLD";
|
||||||
cf.set(p, null);
|
fileConfiguration.set(p, null);
|
||||||
cf.set(p, name);
|
fileConfiguration.set(p, name);
|
||||||
try {
|
try {
|
||||||
cf.save(fi);
|
fileConfiguration.save(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getRebootStatus() {
|
public boolean getRebootStatus() {
|
||||||
return cf.getBoolean("REBOOT_STATUS");
|
return fileConfiguration.getBoolean("REBOOT_STATUS");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRebootStatus(boolean status) {
|
public void setRebootStatus(boolean status) {
|
||||||
cf.set("REBOOT_STATUS", status);
|
fileConfiguration.set("REBOOT_STATUS", status);
|
||||||
try {
|
try {
|
||||||
cf.save(fi);
|
fileConfiguration.save(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getSpawnCords(int faction) {
|
public List<Integer> getSpawnCords(int faction) {
|
||||||
return cf.getIntegerList("FACTIONS." + __selectFactType__(faction) + ".CORDS");
|
return fileConfiguration.getIntegerList("FACTIONS." + selectFactType(faction) + ".CORDS");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpawnCords(int faction, List<Integer> data) {
|
public void setSpawnCords(int faction, List<Integer> data) {
|
||||||
String p = "FACTIONS." + __selectFactType__(faction) + ".CORDS";
|
String p = "FACTIONS." + selectFactType(faction) + ".CORDS";
|
||||||
cf.set(p, null);
|
fileConfiguration.set(p, null);
|
||||||
cf.set(p, data);
|
fileConfiguration.set(p, data);
|
||||||
try {
|
try {
|
||||||
cf.save(fi);
|
fileConfiguration.save(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getDiagonal() {
|
public List<Integer> getDiagonal() {
|
||||||
return cf.getIntegerList("DIAGONAL_POINTS");
|
return fileConfiguration.getIntegerList("DIAGONAL_POINTS");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDiagonal(List<Integer> data) {
|
public void setDiagonal(List<Integer> data) {
|
||||||
if(data.size() == 6) {
|
if (data.size() == 6) {
|
||||||
String dp = "DIAGONAL_POINTS";
|
String dp = "DIAGONAL_POINTS";
|
||||||
cf.set(dp, null);
|
fileConfiguration.set(dp, null);
|
||||||
cf.set(dp, data);
|
fileConfiguration.set(dp, data);
|
||||||
try {
|
try {
|
||||||
cf.save(fi);
|
fileConfiguration.save(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
throw new RuntimeException("data.size() != 6");
|
||||||
throw new InvalidDataException();
|
|
||||||
} catch (InvalidDataException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getGlobalNumTerr(int faction) {
|
public int getGlobalNumTerr(int faction) {
|
||||||
int num = 0;
|
int num = 0;
|
||||||
for(File prison : Objects.requireNonNull(fi.getParentFile().listFiles())) {
|
for (File prison : Objects.requireNonNull(file.getParentFile().listFiles())) {
|
||||||
Manager mng = new Manager(prison.getName());
|
Manager mng = new Manager(prison.getName());
|
||||||
num += mng.getNumTerr(faction);
|
num += mng.getNumTerr(faction);
|
||||||
}
|
}
|
||||||
@@ -101,55 +98,55 @@ public class Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getNumTerr(int faction) {
|
public int getNumTerr(int faction) {
|
||||||
return cf.getInt("FACTIONS." + __selectFactType__(faction) + ".NUM_TERR");
|
return fileConfiguration.getInt("FACTIONS." + selectFactType(faction) + ".NUM_TERR");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNumTerr(int faction, int value) {
|
public void setNumTerr(int faction, int value) {
|
||||||
String p = "FACTIONS." + __selectFactType__(faction) + ".NUM_TERR";
|
String p = "FACTIONS." + selectFactType(faction) + ".NUM_TERR";
|
||||||
cf.set(p, null);
|
fileConfiguration.set(p, null);
|
||||||
cf.set(p, value);
|
fileConfiguration.set(p, value);
|
||||||
try {
|
try {
|
||||||
cf.save(fi);
|
fileConfiguration.save(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTerrOwner(String name) {
|
public String getTerrOwner(String name) {
|
||||||
return cf.getString("TERRITORIES." + name + ".OWNER");
|
return fileConfiguration.getString("TERRITORIES." + name + ".OWNER");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTerrOwner(String name, String owner) {
|
public void setTerrOwner(String name, String owner) {
|
||||||
cf.set("TERRITORIES." + name + ".OWNER", owner);
|
fileConfiguration.set("TERRITORIES." + name + ".OWNER", owner);
|
||||||
try {
|
try {
|
||||||
cf.save(fi);
|
fileConfiguration.save(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTerrConqurer(String name) {
|
public String getTerrConqurer(String name) {
|
||||||
return cf.getString("TERRITORIES." + name + ".CAPTURED");
|
return fileConfiguration.getString("TERRITORIES." + name + ".CAPTURED");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTerrConqurer(String name, String status) {
|
public void setTerrConqurer(String name, String status) {
|
||||||
cf.set("TERRITORIES." + name + ".CAPTURED", status);
|
fileConfiguration.set("TERRITORIES." + name + ".CAPTURED", status);
|
||||||
try {
|
try {
|
||||||
cf.save(fi);
|
fileConfiguration.save(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getAllTerrs() {
|
public List<String> getAllTerrs() {
|
||||||
return new ArrayList<>(cf.getConfigurationSection("TERRITORIES").getKeys(false));
|
return new ArrayList<>(fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String __selectFactType__(int id) {
|
public String selectFactType(int id) {
|
||||||
return PrisonAPI.Factions.values()[id].name();
|
return PrisonAPI.Factions.values()[id].name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int __selectFactId__(String faction) {
|
public int selectFactId(String faction) {
|
||||||
return PrisonAPI.Factions.valueOf(faction).ordinal();
|
return PrisonAPI.Factions.valueOf(faction).ordinal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package ru.prisonlife.PrisonAPI.template;
|
package ru.prisonlife.prisonapi.template;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import ru.prisonlife.PrisonAPI.PrisonAPI;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@@ -14,15 +13,16 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static ru.prisonlife.prisonapi.PrisonAPI.CONN;
|
||||||
|
import static ru.prisonlife.prisonapi.PrisonAPI.PLUGIN_PATH;
|
||||||
|
|
||||||
public class Prisoner {
|
public class Prisoner {
|
||||||
private static final String PLUGIN_PATH = "plugins/PrisonManager";
|
|
||||||
private Player me;
|
private Player me;
|
||||||
private Level level;
|
private Level level;
|
||||||
private Faction faction;
|
private Faction faction;
|
||||||
private Wallet wallet;
|
private Wallet wallet;
|
||||||
private Stats stats;
|
private Stats stats;
|
||||||
private PreparedStatement state;
|
|
||||||
private ResultSet r_set;
|
|
||||||
|
|
||||||
public Prisoner(Player player) {
|
public Prisoner(Player player) {
|
||||||
me = player;
|
me = player;
|
||||||
@@ -32,91 +32,123 @@ public class Prisoner {
|
|||||||
stats = new Stats(this);
|
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() {
|
public String getPrison() {
|
||||||
Location loc = me.getLocation();
|
Location loc = me.getLocation();
|
||||||
for(File file : Objects.requireNonNull(new File(PLUGIN_PATH).listFiles())) {
|
for (File file : Objects.requireNonNull(new File(PLUGIN_PATH).listFiles())) {
|
||||||
FileConfiguration c_ti = YamlConfiguration.loadConfiguration(file);
|
FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||||
List<List<Integer>> data = new ArrayList<>();
|
List<List<Integer>> data = new ArrayList<>();
|
||||||
List<Integer> from_cfg = c_ti.getIntegerList("DIAGONAL_POINTS"),
|
List<Integer> fromConfig = fileConfiguration.getIntegerList("DIAGONAL_POINTS"),
|
||||||
min = new ArrayList<>(), max = new ArrayList<>();
|
min = new ArrayList<>(), max = new ArrayList<>();
|
||||||
int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()};
|
int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()};
|
||||||
data.add(from_cfg.subList(0, 3));
|
data.add(fromConfig.subList(0, 3));
|
||||||
data.add(from_cfg.subList(3, 6));
|
data.add(fromConfig.subList(3, 6));
|
||||||
for(int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
min.add(Math.min(data.get(0).get(i), data.get(1).get(i)));
|
min.add(Math.min(data.get(0).get(i), data.get(1).get(i)));
|
||||||
max.add(Math.max(data.get(0).get(i), data.get(1).get(i)));
|
max.add(Math.max(data.get(0).get(i), data.get(1).get(i)));
|
||||||
}
|
}
|
||||||
int c = 0;
|
int c = 0;
|
||||||
for(int k : loc_n) {
|
for (int k : loc_n) {
|
||||||
for(int n = 0; n < 3; n++)
|
for (int n = 0; n < 3; n++) {
|
||||||
if(k >= min.get(n) && k <= max.get(n))
|
if (k >= min.get(n) && k <= max.get(n)) {
|
||||||
++c;
|
++c;
|
||||||
}
|
}
|
||||||
if(c == 3)
|
}
|
||||||
|
}
|
||||||
|
if (c == 3) {
|
||||||
return file.getName().replace("PRISON_", "").replace(".yml", "");
|
return file.getName().replace("PRISON_", "").replace(".yml", "");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return "Not Prison";
|
return "Not Prison";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTerritory(String type) {
|
public String getTerritory(String type) {
|
||||||
String prs = getPrison();
|
String prison = getPrison();
|
||||||
if(!prs.equals("Not Prison") && (type.equals("name") || type.equals("owner"))) {
|
if (!prison.equals("Not Prison") && (type.equals("name") || type.equals("owner"))) {
|
||||||
Location loc = me.getLocation();
|
Location loc = me.getLocation();
|
||||||
FileConfiguration c_ti = YamlConfiguration.loadConfiguration(new File(PLUGIN_PATH, "PRISON_" + prs + ".yml"));
|
FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(new File(PLUGIN_PATH, "PRISON_" + prison + ".yml"));
|
||||||
try {
|
try {
|
||||||
if(c_ti.getConfigurationSection("TERRITORIES").getKeys(false).size() != 0) {
|
if (fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false).size() != 0) {
|
||||||
for(String terr : c_ti.getConfigurationSection("TERRITORIES").getKeys(false)) {
|
for (String terr : fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false)) {
|
||||||
List<List<Integer>> data = new ArrayList<>();
|
List<List<Integer>> data = new ArrayList<>();
|
||||||
List<Integer> from_cfg = c_ti.getIntegerList("TERRITORIES." + terr + ".DIAGONAL_POINTS"),
|
List<Integer> fromConfig = fileConfiguration.getIntegerList("TERRITORIES." + terr + ".DIAGONAL_POINTS"),
|
||||||
min = new ArrayList<>(), max = new ArrayList<>();
|
min = new ArrayList<>(), max = new ArrayList<>();
|
||||||
int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()};
|
int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()};
|
||||||
data.add(from_cfg.subList(0, 3));
|
data.add(fromConfig.subList(0, 3));
|
||||||
data.add(from_cfg.subList(3, 6));
|
data.add(fromConfig.subList(3, 6));
|
||||||
for(int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
min.add(Math.min(data.get(0).get(i), data.get(1).get(i)));
|
min.add(Math.min(data.get(0).get(i), data.get(1).get(i)));
|
||||||
max.add(Math.max(data.get(0).get(i), data.get(1).get(i)));
|
max.add(Math.max(data.get(0).get(i), data.get(1).get(i)));
|
||||||
}
|
}
|
||||||
int c = 0;
|
int c = 0;
|
||||||
for(int k : loc_n) {
|
for (int k : loc_n) {
|
||||||
for (int n = 0; n < 3; n++)
|
for (int n = 0; n < 3; n++) {
|
||||||
if (k >= min.get(n) && k <= max.get(n))
|
if (k >= min.get(n) && k <= max.get(n)) {
|
||||||
++c;
|
++c;
|
||||||
}
|
}
|
||||||
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) {}
|
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";
|
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 {
|
public void register() throws SQLException {
|
||||||
state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;");
|
PreparedStatement statement = CONN.prepareStatement("SELECT UUID FROM player_stats WHERE UUID = ?");
|
||||||
state.setString(1, me.getUniqueId().toString());
|
statement.setString(1, me.getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getUniqueId() + "'");
|
|
||||||
if(!r_set.next()) {
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
state.execute(
|
if (!resultSet.next()) {
|
||||||
"INSERT INTO player_stats(NAME, UUID, LEVEL, POINTS, FACTION, RESPECT, F_RANG, WALLET, G_TIME, D_BLOCKS, " +
|
statement.close();
|
||||||
"K_PLAYERS, K_MOBS, DEATHS) VALUES (" +"'" + getPlayer().getName()
|
|
||||||
+ "', '" + me.getUniqueId() + "', 1, 0, 'NONE', 0, 0, 0, 0, 0, 0, 0, 0);");
|
statement = CONN.prepareStatement(
|
||||||
state.execute("INSERT INTO daily_respect_task(NAME, UUID, COOLDOWN) VALUES ('" + me.getName() + "', '" + me.getUniqueId() + "', (3600 * 24));");
|
"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);
|
level = new Level(this);
|
||||||
stats = new Stats(this);
|
stats = new Stats(this);
|
||||||
wallet = new Wallet(this);
|
wallet = new Wallet(this);
|
||||||
}
|
}
|
||||||
r_set.close();
|
}
|
||||||
state.close();
|
statement.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,51 +1,43 @@
|
|||||||
package ru.prisonlife.PrisonAPI.template;
|
package ru.prisonlife.prisonapi.template;
|
||||||
|
|
||||||
import ru.prisonlife.PrisonAPI.PrisonAPI;
|
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import static ru.prisonlife.prisonapi.PrisonAPI.CONN;
|
||||||
|
|
||||||
public class Score {
|
public class Score {
|
||||||
private PreparedStatement state;
|
|
||||||
private ResultSet r_set;
|
|
||||||
private Prisoner me;
|
private Prisoner me;
|
||||||
Score(Prisoner prisoner) { me = prisoner; }
|
|
||||||
|
Score(Prisoner prisoner) {
|
||||||
|
me = prisoner;
|
||||||
|
}
|
||||||
|
|
||||||
public double getPoints() throws SQLException {
|
public double getPoints() throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("SELECT POINTS FROM player_stats WHERE UUID = ?")) {
|
||||||
if(r_set.first()) {
|
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT POINTS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
|
||||||
if(r_set.first()) {
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
return r_set.getDouble(1);
|
if (resultSet.next()) {
|
||||||
|
return resultSet.getDouble(1);
|
||||||
|
} else {
|
||||||
|
return 0d; //TODO нужно или default значение, или exception
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dis_t();
|
|
||||||
return NullPointerException.class.hashCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPoints(double value) throws SQLException {
|
public void setPoints(double value) throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET POINTS = ? WHERE UUID = ?")) {
|
||||||
if(r_set.first())
|
statement.setDouble(1, value);
|
||||||
state.execute("UPDATE player_stats SET POINTS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||||
dis_t();
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPoints(double value) throws SQLException {
|
public void addPoints(double value) throws SQLException {
|
||||||
con_t();
|
setPoints(getPoints() + value);
|
||||||
if(r_set.first())
|
|
||||||
state.execute("UPDATE player_stats SET POINTS = " + (getPoints() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
|
||||||
dis_t();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void con_t() 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() + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dis_t() throws SQLException {
|
|
||||||
r_set.close();
|
|
||||||
state.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,150 +1,151 @@
|
|||||||
package ru.prisonlife.PrisonAPI.template;
|
package ru.prisonlife.prisonapi.template;
|
||||||
|
|
||||||
import ru.prisonlife.PrisonAPI.PrisonAPI;
|
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import static ru.prisonlife.prisonapi.PrisonAPI.CONN;
|
||||||
|
|
||||||
public class Stats {
|
public class Stats {
|
||||||
private PreparedStatement state;
|
|
||||||
private ResultSet r_set;
|
|
||||||
private Prisoner me;
|
private Prisoner me;
|
||||||
Stats(Prisoner prisoner) { me = prisoner;}
|
|
||||||
|
Stats(Prisoner prisoner) {
|
||||||
|
me = prisoner;
|
||||||
|
}
|
||||||
|
|
||||||
public void setServerTime(int value) throws SQLException {
|
public void setServerTime(int value) throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET G_TIME = ? WHERE UUID = ?")) {
|
||||||
if(r_set.first())
|
statement.setDouble(1, value);
|
||||||
state.execute("UPDATE player_stats SET G_TIME = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||||
dis_t();
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getServerTime() throws SQLException {
|
public int getServerTime() throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("SELECT G_TIME FROM player_stats WHERE UUID = ?")) {
|
||||||
if(r_set.first()) {
|
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT G_TIME FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
|
||||||
if(r_set.first())
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
return r_set.getInt(1);
|
if (resultSet.next()) {
|
||||||
|
return resultSet.getInt(1);
|
||||||
|
} else {
|
||||||
|
return 0; //TODO нужно или default значение, или exception
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dis_t();
|
|
||||||
return NullPointerException.class.hashCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addServerTime(int value) throws SQLException {
|
public void addServerTime(int value) throws SQLException {
|
||||||
con_t();
|
setServerTime(getServerTime() + value);
|
||||||
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 {
|
public void setBlocks(int value) throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET B = ? WHERE UUID = ?")) {
|
||||||
if(r_set.first())
|
statement.setDouble(1, value);
|
||||||
state.execute("UPDATE player_stats SET B = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||||
dis_t();
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBlocks() throws SQLException {
|
public int getBlocks() throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("SELECT D_BLOCKS FROM player_stats WHERE UUID = ?")) {
|
||||||
if(r_set.first()) {
|
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT D_BLOCKS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
|
||||||
if(r_set.first())
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
return r_set.getInt(1);
|
if (resultSet.next()) {
|
||||||
|
return resultSet.getInt(1);
|
||||||
|
} else {
|
||||||
|
return 0; //TODO нужно или default значение, или exception
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dis_t();
|
|
||||||
return NullPointerException.class.hashCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBlocks(int value) throws SQLException {
|
public void addBlocks(int value) throws SQLException {
|
||||||
con_t();
|
setBlocks(getBlocks() + value);
|
||||||
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 {
|
public void setPlayers(int value) throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET K_PLAYERS = ? WHERE UUID = ?")) {
|
||||||
if(r_set.first())
|
statement.setDouble(1, value);
|
||||||
state.execute("UPDATE player_stats SET K_PLAYERS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||||
dis_t();
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPlayers() throws SQLException {
|
public int getPlayers() throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("SELECT K_PLAYERS FROM player_stats WHERE UUID = ?")) {
|
||||||
if(r_set.first()) {
|
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT K_PLAYERS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
|
||||||
if(r_set.first())
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
return r_set.getInt(1);
|
if (resultSet.next()) {
|
||||||
|
return resultSet.getInt(1);
|
||||||
|
} else {
|
||||||
|
return 0; //TODO нужно или default значение, или exception
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dis_t();
|
|
||||||
return NullPointerException.class.hashCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayers(int value) throws SQLException {
|
public void addPlayers(int value) throws SQLException {
|
||||||
con_t();
|
setPlayers(getPlayers() + value);
|
||||||
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 {
|
public void setMobs(int value) throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET K_MOBS = ? WHERE UUID = ?")) {
|
||||||
if(r_set.first())
|
statement.setDouble(1, value);
|
||||||
state.execute("UPDATE player_stats SET K_MOBS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||||
dis_t();
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMobs() throws SQLException {
|
public int getMobs() throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("SELECT K_MOBS FROM player_stats WHERE UUID = ?")) {
|
||||||
if(r_set.first()) {
|
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT K_MOBS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
|
||||||
if(r_set.first())
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
return r_set.getInt(1);
|
if (resultSet.next()) {
|
||||||
|
return resultSet.getInt(1);
|
||||||
|
} else {
|
||||||
|
return 0; //TODO нужно или default значение, или exception
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dis_t();
|
|
||||||
return NullPointerException.class.hashCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMobs(int value) throws SQLException {
|
public void addMobs(int value) throws SQLException {
|
||||||
con_t();
|
setMobs(getMobs() + value);
|
||||||
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 {
|
public void setDeaths(int value) throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET DEATHS = ? WHERE UUID = ?")) {
|
||||||
if(r_set.first())
|
statement.setDouble(1, value);
|
||||||
state.execute("UPDATE player_stats SET DEATHS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||||
dis_t();
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDeaths() throws SQLException {
|
public int getDeaths() throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("SELECT DEATHS FROM player_stats WHERE UUID = ?")) {
|
||||||
if(r_set.first()) {
|
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT DEATHS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
|
||||||
if(r_set.first())
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
return r_set.getInt(1);
|
if (resultSet.next()) {
|
||||||
|
return resultSet.getInt(1);
|
||||||
|
} else {
|
||||||
|
return 0; //TODO нужно или default значение, или exception
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dis_t();
|
|
||||||
return NullPointerException.class.hashCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDeaths(int value) throws SQLException {
|
public void addDeaths(int value) throws SQLException {
|
||||||
con_t();
|
setDeaths(getDeaths() + value);
|
||||||
if(r_set.first())
|
|
||||||
state.execute("UPDATE player_stats SET DEATHS = " + (getDeaths() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
|
||||||
dis_t();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void con_t() 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() + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dis_t() throws SQLException {
|
|
||||||
r_set.close();
|
|
||||||
state.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,57 +1,47 @@
|
|||||||
package ru.prisonlife.PrisonAPI.template;
|
package ru.prisonlife.prisonapi.template;
|
||||||
|
|
||||||
import ru.prisonlife.PrisonAPI.PrisonAPI;
|
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import static ru.prisonlife.prisonapi.PrisonAPI.CONN;
|
||||||
|
|
||||||
public class Wallet {
|
public class Wallet {
|
||||||
private PreparedStatement state;
|
|
||||||
private ResultSet r_set;
|
|
||||||
private Prisoner me;
|
private Prisoner me;
|
||||||
Wallet(Prisoner prisoner) { me = prisoner; }
|
|
||||||
|
Wallet(Prisoner prisoner) {
|
||||||
|
me = prisoner;
|
||||||
|
}
|
||||||
|
|
||||||
public int getBalance() throws SQLException {
|
public int getBalance() throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("SELECT WALLET FROM player_stats WHERE UUID = ?")) {
|
||||||
if(r_set.first()) {
|
statement.setString(1, me.getPlayer().getUniqueId().toString());
|
||||||
r_set = state.executeQuery("SELECT WALLET FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
|
||||||
if(r_set.first())
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
return r_set.getInt(1);
|
if (resultSet.next()) {
|
||||||
|
return resultSet.getInt(1);
|
||||||
|
} else {
|
||||||
|
return 0; //TODO нужно или default значение, или exception
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dis_t();
|
|
||||||
return NullPointerException.class.hashCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBalance(int value) throws SQLException {
|
public void addBalance(int value) throws SQLException {
|
||||||
con_t();
|
setBalance(getBalance() + value);
|
||||||
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 {
|
public void deposit(int value) throws SQLException {
|
||||||
con_t();
|
setBalance(getBalance() - value);
|
||||||
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 {
|
public void setBalance(int value) throws SQLException {
|
||||||
con_t();
|
try (PreparedStatement statement = CONN.prepareStatement("UPDATE player_stats SET WALLET = ? WHERE UUID = ?")) {
|
||||||
if(r_set.first())
|
statement.setDouble(1, value);
|
||||||
state.execute("UPDATE player_stats SET WALLET = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
statement.setString(2, me.getPlayer().getUniqueId().toString());
|
||||||
dis_t();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void con_t() throws SQLException {
|
statement.executeUpdate();
|
||||||
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() + "'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dis_t() throws SQLException {
|
|
||||||
r_set.close();
|
|
||||||
state.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: PrisonAPI
|
name: PrisonAPI
|
||||||
version: 0.1.0.4
|
version: ${project.version}
|
||||||
authors: [Overlord_S, Prot_CN, Wani4ka]
|
authors: [Overlord_S, Prot_CN, Wani4ka, DmitriyMX]
|
||||||
main: ru.prisonlife.PrisonAPI.PrisonAPI
|
main: ru.prisonlife.prisonapi.PrisonAPI
|
||||||
Reference in New Issue
Block a user