fix(currency-plugin): 修复导入数据会导致玩家名称丢失的问题

This commit is contained in:
2024-11-18 21:12:30 +08:00
parent aacfc4697b
commit 16f5b7f49a
3 changed files with 11 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ plugins {
}
group 'cn.hamster3'
version '2.2.6'
version '2.2.7'
repositories {
maven {

View File

@@ -158,9 +158,11 @@ public class SQLDataManager implements IDataManager {
if (data == null) {
data = new PlayerData(uuid, name);
playerData.put(data.getUuid(), data);
}else {
data.setPlayerName(name);
}
data.setPlayerCurrency(currencyType, money);
getLogUtils().info("已从其他插件中加载了玩家 %s 的存档数据.", data.getUuid());
getLogUtils().info("已从其他插件中加载了玩家 %s(%s) 的存档数据.", uuid, name);
} catch (Exception e) {
getLogUtils().error(e, "导入某一条数据时发生了一个错误: ");
}
@@ -311,7 +313,7 @@ public class SQLDataManager implements IDataManager {
@Override
public PlayerData getPlayerData(UUID uuid) {
return playerData.computeIfAbsent(uuid, PlayerData::new);
return playerData.get(uuid);
}
@Override

View File

@@ -14,7 +14,7 @@ import java.util.UUID;
public class PlayerData {
private final UUID uuid;
private final String playerName;
private String playerName;
private final HashMap<String, Double> playerCurrencies;
public PlayerData(UUID uuid) {
@@ -31,7 +31,7 @@ public class PlayerData {
public PlayerData(JsonObject object) {
uuid = UUID.fromString(object.get("uuid").getAsString());
if (object.has("playerName")) {
if (object.has("playerName") && !object.get("playerName").isJsonNull()) {
playerName = object.get("playerName").getAsString();
} else {
playerName = ServiceInfoAPI.getPlayerInfo(uuid).getPlayerName();
@@ -91,6 +91,10 @@ public class PlayerData {
return playerName;
}
public void setPlayerName(String playerName) {
this.playerName = playerName;
}
public void setPlayerCurrency(String type, double amount) {
playerCurrencies.put(type, amount);
}