mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-12-30 18:08:24 +01:00
Improved logging to skip unnecessary data from newly generated chunks
This commit is contained in:
parent
6a22903240
commit
6714ded600
@ -117,6 +117,7 @@ public class ConfigHandler extends Queue {
|
||||
public static Map<String, List<Object>> lastRollback = syncMap();
|
||||
public static Map<String, Boolean> activeRollbacks = syncMap();
|
||||
public static Map<UUID, Object[]> entityBlockMapper = syncMap();
|
||||
public static ConcurrentHashMap<Long, Long> populatedChunks = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<String, String> language = new ConcurrentHashMap<>();
|
||||
public static List<String> databaseTables = new ArrayList<>();
|
||||
|
||||
|
@ -27,6 +27,7 @@ public class BlockPlaceLogger {
|
||||
if (user == null || ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Material type = block.getType();
|
||||
if (blockData == null && (forceType == null || (!forceType.equals(Material.WATER)) && (!forceType.equals(Material.LAVA)))) {
|
||||
blockData = block.getBlockData().getAsString();
|
||||
@ -53,15 +54,36 @@ public class BlockPlaceLogger {
|
||||
return;
|
||||
}
|
||||
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
long chunkKey = (x >> 4) & 0xffffffffL | ((z >> 4) & 0xffffffffL) << 32;
|
||||
if (ConfigHandler.populatedChunks.get(chunkKey) != null) {
|
||||
boolean isWater = user.equals("#water");
|
||||
boolean isLava = user.equals("#lava");
|
||||
boolean isVine = user.equals("#vine");
|
||||
if (isWater || isLava || isVine) {
|
||||
int timeDelay = isWater ? 60 : 240;
|
||||
long timeSincePopulation = ((System.currentTimeMillis() / 1000L) - ConfigHandler.populatedChunks.getOrDefault(chunkKey, 0L));
|
||||
if (timeSincePopulation <= timeDelay) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (timeSincePopulation > 240) {
|
||||
ConfigHandler.populatedChunks.remove(chunkKey);
|
||||
}
|
||||
}
|
||||
else if (type == Material.WATER || type == Material.LAVA) {
|
||||
ConfigHandler.populatedChunks.remove(chunkKey);
|
||||
}
|
||||
}
|
||||
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
|
||||
int wid = Util.getWorldId(block.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
|
||||
if (event.getUser().length() > 0) {
|
||||
CacheHandler.lookupCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[] { time, event.getUser(), type });
|
||||
|
@ -45,6 +45,7 @@ import net.coreprotect.listener.player.PlayerQuitListener;
|
||||
import net.coreprotect.listener.player.PlayerTakeLecternBookListener;
|
||||
import net.coreprotect.listener.player.ProjectileLaunchListener;
|
||||
import net.coreprotect.listener.player.SignChangeListener;
|
||||
import net.coreprotect.listener.world.ChunkPopulateListener;
|
||||
import net.coreprotect.listener.world.LeavesDecayListener;
|
||||
import net.coreprotect.listener.world.PortalCreateListener;
|
||||
import net.coreprotect.listener.world.StructureGrowListener;
|
||||
@ -105,9 +106,10 @@ public final class ListenerHandler {
|
||||
pluginManager.registerEvents(new ProjectileLaunchListener(), plugin);
|
||||
|
||||
// World Listeners
|
||||
pluginManager.registerEvents(new StructureGrowListener(), plugin);
|
||||
pluginManager.registerEvents(new ChunkPopulateListener(), plugin);
|
||||
pluginManager.registerEvents(new LeavesDecayListener(), plugin);
|
||||
pluginManager.registerEvents(new PortalCreateListener(), plugin);
|
||||
pluginManager.registerEvents(new StructureGrowListener(), plugin);
|
||||
|
||||
// Paper Listeners / Fallbacks
|
||||
try {
|
||||
|
@ -0,0 +1,19 @@
|
||||
package net.coreprotect.listener.world;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.ChunkPopulateEvent;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.consumer.Queue;
|
||||
|
||||
public final class ChunkPopulateListener extends Queue implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
protected void onChunkPopulate(ChunkPopulateEvent event) {
|
||||
long chunkKey = event.getChunk().getX() & 0xffffffffL | (event.getChunk().getZ() & 0xffffffffL) << 32;
|
||||
ConfigHandler.populatedChunks.put(chunkKey, (System.currentTimeMillis() / 1000L));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user