mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 05:55:27 +01:00
Delay between chunk cleans
This commit is contained in:
parent
0cd22b3794
commit
29f5cb1a81
@ -28,7 +28,29 @@ public class ExploitProtectionManager {
|
||||
private static final String NAMETIME = "Time";
|
||||
private static final String NAMEPAID = "Paid";
|
||||
|
||||
private HashMap<String, HashMap<String, CMIChunkPersistentDataContainer>> map = new HashMap<>();
|
||||
private HashMap<String, HashMap<String, chunkData>> map = new HashMap<>();
|
||||
|
||||
class chunkData {
|
||||
private CMIChunkPersistentDataContainer container;
|
||||
private long lastClean = 0;
|
||||
|
||||
chunkData(CMIChunkPersistentDataContainer container) {
|
||||
this.container = container;
|
||||
lastClean = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public long getLastClean() {
|
||||
return lastClean;
|
||||
}
|
||||
|
||||
public void setLastClean(long lastClean) {
|
||||
this.lastClean = lastClean;
|
||||
}
|
||||
|
||||
public CMIChunkPersistentDataContainer getContainer() {
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
||||
private CMIChunkPersistentDataContainer getPDC(Block block) {
|
||||
if (block == null)
|
||||
@ -39,14 +61,21 @@ public class ExploitProtectionManager {
|
||||
private CMIChunkPersistentDataContainer getPDC(Chunk chunk) {
|
||||
if (chunk == null)
|
||||
return null;
|
||||
HashMap<String, CMIChunkPersistentDataContainer> world = map.computeIfAbsent(chunk.getWorld().getName(), x -> new HashMap<>());
|
||||
return world.computeIfAbsent(chunk.getX() + ":" + chunk.getZ(), x -> new CMIChunkPersistentDataContainer(NAMEGENERAL, chunk));
|
||||
chunkData data = getChunkData(chunk);
|
||||
return data == null ? null : data.getContainer();
|
||||
}
|
||||
|
||||
private chunkData getChunkData(Chunk chunk) {
|
||||
if (chunk == null)
|
||||
return null;
|
||||
HashMap<String, chunkData> world = map.computeIfAbsent(chunk.getWorld().getName(), x -> new HashMap<>());
|
||||
return world.computeIfAbsent(chunk.getX() + ":" + chunk.getZ(), x -> new chunkData(new CMIChunkPersistentDataContainer(NAMEGENERAL, chunk)));
|
||||
}
|
||||
|
||||
public void removePDC(Chunk chunk) {
|
||||
if (!Jobs.getGCManager().useNewBlockProtection)
|
||||
return;
|
||||
HashMap<String, CMIChunkPersistentDataContainer> world = map.get(chunk.getWorld().getName());
|
||||
HashMap<String, chunkData> world = map.get(chunk.getWorld().getName());
|
||||
if (world == null)
|
||||
return;
|
||||
world.remove(chunk.getX() + ":" + chunk.getZ());
|
||||
@ -309,17 +338,25 @@ public class ExploitProtectionManager {
|
||||
|
||||
try {
|
||||
|
||||
CMIChunkPersistentDataContainer pdc = getPDC(chunk);
|
||||
chunkData pdc = getChunkData(chunk);
|
||||
|
||||
Set<NamespacedKey> keys = pdc.getKeys();
|
||||
if (pdc == null)
|
||||
return;
|
||||
|
||||
// Delay to clean it up once more to prevent rapid updates of same chunk
|
||||
if (pdc.getLastClean() + (30 * 1000L) > System.currentTimeMillis())
|
||||
return;
|
||||
|
||||
Set<NamespacedKey> keys = pdc.getContainer().getKeys();
|
||||
|
||||
for (NamespacedKey one : keys) {
|
||||
Long time = deconvertLong(pdc.getInt(one.getKey(), NAMETIME));
|
||||
Long time = deconvertLong(pdc.getContainer().getInt(one.getKey(), NAMETIME));
|
||||
if (time != null && time < System.currentTimeMillis()) {
|
||||
pdc.remove(one.getKey());
|
||||
pdc.getContainer().remove(one.getKey());
|
||||
}
|
||||
}
|
||||
pdc.save();
|
||||
pdc.getContainer().save();
|
||||
pdc.setLastClean(System.currentTimeMillis());
|
||||
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
|
Loading…
Reference in New Issue
Block a user