Fixes times-claimed not being properly cleared when using /mmocore admin reset all <player>

This commit is contained in:
Jules 2024-09-07 17:52:18 +02:00
parent 6d71c775f6
commit cdfbb6ef09
3 changed files with 24 additions and 5 deletions

View File

@ -127,7 +127,8 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
/**
* Saves the amount of times the player has claimed some
* exp item in exp tables, for both exp tables used
* item in any experience table. The key used in the map
* is the identifier of the exp table item.
*/
private final Map<String, Integer> tableItemClaims = new HashMap<>();
@ -595,7 +596,12 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
return getClaims(object.getKey() + "." + table.getId() + "." + item.getId());
}
public int getClaims(String key) {
/**
* @param key The identifier of an exp table item.
* @return Amount of times an item has been claimed
* inside an experience table.
*/
public int getClaims(@NotNull String key) {
return tableItemClaims.getOrDefault(key, 0);
}

View File

@ -62,6 +62,8 @@ public class ResetCommandTreeNode extends CommandTreeNode {
ResetAttributesCommandTreeNode.resetAttributes(data, givePoints);
ResetWaypointsCommandTreeNode.resetWaypoints(data);
ResetSkillTreesCommandTreeNode.resetSkillTrees(data);
// Reset times-claimed not being properly emptied otherwise
data.getItemClaims().clear();
CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET, ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s data was successfully reset.");
return CommandResult.SUCCESS;
}

View File

@ -143,22 +143,33 @@ public class YAMLPlayerDataHandler extends YAMLSynchronizedDataHandler<PlayerDat
config.set("friends", data.getFriends().stream().map(UUID::toString).collect(Collectors.toList()));
config.set("last-login", data.getLastLogin());
config.set("guild", data.hasGuild() ? data.getGuild().getId() : null);
config.set("skill-tree-points", null); // Fixes skill tree points leftovers
data.mapSkillTreePoints().forEach((key1, value) -> config.set("skill-tree-points." + key1, value));
config.set("skill-tree-reallocation-points", data.getSkillTreeReallocationPoints());
config.set("skill", null);
config.set("health", data.getHealth());
config.set("mana", data.getMana());
config.set("stellium", data.getStellium());
config.set("stamina", data.getStamina());
config.set("unlocked-items", new ArrayList<>(data.getUnlockedItems()));
// Skill tree points
config.set("skill-tree-points", null); // Fixes skill tree points leftovers
data.mapSkillTreePoints().forEach((key1, value) -> config.set("skill-tree-points." + key1, value));
// Saves the nodes levels
config.set("skill-tree-level", null);
MMOCore.plugin.skillTreeManager.getAllNodes().forEach(node -> config.set("skill-tree-level." + node.getFullId(), data.getNodeLevel(node)));
// Skill levels
config.set("skill", null);
data.mapSkillLevels().forEach((key1, value) -> config.set("skill." + key1, value));
// Times claimed
config.set("times-claimed", null);
data.getItemClaims().forEach((key, times) -> config.set("times-claimed." + key, times));
config.set("bound-skills", null);
data.mapBoundSkills().forEach((slot, skill) -> config.set("bound-skills." + slot, skill));
config.set("unlocked-items", data.getUnlockedItems().stream().collect(Collectors.toList()));
config.set("attribute", null);
config.createSection("attribute");
data.getAttributes().save(config.getConfigurationSection("attribute"));