Skip to content
Open
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
48 changes: 26 additions & 22 deletions src/main/java/me/codedred/playtimes/listeners/Join.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import me.codedred.playtimes.data.database.manager.DatabaseManager;
import me.codedred.playtimes.statistics.StatManager;
import me.codedred.playtimes.statistics.StatisticType;
import me.codedred.playtimes.utils.Async;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -47,33 +48,36 @@ public void onJoin(PlayerJoinEvent event) {
return;
}

ConfigurationSection leaderboardSection = data
.getData()
.getConfigurationSection("leaderboard");
// Run leaderboard update asynchronously to avoid blocking main thread - DerexXD
Async.run(() -> {
ConfigurationSection leaderboardSection = data
.getData()
.getConfigurationSection("leaderboard");

if (leaderboardSection == null) {
leaderboardSection = data.getData().createSection("leaderboard");
}
if (leaderboardSection == null) {
leaderboardSection = data.getData().createSection("leaderboard");
}

if (leaderboardSection.contains(uuid.toString())) {
return;
}
if (leaderboardSection.contains(uuid.toString())) {
return;
}

long time = StatManager
.getInstance()
.getPlayerStat(uuid, StatisticType.PLAYTIME);
long time = StatManager
.getInstance()
.getPlayerStat(uuid, StatisticType.PLAYTIME);

if (
!data.getConfig().getBoolean("top-playtime.track-rawtime", false) &&
data.hasAfkEnabled()
) {
time -=
AFKManager.getInstance().getAFKTime(event.getPlayer().getUniqueId()) *
20;
}
if (
!data.getConfig().getBoolean("top-playtime.track-rawtime", false) &&
data.hasAfkEnabled()
) {
time -=
AFKManager.getInstance().getAFKTime(event.getPlayer().getUniqueId()) *
20;
}

leaderboardSection.set(uuid.toString(), time);
leaderboardSection.set(uuid.toString(), time);

data.saveData();
data.saveData();
});
}
}
10 changes: 5 additions & 5 deletions src/main/java/me/codedred/playtimes/listeners/Quit.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package me.codedred.playtimes.listeners;

import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import me.codedred.playtimes.afk.AFKManager;
import me.codedred.playtimes.data.DataManager;
import me.codedred.playtimes.data.database.manager.DatabaseManager;
import me.codedred.playtimes.statistics.StatManager;
import me.codedred.playtimes.statistics.StatisticType;
import me.codedred.playtimes.utils.Async;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
Expand All @@ -20,7 +20,7 @@ public void onQuit(PlayerQuitEvent event) {

// Database
if (data.hasDatabase()) {
CompletableFuture.runAsync(() -> {
Async.run(() -> {
DatabaseManager dbManager = DatabaseManager.getInstance();
dbManager.updatePlaytime(
uuid,
Expand All @@ -33,7 +33,7 @@ public void onQuit(PlayerQuitEvent event) {
});
} else {
// Save AFK time in data.yml
CompletableFuture.runAsync(() -> {
Async.run(() -> {
data
.getData()
.set("afktime." + uuid, AFKManager.getInstance().getAFKTime(uuid));
Expand All @@ -47,8 +47,8 @@ public void onQuit(PlayerQuitEvent event) {
return;
}

// Run leaderboard update
CompletableFuture.runAsync(() -> {
// Run leaderboard update asynchronously - DerexXD
Async.run(() -> {
StatManager statManager = StatManager.getInstance();
long playtime = statManager.getPlayerStat(uuid, StatisticType.PLAYTIME);
if (
Expand Down