Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify notification log #3

Merged
merged 2 commits into from
Mar 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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