mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 07:06:45 +01:00
Update player names immediately when change is detected
This commit is contained in:
parent
a425ebcd10
commit
72264205d0
@ -1,5 +1,6 @@
|
|||||||
Version 2.1.177
|
Version 2.1.177
|
||||||
Environmentally aware will now protect Wolves from Magma blocks
|
Environmentally aware will now protect Wolves from Magma blocks
|
||||||
|
Fixed a bug where mcMMO would fail to update a players name when it detected a name change
|
||||||
|
|
||||||
Version 2.1.176
|
Version 2.1.176
|
||||||
Another fix for Double Smelt bringing item stack size to illegal values
|
Another fix for Double Smelt bringing item stack size to illegal values
|
||||||
|
@ -14,6 +14,7 @@ import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
|||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.runnables.database.UUIDUpdateAsyncTask;
|
import com.gmail.nossr50.runnables.database.UUIDUpdateAsyncTask;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
import com.gmail.nossr50.util.text.StringUtils;
|
import com.gmail.nossr50.util.text.StringUtils;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -477,6 +478,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PlayerProfile loadPlayerProfile(String playerName, UUID uuid, boolean create) {
|
public PlayerProfile loadPlayerProfile(String playerName, UUID uuid, boolean create) {
|
||||||
|
boolean updateRequired = false;
|
||||||
BufferedReader in = null;
|
BufferedReader in = null;
|
||||||
String usersFilePath = mcMMO.getUsersFilePath();
|
String usersFilePath = mcMMO.getUsersFilePath();
|
||||||
|
|
||||||
@ -504,11 +506,12 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
|
|
||||||
// Update playerName in database after name change
|
// Update playerName in database after name change
|
||||||
if (!character[USERNAME].equalsIgnoreCase(playerName)) {
|
if (!character[USERNAME].equalsIgnoreCase(playerName)) {
|
||||||
mcMMO.p.debug("Name change detected: " + character[USERNAME] + " => " + playerName);
|
// mcMMO.p.debug("Name change detected: " + character[USERNAME] + " => " + playerName);
|
||||||
character[USERNAME] = playerName;
|
character[USERNAME] = playerName;
|
||||||
|
updateRequired = true; //Flag profile to update
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadFromLine(character);
|
return loadFromLine(character, updateRequired);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Didn't find the player, create a new one
|
// Didn't find the player, create a new one
|
||||||
@ -563,7 +566,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
String[] character = line.split(":");
|
String[] character = line.split(":");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
destination.saveUser(loadFromLine(character));
|
destination.saveUser(loadFromLine(character, false));
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -1146,7 +1149,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlayerProfile loadFromLine(String[] character) {
|
private PlayerProfile loadFromLine(@NotNull String[] character, boolean updateRequired) {
|
||||||
Map<PrimarySkillType, Integer> skills = getSkillMapFromLine(character); // Skill levels
|
Map<PrimarySkillType, Integer> skills = getSkillMapFromLine(character); // Skill levels
|
||||||
Map<PrimarySkillType, Float> skillsXp = new EnumMap<>(PrimarySkillType.class); // Skill & XP
|
Map<PrimarySkillType, Float> skillsXp = new EnumMap<>(PrimarySkillType.class); // Skill & XP
|
||||||
Map<SuperAbilityType, Integer> skillsDATS = new EnumMap<>(SuperAbilityType.class); // Ability & Cooldown
|
Map<SuperAbilityType, Integer> skillsDATS = new EnumMap<>(SuperAbilityType.class); // Ability & Cooldown
|
||||||
@ -1212,6 +1215,13 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
uniquePlayerDataMap.put(UniqueDataType.CHIMAERA_WING_DATS, 0);
|
uniquePlayerDataMap.put(UniqueDataType.CHIMAERA_WING_DATS, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlayerProfile playerProfile = new PlayerProfile(character[USERNAME], uuid, skills, skillsXp, skillsDATS, mobHealthbarType, scoreboardTipsShown, uniquePlayerDataMap);
|
||||||
|
|
||||||
|
if(updateRequired) {
|
||||||
|
playerProfile.markProfileDirty();
|
||||||
|
playerProfile.scheduleSyncSave(); //Save profile since fields have changed
|
||||||
|
}
|
||||||
|
|
||||||
return new PlayerProfile(character[USERNAME], uuid, skills, skillsXp, skillsDATS, mobHealthbarType, scoreboardTipsShown, uniquePlayerDataMap);
|
return new PlayerProfile(character[USERNAME], uuid, skills, skillsXp, skillsDATS, mobHealthbarType, scoreboardTipsShown, uniquePlayerDataMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user