1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-26 04:25:15 +01:00

Compacting explore cache

This commit is contained in:
Zrips 2020-09-28 18:57:15 +03:00
parent b70bd4d49b
commit ba37c1b746
6 changed files with 68 additions and 51 deletions

View File

@ -984,7 +984,7 @@ public class PlayerManager {
if (getall) { if (getall) {
if (petPay == null) if (petPay == null)
petPay = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay", force); petPay = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay", force);
if (petPay != null) if (petPay != null)
boost.add(BoostOf.PetPay, new BoostMultiplier().add(petPay)); boost.add(BoostOf.PetPay, new BoostMultiplier().add(petPay));
Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner", force); Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner", force);

View File

@ -79,9 +79,9 @@ public class ExploreManager {
} }
ExploreChunk chunk = eRegions.getChunk(x, z); ExploreChunk chunk = eRegions.getChunk(x, z);
if (chunk == null) if (chunk == null)
chunk = new ExploreChunk(x, z); chunk = new ExploreChunk();
eRegions.addChunk(chunk); eRegions.addChunk(x, z, chunk);
worlds.put(world, eRegions); worlds.put(world, eRegions);
return chunk.addPlayer(playerId); return chunk.addPlayer(playerId);
@ -111,11 +111,11 @@ public class ExploreManager {
} }
ExploreChunk chunk = eRegions.getChunk(x, z); ExploreChunk chunk = eRegions.getChunk(x, z);
if (chunk == null) if (chunk == null)
chunk = new ExploreChunk(x, z); chunk = new ExploreChunk();
chunk.deserializeNames(names); chunk.deserializeNames(names);
chunk.setDbId(id); chunk.setDbId(id);
eRegions.addChunk(chunk); eRegions.addChunk(x, z, chunk);
worlds.put(jobsWorld.getName(), eRegions); worlds.put(jobsWorld.getName(), eRegions);
} catch (SQLException e) { } catch (SQLException e) {

View File

@ -9,23 +9,19 @@ import com.gamingmesh.jobs.Jobs;
public class ExploreChunk { 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; private int dbId = -1;
private Integer dbId; private boolean updated = false;
private Boolean updated;
public ExploreChunk(int playerId, int x, int z) { public ExploreChunk() {
this(x, z);
this.playerIds.add(playerId);
} }
public ExploreChunk(int x, int z) { // public ExploreChunk(int x, int z) {
this.x = x; // this.x = x;
this.z = z; // this.z = z;
} // }
public ExploreRespond addPlayer(int playerId) { public ExploreRespond addPlayer(int playerId) {
if (isFullyExplored()) { if (isFullyExplored()) {
@ -41,7 +37,6 @@ public class ExploreChunk {
} }
if (playerIds.size() >= Jobs.getExplore().getPlayerAmount()) { if (playerIds.size() >= Jobs.getExplore().getPlayerAmount()) {
this.full = true;
if (Jobs.getGCManager().ExploreCompact) if (Jobs.getGCManager().ExploreCompact)
playerIds = null; playerIds = null;
} }
@ -57,13 +52,13 @@ public class ExploreChunk {
return isFullyExplored() ? Jobs.getExplore().getPlayerAmount() : playerIds.size(); return isFullyExplored() ? Jobs.getExplore().getPlayerAmount() : playerIds.size();
} }
public int getX() { // public int getX() {
return x; // return x;
} // }
//
public int getZ() { // public int getZ() {
return z; // return z;
} // }
public Set<Integer> getPlayers() { public Set<Integer> getPlayers() {
return playerIds == null ? new HashSet<>() : playerIds; return playerIds == null ? new HashSet<>() : playerIds;
@ -84,7 +79,6 @@ public class ExploreChunk {
public void deserializeNames(String names) { public void deserializeNames(String names) {
if (names == null || names.isEmpty()) { if (names == null || names.isEmpty()) {
this.full = true;
playerIds = null; playerIds = null;
return; return;
} }
@ -109,7 +103,6 @@ public class ExploreChunk {
} }
if (playerIds.size() >= Jobs.getExplore().getPlayerAmount()) { if (playerIds.size() >= Jobs.getExplore().getPlayerAmount()) {
this.full = true;
if (Jobs.getGCManager().ExploreCompact) { if (Jobs.getGCManager().ExploreCompact) {
playerIds = null; playerIds = null;
if (!names.isEmpty()) if (!names.isEmpty())
@ -118,23 +111,23 @@ public class ExploreChunk {
} }
} }
public Integer getDbId() { public int getDbId() {
return dbId; return dbId;
} }
public void setDbId(Integer dbId) { public void setDbId(int dbId) {
this.dbId = dbId; this.dbId = dbId;
} }
public boolean isUpdated() { public boolean isUpdated() {
return updated == null ? false : updated; return updated;
} }
public void setUpdated(boolean updated) { public void setUpdated(boolean updated) {
this.updated = !updated ? null : true; this.updated = updated;
} }
public boolean isFullyExplored() { public boolean isFullyExplored() {
return full != null && full; return playerIds == null || playerIds.size() >= Jobs.getExplore().getPlayerAmount();
} }
} }

View File

@ -9,30 +9,56 @@ public class ExploreRegion {
int x; int x;
int z; int z;
private final HashMap<String, ExploreChunk> chunks = new HashMap<>(); private final HashMap<Short, ExploreChunk> chunks = new HashMap<>();
public ExploreRegion(int x, int z) { public ExploreRegion(int x, int z) {
this.x = x; this.x = x;
this.z = z; this.z = z;
} }
public void addChunk(ExploreChunk chunk) { public void addChunk(int x, int z, ExploreChunk chunk) {
chunks.put(chunk.getX() + ":" + chunk.getZ(), chunk); chunks.put(getPlace(x, z), chunk);
} }
public HashMap<String, ExploreChunk> getChunks() { public HashMap<Short, ExploreChunk> getChunks() {
return chunks; return chunks;
} }
public ExploreChunk getChunk(int x, int z) { public ExploreChunk getChunk(int x, int z) {
return getChunk(x + ":" + z); return getChunk(getPlace(x, z));
} }
public ExploreChunk getChunk(Chunk chunk) { public ExploreChunk getChunk(Chunk chunk) {
return getChunk(chunk.getX() + ":" + chunk.getZ()); return getChunk(getPlace(chunk));
} }
public ExploreChunk getChunk(String cord) { public ExploreChunk getChunk(short place) {
return chunks.get(cord); return chunks.get(place);
}
private static short getPlace(Chunk chunk) {
return getPlace(chunk.getX(), chunk.getZ());
}
private static short getPlace(int x, int z) {
return (short) ((x - ((x >> 5) * 32)) + ((z - ((z >> 5) * 32)) * 32));
}
public int getChunkX(short place) {
int endX = place % 32;
if (x < 0)
endX = -endX;
endX = x * 32 + endX;
endX = endX < 0 ? endX + 32 : endX;
return endX;
}
public int getChunkZ(short place) {
int endZ = (place - (place % 32)) / 32;
if (z < 0)
endZ = -endZ;
endZ = z * 32 + endZ;
endZ = endZ < 0 ? endZ + 32 : endZ;
return endZ;
} }
} }

View File

@ -2307,13 +2307,14 @@ public abstract class JobsDAO {
int id = jobsWorld == null ? 0 : jobsWorld.getId(); int id = jobsWorld == null ? 0 : jobsWorld.getId();
if (id != 0) if (id != 0)
for (ExploreChunk oneChunk : worlds.getValue().getChunks().values()) { for (Entry<Short, ExploreChunk> oneChunk : worlds.getValue().getChunks().entrySet()) {
if (oneChunk.getDbId() != null) ExploreChunk chunk = oneChunk.getValue();
if (chunk.getDbId() != -1)
continue; continue;
prest2.setInt(1, id); prest2.setInt(1, id);
prest2.setInt(2, oneChunk.getX()); prest2.setInt(2, worlds.getValue().getChunkX(oneChunk.getKey()));
prest2.setInt(3, oneChunk.getZ()); prest2.setInt(3, worlds.getValue().getChunkZ(oneChunk.getKey()));
prest2.setString(4, oneChunk.serializeNames()); prest2.setString(4, chunk.serializeNames());
prest2.setString(5, jobsWorld != null ? jobsWorld.getName() : ""); prest2.setString(5, jobsWorld != null ? jobsWorld.getName() : "");
prest2.addBatch(); prest2.addBatch();
i++; i++;
@ -2356,7 +2357,7 @@ public abstract class JobsDAO {
for (ExploreRegion worlds : temp.values()) { for (ExploreRegion worlds : temp.values()) {
for (ExploreChunk oneChunk : worlds.getChunks().values()) { for (ExploreChunk oneChunk : worlds.getChunks().values()) {
if (oneChunk.getDbId() == null) if (oneChunk.getDbId() == -1)
continue; continue;
if (!oneChunk.isUpdated()) if (!oneChunk.isUpdated())
continue; continue;

View File

@ -20,10 +20,7 @@ public class MyPetManager {
} }
public boolean isMyPet(Object ent) { public boolean isMyPet(Object ent) {
if (!enabled || !(ent instanceof MyPetBukkitEntity)) return enabled && ent instanceof MyPetBukkitEntity;
return false;
return true;
} }
public UUID getOwnerOfPet(Object ent) { public UUID getOwnerOfPet(Object ent) {