mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-02 14:29:07 +01:00
Fixing duplicated points records in database
This commit is contained in:
parent
9adcc1593e
commit
383bf5da2d
@ -112,7 +112,7 @@ public class JobsPlayer {
|
||||
public void setPoints(PlayerPoints points) {
|
||||
getPointsData().setPoints(points.getCurrentPoints());
|
||||
getPointsData().setTotalPoints(points.getTotalPoints());
|
||||
getPointsData().setNewEntry(points.isNewEntry());
|
||||
getPointsData().setDbId(points.getDbId());
|
||||
}
|
||||
|
||||
public boolean havePoints(double points) {
|
||||
|
@ -4,15 +4,12 @@ public class PlayerPoints {
|
||||
|
||||
private double current = 0D;
|
||||
private double total = 0D;
|
||||
private boolean newEntry = false;
|
||||
private int dbId = 0;
|
||||
|
||||
public PlayerPoints() {
|
||||
newEntry = true;
|
||||
}
|
||||
|
||||
public PlayerPoints(double points, double total) {
|
||||
if (points == 0D && total == 0D)
|
||||
newEntry = true;
|
||||
this.current = points;
|
||||
this.total = total;
|
||||
}
|
||||
@ -43,15 +40,15 @@ public class PlayerPoints {
|
||||
return total;
|
||||
}
|
||||
|
||||
public boolean isNewEntry() {
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
public void setNewEntry(boolean newEntry) {
|
||||
this.newEntry = newEntry;
|
||||
}
|
||||
|
||||
public void setTotalPoints(double total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public int getDbId() {
|
||||
return dbId;
|
||||
}
|
||||
|
||||
public void setDbId(int dbId) {
|
||||
this.dbId = dbId;
|
||||
}
|
||||
}
|
||||
|
@ -1929,19 +1929,52 @@ public abstract class JobsDAO {
|
||||
JobsConnection conn = getConnection();
|
||||
if (conn == null)
|
||||
return;
|
||||
PreparedStatement prest = null;
|
||||
try {
|
||||
PlayerPoints pointInfo = jPlayer.getPointsData();
|
||||
prest = conn.prepareStatement("INSERT INTO `" + DBTables.PointsTable.getTableName() + "` (`" + PointsTableFields.totalpoints.getCollumn() + "`, `" + PointsTableFields.currentpoints.getCollumn()
|
||||
+ "`, `" + PointsTableFields.userid.getCollumn() + "`) VALUES (?, ?, ?);");
|
||||
prest.setDouble(1, pointInfo.getTotalPoints());
|
||||
prest.setDouble(2, pointInfo.getCurrentPoints());
|
||||
prest.setInt(3, jPlayer.getUserId());
|
||||
prest.execute();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
close(prest);
|
||||
|
||||
PlayerPoints pointInfo = jPlayer.getPointsData();
|
||||
|
||||
if (pointInfo.getDbId() == 0) {
|
||||
// This needs to exist, removing existing entry by user id unless we have actual line id
|
||||
PreparedStatement prest2 = null;
|
||||
try {
|
||||
prest2 = conn.prepareStatement("DELETE FROM `" + DBTables.PointsTable.getTableName() + "` WHERE `" + PointsTableFields.userid.getCollumn() + "` = ?;");
|
||||
prest2.setInt(1, jPlayer.getUserId());
|
||||
prest2.execute();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
close(prest2);
|
||||
}
|
||||
PreparedStatement prest = null;
|
||||
try {
|
||||
prest = conn.prepareStatement("INSERT INTO `" + DBTables.PointsTable.getTableName() + "` (`" + PointsTableFields.totalpoints.getCollumn() + "`, `" + PointsTableFields.currentpoints
|
||||
.getCollumn()
|
||||
+ "`, `" + PointsTableFields.userid.getCollumn() + "`) VALUES (?, ?, ?);");
|
||||
prest.setDouble(1, pointInfo.getTotalPoints());
|
||||
prest.setDouble(2, pointInfo.getCurrentPoints());
|
||||
prest.setInt(3, jPlayer.getUserId());
|
||||
prest.execute();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
close(prest);
|
||||
}
|
||||
} else {
|
||||
|
||||
PreparedStatement prest = null;
|
||||
try {
|
||||
prest = conn.prepareStatement("UPDATE `" + DBTables.PointsTable.getTableName() + "` SET `" + PointsTableFields.totalpoints.getCollumn()
|
||||
+ "` = ?, `" + PointsTableFields.currentpoints.getCollumn()
|
||||
+ "` = ? WHERE `id` = ?;");
|
||||
prest.setDouble(1, pointInfo.getTotalPoints());
|
||||
prest.setDouble(2, pointInfo.getCurrentPoints());
|
||||
prest.setInt(3, pointInfo.getDbId());
|
||||
prest.execute();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
close(prest);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1958,6 +1991,7 @@ public abstract class JobsDAO {
|
||||
res = prest.executeQuery();
|
||||
|
||||
if (res.next()) {
|
||||
player.getPointsData().setDbId(res.getInt("id"));
|
||||
player.getPointsData().setPoints(res.getDouble(PointsTableFields.currentpoints.getCollumn()));
|
||||
player.getPointsData().setTotalPoints(res.getDouble(PointsTableFields.totalpoints.getCollumn()));
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class PointsData {
|
||||
PlayerPoints pi = Jobs.getPlayerManager().getJobsPlayer(uuid).getPointsData();
|
||||
pi.setPoints(points.getCurrentPoints());
|
||||
pi.setTotalPoints(points.getTotalPoints());
|
||||
pi.setNewEntry(points.isNewEntry());
|
||||
pi.setDbId(points.getDbId());
|
||||
}
|
||||
|
||||
public void addPoints(UUID uuid, Double points) {
|
||||
|
Loading…
Reference in New Issue
Block a user