Skip to content

Commit

Permalink
Merge pull request #3 from cons-tan-tan/feature
Browse files Browse the repository at this point in the history
Unify notification log
  • Loading branch information
cons-tan-tan authored Mar 30, 2024
2 parents ba39dee + 71f4477 commit e592d3d
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/main/java/bqlogging/BetterQuestLogging.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package bqlogging;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

Expand All @@ -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,
Expand All @@ -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<UUID> COMPLETED_QUESTS = new HashSet<>();
private static int tickCount = 60;

// @SidedProxy(clientSide = MODID + ".ClientProxy", serverSide = MODID + ".CommonProxy")
// public static CommonProxy proxy;

Expand All @@ -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");
}
Expand All @@ -51,12 +61,21 @@ public void onQuestEvent(QuestEvent event) {
if (event.getType() != QuestEvent.Type.COMPLETED) {
return;
}
Set<UUID> 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));
Expand All @@ -66,10 +85,11 @@ public void onQuestEvent(QuestEvent event) {
}
LOG.info(
String.format(
"Quest Completed: %s",
"Quest Complete: %s",
QuestTranslation.translateQuestName(uuid, quest)
.replaceAll("§.", "")));
});
COMPLETED_QUESTS.clear();
}

// @Mod.EventHandler
Expand Down

0 comments on commit e592d3d

Please sign in to comment.