mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-29 16:46:46 +01:00
Hopefully this works.
This commit is contained in:
parent
49f2bf5452
commit
7917b84eca
@ -61,7 +61,7 @@ public class ConvertDatabaseCommand implements CommandExecutor {
|
|||||||
mcMMO.getDatabaseManager().saveUser(profile);
|
mcMMO.getDatabaseManager().saveUser(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
UserManager.addUser(player);
|
UserManager.track(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
new DatabaseConversionTask(oldDatabase, sender, previousType.toString(), newType.toString()).runTaskAsynchronously(mcMMO.p);
|
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);
|
new FormulaConversionTask(sender, newType).runTaskLater(mcMMO.p, 1);
|
||||||
|
|
||||||
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
|
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
|
||||||
UserManager.addUser(player);
|
UserManager.track(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -93,13 +93,13 @@ public class McMMOPlayer {
|
|||||||
private boolean isUsingUnarmed;
|
private boolean isUsingUnarmed;
|
||||||
private final FixedMetadataValue playerMetadata;
|
private final FixedMetadataValue playerMetadata;
|
||||||
|
|
||||||
public McMMOPlayer(Player player) {
|
public McMMOPlayer(Player player, PlayerProfile profile) {
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
this.player = player;
|
this.player = player;
|
||||||
playerMetadata = new FixedMetadataValue(mcMMO.p, playerName);
|
playerMetadata = new FixedMetadataValue(mcMMO.p, playerName);
|
||||||
profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, uuid, true);
|
this.profile = profile;
|
||||||
party = PartyManager.getPlayerParty(playerName);
|
party = PartyManager.getPlayerParty(playerName);
|
||||||
ptpRecord = new PartyTeleportRecord();
|
ptpRecord = new PartyTeleportRecord();
|
||||||
|
|
||||||
@ -130,70 +130,6 @@ public class McMMOPlayer {
|
|||||||
for (ToolType toolType : ToolType.values()) {
|
for (ToolType toolType : ToolType.values()) {
|
||||||
toolMode.put(toolType, false);
|
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() {
|
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.datatypes.skills.SkillType;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.party.ShareHandler;
|
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.runnables.skills.BleedTimerTask;
|
||||||
import com.gmail.nossr50.skills.fishing.FishingManager;
|
import com.gmail.nossr50.skills.fishing.FishingManager;
|
||||||
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
||||||
@ -387,9 +387,7 @@ public class PlayerListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.addUser(player);
|
new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(mcMMO.p, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
|
||||||
mcMMOPlayer.actualizeRespawnATS();
|
|
||||||
ScoreboardManager.setupPlayer(player);
|
|
||||||
|
|
||||||
if (Config.getInstance().getMOTDEnabled() && Permissions.motd(player)) {
|
if (Config.getInstance().getMOTDEnabled() && Permissions.motd(player)) {
|
||||||
Motd.displayAll(player);
|
Motd.displayAll(player);
|
||||||
@ -403,11 +401,6 @@ public class PlayerListener implements Listener {
|
|||||||
player.sendMessage(LocaleLoader.getString("UpdateChecker.Outdated"));
|
player.sendMessage(LocaleLoader.getString("UpdateChecker.Outdated"));
|
||||||
player.sendMessage(LocaleLoader.getString("UpdateChecker.NewAvailable"));
|
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();
|
holidayManager = new HolidayManager();
|
||||||
|
|
||||||
for (Player player : getServer().getOnlinePlayers()) {
|
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);
|
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) {
|
if (player != null) {
|
||||||
UserManager.remove(player);
|
UserManager.remove(player);
|
||||||
UserManager.addUser(player);
|
UserManager.track(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,16 +18,12 @@ public final class UserManager {
|
|||||||
private UserManager() {}
|
private UserManager() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new user.
|
* Track a new user.
|
||||||
*
|
*
|
||||||
* @param player The player to create a user record for
|
* @param mcMMOPlayer the player profile to start tracking
|
||||||
* @return the player's {@link McMMOPlayer} object
|
|
||||||
*/
|
*/
|
||||||
public static McMMOPlayer addUser(Player player) {
|
public static void track(McMMOPlayer mcMMOPlayer) {
|
||||||
McMMOPlayer mcMMOPlayer = new McMMOPlayer(player);
|
mcMMOPlayer.getPlayer().setMetadata(mcMMO.playerDataKey, new FixedMetadataValue(mcMMO.p, mcMMOPlayer));
|
||||||
player.setMetadata(mcMMO.playerDataKey, new FixedMetadataValue(mcMMO.p, mcMMOPlayer));
|
|
||||||
|
|
||||||
return mcMMOPlayer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -960,7 +960,7 @@ Scoreboard.Misc.Cooldown=[[LIGHT_PURPLE]]Cooldown
|
|||||||
Scoreboard.Misc.Overall=[[GOLD]]Overall
|
Scoreboard.Misc.Overall=[[GOLD]]Overall
|
||||||
|
|
||||||
#DATABASE RECOVERY
|
#DATABASE RECOVERY
|
||||||
Recovery.Notice=[[RED]]Notice: mcMMO was [[DARK_RED]]unable to load your data.[[RED]] Retrying 5 times...
|
Profile.Loading.Start=[[GREEN]]Notice: mcMMO is now loading your profile. Stats and skills will not function until loaded...
|
||||||
Recovery.Success=[[GREEN]]Success! Your mcMMO data was loaded.
|
Profile.Loading.Success=[[GREEN]]Success! Your mcMMO data was loaded.
|
||||||
Recovery.Failure=[[RED]]mcMMO still cannot load your data. You may want to [[AQUA]]contact the server owner.\n[[YELLOW]]You can still play on the server, but you will have [[BOLD]]no mcMMO levels[[YELLOW]] and any XP you get [[BOLD]]will not be saved[[YELLOW]].
|
Profile.Loading.Failure=[[RED]]mcMMO still cannot load your data. You may want to [[AQUA]]contact the server owner.\n[[YELLOW]]You can still play on the server, but you will have [[BOLD]]no mcMMO levels[[YELLOW]] and any XP you get [[BOLD]]will not be saved[[YELLOW]].
|
||||||
Recovery.AdminFailureNotice=[[DARK_RED]][A][[RED]] mcMMO was unable to load the player data for [[YELLOW]]{0}[[RED]]. [[LIGHT_PURPLE]]Please inspect your database setup.
|
Profile.Loading.AdminFailureNotice=[[DARK_RED]][A][[RED]] mcMMO was unable to load the player data for [[YELLOW]]{0}[[RED]]. [[LIGHT_PURPLE]]Please inspect your database setup.
|
||||||
|
Loading…
Reference in New Issue
Block a user