UPDATE 0.1.0.4 ~ new classes and methods etc.
This commit is contained in:
@@ -8,12 +8,15 @@ import java.sql.SQLException;
|
||||
|
||||
public class PrisonAPI extends JavaPlugin {
|
||||
public static Connection CONN;
|
||||
public enum Factions {
|
||||
NONE, ASIANS, LATINOS, NIGGAZ, POLICE
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
try {
|
||||
CONN = DriverManager.getConnection(
|
||||
"jdbc:mysql://54.37.128.221:3306/prison",
|
||||
"forsplay", "ay18qILi5z1RTwWi");
|
||||
"jdbc:mysql://localhost:3306/prison4life",
|
||||
"root", "root");
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,33 +1,149 @@
|
||||
package ru.prisonlife.PrisonAPI.template;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import ru.prisonlife.PrisonAPI.PrisonAPI;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class Faction {
|
||||
private enum Factions { NONE, ASIANS, LATINOS, NIGGAZ, POLICE }
|
||||
private Map<Integer, Factions> pick = new HashMap<Integer, Factions>();
|
||||
{
|
||||
for(int i = 0; i < Factions.values().length; i++)
|
||||
pick.put(i, Factions.values()[i]);
|
||||
}
|
||||
private PreparedStatement state;
|
||||
private ResultSet r_set;
|
||||
private Prisoner me;
|
||||
Faction(Prisoner prisoner) { me = prisoner; }
|
||||
Faction(Prisoner prisoner) {
|
||||
me = prisoner;
|
||||
}
|
||||
|
||||
public void change(int id) throws SQLException {
|
||||
get_t();
|
||||
public String getType() throws SQLException {
|
||||
con_t();
|
||||
if(r_set.first()) {
|
||||
r_set = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
if(r_set.first())
|
||||
return r_set.getString(1);
|
||||
}
|
||||
dis_t();
|
||||
return "null";
|
||||
}
|
||||
|
||||
public int getId() throws SQLException {
|
||||
con_t();
|
||||
if(r_set.first()) {
|
||||
r_set = state.executeQuery("SELECT FACTION FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
if(r_set.first())
|
||||
for(int i = 0; i < PrisonAPI.Factions.values().length; i++)
|
||||
if(PrisonAPI.Factions.values()[i].name().equals(r_set.getString(1)))
|
||||
return i;
|
||||
}
|
||||
dis_t();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getRangId() throws SQLException {
|
||||
con_t();
|
||||
if(r_set.first()) {
|
||||
r_set = state.executeQuery("SELECT F_RANG FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
if(r_set.first())
|
||||
return r_set.getInt(1);
|
||||
}
|
||||
dis_t();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getRangType() throws SQLException {
|
||||
String[][] post = {
|
||||
{"Vakasu", "Tomadati", "So Honbute", "Vakagasira", "Kambu", "Kumite"},
|
||||
{"Novaro", "Amigo", "Latino", "Veterano", "Elite", "Padre"},
|
||||
{"Baby", "Cracker", "Little Nigga", "Big Nigga", "Star", "Daddy"}};
|
||||
|
||||
return post[getId() - 1][getRangId() - 1];
|
||||
}
|
||||
|
||||
public void addRang(int value) throws SQLException {
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET FACTION = '" + pick.get(id) + "'");
|
||||
state.execute("UPDATE player_stats SET F_RANG = " + (getRangId() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
dis_t();
|
||||
}
|
||||
|
||||
private void get_t() throws SQLException {
|
||||
public void setRang(int value) throws SQLException {
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET F_RANG = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public void setFaction(int id) throws SQLException {
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET FACTION = '" + PrisonAPI.Factions.values()[id].name() + "' WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public int getRespect() throws SQLException {
|
||||
con_t();
|
||||
if(r_set.first()) {
|
||||
r_set = state.executeQuery("SELECT RESPECT FROM prison4life.player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
if(r_set.first())
|
||||
return r_set.getInt(1);
|
||||
}
|
||||
dis_t();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void addRespect(int value) throws SQLException {
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET RESPECT = " + (getRespect() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public void setRespect(int value) throws SQLException {
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET RESPECT = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public int getRespectDailyCooldown() throws SQLException {
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
r_set = state.executeQuery("SELECT COOLDOWN FROM daily_respect_task WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
if(r_set.first())
|
||||
return r_set.getInt(1);
|
||||
dis_t();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void addRespectDailyCooldown(int value) throws SQLException {
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE daily_respect_task SET COOLDOWN = " + (getRespectDailyCooldown() + value)
|
||||
+ " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
}
|
||||
|
||||
public void setRespectDailyCooldown(int value) throws SQLException {
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE daily_respect_task SET COOLDOWN = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
}
|
||||
|
||||
public List<Prisoner> getOnlineList() throws SQLException {
|
||||
List<Prisoner> list = new ArrayList<>();
|
||||
Iterator itr = Bukkit.getOnlinePlayers().iterator();
|
||||
while(itr.hasNext()) {
|
||||
Prisoner m = new Prisoner((Player) itr.next());
|
||||
if(m.getFaction().getType().equals(me.getFaction().getType()))
|
||||
list.add(m);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
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() + "'");
|
||||
|
||||
@@ -14,45 +14,45 @@ public class Level {
|
||||
Level(Prisoner prisoner) { me = prisoner; score = new Score(me); }
|
||||
|
||||
public Score getScore() throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
return this.score;
|
||||
disconnect();
|
||||
dis_t();
|
||||
return null;
|
||||
}
|
||||
|
||||
public double getLevel() throws SQLException, NullPointerException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first()) {
|
||||
r_set = state.executeQuery("SELECT LEVEL FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
if(r_set.first())
|
||||
return r_set.getDouble(1);
|
||||
}
|
||||
disconnect();
|
||||
dis_t();
|
||||
return NullPointerException.class.hashCode();
|
||||
}
|
||||
|
||||
public void addLevel(double value) throws SQLException, NullPointerException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET LEVEL = " + (getLevel() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public void setLevel(double value) throws SQLException, NullPointerException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET LEVEL = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
private void setInResUUID() throws SQLException {
|
||||
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 disconnect() throws SQLException {
|
||||
private void dis_t() throws SQLException {
|
||||
r_set.close();
|
||||
state.close();
|
||||
}
|
||||
|
||||
155
src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java
Normal file
155
src/main/java/ru/prisonlife/PrisonAPI/template/Manager.java
Normal file
@@ -0,0 +1,155 @@
|
||||
package ru.prisonlife.PrisonAPI.template;
|
||||
|
||||
import com.sun.media.sound.InvalidDataException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import ru.prisonlife.PrisonAPI.PrisonAPI;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Manager {
|
||||
private File fi;
|
||||
private FileConfiguration cf;
|
||||
|
||||
|
||||
public Manager(String id) {
|
||||
fi = new File("plugins/PrisonManager/", id);
|
||||
cf = YamlConfiguration.loadConfiguration(fi);
|
||||
}
|
||||
|
||||
public boolean contains() {
|
||||
return fi.exists();
|
||||
}
|
||||
|
||||
public String getWorld() {
|
||||
return cf.getString("WORLD");
|
||||
}
|
||||
|
||||
public void setWorld(String name) {
|
||||
String p = "WORLD";
|
||||
cf.set(p, null);
|
||||
cf.set(p, name);
|
||||
try {
|
||||
cf.save(fi);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getRebootStatus() {
|
||||
return cf.getBoolean("REBOOT_STATUS");
|
||||
}
|
||||
|
||||
public void setRebootStatus(boolean status) {
|
||||
cf.set("REBOOT_STATUS", status);
|
||||
try {
|
||||
cf.save(fi);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Integer> getSpawnCords(int faction) {
|
||||
return cf.getIntegerList("FACTIONS." + __selectFactType__(faction) + ".CORDS");
|
||||
}
|
||||
|
||||
public void setSpawnCords(int faction, List<Integer> data) {
|
||||
String p = "FACTIONS." + __selectFactType__(faction) + ".CORDS";
|
||||
cf.set(p, null);
|
||||
cf.set(p, data);
|
||||
try {
|
||||
cf.save(fi);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Integer> getDiagonal() {
|
||||
return cf.getIntegerList("DIAGONAL_POINTS");
|
||||
}
|
||||
|
||||
public void setDiagonal(List<Integer> data) {
|
||||
if(data.size() == 6) {
|
||||
String dp = "DIAGONAL_POINTS";
|
||||
cf.set(dp, null);
|
||||
cf.set(dp, data);
|
||||
try {
|
||||
cf.save(fi);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
throw new InvalidDataException();
|
||||
} catch (InvalidDataException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getGlobalNumTerr(int faction) {
|
||||
int num = 0;
|
||||
for(File prison : Objects.requireNonNull(fi.getParentFile().listFiles())) {
|
||||
Manager mng = new Manager(prison.getName());
|
||||
num += mng.getNumTerr(faction);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public int getNumTerr(int faction) {
|
||||
return cf.getInt("FACTIONS." + __selectFactType__(faction) + ".NUM_TERR");
|
||||
}
|
||||
|
||||
public void setNumTerr(int faction, int value) {
|
||||
String p = "FACTIONS." + __selectFactType__(faction) + ".NUM_TERR";
|
||||
cf.set(p, null);
|
||||
cf.set(p, value);
|
||||
try {
|
||||
cf.save(fi);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getTerrOwner(String name) {
|
||||
return cf.getString("TERRITORIES." + name + ".OWNER");
|
||||
}
|
||||
|
||||
public void setTerrOwner(String name, String owner) {
|
||||
cf.set("TERRITORIES." + name + ".OWNER", owner);
|
||||
try {
|
||||
cf.save(fi);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getTerrConqurer(String name) {
|
||||
return cf.getString("TERRITORIES." + name + ".CAPTURED");
|
||||
}
|
||||
|
||||
public void setTerrConqurer(String name, String status) {
|
||||
cf.set("TERRITORIES." + name + ".CAPTURED", status);
|
||||
try {
|
||||
cf.save(fi);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getAllTerrs() {
|
||||
return new ArrayList<>(cf.getConfigurationSection("TERRITORIES").getKeys(false));
|
||||
}
|
||||
|
||||
public String __selectFactType__(int id) {
|
||||
return PrisonAPI.Factions.values()[id].name();
|
||||
}
|
||||
|
||||
public int __selectFactId__(String faction) {
|
||||
return PrisonAPI.Factions.valueOf(faction).ordinal();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,21 @@
|
||||
package ru.prisonlife.PrisonAPI.template;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import ru.prisonlife.PrisonAPI.PrisonAPI;
|
||||
|
||||
import 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 {
|
||||
private static final String PLUGIN_PATH = "plugins/PrisonManager";
|
||||
private Player me;
|
||||
private Level level;
|
||||
private Faction faction;
|
||||
@@ -28,6 +36,66 @@ public class Prisoner {
|
||||
|
||||
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 c_ti = YamlConfiguration.loadConfiguration(file);
|
||||
List<List<Integer>> data = new ArrayList<>();
|
||||
List<Integer> from_cfg = c_ti.getIntegerList("DIAGONAL_POINTS"),
|
||||
min = new ArrayList<>(), max = new ArrayList<>();
|
||||
int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()};
|
||||
data.add(from_cfg.subList(0, 3));
|
||||
data.add(from_cfg.subList(3, 6));
|
||||
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 prs = getPrison();
|
||||
if(!prs.equals("Not Prison") && (type.equals("name") || type.equals("owner"))) {
|
||||
Location loc = me.getLocation();
|
||||
FileConfiguration c_ti = YamlConfiguration.loadConfiguration(new File(PLUGIN_PATH, "PRISON_" + prs + ".yml"));
|
||||
try {
|
||||
if(c_ti.getConfigurationSection("TERRITORIES").getKeys(false).size() != 0) {
|
||||
for(String terr : c_ti.getConfigurationSection("TERRITORIES").getKeys(false)) {
|
||||
List<List<Integer>> data = new ArrayList<>();
|
||||
List<Integer> from_cfg = c_ti.getIntegerList("TERRITORIES." + terr + ".DIAGONAL_POINTS"),
|
||||
min = new ArrayList<>(), max = new ArrayList<>();
|
||||
int[] loc_n = {loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()};
|
||||
data.add(from_cfg.subList(0, 3));
|
||||
data.add(from_cfg.subList(3, 6));
|
||||
for(int i = 0; i < 3; i++) {
|
||||
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") ? c_ti.getString("TERRITORIES." + terr + ".NAME") :
|
||||
(type.equals("owner") ? c_ti.getString("TERRITORIES." + terr + ".OWNER") : null);
|
||||
}
|
||||
}
|
||||
} catch(NullPointerException z) {}
|
||||
}
|
||||
return "Not Territory";
|
||||
}
|
||||
|
||||
public Faction getFaction() { return faction; }
|
||||
|
||||
public Wallet getWallet() { return wallet; }
|
||||
@@ -40,9 +108,10 @@ public class Prisoner {
|
||||
r_set = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getUniqueId() + "'");
|
||||
if(!r_set.next()) {
|
||||
state.execute(
|
||||
"INSERT INTO player_stats(NAME, UUID, LEVEL, POINTS, FACTION, WALLET, G_TIME, D_BLOCKS, " +
|
||||
"INSERT INTO player_stats(NAME, UUID, LEVEL, POINTS, FACTION, RESPECT, F_RANG, WALLET, G_TIME, D_BLOCKS, " +
|
||||
"K_PLAYERS, K_MOBS, DEATHS) VALUES (" +"'" + getPlayer().getName()
|
||||
+ "', '" + me.getUniqueId() + "', 1, 0, 'None', 0, 0, 0, 0, 0, 0);");
|
||||
+ "', '" + me.getUniqueId() + "', 1, 0, 'NONE', 0, 0, 0, 0, 0, 0, 0, 0);");
|
||||
state.execute("INSERT INTO daily_respect_task(NAME, UUID, COOLDOWN) VALUES ('" + me.getName() + "', '" + me.getUniqueId() + "', (3600 * 24));");
|
||||
level = new Level(this);
|
||||
stats = new Stats(this);
|
||||
wallet = new Wallet(this);
|
||||
|
||||
@@ -13,38 +13,38 @@ public class Score {
|
||||
Score(Prisoner prisoner) { me = prisoner; }
|
||||
|
||||
public double getPoints() throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first()) {
|
||||
r_set = state.executeQuery("SELECT POINTS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
if(r_set.first()) {
|
||||
return r_set.getDouble(1);
|
||||
}
|
||||
}
|
||||
disconnect();
|
||||
dis_t();
|
||||
return NullPointerException.class.hashCode();
|
||||
}
|
||||
|
||||
public void setPoints(double value) throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET POINTS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public void addPoints(double value) throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET POINTS = " + (getPoints() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
private void setInResUUID() throws SQLException {
|
||||
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 disconnect() throws SQLException {
|
||||
private void dis_t() throws SQLException {
|
||||
r_set.close();
|
||||
state.close();
|
||||
}
|
||||
|
||||
@@ -13,137 +13,137 @@ public class Stats {
|
||||
Stats(Prisoner prisoner) { me = prisoner;}
|
||||
|
||||
public void setServerTime(int value) throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET G_TIME = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public int getServerTime() throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first()) {
|
||||
r_set = state.executeQuery("SELECT G_TIME FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
if(r_set.first())
|
||||
return r_set.getInt(1);
|
||||
}
|
||||
disconnect();
|
||||
dis_t();
|
||||
return NullPointerException.class.hashCode();
|
||||
}
|
||||
|
||||
public void addServerTime(int value) throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET G_TIME = " + (getServerTime() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public void setBlocks(int value) throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET B = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public int getBlocks() throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first()) {
|
||||
r_set = state.executeQuery("SELECT D_BLOCKS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
if(r_set.first())
|
||||
return r_set.getInt(1);
|
||||
}
|
||||
disconnect();
|
||||
dis_t();
|
||||
return NullPointerException.class.hashCode();
|
||||
}
|
||||
|
||||
public void addBlocks(int value) throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET D_BLOCKS = " + (getBlocks() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public void setPlayers(int value) throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET K_PLAYERS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public int getPlayers() throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first()) {
|
||||
r_set = state.executeQuery("SELECT K_PLAYERS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
if(r_set.first())
|
||||
return r_set.getInt(1);
|
||||
}
|
||||
disconnect();
|
||||
dis_t();
|
||||
return NullPointerException.class.hashCode();
|
||||
}
|
||||
|
||||
public void addPlayers(int value) throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET K_PLAYERS = " + (getPlayers() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public void setMobs(int value) throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET K_MOBS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public int getMobs() throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first()) {
|
||||
r_set = state.executeQuery("SELECT K_MOBS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
if(r_set.first())
|
||||
return r_set.getInt(1);
|
||||
}
|
||||
disconnect();
|
||||
dis_t();
|
||||
return NullPointerException.class.hashCode();
|
||||
}
|
||||
|
||||
public void addMobs(int value) throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET K_MOBS = " + (getMobs() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public void setDeaths(int value) throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET DEATHS = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public int getDeaths() throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first()) {
|
||||
r_set = state.executeQuery("SELECT DEATHS FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
if(r_set.first())
|
||||
return r_set.getInt(1);
|
||||
}
|
||||
disconnect();
|
||||
dis_t();
|
||||
return NullPointerException.class.hashCode();
|
||||
}
|
||||
|
||||
public void addDeaths(int value) throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET DEATHS = " + (getDeaths() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
private void setInResUUID() throws SQLException {
|
||||
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 disconnect() throws SQLException {
|
||||
private void dis_t() throws SQLException {
|
||||
r_set.close();
|
||||
state.close();
|
||||
}
|
||||
|
||||
@@ -13,44 +13,44 @@ public class Wallet {
|
||||
Wallet(Prisoner prisoner) { me = prisoner; }
|
||||
|
||||
public int getBalance() throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first()) {
|
||||
r_set = state.executeQuery("SELECT WALLET FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
if(r_set.first())
|
||||
return r_set.getInt(1);
|
||||
}
|
||||
disconnect();
|
||||
dis_t();
|
||||
return NullPointerException.class.hashCode();
|
||||
}
|
||||
|
||||
public void addBalance(int value) throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET WALLET = " + (getBalance() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public void deposit(int value) throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET WALLET = " + (getBalance() - value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
public void setBalance(int value) throws SQLException {
|
||||
setInResUUID();
|
||||
con_t();
|
||||
if(r_set.first())
|
||||
state.execute("UPDATE player_stats SET WALLET = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
|
||||
disconnect();
|
||||
dis_t();
|
||||
}
|
||||
|
||||
private void setInResUUID() throws SQLException {
|
||||
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 disconnect() throws SQLException {
|
||||
private void dis_t() throws SQLException {
|
||||
r_set.close();
|
||||
state.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user