Fix issue with corrupted world names after upgrading from 1.13 to 1.14.

This commit is contained in:
BuildTools 2019-06-20 08:11:38 +03:00
parent 4527216dc2
commit b2f2c4a0bb

View File

@ -112,6 +112,77 @@ public class ChallengesManager
this.playerCacheData = new HashMap<>(); this.playerCacheData = new HashMap<>();
this.load(); this.load();
// TODO: Remove this code after some time, as this is just a protective code against invalid world names.
if (Bukkit.getBukkitVersion().startsWith("1.14"))
{
Set<Challenge> updatedChallenges = new HashSet<>();
this.challengeCacheData.values().forEach(challengeObject -> {
if (challengeObject.getUniqueId().matches(".*[A-Z]+.*"))
{
challengeObject.setUniqueId(challengeObject.getUniqueId().toLowerCase());
challengeObject.setLevel(challengeObject.getLevel().toLowerCase());
updatedChallenges.add(challengeObject);
this.addon.logWarning("Challenge addon fixed your data for Challenge " +
challengeObject.getUniqueId() +
". 1.14 does not allow to use capital letters in world names.");
}
});
Set<ChallengeLevel> updatedLevels = new HashSet<>();
this.levelCacheData.values().forEach(levelObject -> {
if (levelObject.getUniqueId().matches(".*[A-Z]+.*"))
{
levelObject.setUniqueId(levelObject.getUniqueId().toLowerCase());
levelObject.setWorld(levelObject.getWorld().toLowerCase());
Set<String> correctNames = levelObject.getChallenges().stream().
map(String::toLowerCase).
collect(Collectors.toSet());
levelObject.setChallenges(correctNames);
updatedLevels.add(levelObject);
this.addon.logWarning("Challenge addon fixed your data for Challenge Level " +
levelObject.getUniqueId() +
". 1.14 does not allow to use capital letters in world names.");
}
});
// As at least one challenge or level was corrupted we must update all player data objects!
if (!updatedLevels.isEmpty() || !updatedChallenges.isEmpty())
{
List<ChallengesPlayerData> playerDataList = this.playersDatabase.loadObjects();
playerDataList.forEach(challengesPlayerData -> {
Map<String, Integer> fixedChallengeStatus = new HashMap<>();
challengesPlayerData.getChallengeStatus().forEach((challenge, count) ->
fixedChallengeStatus.put(challenge.toLowerCase(), count));
challengesPlayerData.setChallengeStatus(fixedChallengeStatus);
Map<String, Long> fixedChallengeTimestamp = new HashMap<>();
challengesPlayerData.getChallengesTimestamp().forEach((challenge, count) ->
fixedChallengeTimestamp.put(challenge.toLowerCase(), count));
challengesPlayerData.setChallengesTimestamp(fixedChallengeTimestamp);
Set<String> fixedLevelsDone = new HashSet<>();
challengesPlayerData.getLevelsDone().forEach(level -> fixedLevelsDone.add(level.toLowerCase()));
challengesPlayerData.setLevelsDone(fixedLevelsDone);
this.playersDatabase.saveObject(challengesPlayerData);
this.addon.logWarning("Challenge addon fixed your data for PlayerData " +
challengesPlayerData.getUniqueId() +
". 1.14 does not allow to use capital letters in world names.");
});
}
}
} }