mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-31 13:37:46 +01:00
Fix offline player account creation (#4199)
This bug occurs when a player has joined before EssentialsX was installed and a player account creation is requested through Vault while they are offline. Fixes #4195
This commit is contained in:
parent
347751a826
commit
a4fbfbef02
@ -9,6 +9,7 @@ import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
@ -177,22 +178,42 @@ public class UserMap extends CacheLoader<String, User> implements IConf {
|
||||
}
|
||||
|
||||
if (player instanceof Player) {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().info("Loading online OfflinePlayer into user map...");
|
||||
}
|
||||
final User user = new User((Player) player, ess);
|
||||
trackUUID(player.getUniqueId(), player.getName(), true);
|
||||
return user;
|
||||
}
|
||||
|
||||
final File userFile = getUserFileFromID(player.getUniqueId());
|
||||
|
||||
if (userFile.exists()) {
|
||||
final OfflinePlayer essPlayer = new OfflinePlayer(player.getUniqueId(), ess.getServer());
|
||||
final User user = new User(essPlayer, ess);
|
||||
essPlayer.setName(user.getLastAccountName());
|
||||
trackUUID(player.getUniqueId(), user.getName(), false);
|
||||
return user;
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().info("Loading OfflinePlayer into user map. Has data: " + userFile.exists() + " for " + player);
|
||||
}
|
||||
|
||||
throw new UserDoesNotExistException("User not found!");
|
||||
final OfflinePlayer essPlayer = new OfflinePlayer(player.getUniqueId(), ess.getServer());
|
||||
final User user = new User(essPlayer, ess);
|
||||
if (userFile.exists()) {
|
||||
essPlayer.setName(user.getLastAccountName());
|
||||
} else {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().info("OfflinePlayer usermap load saving user data for " + player);
|
||||
}
|
||||
|
||||
// this code makes me sad
|
||||
user.startTransaction();
|
||||
try {
|
||||
user.setMoney(ess.getSettings().getStartingBalance());
|
||||
} catch (MaxMoneyException e) {
|
||||
// Shouldn't happen as it would be an illegal configuration state
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
user.setLastAccountName(user.getName());
|
||||
user.stopTransaction();
|
||||
}
|
||||
|
||||
trackUUID(player.getUniqueId(), user.getName(), false);
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -315,6 +315,9 @@ public class VaultEconomyProvider implements Economy {
|
||||
|
||||
// Loading a v4 UUID that we somehow didn't track, mark it as a normal player and hope for the best, vault sucks :/
|
||||
try {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
LOGGER.info("Vault requested a player account creation for a v4 UUID: " + player);
|
||||
}
|
||||
ess.getUserMap().load(player);
|
||||
return true;
|
||||
} catch (UserDoesNotExistException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user