mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-07-16 12:34:42 +02:00
Hopefully this works.
This commit is contained in:
@ -61,7 +61,7 @@ public class ConvertDatabaseCommand implements CommandExecutor {
|
||||
mcMMO.getDatabaseManager().saveUser(profile);
|
||||
}
|
||||
|
||||
UserManager.addUser(player);
|
||||
UserManager.track(player);
|
||||
}
|
||||
|
||||
new DatabaseConversionTask(oldDatabase, sender, previousType.toString(), newType.toString()).runTaskAsynchronously(mcMMO.p);
|
||||
|
@ -37,7 +37,7 @@ public class ConvertExperienceCommand implements CommandExecutor {
|
||||
new FormulaConversionTask(sender, newType).runTaskLater(mcMMO.p, 1);
|
||||
|
||||
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
|
||||
UserManager.addUser(player);
|
||||
UserManager.track(player);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -93,13 +93,13 @@ public class McMMOPlayer {
|
||||
private boolean isUsingUnarmed;
|
||||
private final FixedMetadataValue playerMetadata;
|
||||
|
||||
public McMMOPlayer(Player player) {
|
||||
public McMMOPlayer(Player player, PlayerProfile profile) {
|
||||
String playerName = player.getName();
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
this.player = player;
|
||||
playerMetadata = new FixedMetadataValue(mcMMO.p, playerName);
|
||||
profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, uuid, true);
|
||||
this.profile = profile;
|
||||
party = PartyManager.getPlayerParty(playerName);
|
||||
ptpRecord = new PartyTeleportRecord();
|
||||
|
||||
@ -130,70 +130,6 @@ public class McMMOPlayer {
|
||||
for (ToolType toolType : ToolType.values()) {
|
||||
toolMode.put(toolType, false);
|
||||
}
|
||||
|
||||
if (!profile.isLoaded()) {
|
||||
mcMMO.p.getLogger().warning("Unable to load the PlayerProfile for " + playerName + ". Will retry over the next several seconds.");
|
||||
new RetryProfileLoadingTask().runTaskTimerAsynchronously(mcMMO.p, 11L, 31L);
|
||||
}
|
||||
}
|
||||
|
||||
private class RetryProfileLoadingTask extends BukkitRunnable {
|
||||
private static final int MAX_TRIES = 5;
|
||||
private final String playerName = McMMOPlayer.this.player.getName();
|
||||
private final UUID uniqueId = McMMOPlayer.this.player.getUniqueId();
|
||||
private int attempt = 0;
|
||||
|
||||
// WARNING: ASYNC TASK
|
||||
// DO NOT MODIFY THE McMMOPLAYER FROM THIS CODE
|
||||
@Override
|
||||
public void run() {
|
||||
// Quit if they logged out
|
||||
if (!player.isOnline()) {
|
||||
mcMMO.p.getLogger().info("Aborting profile loading recovery for " + playerName + " - player logged out");
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
// Send the message that we're doing the recovery
|
||||
if (attempt == 0) {
|
||||
player.sendMessage(LocaleLoader.getString("Recovery.Notice"));
|
||||
}
|
||||
|
||||
// Increment attempt counter and try
|
||||
attempt++;
|
||||
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uniqueId, true);
|
||||
// If successful, schedule the apply
|
||||
if (profile.isLoaded()) {
|
||||
new ApplySuccessfulProfile(profile).runTask(mcMMO.p);
|
||||
player.sendMessage(LocaleLoader.getString("Recovery.Success"));
|
||||
this.cancel();
|
||||
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 " + playerName);
|
||||
mcMMO.p.getServer().broadcast(LocaleLoader.getString("Recovery.AdminFailureNotice", playerName), Server.BROADCAST_CHANNEL_ADMINISTRATIVE);
|
||||
player.sendMessage(LocaleLoader.getString("Recovery.Failure").split("\n"));
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ApplySuccessfulProfile extends BukkitRunnable {
|
||||
private final PlayerProfile profile;
|
||||
|
||||
private ApplySuccessfulProfile(PlayerProfile profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
// Synchronized task
|
||||
// No database access permitted
|
||||
@Override
|
||||
public void run() {
|
||||
McMMOPlayer.this.profile = profile;
|
||||
}
|
||||
}
|
||||
|
||||
public AcrobaticsManager getAcrobaticsManager() {
|
||||
|
@ -41,7 +41,7 @@ import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.ShareHandler;
|
||||
import com.gmail.nossr50.runnables.commands.McScoreboardKeepTask;
|
||||
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
|
||||
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
|
||||
import com.gmail.nossr50.skills.fishing.FishingManager;
|
||||
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
||||
@ -387,9 +387,7 @@ public class PlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.addUser(player);
|
||||
mcMMOPlayer.actualizeRespawnATS();
|
||||
ScoreboardManager.setupPlayer(player);
|
||||
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)) {
|
||||
Motd.displayAll(player);
|
||||
@ -403,11 +401,6 @@ public class PlayerListener implements Listener {
|
||||
player.sendMessage(LocaleLoader.getString("UpdateChecker.Outdated"));
|
||||
player.sendMessage(LocaleLoader.getString("UpdateChecker.NewAvailable"));
|
||||
}
|
||||
|
||||
if (Config.getInstance().getShowStatsAfterLogin()) {
|
||||
ScoreboardManager.enablePlayerStatsScoreboard(player);
|
||||
new McScoreboardKeepTask(player).runTaskLater(mcMMO.p, 1 * Misc.TICK_CONVERSION_FACTOR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,7 +167,7 @@ public class mcMMO extends JavaPlugin {
|
||||
holidayManager = new HolidayManager();
|
||||
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
UserManager.addUser(player); // In case of reload add all users back into UserManager
|
||||
UserManager.track(player); // In case of reload add all users back into UserManager
|
||||
ScoreboardManager.setupPlayer(player);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,93 @@
|
||||
package com.gmail.nossr50.runnables.player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.runnables.commands.McScoreboardKeepTask;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
|
||||
|
||||
public class PlayerProfileLoadingTask extends BukkitRunnable {
|
||||
private static final int MAX_TRIES = 5;
|
||||
private final Player player;
|
||||
private int attempt = 0;
|
||||
|
||||
public PlayerProfileLoadingTask(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
// WARNING: ASYNC TASK
|
||||
// DO NOT MODIFY THE McMMOPLAYER FROM THIS CODE
|
||||
@Override
|
||||
public void run() {
|
||||
// Quit if they logged out
|
||||
if (!player.isOnline()) {
|
||||
mcMMO.p.getLogger().info("Aborting profile loading recovery for " + player.getName() + " - player logged out");
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
// Send the message that we're doing the recovery
|
||||
if (attempt == 0) {
|
||||
player.sendMessage(LocaleLoader.getString("Profile.Loading.Starting"));
|
||||
}
|
||||
|
||||
// Increment attempt counter and try
|
||||
attempt++;
|
||||
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(player.getUniqueId(), true);
|
||||
// If successful, schedule the apply
|
||||
if (profile.isLoaded()) {
|
||||
new ApplySuccessfulProfile(profile).runTask(mcMMO.p);
|
||||
this.cancel();
|
||||
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();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private class ApplySuccessfulProfile extends BukkitRunnable {
|
||||
private final PlayerProfile profile;
|
||||
|
||||
private ApplySuccessfulProfile(PlayerProfile profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
// Synchronized task
|
||||
// No database access permitted
|
||||
@Override
|
||||
public void run() {
|
||||
if (!player.isOnline()) {
|
||||
mcMMO.p.getLogger().info("Aborting profile loading recovery for " + player.getName() + " - player logged out");
|
||||
return;
|
||||
}
|
||||
McMMOPlayer mcMMOPlayer = new McMMOPlayer(player, profile);
|
||||
UserManager.track(mcMMOPlayer);
|
||||
player.sendMessage(LocaleLoader.getString("Profile.Loading.Success"));
|
||||
mcMMOPlayer.actualizeRespawnATS();
|
||||
ScoreboardManager.setupPlayer(player);
|
||||
if (Config.getInstance().getShowStatsAfterLogin()) {
|
||||
ScoreboardManager.enablePlayerStatsScoreboard(player);
|
||||
new McScoreboardKeepTask(player).runTaskLater(mcMMO.p, 1 * Misc.TICK_CONVERSION_FACTOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ public final class Misc {
|
||||
|
||||
if (player != null) {
|
||||
UserManager.remove(player);
|
||||
UserManager.addUser(player);
|
||||
UserManager.track(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,16 +18,12 @@ public final class UserManager {
|
||||
private UserManager() {}
|
||||
|
||||
/**
|
||||
* Add a new user.
|
||||
* Track a new user.
|
||||
*
|
||||
* @param player The player to create a user record for
|
||||
* @return the player's {@link McMMOPlayer} object
|
||||
* @param mcMMOPlayer the player profile to start tracking
|
||||
*/
|
||||
public static McMMOPlayer addUser(Player player) {
|
||||
McMMOPlayer mcMMOPlayer = new McMMOPlayer(player);
|
||||
player.setMetadata(mcMMO.playerDataKey, new FixedMetadataValue(mcMMO.p, mcMMOPlayer));
|
||||
|
||||
return mcMMOPlayer;
|
||||
public static void track(McMMOPlayer mcMMOPlayer) {
|
||||
mcMMOPlayer.getPlayer().setMetadata(mcMMO.playerDataKey, new FixedMetadataValue(mcMMO.p, mcMMOPlayer));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user