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:
parent
b70bd4d49b
commit
ba37c1b746
@ -984,7 +984,7 @@ public class PlayerManager {
|
||||
|
||||
if (getall) {
|
||||
if (petPay == null)
|
||||
petPay = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay", force);
|
||||
petPay = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay", force);
|
||||
if (petPay != null)
|
||||
boost.add(BoostOf.PetPay, new BoostMultiplier().add(petPay));
|
||||
Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner", force);
|
||||
|
@ -79,9 +79,9 @@ public class ExploreManager {
|
||||
}
|
||||
ExploreChunk chunk = eRegions.getChunk(x, z);
|
||||
if (chunk == null)
|
||||
chunk = new ExploreChunk(x, z);
|
||||
chunk = new ExploreChunk();
|
||||
|
||||
eRegions.addChunk(chunk);
|
||||
eRegions.addChunk(x, z, chunk);
|
||||
worlds.put(world, eRegions);
|
||||
|
||||
return chunk.addPlayer(playerId);
|
||||
@ -111,11 +111,11 @@ public class ExploreManager {
|
||||
}
|
||||
ExploreChunk chunk = eRegions.getChunk(x, z);
|
||||
if (chunk == null)
|
||||
chunk = new ExploreChunk(x, z);
|
||||
chunk = new ExploreChunk();
|
||||
chunk.deserializeNames(names);
|
||||
chunk.setDbId(id);
|
||||
|
||||
eRegions.addChunk(chunk);
|
||||
eRegions.addChunk(x, z, chunk);
|
||||
worlds.put(jobsWorld.getName(), eRegions);
|
||||
|
||||
} catch (SQLException e) {
|
||||
|
@ -9,23 +9,19 @@ import com.gamingmesh.jobs.Jobs;
|
||||
|
||||
public class ExploreChunk {
|
||||
|
||||
private int x;
|
||||
private int z;
|
||||
// private int x;
|
||||
// private int z;
|
||||
private Set<Integer> playerIds = new HashSet<>();
|
||||
private Boolean full;
|
||||
private Integer dbId;
|
||||
private Boolean updated;
|
||||
private int dbId = -1;
|
||||
private boolean updated = false;
|
||||
|
||||
public ExploreChunk(int playerId, int x, int z) {
|
||||
this(x, z);
|
||||
|
||||
this.playerIds.add(playerId);
|
||||
public ExploreChunk() {
|
||||
}
|
||||
|
||||
public ExploreChunk(int x, int z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
// public ExploreChunk(int x, int z) {
|
||||
// this.x = x;
|
||||
// this.z = z;
|
||||
// }
|
||||
|
||||
public ExploreRespond addPlayer(int playerId) {
|
||||
if (isFullyExplored()) {
|
||||
@ -41,7 +37,6 @@ public class ExploreChunk {
|
||||
}
|
||||
|
||||
if (playerIds.size() >= Jobs.getExplore().getPlayerAmount()) {
|
||||
this.full = true;
|
||||
if (Jobs.getGCManager().ExploreCompact)
|
||||
playerIds = null;
|
||||
}
|
||||
@ -57,13 +52,13 @@ public class ExploreChunk {
|
||||
return isFullyExplored() ? Jobs.getExplore().getPlayerAmount() : playerIds.size();
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
// public int getX() {
|
||||
// return x;
|
||||
// }
|
||||
//
|
||||
// public int getZ() {
|
||||
// return z;
|
||||
// }
|
||||
|
||||
public Set<Integer> getPlayers() {
|
||||
return playerIds == null ? new HashSet<>() : playerIds;
|
||||
@ -84,7 +79,6 @@ public class ExploreChunk {
|
||||
|
||||
public void deserializeNames(String names) {
|
||||
if (names == null || names.isEmpty()) {
|
||||
this.full = true;
|
||||
playerIds = null;
|
||||
return;
|
||||
}
|
||||
@ -109,7 +103,6 @@ public class ExploreChunk {
|
||||
}
|
||||
|
||||
if (playerIds.size() >= Jobs.getExplore().getPlayerAmount()) {
|
||||
this.full = true;
|
||||
if (Jobs.getGCManager().ExploreCompact) {
|
||||
playerIds = null;
|
||||
if (!names.isEmpty())
|
||||
@ -118,23 +111,23 @@ public class ExploreChunk {
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getDbId() {
|
||||
public int getDbId() {
|
||||
return dbId;
|
||||
}
|
||||
|
||||
public void setDbId(Integer dbId) {
|
||||
public void setDbId(int dbId) {
|
||||
this.dbId = dbId;
|
||||
}
|
||||
|
||||
public boolean isUpdated() {
|
||||
return updated == null ? false : updated;
|
||||
return updated;
|
||||
}
|
||||
|
||||
public void setUpdated(boolean updated) {
|
||||
this.updated = !updated ? null : true;
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public boolean isFullyExplored() {
|
||||
return full != null && full;
|
||||
return playerIds == null || playerIds.size() >= Jobs.getExplore().getPlayerAmount();
|
||||
}
|
||||
}
|
||||
|
@ -9,30 +9,56 @@ public class ExploreRegion {
|
||||
int x;
|
||||
int z;
|
||||
|
||||
private final HashMap<String, ExploreChunk> chunks = new HashMap<>();
|
||||
private final HashMap<Short, ExploreChunk> chunks = new HashMap<>();
|
||||
|
||||
public ExploreRegion(int x, int z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public void addChunk(ExploreChunk chunk) {
|
||||
chunks.put(chunk.getX() + ":" + chunk.getZ(), chunk);
|
||||
public void addChunk(int x, int z, ExploreChunk chunk) {
|
||||
chunks.put(getPlace(x, z), chunk);
|
||||
}
|
||||
|
||||
public HashMap<String, ExploreChunk> getChunks() {
|
||||
public HashMap<Short, ExploreChunk> getChunks() {
|
||||
return chunks;
|
||||
}
|
||||
|
||||
public ExploreChunk getChunk(int x, int z) {
|
||||
return getChunk(x + ":" + z);
|
||||
return getChunk(getPlace(x, z));
|
||||
}
|
||||
|
||||
public ExploreChunk getChunk(Chunk chunk) {
|
||||
return getChunk(chunk.getX() + ":" + chunk.getZ());
|
||||
return getChunk(getPlace(chunk));
|
||||
}
|
||||
|
||||
public ExploreChunk getChunk(String cord) {
|
||||
return chunks.get(cord);
|
||||
public ExploreChunk getChunk(short place) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -2307,13 +2307,14 @@ public abstract class JobsDAO {
|
||||
|
||||
int id = jobsWorld == null ? 0 : jobsWorld.getId();
|
||||
if (id != 0)
|
||||
for (ExploreChunk oneChunk : worlds.getValue().getChunks().values()) {
|
||||
if (oneChunk.getDbId() != null)
|
||||
for (Entry<Short, ExploreChunk> oneChunk : worlds.getValue().getChunks().entrySet()) {
|
||||
ExploreChunk chunk = oneChunk.getValue();
|
||||
if (chunk.getDbId() != -1)
|
||||
continue;
|
||||
prest2.setInt(1, id);
|
||||
prest2.setInt(2, oneChunk.getX());
|
||||
prest2.setInt(3, oneChunk.getZ());
|
||||
prest2.setString(4, oneChunk.serializeNames());
|
||||
prest2.setInt(2, worlds.getValue().getChunkX(oneChunk.getKey()));
|
||||
prest2.setInt(3, worlds.getValue().getChunkZ(oneChunk.getKey()));
|
||||
prest2.setString(4, chunk.serializeNames());
|
||||
prest2.setString(5, jobsWorld != null ? jobsWorld.getName() : "");
|
||||
prest2.addBatch();
|
||||
i++;
|
||||
@ -2356,7 +2357,7 @@ public abstract class JobsDAO {
|
||||
|
||||
for (ExploreRegion worlds : temp.values()) {
|
||||
for (ExploreChunk oneChunk : worlds.getChunks().values()) {
|
||||
if (oneChunk.getDbId() == null)
|
||||
if (oneChunk.getDbId() == -1)
|
||||
continue;
|
||||
if (!oneChunk.isUpdated())
|
||||
continue;
|
||||
|
@ -20,10 +20,7 @@ public class MyPetManager {
|
||||
}
|
||||
|
||||
public boolean isMyPet(Object ent) {
|
||||
if (!enabled || !(ent instanceof MyPetBukkitEntity))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return enabled && ent instanceof MyPetBukkitEntity;
|
||||
}
|
||||
|
||||
public UUID getOwnerOfPet(Object ent) {
|
||||
|
Loading…
Reference in New Issue
Block a user