1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-04 23:37:49 +01:00

Correct way to remove old explore data

This commit is contained in:
Zrips 2020-05-11 16:10:19 +03:00
parent 6acf9bee0a
commit 27bc14f214
2 changed files with 38 additions and 17 deletions

View File

@ -12,9 +12,9 @@ public class ExploreChunk {
private int x;
private int z;
private Set<Integer> playerIds = new HashSet<>();
private boolean full = false;
private Integer dbId = null;
private boolean updated = false;
private Boolean full;
private Integer dbId;
private Boolean updated;
public ExploreChunk(int playerId, int x, int z) {
this(x, z);
@ -28,7 +28,7 @@ public class ExploreChunk {
}
public ExploreRespond addPlayer(int playerId) {
if (full) {
if (isFullyExplored()) {
return new ExploreRespond(Jobs.getExplore().getPlayerAmount() + 1, false);
}
boolean newChunkForPlayer = false;
@ -50,13 +50,13 @@ public class ExploreChunk {
}
public boolean isAlreadyVisited(int playerId) {
if (full)
if (isFullyExplored())
return true;
return playerIds.contains(playerId);
}
public int getCount() {
if (full)
if (isFullyExplored())
return Jobs.getExplore().getPlayerAmount();
return playerIds.size();
}
@ -131,14 +131,17 @@ public class ExploreChunk {
}
public boolean isUpdated() {
return updated;
return updated == null ? false : updated;
}
public void setUpdated(boolean updated) {
this.updated = updated;
if (!updated)
this.updated = null;
else
this.updated = true;
}
public boolean isFullyExplored() {
return full;
return full == null ? false : full;
}
}

View File

@ -6,8 +6,10 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@ -1748,7 +1750,7 @@ public abstract class JobsDAO {
String uuid = res.getString(UserTableFields.player_uuid.getCollumn());
if (uuid == null || uuid.isEmpty()) {
PreparedStatement ps = conn.prepareStatement("DELETE FROM `" + DBTables.UsersTable.getTableName()
+ "` WHERE `" + UserTableFields.player_uuid.getCollumn() + "` = ?;");
+ "` WHERE `" + UserTableFields.player_uuid.getCollumn() + "` = ?;");
ps.setString(1, uuid);
ps.execute();
continue;
@ -2469,18 +2471,25 @@ public abstract class JobsDAO {
try {
prest = conn.prepareStatement("SELECT * FROM `" + DBTables.ExploreDataTable.getTableName() + "`;");
res = prest.executeQuery();
Set<Integer> missingWorlds = new HashSet<Integer>();
while (res.next()) {
String worldName = res.getString(ExploreDataTableFields.worldname.getCollumn());
if (worldName == null || Bukkit.getWorld(worldName) == null) {
PreparedStatement prest2 = null;
prest2 = conn.prepareStatement("DELETE FROM `" + DBTables.ExploreDataTable.getTableName() + "` WHERE `" + ExploreDataTableFields.worldname.getCollumn() + "` = ?;");
prest2.setString(1, worldName);
prest2.execute();
close(prest2);
int worldId = res.getInt(ExploreDataTableFields.worldid.getCollumn());
JobsWorld jworld = Util.getJobsWorld(worldId);
if (jworld == null || jworld.getWorld() == null) {
missingWorlds.add(worldId);
} else {
Jobs.getExplore().load(res);
}
}
for (Integer one : missingWorlds) {
PreparedStatement prest2 = null;
prest2 = conn.prepareStatement("DELETE FROM `" + DBTables.ExploreDataTable.getTableName() + "` WHERE `" + ExploreDataTableFields.worldid.getCollumn() + "` = ?;");
prest2.setInt(1, one);
prest2.execute();
close(prest2);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
@ -2677,6 +2686,15 @@ public abstract class JobsDAO {
}
}
protected static void close(PreparedStatement stmt) {
if (stmt != null)
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public HashMap<Integer, ArrayList<JobsDAOData>> getMap() {
return map;
}