Skip to content

Commit

Permalink
(optimise) message delivery delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Lori3f6 committed Sep 6, 2024
1 parent 087a59f commit e7f5b74
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/cat/nyaa/ukit/loginpush/LoginPushFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ public boolean invokeCommand(CommandSender commandSender, Command command, Strin
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Bukkit.getAsyncScheduler().runNow(pluginInstance,(task)->{
countAndSendMessageIfHasMessage(event.getPlayer());
countAndSendMessageIfHasMessage(event.getPlayer(), 20 * 3);
});
}

@EventHandler
public void onAFKStatusChange(AfkStatusChangeEvent event) {
if (!event.getValue()) {
countAndSendMessageIfHasMessage(event.getAffected().getBase());
countAndSendMessageIfHasMessage(event.getAffected().getBase(), 10);
}
}

Expand All @@ -108,13 +108,13 @@ public LoginPushRecorder getLoginPushRecorder() {
return loginPushRecorder;
}

private void countAndSendMessageIfHasMessage(Player player) {
private void countAndSendMessageIfHasMessage(Player player, long delayInTick) {
try {
int unreadPush = loginPushRecorder.countUnreadPush(player.getUniqueId());
if (unreadPush > 0) {
Bukkit.getGlobalRegionScheduler().runDelayed(pluginInstance, (ignored) -> player.sendMessage(pluginInstance.language.loginPushLang.login_push_notice.produce(
Pair.of("number", unreadPush)
)), 20 * 3);
)), delayInTick);
}
} catch (SQLException e) {
pluginInstance.getLogger().warning(e.getMessage());
Expand Down

0 comments on commit e7f5b74

Please sign in to comment.