From 9639b38e3205fda536968bc1972cd7ff61128bf0 Mon Sep 17 00:00:00 2001 From: cons-tan-tan <132136681+cons-tan-tan@users.noreply.github.com> Date: Sat, 30 Mar 2024 12:56:09 +0900 Subject: [PATCH 1/2] fix: unify notification log --- .../java/bqlogging/BetterQuestLogging.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/bqlogging/BetterQuestLogging.java b/src/main/java/bqlogging/BetterQuestLogging.java index 7a0eaa2..a60fc97 100644 --- a/src/main/java/bqlogging/BetterQuestLogging.java +++ b/src/main/java/bqlogging/BetterQuestLogging.java @@ -1,5 +1,6 @@ package bqlogging; +import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -13,10 +14,13 @@ import betterquesting.api.questing.IQuest; import betterquesting.api2.utils.QuestTranslation; import betterquesting.questing.QuestDatabase; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent; @Mod( modid = BetterQuestLogging.MODID, @@ -30,6 +34,9 @@ public class BetterQuestLogging { public static final String MODID = "bqlogging"; public static final Logger LOG = LogManager.getLogger(MODID); + private static final Set COMPLETED_QUESTS = new HashSet<>(); + private static int tickCount = 60; + // @SidedProxy(clientSide = MODID + ".ClientProxy", serverSide = MODID + ".CommonProxy") // public static CommonProxy proxy; @@ -41,6 +48,9 @@ public void preInit(FMLPreInitializationEvent event) { if (Loader.isModLoaded("betterquesting")) { LOG.info("BetterQuesting is already loaded"); MinecraftForge.EVENT_BUS.register(this); + FMLCommonHandler.instance() + .bus() + .register(this); } else { LOG.error("BetterQuesting is not loaded"); } @@ -51,12 +61,21 @@ public void onQuestEvent(QuestEvent event) { if (event.getType() != QuestEvent.Type.COMPLETED) { return; } - Set questIds = event.getQuestIDs(); - if (questIds.isEmpty()) { + COMPLETED_QUESTS.addAll(event.getQuestIDs()); + } + + @SubscribeEvent(priority = EventPriority.LOW) + public void onServerTick(TickEvent.ServerTickEvent event) { + if (event.phase != TickEvent.Phase.START) { + return; + } + + if (--tickCount != 0) { return; } + tickCount = 60; - questIds.forEach(uuid -> { + COMPLETED_QUESTS.forEach(uuid -> { IQuest quest = QuestDatabase.INSTANCE.get(uuid); if (quest == null) { LOG.error(String.format("Quest with ID %s does not exist", uuid)); @@ -70,6 +89,7 @@ public void onQuestEvent(QuestEvent event) { QuestTranslation.translateQuestName(uuid, quest) .replaceAll("§.", ""))); }); + COMPLETED_QUESTS.clear(); } // @Mod.EventHandler From 71f44778435a35c7dbfe9ec399d2f55be013b095 Mon Sep 17 00:00:00 2001 From: cons-tan-tan <132136681+cons-tan-tan@users.noreply.github.com> Date: Sat, 30 Mar 2024 12:56:33 +0900 Subject: [PATCH 2/2] fix: change log template --- src/main/java/bqlogging/BetterQuestLogging.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/bqlogging/BetterQuestLogging.java b/src/main/java/bqlogging/BetterQuestLogging.java index a60fc97..0f696ed 100644 --- a/src/main/java/bqlogging/BetterQuestLogging.java +++ b/src/main/java/bqlogging/BetterQuestLogging.java @@ -85,7 +85,7 @@ public void onServerTick(TickEvent.ServerTickEvent event) { } LOG.info( String.format( - "Quest Completed: %s", + "Quest Complete: %s", QuestTranslation.translateQuestName(uuid, quest) .replaceAll("§.", ""))); });