add logging

This commit is contained in:
okx-code
2024-03-23 01:09:07 +00:00
parent 910222941a
commit 10b6ab9506
4 changed files with 54 additions and 2 deletions

View File

@@ -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();

View File

@@ -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));
}
}
}

View File

@@ -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();

View File

@@ -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<D extends TableBasedDataObject>
@Override
public void insert() {
if (ChunkMetaCommand.chunkMetaLogsEnabled()) {
CivModCorePlugin.getInstance().getLogger().info("Inserting at " + chunkCoord);
}
for (D data : modifiedEntries) {
switch (data.getCacheState()) {
case NORMAL: