mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 15:16:45 +01:00
Remove need for thread locks in profile loading, just reschedule as needed. also stagger based on number of previous attempts.
This commit is contained in:
parent
da7507fc75
commit
b7774251eb
@ -62,7 +62,7 @@ public class ConvertDatabaseCommand implements CommandExecutor {
|
|||||||
mcMMO.getDatabaseManager().saveUser(profile);
|
mcMMO.getDatabaseManager().saveUser(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
new PlayerProfileLoadingTask(player).runTaskTimerAsynchronously(mcMMO.p, 1, 100); // 1 Tick delay to ensure the player is marked as online before we begin loading
|
new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(mcMMO.p, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
|
||||||
}
|
}
|
||||||
|
|
||||||
new DatabaseConversionTask(oldDatabase, sender, previousType.toString(), newType.toString()).runTaskAsynchronously(mcMMO.p);
|
new DatabaseConversionTask(oldDatabase, sender, previousType.toString(), newType.toString()).runTaskAsynchronously(mcMMO.p);
|
||||||
|
@ -38,7 +38,7 @@ public class ConvertExperienceCommand implements CommandExecutor {
|
|||||||
new FormulaConversionTask(sender, newType).runTaskLater(mcMMO.p, 1);
|
new FormulaConversionTask(sender, newType).runTaskLater(mcMMO.p, 1);
|
||||||
|
|
||||||
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
|
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
|
||||||
new PlayerProfileLoadingTask(player).runTaskTimerAsynchronously(mcMMO.p, 1, 100); // 1 Tick delay to ensure the player is marked as online before we begin loading
|
new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(mcMMO.p, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -387,7 +387,7 @@ public class PlayerListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new PlayerProfileLoadingTask(player).runTaskTimerAsynchronously(mcMMO.p, 1, 100); // 1 Tick delay to ensure the player is marked as online before we begin loading
|
new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(mcMMO.p, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
|
||||||
|
|
||||||
if (Config.getInstance().getMOTDEnabled() && Permissions.motd(player)) {
|
if (Config.getInstance().getMOTDEnabled() && Permissions.motd(player)) {
|
||||||
Motd.displayAll(player);
|
Motd.displayAll(player);
|
||||||
|
@ -168,7 +168,7 @@ public class mcMMO extends JavaPlugin {
|
|||||||
holidayManager = new HolidayManager();
|
holidayManager = new HolidayManager();
|
||||||
|
|
||||||
for (Player player : getServer().getOnlinePlayers()) {
|
for (Player player : getServer().getOnlinePlayers()) {
|
||||||
new PlayerProfileLoadingTask(player).runTaskTimerAsynchronously(mcMMO.p, 1, 100); // 1 Tick delay to ensure the player is marked as online before we begin loading
|
new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(mcMMO.p, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("Version " + getDescription().getVersion() + " is enabled!");
|
debug("Version " + getDescription().getVersion() + " is enabled!");
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.gmail.nossr50.runnables.player;
|
package com.gmail.nossr50.runnables.player;
|
||||||
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
|
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
@ -20,8 +18,6 @@ public class PlayerProfileLoadingTask extends BukkitRunnable {
|
|||||||
private static final int MAX_TRIES = 5;
|
private static final int MAX_TRIES = 5;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private int attempt = 0;
|
private int attempt = 0;
|
||||||
private ReentrantLock lock = new ReentrantLock();
|
|
||||||
private boolean cancelled = false;
|
|
||||||
|
|
||||||
public PlayerProfileLoadingTask(Player player) {
|
public PlayerProfileLoadingTask(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
@ -31,45 +27,30 @@ public class PlayerProfileLoadingTask extends BukkitRunnable {
|
|||||||
// DO NOT MODIFY THE McMMOPLAYER FROM THIS CODE
|
// DO NOT MODIFY THE McMMOPLAYER FROM THIS CODE
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
lock.lock();
|
// Quit if they logged out
|
||||||
|
if (!player.isOnline()) {
|
||||||
try {
|
mcMMO.p.getLogger().info("Aborting profile loading recovery for " + player.getName() + " - player logged out");
|
||||||
if (this.cancelled) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Quit if they logged out
|
|
||||||
if (!player.isOnline()) {
|
|
||||||
mcMMO.p.getLogger().info("Aborting profile loading recovery for " + player.getName() + " - player logged out");
|
|
||||||
this.cancel();
|
|
||||||
cancelled = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increment attempt counter and try
|
|
||||||
attempt++;
|
|
||||||
|
|
||||||
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(player.getName(), player.getUniqueId(), true);
|
|
||||||
// If successful, schedule the apply
|
|
||||||
if (profile.isLoaded()) {
|
|
||||||
new ApplySuccessfulProfile(profile).runTask(mcMMO.p);
|
|
||||||
this.cancel();
|
|
||||||
cancelled = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we've failed five times, give up
|
|
||||||
if (attempt >= MAX_TRIES) {
|
|
||||||
mcMMO.p.getLogger().severe("Giving up on attempting to load the PlayerProfile for " + player.getName());
|
|
||||||
mcMMO.p.getServer().broadcast(LocaleLoader.getString("Profile.Loading.AdminFailureNotice", player.getName()), Server.BROADCAST_CHANNEL_ADMINISTRATIVE);
|
|
||||||
player.sendMessage(LocaleLoader.getString("Profile.Loading.Failure").split("\n"));
|
|
||||||
this.cancel();
|
|
||||||
cancelled = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Increment attempt counter and try
|
||||||
|
attempt++;
|
||||||
|
|
||||||
|
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(player.getName(), player.getUniqueId(), true);
|
||||||
|
// If successful, schedule the apply
|
||||||
|
if (profile.isLoaded()) {
|
||||||
|
new ApplySuccessfulProfile(profile).runTask(mcMMO.p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we've failed five times, give up
|
||||||
|
if (attempt >= MAX_TRIES) {
|
||||||
|
mcMMO.p.getLogger().severe("Giving up on attempting to load the PlayerProfile for " + player.getName());
|
||||||
|
mcMMO.p.getServer().broadcast(LocaleLoader.getString("Profile.Loading.AdminFailureNotice", player.getName()), Server.BROADCAST_CHANNEL_ADMINISTRATIVE);
|
||||||
|
player.sendMessage(LocaleLoader.getString("Profile.Loading.Failure").split("\n"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.runTaskLaterAsynchronously(mcMMO.p, 100 * attempt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ApplySuccessfulProfile extends BukkitRunnable {
|
private class ApplySuccessfulProfile extends BukkitRunnable {
|
||||||
|
@ -113,7 +113,7 @@ public final class Misc {
|
|||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
UserManager.remove(player);
|
UserManager.remove(player);
|
||||||
new PlayerProfileLoadingTask(player).runTaskTimerAsynchronously(mcMMO.p, 1, 100); // 1 Tick delay to ensure the player is marked as online before we begin loading
|
new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(mcMMO.p, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user