Skip to content

Commit

Permalink
Added loading players after server load.
Browse files Browse the repository at this point in the history
  • Loading branch information
imDMK committed Aug 27, 2023
1 parent 9b82482 commit a71b94c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/github/imdmk/spenttime/SpentTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.github.imdmk.spenttime.notification.Notification;
import com.github.imdmk.spenttime.notification.NotificationSender;
import com.github.imdmk.spenttime.placeholder.PlaceholderRegistry;
import com.github.imdmk.spenttime.placeholder.implementation.SpentTimeFormattedPlaceholder;
import com.github.imdmk.spenttime.placeholder.implementation.SpentTimePlaceholder;
import com.github.imdmk.spenttime.scheduler.TaskScheduler;
import com.github.imdmk.spenttime.scheduler.TaskSchedulerImpl;
import com.github.imdmk.spenttime.update.UpdateService;
Expand Down Expand Up @@ -139,6 +141,9 @@ public SpentTime(Plugin plugin) {
this.taskScheduler.runLaterAsync(updateService::check, DurationUtil.toTicks(Duration.ofSeconds(5)));
}

/* Load all players; Used when the server reload */
this.loadAllPlayers();

/* Metrics */
this.metrics = new Metrics((JavaPlugin) plugin, 19362);

Expand Down Expand Up @@ -196,6 +201,14 @@ private LiteCommands<CommandSender> registerLiteCommands() {
.register();
}

private void loadAllPlayers() {
this.taskScheduler.runSync(() -> {
for (Player player : this.server.getOnlinePlayers()) {
this.userManager.findOrCreateUser(player.getUniqueId(), player.getName());
}
});
}

private void closeAllPlayersInventory() {
for (Player player : this.server.getOnlinePlayers()) {
player.closeInventory();
Expand Down

0 comments on commit a71b94c

Please sign in to comment.