Add an optional delay to broadcast schedules
This commit is contained in:
parent
b842deb0d2
commit
1d7e83e89c
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import java.time.Duration;
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import tc.oc.commons.bukkit.broadcast.model.BroadcastPrefix;
|
||||
|
@ -44,8 +45,13 @@ public class BroadcastParser implements DocumentParser<List<BroadcastSchedule>>
|
|||
}
|
||||
|
||||
public BroadcastSchedule parseSchedule(Element el) throws ParseException {
|
||||
Duration delay = Duration.ZERO;
|
||||
Attr delayAttr = el.getAttributeNode("delay");
|
||||
if (delayAttr != null) {
|
||||
delay = durationParser.parse(delayAttr);
|
||||
}
|
||||
return new BroadcastSchedule(
|
||||
durationParser.parse(XML.requireAttr(el, "interval")),
|
||||
delay, durationParser.parse(XML.requireAttr(el, "interval")),
|
||||
serverFilterParser.parse(el), XML.childrenNamed(el, "messages").map(this::parseMessages)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ public class BroadcastScheduler implements PluginFacet {
|
|||
set -> messageMapFactory.create(configPath.resolve(SOURCES_PATH).resolve(set.path()),
|
||||
TRANSLATIONS_PATH.resolve(set.path())))
|
||||
);
|
||||
this.task = scheduler.createRepeatingTask(schedule.interval(), this::dispatch);
|
||||
this.task = scheduler.createRepeatingTask(schedule.delay(), schedule.interval(), this::dispatch);
|
||||
}
|
||||
|
||||
void dispatch() {
|
||||
|
|
|
@ -14,11 +14,13 @@ import tc.oc.minecraft.server.ServerFilter;
|
|||
*/
|
||||
public class BroadcastSchedule extends Inspectable.Impl {
|
||||
|
||||
@Inspect private final Duration delay;
|
||||
@Inspect private final Duration interval;
|
||||
@Inspect private final ImmutableList<BroadcastSet> messages;
|
||||
@Inspect private final ServerFilter serverFilter;
|
||||
|
||||
public BroadcastSchedule(Duration interval, ServerFilter serverFilter, Stream<BroadcastSet> messages) {
|
||||
public BroadcastSchedule(Duration delay, Duration interval, ServerFilter serverFilter, Stream<BroadcastSet> messages) {
|
||||
this.delay = delay;
|
||||
this.interval = interval;
|
||||
this.serverFilter = serverFilter;
|
||||
this.messages = messages.collect(Collectors.toImmutableList());
|
||||
|
@ -31,6 +33,13 @@ public class BroadcastSchedule extends Inspectable.Impl {
|
|||
return interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time before first broadcast
|
||||
*/
|
||||
public Duration delay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative path of the localized message list.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue