This commit is contained in:
okx-code
2024-03-25 21:27:08 +00:00
parent ace42ef2c8
commit bd37d9a375
5 changed files with 27 additions and 15 deletions

View File

@@ -7,24 +7,26 @@ import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Subcommand;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;
import org.bukkit.command.CommandSender;
import java.util.logging.Level;
import java.util.logging.Logger;
@CommandAlias("cmc")
public class ChunkMetaCommand extends BaseCommand {
private static final Logger CHUNK_META_LOGGER = Logger.getLogger("Chunk meta");
private static final Logger CHUNK_META_LOGGER = LogManager.getLogger("Chunk meta");
@Subcommand("togglechunkmeta")
@Description("Toggle showing chunk meta logs")
@CommandPermission("cmc.debug")
public void chunkmeta(CommandSender sender) {
if (CHUNK_META_LOGGER.getLevel().intValue() < Level.INFO.intValue()) {
CHUNK_META_LOGGER.setLevel(Level.INFO);
if (!CHUNK_META_LOGGER.getLevel().isMoreSpecificThan(Level.INFO)) {
Configurator.setLevel("Chunk meta", Level.INFO);
sender.sendMessage(Component.text("Chunk meta logs disabled.", NamedTextColor.RED));
} else {
CHUNK_META_LOGGER.setLevel(Level.FINE);
Configurator.setLevel("Chunk meta", Level.DEBUG);
sender.sendMessage(Component.text("Chunk meta logs enabled.", NamedTextColor.GREEN));
}
}

View File

@@ -115,6 +115,10 @@ public class ChunkCoord extends XZWCoord {
return lastUnloadedTime;
}
public long getLastLoadedTime() {
return lastLoadedTime;
}
void clearUnloaded() {
lastUnloadedTime = INVALID_TIME;
}

View File

@@ -1,6 +1,7 @@
package vg.civcraft.mc.civmodcore.world.locations.chunkmeta;
import java.util.concurrent.LinkedBlockingQueue;
import org.apache.logging.log4j.LogManager;
import org.bukkit.Chunk;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -13,6 +14,7 @@ import vg.civcraft.mc.civmodcore.world.locations.chunkmeta.api.ChunkMetaViewTrac
import vg.civcraft.mc.civmodcore.world.locations.global.WorldIDManager;
public class ChunkMetaListener implements Listener {
private static final org.apache.logging.log4j.Logger CHUNK_META_LOGGER = LogManager.getLogger("Chunk meta");
private final GlobalChunkMetaManager manager;
private final ChunkMetaViewTracker viewTracker;
@@ -52,6 +54,7 @@ public class ChunkMetaListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void chunkUnload(ChunkUnloadEvent e) {
CHUNK_META_LOGGER.debug("Adding " + e.getChunk() + " to unload queue - length " + unloadQueue.size());
unloadQueue.add(e.getChunk());
viewTracker.applyToAllSingleBlockViews(s -> s.handleChunkUnload(e.getChunk()));
}

View File

@@ -10,8 +10,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import java.util.logging.Logger;
import org.apache.logging.log4j.LogManager;
import org.bukkit.World;
import vg.civcraft.mc.civmodcore.commands.ChunkMetaCommand;
/**
* Stores Chunk metadata for all plugins for one specific world. Metadata is
@@ -21,7 +21,7 @@ import vg.civcraft.mc.civmodcore.commands.ChunkMetaCommand;
*
*/
public class WorldChunkMetaManager {
private static final Logger CHUNK_META_LOGGER = Logger.getLogger("Chunk meta");
private static final org.apache.logging.log4j.Logger CHUNK_META_LOGGER = LogManager.getLogger("Chunk meta");
/**
* How long should chunk data be kept in memory after the chunk is unloaded? 5
@@ -220,17 +220,19 @@ public class WorldChunkMetaManager {
if (unloadingQueue.isEmpty()) {
return;
}
CHUNK_META_LOGGER.debug("World " + worldID + ": Processing unloading queue");
Set<ChunkCoord> readdList = null;
ChunkCoord coord;
while((coord = unloadingQueue.poll()) != null) {
if (!coord.isUnloaded()) {
CHUNK_META_LOGGER.debug("World " + worldID + ": Skipping chunk " + coord + " because it is loaded at " + coord.getLastLoadedTime() + " after " + coord.getLastUnloadedTime());
continue;
}
if (System.currentTimeMillis() - coord.getLastUnloadedTime() > UNLOAD_DELAY) {
CHUNK_META_LOGGER.fine("Unloading chunk " + coord + " - unloaded: " + coord.getLastUnloadedTime());
CHUNK_META_LOGGER.debug("World " + worldID + ": Unloading chunk " + coord + " - unloaded: " + coord.getLastUnloadedTime());
unloadChunkCoord(coord);
} else {
if (readdList == null) {
@@ -241,7 +243,7 @@ public class WorldChunkMetaManager {
}
}
if (readdList != null) {
CHUNK_META_LOGGER.fine("Unloaded chunks remaining unsaved: " + readdList);
CHUNK_META_LOGGER.debug("World " + worldID + ": Unloaded chunks remaining unsaved: " + readdList);
unloadingQueue.addAll(readdList);
}
}, UNLOAD_CHECK_INTERVAL, UNLOAD_CHECK_INTERVAL, TimeUnit.MILLISECONDS);
@@ -271,7 +273,7 @@ public class WorldChunkMetaManager {
// written to the db
synchronized (metas) {
if (coord.isUnloaded()) {
CHUNK_META_LOGGER.fine("Chunk no longer being tracked: " + coord);
CHUNK_META_LOGGER.debug("Chunk no longer being tracked: " + coord);
metas.remove(coord);
coord.clearUnloaded();
}
@@ -318,7 +320,7 @@ public class WorldChunkMetaManager {
*/
void unloadChunk(int x, int z) {
ChunkCoord chunkCoord = getChunkCoord(x, z, false, false);
CHUNK_META_LOGGER.fine("Add to unloading queue: " + chunkCoord);
CHUNK_META_LOGGER.debug("World " + worldID + ": Add to unloading queue: " + chunkCoord);
// chunkCoord can never be null here, otherwise our data structure would be
// broken, in which case we'd want to know
chunkCoord.minecraftChunkUnloaded();

View File

@@ -2,14 +2,15 @@ package vg.civcraft.mc.civmodcore.world.locations.chunkmeta.block.table;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bukkit.Location;
import vg.civcraft.mc.civmodcore.world.locations.chunkmeta.CacheState;
import vg.civcraft.mc.civmodcore.world.locations.chunkmeta.block.BlockBasedChunkMeta;
public abstract class TableBasedBlockChunkMeta<D extends TableBasedDataObject>
extends BlockBasedChunkMeta<TableBasedDataObject, TableStorageEngine<D>> {
private static final Logger CHUNK_META_LOGGER = Logger.getLogger("Chunk meta");
private static final Logger CHUNK_META_LOGGER = LogManager.getLogger("Chunk meta");
private List<D> modifiedEntries;
@@ -54,7 +55,7 @@ public abstract class TableBasedBlockChunkMeta<D extends TableBasedDataObject>
@Override
public void insert() {
CHUNK_META_LOGGER.fine("Inserting at " + chunkCoord);
CHUNK_META_LOGGER.debug("Inserting at " + chunkCoord);
for (D data : modifiedEntries) {
switch (data.getCacheState()) {
case NORMAL: