diff --git a/playersql/src/main/java/com/mengcraft/playersql/EventExecutor.java b/playersql/src/main/java/com/mengcraft/playersql/EventExecutor.java index 2cf6ab2..a96efa7 100644 --- a/playersql/src/main/java/com/mengcraft/playersql/EventExecutor.java +++ b/playersql/src/main/java/com/mengcraft/playersql/EventExecutor.java @@ -1,5 +1,6 @@ package com.mengcraft.playersql; +import com.mengcraft.playersql.internal.GuidResolveService; import com.mengcraft.playersql.lib.BiRegistry; import com.mengcraft.playersql.lib.CustomInventory; import com.mengcraft.playersql.peer.DataRequest; @@ -102,16 +103,17 @@ public void handle(PlayerJoinEvent event) { manager.lockUser(player); UUID id = player.getUniqueId(); - PlayerData pend = (PlayerData) pending.remove(id); + Object pend = pending.remove(id); if (pend == null) { FetchUserTask task = new FetchUserTask(player); pending.put(id, task); task.runTaskTimerAsynchronously(main, Config.SYN_DELAY, Config.SYN_DELAY); - } else { + } else if (pend instanceof PlayerData) { main.debug("process pending data_buf on join event"); + UUID guid = GuidResolveService.getService().getGuid(player); main.run(() -> { - manager.pend(player, pend); - runAsync(() -> manager.updateDataLock(id, true)); + manager.pend(player, (PlayerData) pend); + runAsync(() -> manager.updateDataLock(guid, true)); }); } } @@ -161,7 +163,8 @@ public void handle(PlayerQuitEvent event) { runAsync(() -> manager.saveUser(data, false)).thenRun(() -> main.run(() -> manager.unlockUser(player))); } } else { - runAsync(() -> manager.updateDataLock(id, false)).thenRun(() -> main.run(() -> manager.unlockUser(player))); + UUID guid = GuidResolveService.getService().getGuid(player); + runAsync(() -> manager.updateDataLock(guid, false)).thenRun(() -> main.run(() -> manager.unlockUser(player))); } pending.remove(id); LocalDataMgr.quit(player); diff --git a/playersql/src/main/java/com/mengcraft/playersql/UserManager.java b/playersql/src/main/java/com/mengcraft/playersql/UserManager.java index 90e208b..0a6d9a6 100644 --- a/playersql/src/main/java/com/mengcraft/playersql/UserManager.java +++ b/playersql/src/main/java/com/mengcraft/playersql/UserManager.java @@ -185,7 +185,7 @@ void onLoadFailed(Player who) { who.kickPlayer(PluginMain.getMessenger().find("kick_load", "Your game data loading error, please contact the operator")); } else { unlockUser(who); - createTask(who.getUniqueId()); + createTask(who); } } @@ -261,7 +261,7 @@ private void syncUserdata(Player who, PlayerData data) { if (Config.SYN_CHEST) { who.getEnderChest().setContents(toStack(data.getChest())); } - createTask(who.getUniqueId()); + createTask(who); unlockUser(who); } @@ -336,17 +336,17 @@ public void cancelTimerSaver(UUID uuid) { } } - public void createTask(UUID who) { + public void createTask(Player player) { if (Config.DEBUG) { - this.main.log("Scheduling daily save task for user " + who + '.'); + this.main.log("Scheduling daily save task for user " + player.getName() + '.'); } - val task = new DailySaveTask(who); + val task = new DailySaveTask(player); task.runTaskTimer(main, 6000, 6000); - val old = scheduled.put(who, task); + val old = scheduled.put(player.getUniqueId(), task); if (!nil(old)) { old.cancel(); if (Config.DEBUG) { - this.main.log("Already scheduled task for user " + who + '!'); + this.main.log("Already scheduled task for user " + player.getName() + '!'); } } } diff --git a/playersql/src/main/java/com/mengcraft/playersql/task/DailySaveTask.java b/playersql/src/main/java/com/mengcraft/playersql/task/DailySaveTask.java index 4aa27a1..61a96a3 100644 --- a/playersql/src/main/java/com/mengcraft/playersql/task/DailySaveTask.java +++ b/playersql/src/main/java/com/mengcraft/playersql/task/DailySaveTask.java @@ -2,8 +2,11 @@ import com.mengcraft.playersql.Config; import com.mengcraft.playersql.PlayerData; +import com.mengcraft.playersql.PluginMain; import com.mengcraft.playersql.UserManager; import lombok.RequiredArgsConstructor; + +import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import java.util.UUID; @@ -17,23 +20,23 @@ public class DailySaveTask extends BukkitRunnable { private UserManager manager = UserManager.INSTANCE; - private final UUID who; + private final Player player; private int count; @Override public void run() { - PlayerData user = manager.getUserData(this.who, false); + PlayerData user = manager.getUserData(player, false); if (nil(user)) { if (Config.DEBUG) { - manager.getMain().log("Cancel task for " + who + " offline!"); + manager.getMain().log("Cancel task for " + player.getName() + " offline!"); } cancel(); } else { this.count++; if (Config.DEBUG) { - manager.getMain().log("Save user " + this.who + " count " + this.count + '.'); + manager.getMain().log("Save user " + player.getName() + " count " + this.count + '.'); } - manager.getMain().runAsync(() -> manager.saveUser(user, true)); + PluginMain.runAsync(() -> manager.saveUser(user, true)); } } diff --git a/playersql/src/main/java/com/mengcraft/playersql/task/FetchUserTask.java b/playersql/src/main/java/com/mengcraft/playersql/task/FetchUserTask.java index d8a4826..03dbf8f 100644 --- a/playersql/src/main/java/com/mengcraft/playersql/task/FetchUserTask.java +++ b/playersql/src/main/java/com/mengcraft/playersql/task/FetchUserTask.java @@ -57,7 +57,7 @@ public synchronized void run() { PluginMain.resetPlayerState(player); } manager.unlockUser(player); - manager.createTask(id); + manager.createTask(player); }); if (Config.DEBUG) {