mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-06 16:27:59 +01:00
Correct way to remove old explore data
This commit is contained in:
parent
6acf9bee0a
commit
27bc14f214
@ -12,9 +12,9 @@ public class ExploreChunk {
|
|||||||
private int x;
|
private int x;
|
||||||
private int z;
|
private int z;
|
||||||
private Set<Integer> playerIds = new HashSet<>();
|
private Set<Integer> playerIds = new HashSet<>();
|
||||||
private boolean full = false;
|
private Boolean full;
|
||||||
private Integer dbId = null;
|
private Integer dbId;
|
||||||
private boolean updated = false;
|
private Boolean updated;
|
||||||
|
|
||||||
public ExploreChunk(int playerId, int x, int z) {
|
public ExploreChunk(int playerId, int x, int z) {
|
||||||
this(x, z);
|
this(x, z);
|
||||||
@ -28,7 +28,7 @@ public class ExploreChunk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ExploreRespond addPlayer(int playerId) {
|
public ExploreRespond addPlayer(int playerId) {
|
||||||
if (full) {
|
if (isFullyExplored()) {
|
||||||
return new ExploreRespond(Jobs.getExplore().getPlayerAmount() + 1, false);
|
return new ExploreRespond(Jobs.getExplore().getPlayerAmount() + 1, false);
|
||||||
}
|
}
|
||||||
boolean newChunkForPlayer = false;
|
boolean newChunkForPlayer = false;
|
||||||
@ -50,13 +50,13 @@ public class ExploreChunk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAlreadyVisited(int playerId) {
|
public boolean isAlreadyVisited(int playerId) {
|
||||||
if (full)
|
if (isFullyExplored())
|
||||||
return true;
|
return true;
|
||||||
return playerIds.contains(playerId);
|
return playerIds.contains(playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
if (full)
|
if (isFullyExplored())
|
||||||
return Jobs.getExplore().getPlayerAmount();
|
return Jobs.getExplore().getPlayerAmount();
|
||||||
return playerIds.size();
|
return playerIds.size();
|
||||||
}
|
}
|
||||||
@ -131,14 +131,17 @@ public class ExploreChunk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUpdated() {
|
public boolean isUpdated() {
|
||||||
return updated;
|
return updated == null ? false : updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUpdated(boolean updated) {
|
public void setUpdated(boolean updated) {
|
||||||
this.updated = updated;
|
if (!updated)
|
||||||
|
this.updated = null;
|
||||||
|
else
|
||||||
|
this.updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFullyExplored() {
|
public boolean isFullyExplored() {
|
||||||
return full;
|
return full == null ? false : full;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,10 @@ import java.sql.SQLException;
|
|||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@ -1748,7 +1750,7 @@ public abstract class JobsDAO {
|
|||||||
String uuid = res.getString(UserTableFields.player_uuid.getCollumn());
|
String uuid = res.getString(UserTableFields.player_uuid.getCollumn());
|
||||||
if (uuid == null || uuid.isEmpty()) {
|
if (uuid == null || uuid.isEmpty()) {
|
||||||
PreparedStatement ps = conn.prepareStatement("DELETE FROM `" + DBTables.UsersTable.getTableName()
|
PreparedStatement ps = conn.prepareStatement("DELETE FROM `" + DBTables.UsersTable.getTableName()
|
||||||
+ "` WHERE `" + UserTableFields.player_uuid.getCollumn() + "` = ?;");
|
+ "` WHERE `" + UserTableFields.player_uuid.getCollumn() + "` = ?;");
|
||||||
ps.setString(1, uuid);
|
ps.setString(1, uuid);
|
||||||
ps.execute();
|
ps.execute();
|
||||||
continue;
|
continue;
|
||||||
@ -2469,18 +2471,25 @@ public abstract class JobsDAO {
|
|||||||
try {
|
try {
|
||||||
prest = conn.prepareStatement("SELECT * FROM `" + DBTables.ExploreDataTable.getTableName() + "`;");
|
prest = conn.prepareStatement("SELECT * FROM `" + DBTables.ExploreDataTable.getTableName() + "`;");
|
||||||
res = prest.executeQuery();
|
res = prest.executeQuery();
|
||||||
|
Set<Integer> missingWorlds = new HashSet<Integer>();
|
||||||
while (res.next()) {
|
while (res.next()) {
|
||||||
String worldName = res.getString(ExploreDataTableFields.worldname.getCollumn());
|
int worldId = res.getInt(ExploreDataTableFields.worldid.getCollumn());
|
||||||
if (worldName == null || Bukkit.getWorld(worldName) == null) {
|
JobsWorld jworld = Util.getJobsWorld(worldId);
|
||||||
PreparedStatement prest2 = null;
|
if (jworld == null || jworld.getWorld() == null) {
|
||||||
prest2 = conn.prepareStatement("DELETE FROM `" + DBTables.ExploreDataTable.getTableName() + "` WHERE `" + ExploreDataTableFields.worldname.getCollumn() + "` = ?;");
|
missingWorlds.add(worldId);
|
||||||
prest2.setString(1, worldName);
|
|
||||||
prest2.execute();
|
|
||||||
close(prest2);
|
|
||||||
} else {
|
} else {
|
||||||
Jobs.getExplore().load(res);
|
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) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} 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() {
|
public HashMap<Integer, ArrayList<JobsDAOData>> getMap() {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user