PrepareStatement -> MyBatis
This commit is contained in:
@@ -17,6 +17,7 @@ public class PlayerStatsEntity {
|
|||||||
private Integer players;
|
private Integer players;
|
||||||
private Integer mobs;
|
private Integer mobs;
|
||||||
private Integer deaths;
|
private Integer deaths;
|
||||||
|
private Integer suspect;
|
||||||
|
|
||||||
public String getUuid() {
|
public String getUuid() {
|
||||||
return uuid;
|
return uuid;
|
||||||
@@ -134,4 +135,12 @@ public class PlayerStatsEntity {
|
|||||||
public void setDeaths(Integer deaths) {
|
public void setDeaths(Integer deaths) {
|
||||||
this.deaths = deaths;
|
this.deaths = deaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getSuspect() {
|
||||||
|
return suspect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSuspect(Integer suspect) {
|
||||||
|
this.suspect = suspect;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package ru.prisonlife.api.store;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class PlayersInCagesEntity {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String uuid;
|
||||||
|
private Integer timeInCage;
|
||||||
|
private Integer blocksLeft;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUuid(String uuid) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getTimeInCage() {
|
||||||
|
return timeInCage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeInCage(Integer timeInCage) {
|
||||||
|
this.timeInCage = timeInCage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getBlocksLeft() {
|
||||||
|
return blocksLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlocksLeft(Integer blocksLeft) {
|
||||||
|
this.blocksLeft = blocksLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
PlayersInCagesEntity that = (PlayersInCagesEntity) o;
|
||||||
|
return Objects.equals(uuid, that.uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package ru.prisonlife.api.template;
|
package ru.prisonlife.api.template;
|
||||||
|
|
||||||
import org.apache.ibatis.session.SqlSession;
|
import org.apache.ibatis.session.SqlSession;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import ru.prisonlife.api.PrisonAPI;
|
import ru.prisonlife.api.PrisonAPI;
|
||||||
import ru.prisonlife.api.store.PlayerStatsEntity;
|
import ru.prisonlife.api.store.PlayerStatsEntity;
|
||||||
|
|
||||||
@@ -8,24 +9,26 @@ import java.lang.ref.WeakReference;
|
|||||||
|
|
||||||
public abstract class AbstractApiData {
|
public abstract class AbstractApiData {
|
||||||
|
|
||||||
protected Prisoner me;
|
protected Player me;
|
||||||
private WeakReference<PlayerStatsEntity> refPlayerStatsEntity;
|
private WeakReference<PlayerStatsEntity> refPlayerStatsEntity;
|
||||||
|
|
||||||
public AbstractApiData(Prisoner me) {
|
public AbstractApiData(Player player) {
|
||||||
this.me = me;
|
this.me = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PlayerStatsEntity getPlayerStatsEntity() {
|
protected PlayerStatsEntity getPlayerStatsEntity() {
|
||||||
PlayerStatsEntity entity;
|
PlayerStatsEntity entity;
|
||||||
if (refPlayerStatsEntity != null && (entity = refPlayerStatsEntity.get()) != null) {
|
|
||||||
|
if (refPlayerStatsEntity != null && refPlayerStatsEntity.get() != null) {
|
||||||
|
entity = refPlayerStatsEntity.get();
|
||||||
return entity;
|
return entity;
|
||||||
} else {
|
} else {
|
||||||
final SqlSession session = PrisonAPI.getSqlStore().openSession();
|
try (SqlSession session = PrisonAPI.getSqlStore().openSession()) {
|
||||||
entity = session.selectOne("PlayerStats.selectOne", me.getPlayer().getUniqueId().toString());
|
entity = session.selectOne("PlayerStats.selectOne", me.getUniqueId().toString());
|
||||||
session.close();
|
}
|
||||||
|
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
throw new RuntimeException("no data in db by '" + me.getPlayer().getUniqueId().toString() + "'");
|
throw new RuntimeException("no data in db by '" + me.getUniqueId().toString() + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
refPlayerStatsEntity = new WeakReference<>(entity);
|
refPlayerStatsEntity = new WeakReference<>(entity);
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package ru.prisonlife.api.template;
|
||||||
|
|
||||||
|
public abstract class AbstractSubApiData {
|
||||||
|
|
||||||
|
protected Prisoner me;
|
||||||
|
|
||||||
|
public AbstractSubApiData(Prisoner me) {
|
||||||
|
this.me = me;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ import java.lang.ref.WeakReference;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Faction extends AbstractApiData {
|
public class Faction extends AbstractSubApiData {
|
||||||
|
|
||||||
private WeakReference<DailyRespectTaskEntity> refDailyRespectTaskEntity;
|
private WeakReference<DailyRespectTaskEntity> refDailyRespectTaskEntity;
|
||||||
|
|
||||||
@@ -42,15 +42,15 @@ public class Faction extends AbstractApiData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return Factions.valueOf(getPlayerStatsEntity().getFaction()).name();
|
return Factions.valueOf(me.getPlayerStatsEntity().getFaction()).name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return getPlayerStatsEntity().getFaction();
|
return me.getPlayerStatsEntity().getFaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRangId() {
|
public int getRangId() {
|
||||||
return getPlayerStatsEntity().getRang();
|
return me.getPlayerStatsEntity().getRang();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRangType() {
|
public String getRangType() {
|
||||||
@@ -62,15 +62,15 @@ public class Faction extends AbstractApiData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setRang(int value) {
|
public void setRang(int value) {
|
||||||
getPlayerStatsEntity().setRang(value);
|
me.getPlayerStatsEntity().setRang(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFaction(int id) {
|
public void setFaction(int id) {
|
||||||
getPlayerStatsEntity().setFaction(id);
|
me.getPlayerStatsEntity().setFaction(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRespect() {
|
public int getRespect() {
|
||||||
return getPlayerStatsEntity().getRespect();
|
return me.getPlayerStatsEntity().getRespect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRespect(int value) {
|
public void addRespect(int value) {
|
||||||
@@ -78,7 +78,7 @@ public class Faction extends AbstractApiData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setRespect(int value) {
|
public void setRespect(int value) {
|
||||||
getPlayerStatsEntity().setRespect(value);
|
me.getPlayerStatsEntity().setRespect(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRespectDailyCooldown() {
|
public int getRespectDailyCooldown() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package ru.prisonlife.api.template;
|
package ru.prisonlife.api.template;
|
||||||
|
|
||||||
public class Level extends AbstractApiData {
|
public class Level extends AbstractSubApiData {
|
||||||
|
|
||||||
private Score score;
|
private Score score;
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ public class Level extends AbstractApiData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getLevel() {
|
public double getLevel() {
|
||||||
return getPlayerStatsEntity().getLevel();
|
return me.getPlayerStatsEntity().getLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLevel(double value) {
|
public void addLevel(double value) {
|
||||||
@@ -22,6 +22,6 @@ public class Level extends AbstractApiData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setLevel(double value) {
|
public void setLevel(double value) {
|
||||||
getPlayerStatsEntity().setLevel(value);
|
me.getPlayerStatsEntity().setLevel(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.prisonlife.api.template;
|
package ru.prisonlife.api.template;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.apache.ibatis.session.SqlSession;
|
import org.apache.ibatis.session.SqlSession;
|
||||||
@@ -11,10 +12,6 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
import ru.prisonlife.api.PrisonAPI;
|
import ru.prisonlife.api.PrisonAPI;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -30,30 +27,25 @@ public class Policeman extends Prisoner {
|
|||||||
super(player);
|
super(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void arrestPrisoner(Prisoner prs) throws SQLException {
|
public void arrestPrisoner(Prisoner prs) {
|
||||||
try (SqlSession session = getSqlStore().openSession()) {
|
try (SqlSession session = getSqlStore().openSession()) {
|
||||||
final Connection connection = session.getConnection();
|
|
||||||
|
|
||||||
if (prs.getPlayer().isOnline()) {
|
if (prs.getPlayer().isOnline()) {
|
||||||
Manager mng = new Manager(super.getPrison());
|
Manager mng = new Manager(super.getPrison());
|
||||||
List<String> all_cages = mng.getCages();
|
List<String> all_cages = mng.getCages();
|
||||||
PreparedStatement st = connection.prepareStatement("SELECT UUID FROM player_stats WHERE UUID = ?");
|
|
||||||
st.setString(1, me.getUniqueId().toString());
|
Integer result = session.selectOne("PlayerStats.countByUuid");
|
||||||
try (ResultSet resultSet = st.executeQuery()) {
|
if (result == null || result == 0) {
|
||||||
if (!resultSet.next()) {
|
int su = prs.getSuspect();
|
||||||
int su = prs.getSuspect();
|
|
||||||
st.close();
|
session.insert("PlayersInCages.register", ImmutableMap.builder()
|
||||||
st = connection.prepareStatement(
|
.put("name", getPlayer().getName())
|
||||||
"INSERT INTO players_in_cages(NAME, UUID, TIME_IN_CAGE, BLOCKS_LEFT) " +
|
.put("uuid", getPlayer().getUniqueId().toString())
|
||||||
"VALUES (?, ?, ?, ?)");
|
.put("timeInCage", su * 6)
|
||||||
st.setString(1, getPlayer().getName());
|
.put("blocksLeft", su * 100)
|
||||||
st.setString(2, me.getUniqueId().toString());
|
.build()
|
||||||
st.setInt(3, (su * 6));
|
);
|
||||||
st.setInt(4, (su * 100));
|
|
||||||
st.executeUpdate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
st.close();
|
|
||||||
prs.setSuspect(0);
|
prs.setSuspect(0);
|
||||||
mng.teleportInToCage(prs, all_cages.get(new Random().nextInt(all_cages.size())));
|
mng.teleportInToCage(prs, all_cages.get(new Random().nextInt(all_cages.size())));
|
||||||
FileConfiguration configurationSuspect = YamlConfiguration.loadConfiguration(new File("plugins/PrisonSuspect/", "parameters.yml"));
|
FileConfiguration configurationSuspect = YamlConfiguration.loadConfiguration(new File("plugins/PrisonSuspect/", "parameters.yml"));
|
||||||
@@ -68,35 +60,27 @@ public class Policeman extends Prisoner {
|
|||||||
timeInCage.put(prs, new BukkitRunnable() {
|
timeInCage.put(prs, new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() { // Future = Пометить, что когда in Cage и вышел, то удалить поток, а если зашёл и in Cage - запустить ~ Optimize
|
public void run() { // Future = Пометить, что когда in Cage и вышел, то удалить поток, а если зашёл и in Cage - запустить ~ Optimize
|
||||||
try {
|
try (SqlSession session = getSqlStore().openSession()) {
|
||||||
int time = 0;
|
final String uuid = prs.getPlayer().getUniqueId().toString();
|
||||||
String uuid = prs.getPlayer().getUniqueId().toString();
|
|
||||||
PreparedStatement st = connection.prepareStatement(
|
int time = session.selectOne("PlayersInCages.getTimeInCage", uuid);
|
||||||
"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) {
|
if (time == 0) {
|
||||||
prs.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&',
|
prs.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
configurationSuspect.getString("MESSAGES.WHEN_PRISONER_CAN_EXIT_FROM_CAGE")));
|
configurationSuspect.getString("MESSAGES.WHEN_PRISONER_CAN_EXIT_FROM_CAGE")));
|
||||||
actionBar.cancel();
|
actionBar.cancel();
|
||||||
cancel();
|
cancel();
|
||||||
timeInCage.remove(prs);
|
timeInCage.remove(prs);
|
||||||
st = connection.prepareStatement("DELETE FROM players_in_cages WHERE UUID = ?");
|
session.delete("PlayersInCages.deleteByUuid", uuid);
|
||||||
st.setString(1, uuid);
|
|
||||||
st.execute();
|
|
||||||
} else {
|
} else {
|
||||||
if (prs.getPlayer().isOnline()) {
|
if (prs.getPlayer().isOnline()) {
|
||||||
st = connection.prepareStatement("UPDATE players_in_cages SET TIME_IN_CAGE = " + (time - 1) + " WHERE UUID = ?");
|
session.update("PlayersInCages.updateTimeInCage", ImmutableMap.builder()
|
||||||
st.setString(1, uuid);
|
.put("uuid", uuid)
|
||||||
st.execute();
|
.put("time", time - 1)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
st.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.prisonlife.api.template;
|
package ru.prisonlife.api.template;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.apache.ibatis.session.SqlSession;
|
import org.apache.ibatis.session.SqlSession;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@@ -7,11 +8,10 @@ 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.api.PrisonAPI;
|
import ru.prisonlife.api.PrisonAPI;
|
||||||
|
import ru.prisonlife.api.store.PlayersInCagesEntity;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
import java.lang.ref.WeakReference;
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -19,16 +19,17 @@ import java.util.Objects;
|
|||||||
|
|
||||||
import static ru.prisonlife.api.PrisonAPI.getSqlStore;
|
import static ru.prisonlife.api.PrisonAPI.getSqlStore;
|
||||||
|
|
||||||
public class Prisoner {
|
public class Prisoner extends AbstractApiData {
|
||||||
|
|
||||||
|
private WeakReference<PlayersInCagesEntity> refPlayersInCagesEntity;
|
||||||
|
|
||||||
protected Player me;
|
|
||||||
protected Level level;
|
protected Level level;
|
||||||
protected Faction faction;
|
protected Faction faction;
|
||||||
protected Wallet wallet;
|
protected Wallet wallet;
|
||||||
protected Stats stats;
|
protected Stats stats;
|
||||||
|
|
||||||
public Prisoner(Player player) {
|
public Prisoner(Player player) {
|
||||||
me = player;
|
super(player);
|
||||||
level = new Level(this);
|
level = new Level(this);
|
||||||
wallet = new Wallet(this);
|
wallet = new Wallet(this);
|
||||||
faction = new Faction(this);
|
faction = new Faction(this);
|
||||||
@@ -120,115 +121,36 @@ public class Prisoner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getSuspect() {
|
public int getSuspect() {
|
||||||
try (SqlSession session = getSqlStore().openSession()) {
|
return getPlayerStatsEntity().getSuspect();
|
||||||
try (PreparedStatement statement = session.getConnection().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) {
|
public void setSuspect(int value) {
|
||||||
try (SqlSession session = getSqlStore().openSession()) {
|
getPlayerStatsEntity().setSuspect(value);
|
||||||
try (PreparedStatement statement = session.getConnection().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) {
|
public void addSuspect(int value) {
|
||||||
int su = getSuspect() + value;
|
int newValue = getSuspect() + value;
|
||||||
setSuspect(su);
|
if (newValue > 6) {
|
||||||
if(su > 6) {
|
setSuspect(newValue - (newValue - 6));
|
||||||
setSuspect(su - (su - 6));
|
} else {
|
||||||
|
setSuspect(newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTimeLeftInCage() {
|
public int getTimeLeftInCage() {
|
||||||
try (SqlSession session = getSqlStore().openSession()) {
|
return getPlayersInCagesEntity().getTimeInCage();
|
||||||
try (PreparedStatement statement = session.getConnection().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) {
|
public void setTimeLeftInCage(int value) {
|
||||||
try (SqlSession session = getSqlStore().openSession()) {
|
getPlayersInCagesEntity().setTimeInCage(value);
|
||||||
try {
|
|
||||||
PreparedStatement statement = session.getConnection().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.close();
|
|
||||||
|
|
||||||
statement = session.getConnection().prepareStatement("UPDATE players_in_cages SET TIME_IN_CAGE = ? WHERE UUID = ?");
|
|
||||||
statement.setInt(1, value);
|
|
||||||
statement.setString(2, me.getUniqueId().toString());
|
|
||||||
statement.execute();
|
|
||||||
|
|
||||||
statement.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException z) {
|
|
||||||
z.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBlocksLeftToBreak() {
|
public int getBlocksLeftToBreak() {
|
||||||
try (SqlSession session = getSqlStore().openSession()) {
|
return getPlayersInCagesEntity().getBlocksLeft();
|
||||||
try (PreparedStatement statement = session.getConnection().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() {
|
public boolean isLocateInCage() {
|
||||||
try (SqlSession session = getSqlStore().openSession()) {
|
return getPlayersInCagesEntity() != null;
|
||||||
try (PreparedStatement statement = session.getConnection().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() {
|
public Faction getFaction() {
|
||||||
@@ -244,39 +166,45 @@ public class Prisoner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void register() throws SQLException {
|
public void register() throws SQLException {
|
||||||
try (SqlSession session = getSqlStore().openSession()) {
|
try (SqlSession sqlSession = getSqlStore().openSession()) {
|
||||||
final Connection connection = session.getConnection();
|
Integer result = sqlSession.selectOne("PlayerStats.countByUuid", getPlayer().getUniqueId().toString());
|
||||||
|
if (result == null || result == 0) {
|
||||||
|
sqlSession.insert("PlayerStats.register", ImmutableMap.builder()
|
||||||
|
.put("name", getPlayer().getName())
|
||||||
|
.put("uuid", getPlayer().getUniqueId().toString())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
PreparedStatement statement = connection.prepareStatement("SELECT UUID FROM player_stats WHERE UUID = ?");
|
sqlSession.insert("DailyRespectTask.register", ImmutableMap.builder()
|
||||||
statement.setString(1, me.getUniqueId().toString());
|
.put("name", getPlayer().getName())
|
||||||
|
.put("uuid", getPlayer().getUniqueId().toString())
|
||||||
|
.put("cooldown", 3600 * 24)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
try (ResultSet resultSet = statement.executeQuery()) {
|
level = new Level(this);
|
||||||
if (!resultSet.next()) {
|
stats = new Stats(this);
|
||||||
statement.close();
|
wallet = new Wallet(this);
|
||||||
|
|
||||||
statement = connection.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 = connection.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();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PlayersInCagesEntity getPlayersInCagesEntity() {
|
||||||
|
PlayersInCagesEntity entity;
|
||||||
|
if (refPlayersInCagesEntity != null) {
|
||||||
|
entity = refPlayersInCagesEntity.get();
|
||||||
|
return entity;
|
||||||
|
} else {
|
||||||
|
try (SqlSession session = PrisonAPI.getSqlStore().openSession()) {
|
||||||
|
entity = session.selectOne("PlayersInCages.selectOne", me.getPlayer().getUniqueId().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity == null) {
|
||||||
|
throw new RuntimeException("no data in db by '" + me.getPlayer().getUniqueId().toString() + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
refPlayersInCagesEntity = new WeakReference<>(entity);
|
||||||
|
return entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
package ru.prisonlife.api.template;
|
package ru.prisonlife.api.template;
|
||||||
|
|
||||||
public class Score extends AbstractApiData {
|
public class Score extends AbstractSubApiData {
|
||||||
|
|
||||||
public Score(Prisoner me) {
|
public Score(Prisoner me) {
|
||||||
super(me);
|
super(me);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPoints() {
|
public double getPoints() {
|
||||||
return getPlayerStatsEntity().getPoints();
|
return me.getPlayerStatsEntity().getPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPoints(double value) {
|
public void setPoints(double value) {
|
||||||
getPlayerStatsEntity().setPoints(value);
|
me.getPlayerStatsEntity().setPoints(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPoints(double value) {
|
public void addPoints(double value) {
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
package ru.prisonlife.api.template;
|
package ru.prisonlife.api.template;
|
||||||
|
|
||||||
public class Stats extends AbstractApiData {
|
public class Stats extends AbstractSubApiData {
|
||||||
|
|
||||||
public Stats(Prisoner me) {
|
public Stats(Prisoner me) {
|
||||||
super(me);
|
super(me);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServerTime(int value) {
|
public void setServerTime(int value) {
|
||||||
getPlayerStatsEntity().setServerTime(value);
|
me.getPlayerStatsEntity().setServerTime(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getServerTime() {
|
public int getServerTime() {
|
||||||
return getPlayerStatsEntity().getServerTime();
|
return me.getPlayerStatsEntity().getServerTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addServerTime(int value) {
|
public void addServerTime(int value) {
|
||||||
@@ -19,11 +19,11 @@ public class Stats extends AbstractApiData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setBlocks(int value) {
|
public void setBlocks(int value) {
|
||||||
getPlayerStatsEntity().setBlocks(value);
|
me.getPlayerStatsEntity().setBlocks(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBlocks() {
|
public int getBlocks() {
|
||||||
return getPlayerStatsEntity().getBlocks();
|
return me.getPlayerStatsEntity().getBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBlocks(int value) {
|
public void addBlocks(int value) {
|
||||||
@@ -31,11 +31,11 @@ public class Stats extends AbstractApiData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayers(int value) {
|
public void setPlayers(int value) {
|
||||||
getPlayerStatsEntity().setPlayers(value);
|
me.getPlayerStatsEntity().setPlayers(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPlayers() {
|
public int getPlayers() {
|
||||||
return getPlayerStatsEntity().getPlayers();
|
return me.getPlayerStatsEntity().getPlayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayers(int value) {
|
public void addPlayers(int value) {
|
||||||
@@ -43,11 +43,11 @@ public class Stats extends AbstractApiData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setMobs(int value) {
|
public void setMobs(int value) {
|
||||||
getPlayerStatsEntity().setMobs(value);
|
me.getPlayerStatsEntity().setMobs(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMobs() {
|
public int getMobs() {
|
||||||
return getPlayerStatsEntity().getMobs();
|
return me.getPlayerStatsEntity().getMobs();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMobs(int value) {
|
public void addMobs(int value) {
|
||||||
@@ -55,11 +55,11 @@ public class Stats extends AbstractApiData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setDeaths(int value) {
|
public void setDeaths(int value) {
|
||||||
getPlayerStatsEntity().setDeaths(value);
|
me.getPlayerStatsEntity().setDeaths(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDeaths() {
|
public int getDeaths() {
|
||||||
return getPlayerStatsEntity().getDeaths();
|
return me.getPlayerStatsEntity().getDeaths();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDeaths(int value) {
|
public void addDeaths(int value) {
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package ru.prisonlife.api.template;
|
package ru.prisonlife.api.template;
|
||||||
|
|
||||||
public class Wallet extends AbstractApiData {
|
public class Wallet extends AbstractSubApiData {
|
||||||
|
|
||||||
public Wallet(Prisoner me) {
|
public Wallet(Prisoner me) {
|
||||||
super(me);
|
super(me);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBalance() {
|
public int getBalance() {
|
||||||
return getPlayerStatsEntity().getWallet();
|
return me.getPlayerStatsEntity().getWallet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBalance(int value) {
|
public void addBalance(int value) {
|
||||||
@@ -19,6 +19,6 @@ public class Wallet extends AbstractApiData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setBalance(int value) {
|
public void setBalance(int value) {
|
||||||
getPlayerStatsEntity().setWallet(value);
|
me.getPlayerStatsEntity().setWallet(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,11 @@
|
|||||||
SELECT COOLDOWN FROM daily_respect_task WHERE UUID = #{id}
|
SELECT COOLDOWN FROM daily_respect_task WHERE UUID = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<insert id="register">
|
||||||
|
INSERT INTO daily_respect_task(NAME, UUID, COOLDOWN)
|
||||||
|
VALUES (#{name}, #{uuid}, #{cooldown})
|
||||||
|
</insert>
|
||||||
|
|
||||||
<update id="update" parameterType="DailyRespectTask">
|
<update id="update" parameterType="DailyRespectTask">
|
||||||
UPDATE daily_respect_task
|
UPDATE daily_respect_task
|
||||||
SET COOLDOWN = #{cooldownRespect}
|
SET COOLDOWN = #{cooldownRespect}
|
||||||
|
|||||||
@@ -16,12 +16,22 @@
|
|||||||
<result property = "players" column = "K_PLAYERS"/>
|
<result property = "players" column = "K_PLAYERS"/>
|
||||||
<result property = "mobs" column = "K_MOBS"/>
|
<result property = "mobs" column = "K_MOBS"/>
|
||||||
<result property = "deaths" column = "DEATHS"/>
|
<result property = "deaths" column = "DEATHS"/>
|
||||||
|
<result property = "suspect" column = "SUSPECT"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<select id="selectOne" parameterType="String" resultMap="result">
|
<select id="selectOne" parameterType="String" resultMap="result">
|
||||||
SELECT * FROM player_stats WHERE UUID = #{id}
|
SELECT * FROM player_stats WHERE UUID = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="countByUuid" parameterType="String" resultType="java.lang.Integer">
|
||||||
|
SELECT COUNT(*) FROM player_stats WHERE UUID = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="register">
|
||||||
|
INSERT INTO player_stats (NAME, UUID, LEVEL, POINTS, FACTION, RESPECT, F_RANG, SUSPECT, WALLET, G_TIME, D_BLOCKS, K_PLAYERS, K_MOBS, DEATHS)
|
||||||
|
VALUES (#{name}, #{uuid}, 1, 0, 'NONE', 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||||
|
</insert>
|
||||||
|
|
||||||
<update id="update" parameterType="PlayerStats">
|
<update id="update" parameterType="PlayerStats">
|
||||||
UPDATE player_stats
|
UPDATE player_stats
|
||||||
SET WALLET = #{wallet},
|
SET WALLET = #{wallet},
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version = "1.0" encoding = "UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="PlayersInCages">
|
||||||
|
|
||||||
|
<resultMap id = "result" type = "PlayersInCages">
|
||||||
|
<result property = "name" column = "NAME"/>
|
||||||
|
<result property = "uuid" column = "UUID"/>
|
||||||
|
<result property = "timeInCage" column = "TIME_IN_CAGE"/>
|
||||||
|
<result property = "blocksLeft" column = "BLOCKS_LEFT"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<select id="selectOne" parameterType="String" resultMap="PlayersInCages">
|
||||||
|
SELECT * FROM players_in_cages WHERE UUID = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getTimeInCage" parameterType="String" resultType="java.lang.Integer">
|
||||||
|
SELECT TIME_IN_CAGE FROM players_in_cages WHERE UUID = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="register" parameterType="PlayersInCages">
|
||||||
|
INSERT INTO players_in_cages (NAME, UUID, TIME_IN_CAGE, BLOCKS_LEFT)
|
||||||
|
VALUES (#{name}, #{uuid}, #{timeInCage}, #{blocksLeft})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="updateTimeInCage">
|
||||||
|
UPDATE players_in_cages SET TIME_IN_CAGE = #{time} WHERE UUID = #{uuid}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<delete id="deleteByUuid">
|
||||||
|
DELETE FROM players_in_cages WHERE UUID = #{id}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
<mappers>
|
<mappers>
|
||||||
<mapper resource = "PlayerStatsMapper.xml"/>
|
<mapper resource = "PlayerStatsMapper.xml"/>
|
||||||
<mapper resource = "DailyRespectTaskMapper.xml"/>
|
<mapper resource = "DailyRespectTaskMapper.xml"/>
|
||||||
|
<mapper resource = "PlayersInCagesMapper.xml"/>
|
||||||
</mappers>
|
</mappers>
|
||||||
|
|
||||||
</configuration>
|
</configuration>
|
||||||
Reference in New Issue
Block a user