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

Add event notifications criterion #763

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
shouldPlaySound = false;
return ConfigCategory.createBuilder()
.name(Text.translatable("skyblocker.config.eventNotifications"))
.option(Option.<EventNotificationsConfig.Criterion>createBuilder()
.binding(defaults.eventNotifications.criterion,
() -> config.eventNotifications.criterion,
criterion -> config.eventNotifications.criterion = criterion)
.controller(ConfigUtils::createEnumCyclingListController)
.name(Text.translatable("skyblocker.config.eventNotifications.criterion"))
.build())
.option(Option.<EventNotificationsConfig.Sound>createBuilder()
.binding(defaults.eventNotifications.reminderSound,
() -> config.eventNotifications.reminderSound,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@
import java.util.Map;

public class EventNotificationsConfig {
@SerialEntry
public Criterion criterion = Criterion.SKYBLOCK;

@SerialEntry
public Sound reminderSound = Sound.PLING;

@SerialEntry
public Map<String, IntList> eventsReminderTimes = new HashMap<>();

public enum Criterion {
NONE,
SKYBLOCK,
HYPIXEL,
EVERYWHERE
}

public enum Sound {
NONE(null),
BELL(SoundEvents.BLOCK_BELL_USE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.events.SkyblockEvents;
import de.hysky.skyblocker.utils.Http;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
Expand All @@ -23,7 +24,10 @@
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;

import java.util.*;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

public class EventNotifications {
Expand Down Expand Up @@ -140,7 +144,7 @@ private static void timeUpdate() {
if (reminderTimes.isEmpty()) continue;

for (Integer reminderTime : reminderTimes) {
if (currentTime + reminderTime < skyblockEvent.start() && newTime + reminderTime >= skyblockEvent.start()) {
if (criterionMet() && currentTime + reminderTime < skyblockEvent.start() && newTime + reminderTime >= skyblockEvent.start()) {
MinecraftClient instance = MinecraftClient.getInstance();
if (eventName.equals(JACOBS)) {
instance.getToastManager().add(
Expand All @@ -161,6 +165,15 @@ private static void timeUpdate() {
currentTime = newTime;
}

private static boolean criterionMet() {
return switch (SkyblockerConfigManager.get().eventNotifications.criterion) {
case NONE -> false;
case SKYBLOCK -> Utils.isOnSkyblock();
case HYPIXEL -> Utils.isOnHypixel();
case EVERYWHERE -> true;
};
}

public record SkyblockEvent(long start, int duration, String[] extras, @Nullable String warpCommand) {
public static SkyblockEvent of(JsonObject jsonObject) {
String location = jsonObject.get("location").getAsString();
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@

"skyblocker.config.eventNotifications": "Event Notifications",

"skyblocker.config.eventNotifications.criterion": "Notification Criterion",
"skyblocker.config.eventNotifications.monologue": "can you pls log onto skyblock rq pls? that would be cool cuz like if you are seeing dis then it means that ur config either got cleared or that this is ur first time using the mod if so then thanks for choosing it and hopefully you enjoy it! so yea this is where you will be able to set reminders for all events in skyblock they will be added as you encounter so you first need to log onto skyblock so yea hope you enjoy the mod and all that",
"skyblocker.config.eventNotifications.notificationSound": "Notification Sound",
"skyblocker.config.eventNotifications.@Tooltip[0]": "Configure how much time before an event you will be reminded with a notification toast! For example if you set '5m' and '30s' in the list, you will receive a notification 5 minutes before and another 30 seconds before an event starts.",
Expand Down