-
-
Notifications
You must be signed in to change notification settings - Fork 134
Spiders den rain notifications #1069
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
base: master
Are you sure you want to change the base?
Spiders den rain notifications #1069
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pr needs to be updated. I've also left some comments that can be addressed while updating.
@@ -85,10 +120,18 @@ public static void init() { | |||
)); | |||
} | |||
|
|||
private static final Map<String, LinkedList<SkyblockEvent>> events = new ConcurrentHashMap<>(); | |||
private static final AtomicReference<Map<String, LinkedList<SkyblockEvent>>> events = new AtomicReference<>(Map.of()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need an atomic reference here. A non-final field will do.
private static void register() { | ||
if (initialized) { | ||
return; | ||
} | ||
Scheduler.INSTANCE.scheduleCyclic(EventNotifications::refreshEvents, 20 * (int) EVENTS_UPDATE_PERIOD.toSeconds()); | ||
initialized = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more complicated than necessary. Just put this in init()
.
public static IntList getDefaultReminders(String eventName) { | ||
var periodicEvent = PERIODIC_EVENTS.stream().filter(event -> event.name.equals(eventName)).findFirst(); | ||
if (periodicEvent.isPresent()) { | ||
return periodicEvent.get().defaultReminders(); | ||
} | ||
return DEFAULT_REMINDERS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put this above getEvents
.
private static void addFixedEvents(long nowSeconds, Map<String, LinkedList<SkyblockEvent>> events) { | ||
PERIODIC_EVENTS.forEach(event -> { | ||
long firstEvent = SkyblockTime.SKYBLOCK_EPOCH / 1000 + event.offsetFromSkyblockEpochSeconds; | ||
long currentEvent = firstEvent + (nowSeconds - firstEvent + event.periodSeconds - 1) / event.periodSeconds * event.periodSeconds; | ||
// Prepare events for next two update periods in case one is skipped for some reason, or at least one if event is rare. | ||
long eventsToAdd = Math.max(1, 2 * EVENTS_UPDATE_PERIOD.toSeconds() / event.periodSeconds); | ||
events.put(event.name, LongStream.range(0, eventsToAdd) | ||
.map(i -> currentEvent + i * event.periodSeconds) | ||
.mapToObj(ts -> new SkyblockEvent(event.name, ts, event.durationSeconds, new String[0], event.warpCommand)) | ||
.collect(Collectors.toCollection(LinkedList::new))); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lambda (passed into forEach
) could be turned into a method in SkyblockerPeriodicEvent
. Also, please add some javadoc for what this method does, as the name add
could be unclear.
Map<String, LinkedList<SkyblockEvent>> newEvents = objects.stream() | ||
.map(SkyblockEvent::of) | ||
.filter(event -> event.start + event.duration >= nowSeconds) | ||
.collect(Collectors.groupingBy(SkyblockEvent::name, Collectors.toCollection(LinkedList::new))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think we need linkedlist.
Implementation of #1068. Could not find the code for
/api/calendar
endpoint, so I added calculation to the mod itself, since the logic is quite simple. Also the API seems to return only old events now and I can't test that patch does not break existing code :(