use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class StorageProvider method addLoadedPlayersToLeaderboards.
protected Set<UUID> addLoadedPlayersToLeaderboards(Map<Skill, List<SkillValue>> leaderboards, List<SkillValue> powerLeaderboard, List<SkillValue> averageLeaderboard) {
Set<UUID> loadedFromMemory = new HashSet<>();
for (PlayerData playerData : playerManager.getPlayerDataMap().values()) {
UUID id = playerData.getPlayer().getUniqueId();
int powerLevel = 0;
double powerXp = 0;
int numEnabled = 0;
for (Skill skill : Skills.values()) {
int level = playerData.getSkillLevel(skill);
double xp = playerData.getSkillXp(skill);
// Add to lists
SkillValue skillLevel = new SkillValue(id, level, xp);
leaderboards.get(skill).add(skillLevel);
if (OptionL.isEnabled(skill)) {
powerLevel += level;
powerXp += xp;
numEnabled++;
}
}
// Add power and average
SkillValue powerValue = new SkillValue(id, powerLevel, powerXp);
powerLeaderboard.add(powerValue);
double averageLevel = (double) powerLevel / numEnabled;
SkillValue averageValue = new SkillValue(id, 0, averageLevel);
averageLeaderboard.add(averageValue);
loadedFromMemory.add(playerData.getPlayer().getUniqueId());
}
return loadedFromMemory;
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class StorageProvider method createNewPlayer.
public PlayerData createNewPlayer(Player player) {
PlayerData playerData = new PlayerData(player, plugin);
playerManager.addPlayerData(playerData);
plugin.getLeveler().updatePermissions(player);
PlayerDataLoadEvent event = new PlayerDataLoadEvent(playerData);
new BukkitRunnable() {
@Override
public void run() {
Bukkit.getPluginManager().callEvent(event);
}
}.runTask(plugin);
return playerData;
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class YamlStorageProvider method load.
@Override
public void load(Player player) {
File file = new File(plugin.getDataFolder() + "/playerdata/" + player.getUniqueId() + ".yml");
if (file.exists()) {
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
PlayerData playerData = new PlayerData(player, plugin);
try {
// Make sure file name and uuid match
UUID id = UUID.fromString(config.getString("uuid", player.getUniqueId().toString()));
if (!player.getUniqueId().equals(id)) {
throw new IllegalArgumentException("File name and uuid field do not match!");
}
// Load skill data
for (Skill skill : Skills.values()) {
String path = "skills." + skill.name().toLowerCase(Locale.ROOT) + ".";
int level = config.getInt(path + "level", 1);
double xp = config.getDouble(path + "xp", 0.0);
playerData.setSkillLevel(skill, level);
playerData.setSkillXp(skill, xp);
// Add stat levels
plugin.getRewardManager().getRewardTable(skill).applyStats(playerData, level);
}
// Load stat modifiers
ConfigurationSection modifiersSection = config.getConfigurationSection("stat_modifiers");
if (modifiersSection != null) {
for (String entry : modifiersSection.getKeys(false)) {
ConfigurationSection modifierEntry = modifiersSection.getConfigurationSection(entry);
if (modifierEntry != null) {
String name = modifierEntry.getString("name");
String statName = modifierEntry.getString("stat");
double value = modifierEntry.getDouble("value");
if (name != null && statName != null) {
Stat stat = plugin.getStatRegistry().getStat(statName);
StatModifier modifier = new StatModifier(name, stat, value);
playerData.addStatModifier(modifier);
}
}
}
}
// Load mana
playerData.setMana(config.getDouble("mana"));
// Load locale
String locale = config.getString("locale");
if (locale != null) {
playerData.setLocale(new Locale(locale));
}
// Load ability data
ConfigurationSection abilitySection = config.getConfigurationSection("ability_data");
if (abilitySection != null) {
for (String abilityName : abilitySection.getKeys(false)) {
ConfigurationSection abilityEntry = abilitySection.getConfigurationSection(abilityName);
if (abilityEntry != null) {
AbstractAbility ability = AbstractAbility.valueOf(abilityName.toUpperCase(Locale.ROOT));
if (ability != null) {
AbilityData abilityData = playerData.getAbilityData(ability);
for (String key : abilityEntry.getKeys(false)) {
Object value = abilityEntry.get(key);
abilityData.setData(key, value);
}
}
}
}
}
// Unclaimed item rewards
List<String> unclaimedItemsList = config.getStringList("unclaimed_items");
if (unclaimedItemsList.size() > 0) {
List<KeyIntPair> unclaimedItems = new ArrayList<>();
for (String entry : unclaimedItemsList) {
String[] splitEntry = entry.split(" ");
String itemKey = splitEntry[0];
int amount = 1;
if (splitEntry.length >= 2) {
amount = NumberUtils.toInt(splitEntry[1], 1);
}
unclaimedItems.add(new KeyIntPair(itemKey, amount));
}
playerData.setUnclaimedItems(unclaimedItems);
playerData.clearInvalidItems();
}
playerManager.addPlayerData(playerData);
plugin.getLeveler().updatePermissions(player);
PlayerDataLoadEvent event = new PlayerDataLoadEvent(playerData);
new BukkitRunnable() {
@Override
public void run() {
Bukkit.getPluginManager().callEvent(event);
}
}.runTask(plugin);
} catch (Exception e) {
Bukkit.getLogger().warning("There was an error loading player data for player " + player.getName() + " with UUID " + player.getUniqueId() + ", see below for details.");
e.printStackTrace();
PlayerData data = createNewPlayer(player);
data.setShouldSave(false);
sendErrorMessageToPlayer(player, e);
}
} else {
createNewPlayer(player);
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class YamlStorageProvider method loadBackup.
@Override
public void loadBackup(FileConfiguration config, CommandSender sender) {
ConfigurationSection playerDataSection = config.getConfigurationSection("player_data");
Locale locale = plugin.getLang().getLocale(sender);
if (playerDataSection != null) {
try {
for (String stringId : playerDataSection.getKeys(false)) {
UUID id = UUID.fromString(stringId);
// Load levels and xp from backup
Map<Skill, Integer> levels = getLevelsFromBackup(playerDataSection, stringId);
Map<Skill, Double> xpLevels = getXpLevelsFromBackup(playerDataSection, stringId);
PlayerData playerData = playerManager.getPlayerData(id);
if (playerData != null) {
applyData(playerData, levels, xpLevels);
} else {
// Load file for offline players
File file = new File(plugin.getDataFolder() + "/playerdata/" + id + ".yml");
FileConfiguration playerConfig = YamlConfiguration.loadConfiguration(file);
playerConfig.set("uuid", id.toString());
// Save skill data
for (Skill skill : Skills.values()) {
String path = "skills." + skill.toString().toLowerCase(Locale.ROOT) + ".";
playerConfig.set(path + "level", levels.get(skill));
playerConfig.set(path + "xp", xpLevels.get(skill));
}
// Save file
playerConfig.save(file);
}
}
sender.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.BACKUP_LOAD_LOADED, locale));
} catch (Exception e) {
sender.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.BACKUP_LOAD_ERROR, locale), "{error}", e.getMessage()));
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class LootHandler method attemptSendMessage.
private void attemptSendMessage(Player player, Loot loot) {
String message = loot.getMessage();
if (message != null && !message.equals("")) {
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
Locale locale = playerData.getLocale();
// Try to get message as message key
CustomMessageKey key = new CustomMessageKey(message);
String finalMessage = Lang.getMessage(key, locale);
// Use input as message if fail
if (finalMessage == null) {
finalMessage = message;
}
// Replace placeholders
if (plugin.isPlaceholderAPIEnabled()) {
finalMessage = PlaceholderAPI.setPlaceholders(player, finalMessage);
}
player.sendMessage(finalMessage);
}
}
Aggregations