From 10b6ab95065124dd9ce51170a8470bcbedd9b17d Mon Sep 17 00:00:00 2001 From: okx-code Date: Sat, 23 Mar 2024 01:09:07 +0000 Subject: [PATCH 1/6] add logging --- .../mc/civmodcore/CivModCorePlugin.java | 2 ++ .../civmodcore/commands/ChunkMetaCommand.java | 33 +++++++++++++++++++ .../chunkmeta/WorldChunkMetaManager.java | 16 +++++++-- .../block/table/TableBasedBlockChunkMeta.java | 5 +++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/commands/ChunkMetaCommand.java diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/CivModCorePlugin.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/CivModCorePlugin.java index 0aab7bd5f..ab877bbaf 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/CivModCorePlugin.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/CivModCorePlugin.java @@ -9,6 +9,7 @@ import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPluginLoader; import org.ipvp.canvas.MenuFunctionListener; import vg.civcraft.mc.civmodcore.chat.dialog.DialogManager; +import vg.civcraft.mc.civmodcore.commands.ChunkMetaCommand; import vg.civcraft.mc.civmodcore.commands.CommandManager; import vg.civcraft.mc.civmodcore.commands.StatCommand; import vg.civcraft.mc.civmodcore.dao.DatabaseCredentials; @@ -95,6 +96,7 @@ public class CivModCorePlugin extends ACivMod { this.commands.init(); this.commands.registerCommand(new ConfigCommand()); this.commands.registerCommand(new StatCommand()); + this.commands.registerCommand(new ChunkMetaCommand()); // Load APIs EnchantUtils.loadEnchantAbbreviations(this); MoreTags.init(); diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/commands/ChunkMetaCommand.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/commands/ChunkMetaCommand.java new file mode 100644 index 000000000..f57ba8a3a --- /dev/null +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/commands/ChunkMetaCommand.java @@ -0,0 +1,33 @@ +package vg.civcraft.mc.civmodcore.commands; + +import co.aikar.commands.BaseCommand; +import co.aikar.commands.annotation.CommandAlias; +import co.aikar.commands.annotation.CommandPermission; +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.bukkit.command.CommandSender; + +@CommandAlias("cmc") +public class ChunkMetaCommand extends BaseCommand { + + private static boolean ENABLE_CHUNK_META_LOGS = false; + + public static boolean chunkMetaLogsEnabled() { + return ENABLE_CHUNK_META_LOGS; + } + + @Subcommand("chunkmeta") + @Description("Toggle showing chunk meta logs") + @CommandPermission("cmc.debug") + public void chunkmeta(CommandSender sender) { + if (ENABLE_CHUNK_META_LOGS) { + ENABLE_CHUNK_META_LOGS = false; + sender.sendMessage(Component.text("Chunk meta logs disabled.", NamedTextColor.RED)); + } else { + ENABLE_CHUNK_META_LOGS = true; + sender.sendMessage(Component.text("Chunk meta logs enabled.", NamedTextColor.GREEN)); + } + } +} diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java index 20bb1baf0..549016066 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java @@ -11,6 +11,7 @@ import java.util.function.Supplier; import java.util.logging.Logger; import org.bukkit.World; +import vg.civcraft.mc.civmodcore.commands.ChunkMetaCommand; /** * Stores Chunk metadata for all plugins for one specific world. Metadata is @@ -20,7 +21,6 @@ import org.bukkit.World; * */ public class WorldChunkMetaManager { - /** * How long should chunk data be kept in memory after the chunk is unloaded? 5 * minutes @@ -228,16 +228,22 @@ public class WorldChunkMetaManager { } if (System.currentTimeMillis() - coord.getLastUnloadedTime() > UNLOAD_DELAY) { + if (ChunkMetaCommand.chunkMetaLogsEnabled()) { + logger.info("[Chunkmeta] Unloading chunk " + coord + " - unloaded: " + coord.getLastUnloadedTime()); + } unloadChunkCoord(coord); } else { if (readdList == null) { readdList = new HashSet<>(); } readdList.add(coord); + } } - if (readdList != null) { + if (ChunkMetaCommand.chunkMetaLogsEnabled()) { + logger.info("[Chunkmeta] Unloaded chunks remaining unsaved: " + readdList); + } unloadingQueue.addAll(readdList); } }, UNLOAD_CHECK_INTERVAL, UNLOAD_CHECK_INTERVAL, TimeUnit.MILLISECONDS); @@ -267,6 +273,9 @@ public class WorldChunkMetaManager { // written to the db synchronized (metas) { if (coord.isUnloaded()) { + if (ChunkMetaCommand.chunkMetaLogsEnabled()) { + logger.info("[Chunkmeta] Chunk no longer being tracked: " + coord); + } metas.remove(coord); coord.clearUnloaded(); } @@ -313,6 +322,9 @@ public class WorldChunkMetaManager { */ void unloadChunk(int x, int z) { ChunkCoord chunkCoord = getChunkCoord(x, z, false, false); + if (ChunkMetaCommand.chunkMetaLogsEnabled()) { + logger.info("[Chunkmeta] 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(); diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java index d4a969987..644ba85de 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java @@ -3,6 +3,8 @@ package vg.civcraft.mc.civmodcore.world.locations.chunkmeta.block.table; import java.util.ArrayList; import java.util.List; import org.bukkit.Location; +import vg.civcraft.mc.civmodcore.CivModCorePlugin; +import vg.civcraft.mc.civmodcore.commands.ChunkMetaCommand; import vg.civcraft.mc.civmodcore.world.locations.chunkmeta.CacheState; import vg.civcraft.mc.civmodcore.world.locations.chunkmeta.block.BlockBasedChunkMeta; @@ -52,6 +54,9 @@ public abstract class TableBasedBlockChunkMeta @Override public void insert() { + if (ChunkMetaCommand.chunkMetaLogsEnabled()) { + CivModCorePlugin.getInstance().getLogger().info("Inserting at " + chunkCoord); + } for (D data : modifiedEntries) { switch (data.getCacheState()) { case NORMAL: From 8591714160e2db65de82fdada99f9fdeaa72d77b Mon Sep 17 00:00:00 2001 From: okx-code Date: Sat, 23 Mar 2024 15:57:31 +0000 Subject: [PATCH 2/6] fix prefix --- .../chunkmeta/block/table/TableBasedBlockChunkMeta.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java index 644ba85de..8e913e30f 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java @@ -55,7 +55,7 @@ public abstract class TableBasedBlockChunkMeta @Override public void insert() { if (ChunkMetaCommand.chunkMetaLogsEnabled()) { - CivModCorePlugin.getInstance().getLogger().info("Inserting at " + chunkCoord); + CivModCorePlugin.getInstance().getLogger().info("[Chunkmeta] Inserting at " + chunkCoord); } for (D data : modifiedEntries) { switch (data.getCacheState()) { From bd7fc1c27ada61f05117b494081b40a78afb95cc Mon Sep 17 00:00:00 2001 From: okx-code Date: Sat, 23 Mar 2024 20:35:22 +0000 Subject: [PATCH 3/6] address review --- .../mc/civmodcore/commands/ChunkMetaCommand.java | 16 +++++++--------- .../chunkmeta/WorldChunkMetaManager.java | 12 ++++++------ .../block/table/TableBasedBlockChunkMeta.java | 8 +++----- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/commands/ChunkMetaCommand.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/commands/ChunkMetaCommand.java index f57ba8a3a..6814e4df2 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/commands/ChunkMetaCommand.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/commands/ChunkMetaCommand.java @@ -8,25 +8,23 @@ import co.aikar.commands.annotation.Subcommand; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.command.CommandSender; +import java.util.logging.Level; +import java.util.logging.Logger; @CommandAlias("cmc") public class ChunkMetaCommand extends BaseCommand { - private static boolean ENABLE_CHUNK_META_LOGS = false; + private static final Logger CHUNK_META_LOGGER = Logger.getLogger("Chunk meta"); - public static boolean chunkMetaLogsEnabled() { - return ENABLE_CHUNK_META_LOGS; - } - - @Subcommand("chunkmeta") + @Subcommand("togglechunkmeta") @Description("Toggle showing chunk meta logs") @CommandPermission("cmc.debug") public void chunkmeta(CommandSender sender) { - if (ENABLE_CHUNK_META_LOGS) { - ENABLE_CHUNK_META_LOGS = false; + if (CHUNK_META_LOGGER.getLevel().intValue() < Level.INFO.intValue()) { + CHUNK_META_LOGGER.setLevel(Level.INFO); sender.sendMessage(Component.text("Chunk meta logs disabled.", NamedTextColor.RED)); } else { - ENABLE_CHUNK_META_LOGS = true; + CHUNK_META_LOGGER.setLevel(Level.FINE); sender.sendMessage(Component.text("Chunk meta logs enabled.", NamedTextColor.GREEN)); } } diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java index 549016066..ff52be7ba 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java @@ -21,6 +21,8 @@ import vg.civcraft.mc.civmodcore.commands.ChunkMetaCommand; * */ public class WorldChunkMetaManager { + private static final Logger CHUNK_META_LOGGER = Logger.getLogger("Chunk meta"); + /** * How long should chunk data be kept in memory after the chunk is unloaded? 5 * minutes @@ -228,9 +230,7 @@ public class WorldChunkMetaManager { } if (System.currentTimeMillis() - coord.getLastUnloadedTime() > UNLOAD_DELAY) { - if (ChunkMetaCommand.chunkMetaLogsEnabled()) { - logger.info("[Chunkmeta] Unloading chunk " + coord + " - unloaded: " + coord.getLastUnloadedTime()); - } + CHUNK_META_LOGGER.fine("[Chunkmeta] Unloading chunk " + coord + " - unloaded: " + coord.getLastUnloadedTime()); unloadChunkCoord(coord); } else { if (readdList == null) { @@ -242,7 +242,7 @@ public class WorldChunkMetaManager { } if (readdList != null) { if (ChunkMetaCommand.chunkMetaLogsEnabled()) { - logger.info("[Chunkmeta] Unloaded chunks remaining unsaved: " + readdList); + CHUNK_META_LOGGER.fine("[Chunkmeta] Unloaded chunks remaining unsaved: " + readdList); } unloadingQueue.addAll(readdList); } @@ -274,7 +274,7 @@ public class WorldChunkMetaManager { synchronized (metas) { if (coord.isUnloaded()) { if (ChunkMetaCommand.chunkMetaLogsEnabled()) { - logger.info("[Chunkmeta] Chunk no longer being tracked: " + coord); + CHUNK_META_LOGGER.fine("[Chunkmeta] Chunk no longer being tracked: " + coord); } metas.remove(coord); coord.clearUnloaded(); @@ -323,7 +323,7 @@ public class WorldChunkMetaManager { void unloadChunk(int x, int z) { ChunkCoord chunkCoord = getChunkCoord(x, z, false, false); if (ChunkMetaCommand.chunkMetaLogsEnabled()) { - logger.info("[Chunkmeta] Add to unloading queue: " + chunkCoord); + CHUNK_META_LOGGER.fine("[Chunkmeta] 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 diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java index 8e913e30f..ddc981b93 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java @@ -2,14 +2,14 @@ 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.bukkit.Location; -import vg.civcraft.mc.civmodcore.CivModCorePlugin; -import vg.civcraft.mc.civmodcore.commands.ChunkMetaCommand; import vg.civcraft.mc.civmodcore.world.locations.chunkmeta.CacheState; import vg.civcraft.mc.civmodcore.world.locations.chunkmeta.block.BlockBasedChunkMeta; public abstract class TableBasedBlockChunkMeta extends BlockBasedChunkMeta> { + private static final Logger CHUNK_META_LOGGER = Logger.getLogger("Chunk meta"); private List modifiedEntries; @@ -54,9 +54,7 @@ public abstract class TableBasedBlockChunkMeta @Override public void insert() { - if (ChunkMetaCommand.chunkMetaLogsEnabled()) { - CivModCorePlugin.getInstance().getLogger().info("[Chunkmeta] Inserting at " + chunkCoord); - } + CHUNK_META_LOGGER.fine("[Chunkmeta] Inserting at " + chunkCoord); for (D data : modifiedEntries) { switch (data.getCacheState()) { case NORMAL: From f4bc6fb407d099a9500f130556c90a085d6d0940 Mon Sep 17 00:00:00 2001 From: okx-code Date: Sat, 23 Mar 2024 20:36:59 +0000 Subject: [PATCH 4/6] fix messages --- .../locations/chunkmeta/WorldChunkMetaManager.java | 14 ++++---------- .../block/table/TableBasedBlockChunkMeta.java | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java index ff52be7ba..7a395be07 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java @@ -230,7 +230,7 @@ public class WorldChunkMetaManager { } if (System.currentTimeMillis() - coord.getLastUnloadedTime() > UNLOAD_DELAY) { - CHUNK_META_LOGGER.fine("[Chunkmeta] Unloading chunk " + coord + " - unloaded: " + coord.getLastUnloadedTime()); + CHUNK_META_LOGGER.fine("Unloading chunk " + coord + " - unloaded: " + coord.getLastUnloadedTime()); unloadChunkCoord(coord); } else { if (readdList == null) { @@ -241,9 +241,7 @@ public class WorldChunkMetaManager { } } if (readdList != null) { - if (ChunkMetaCommand.chunkMetaLogsEnabled()) { - CHUNK_META_LOGGER.fine("[Chunkmeta] Unloaded chunks remaining unsaved: " + readdList); - } + CHUNK_META_LOGGER.fine("Unloaded chunks remaining unsaved: " + readdList); unloadingQueue.addAll(readdList); } }, UNLOAD_CHECK_INTERVAL, UNLOAD_CHECK_INTERVAL, TimeUnit.MILLISECONDS); @@ -273,9 +271,7 @@ public class WorldChunkMetaManager { // written to the db synchronized (metas) { if (coord.isUnloaded()) { - if (ChunkMetaCommand.chunkMetaLogsEnabled()) { - CHUNK_META_LOGGER.fine("[Chunkmeta] Chunk no longer being tracked: " + coord); - } + CHUNK_META_LOGGER.fine("Chunk no longer being tracked: " + coord); metas.remove(coord); coord.clearUnloaded(); } @@ -322,9 +318,7 @@ public class WorldChunkMetaManager { */ void unloadChunk(int x, int z) { ChunkCoord chunkCoord = getChunkCoord(x, z, false, false); - if (ChunkMetaCommand.chunkMetaLogsEnabled()) { - CHUNK_META_LOGGER.fine("[Chunkmeta] Add to unloading queue: " + chunkCoord); - } + CHUNK_META_LOGGER.fine("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(); diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java index ddc981b93..0e1559dd2 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java @@ -54,7 +54,7 @@ public abstract class TableBasedBlockChunkMeta @Override public void insert() { - CHUNK_META_LOGGER.fine("[Chunkmeta] Inserting at " + chunkCoord); + CHUNK_META_LOGGER.fine("Inserting at " + chunkCoord); for (D data : modifiedEntries) { switch (data.getCacheState()) { case NORMAL: From da67fa4b14ca956f133beb0424806dfbb4563d93 Mon Sep 17 00:00:00 2001 From: okx-code Date: Mon, 25 Mar 2024 21:27:08 +0000 Subject: [PATCH 5/6] Fix logs --- .../mc/civmodcore/commands/ChunkMetaCommand.java | 14 ++++++++------ .../world/locations/chunkmeta/ChunkCoord.java | 4 ++++ .../locations/chunkmeta/ChunkMetaListener.java | 3 +++ .../locations/chunkmeta/WorldChunkMetaManager.java | 14 ++++++++------ .../block/table/TableBasedBlockChunkMeta.java | 7 ++++--- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/commands/ChunkMetaCommand.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/commands/ChunkMetaCommand.java index 6814e4df2..e3670d486 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/commands/ChunkMetaCommand.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/commands/ChunkMetaCommand.java @@ -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)); } } diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/ChunkCoord.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/ChunkCoord.java index e1046230c..a84b0907e 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/ChunkCoord.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/ChunkCoord.java @@ -115,6 +115,10 @@ public class ChunkCoord extends XZWCoord { return lastUnloadedTime; } + public long getLastLoadedTime() { + return lastLoadedTime; + } + void clearUnloaded() { lastUnloadedTime = INVALID_TIME; } diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/ChunkMetaListener.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/ChunkMetaListener.java index 244ce141f..7200c2e12 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/ChunkMetaListener.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/ChunkMetaListener.java @@ -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())); } diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java index 7a395be07..5a4dcb311 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/WorldChunkMetaManager.java @@ -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 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(); diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java index 0e1559dd2..d64aeed2a 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/block/table/TableBasedBlockChunkMeta.java @@ -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 extends BlockBasedChunkMeta> { - private static final Logger CHUNK_META_LOGGER = Logger.getLogger("Chunk meta"); + private static final Logger CHUNK_META_LOGGER = LogManager.getLogger("Chunk meta"); private List modifiedEntries; @@ -54,7 +55,7 @@ public abstract class TableBasedBlockChunkMeta @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: From 7db18ce00931a0fe71e9af87bcd6137c6aef8cd3 Mon Sep 17 00:00:00 2001 From: okx-code Date: Mon, 25 Mar 2024 21:30:05 +0000 Subject: [PATCH 6/6] add world --- .../civmodcore/world/locations/chunkmeta/ChunkMetaListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/ChunkMetaListener.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/ChunkMetaListener.java index 7200c2e12..1340f5b9c 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/ChunkMetaListener.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/world/locations/chunkmeta/ChunkMetaListener.java @@ -54,7 +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()); + CHUNK_META_LOGGER.debug("World " + CivModCorePlugin.getInstance().getWorldIdManager().getInternalWorldId(e.getWorld()) + ": Adding " + e.getChunk() + " to unload queue - length " + unloadQueue.size()); unloadQueue.add(e.getChunk()); viewTracker.applyToAllSingleBlockViews(s -> s.handleChunkUnload(e.getChunk())); }