I wrote this piece of code in order to transfer skills from a player to another. Those could be offline or online players, so I need the transfer to be possibile in both cases, but when setting the level for offline players and doing /inspect , the values are not changed, even after a restart or when the offline player logs-in. I suppose that there's a problem on the setLevelOffline or in the way I'm using it.
public static void transferSkills(OfflinePlayer from, OfflinePlayer to) {
for (SkillType skillType: SkillType.NON_CHILD_SKILLS) {
int level = 0;
if (from.isOnline()) {
level = ExperienceAPI.getLevel((Player) from, skillType.getName());
ExperienceAPI.setLevel((Player) from, skillType.getName(), 0);
} else {
level = ExperienceAPI.getLevelOffline(from.getUniqueId(), skillType.getName());
ExperienceAPI.setLevelOffline(from.getUniqueId(), skillType.getName(), 0);
}
if (to.isOnline()) {
ExperienceAPI.setLevel((Player) to, skillType.getName(), level);
} else {
ExperienceAPI.setLevelOffline(to.getUniqueId(), skillType.getName(), level);
}
}
I wrote this piece of code in order to transfer skills from a player to another. Those could be offline or online players, so I need the transfer to be possibile in both cases, but when setting the level for offline players and doing /inspect, the values are not changed, even after a restart or when the offline player logs-in. I suppose that there's a problem on the setLevelOffline or in the way I'm using it.