Skip to content

Commit

Permalink
fix guid resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
caoli5288 committed May 18, 2020
1 parent 4d57c62 commit 1e2d1a4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));
});
}
}
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions playersql/src/main/java/com/mengcraft/playersql/UserManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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() + '!');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public synchronized void run() {
PluginMain.resetPlayerState(player);
}
manager.unlockUser(player);
manager.createTask(id);
manager.createTask(player);
});

if (Config.DEBUG) {
Expand Down

0 comments on commit 1e2d1a4

Please sign in to comment.