use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.
the class StorageProvider method getXpLevelsFromBackup.
protected Map<Skill, Double> getXpLevelsFromBackup(ConfigurationSection playerDataSection, String stringId) {
Map<Skill, Double> xpLevels = new HashMap<>();
for (Skill skill : Skills.values()) {
double xp = playerDataSection.getDouble(stringId + "." + skill.toString().toLowerCase(Locale.ROOT) + ".xp");
xpLevels.put(skill, xp);
}
return xpLevels;
}
use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.
the class YamlStorageProvider method updateLeaderboards.
@Override
public void updateLeaderboards() {
LeaderboardManager manager = plugin.getLeaderboardManager();
manager.setSorting(true);
// Initialize lists
Map<Skill, List<SkillValue>> leaderboards = new HashMap<>();
for (Skill skill : Skills.values()) {
leaderboards.put(skill, new ArrayList<>());
}
List<SkillValue> powerLeaderboard = new ArrayList<>();
List<SkillValue> averageLeaderboard = new ArrayList<>();
// Add players already in memory
Set<UUID> loadedFromMemory = addLoadedPlayersToLeaderboards(leaderboards, powerLeaderboard, averageLeaderboard);
File playerDataFolder = new File(plugin.getDataFolder() + "/playerdata");
// Load data from files
if (playerDataFolder.exists() && playerDataFolder.isDirectory()) {
File[] files = playerDataFolder.listFiles();
if (files != null) {
for (File file : files) {
if (file.getName().endsWith(".yml")) {
UUID id = UUID.fromString(file.getName().substring(0, file.getName().lastIndexOf('.')));
if (!loadedFromMemory.contains(id)) {
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
try {
int powerLevel = 0;
double powerXp = 0;
int numEnabled = 0;
for (Skill skill : Skills.values()) {
// Load from config
String path = "skills." + skill.toString().toLowerCase(Locale.ROOT) + ".";
int level = config.getInt(path + "level", 1);
double xp = config.getDouble(path + "xp");
// 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);
} catch (Exception e) {
Bukkit.getLogger().warning("[AureliumSkills] Error reading playerdata file " + file.getName() + ", see error below for details:");
e.printStackTrace();
}
}
}
}
}
}
sortLeaderboards(leaderboards, powerLeaderboard, averageLeaderboard);
}
use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.
the class YamlStorageProvider method save.
@Override
public void save(Player player, boolean removeFromMemory) {
PlayerData playerData = playerManager.getPlayerData(player);
if (playerData == null)
return;
if (playerData.shouldNotSave())
return;
// Save lock
if (playerData.isSaving())
return;
playerData.setSaving(true);
// Load file
File file = new File(plugin.getDataFolder() + "/playerdata/" + player.getUniqueId() + ".yml");
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
try {
config.set("uuid", player.getUniqueId().toString());
// Save skill data
for (Skill skill : Skills.values()) {
String path = "skills." + skill.toString().toLowerCase(Locale.ROOT) + ".";
config.set(path + "level", playerData.getSkillLevel(skill));
config.set(path + "xp", playerData.getSkillXp(skill));
}
// Clear existing modifiers
config.set("stat_modifiers", null);
// Save stat modifiers
int count = 0;
for (StatModifier modifier : playerData.getStatModifiers().values()) {
String path = "stat_modifiers." + count + ".";
config.set(path + "name", modifier.getName());
config.set(path + "stat", modifier.getStat().toString().toLowerCase(Locale.ROOT));
config.set(path + "value", modifier.getValue());
count++;
}
// Save mana
config.set("mana", playerData.getMana());
// Save locale
Locale locale = playerData.getLocale();
if (locale != null) {
config.set("locale", locale.toString());
}
// Save ability data
for (AbilityData abilityData : playerData.getAbilityDataMap().values()) {
String path = "ability_data." + abilityData.getAbility().toString().toLowerCase(Locale.ROOT) + ".";
for (Map.Entry<String, Object> entry : abilityData.getDataMap().entrySet()) {
config.set(path + entry.getKey(), entry.getValue());
}
}
// Save unclaimed items
List<KeyIntPair> unclaimedItems = playerData.getUnclaimedItems();
config.set("unclaimed_items", null);
if (unclaimedItems != null && unclaimedItems.size() > 0) {
List<String> stringList = new ArrayList<>();
for (KeyIntPair unclaimedItem : unclaimedItems) {
stringList.add(unclaimedItem.getKey() + " " + unclaimedItem.getValue());
}
config.set("unclaimed_items", stringList);
}
config.save(file);
if (removeFromMemory) {
// Remove from memory
playerManager.removePlayerData(player.getUniqueId());
}
} catch (Exception e) {
Bukkit.getLogger().warning("There was an error saving player data for player " + player.getName() + " with UUID " + player.getUniqueId() + ", see below for details.");
e.printStackTrace();
}
// Unlock
playerData.setSaving(false);
}
use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.
the class SkillsCommand method onSkillSetall.
@Subcommand("skill setall")
@CommandCompletion("@players")
@CommandPermission("aureliumskills.skill.setlevel")
@Description("Sets all of a player's skills to a level.")
public void onSkillSetall(CommandSender sender, @Flags("other") Player player, int level) {
Locale locale = plugin.getLang().getLocale(sender);
if (level > 0) {
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
for (Skill skill : plugin.getSkillRegistry().getSkills()) {
if (OptionL.isEnabled(skill)) {
int oldLevel = playerData.getSkillLevel(skill);
playerData.setSkillLevel(skill, level);
playerData.setSkillXp(skill, 0);
// Reload items and armor to check for newly met requirements
plugin.getModifierManager().reloadPlayer(player);
plugin.getLeveler().applyRevertCommands(player, skill, oldLevel, level);
plugin.getLeveler().applyLevelUpCommands(player, skill, oldLevel, level);
}
}
plugin.getLeveler().updateStats(player);
plugin.getLeveler().updatePermissions(player);
sender.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.SKILL_SETALL_SET, locale).replace("{level}", String.valueOf(level)).replace("{player}", player.getName()));
} else {
sender.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.SKILL_SETALL_AT_LEAST_ONE, locale));
}
}
use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.
the class SkillsCommand method onItemRequirementList.
@Subcommand("item requirement list")
@CommandPermission("aureliumskills.item.requirement.list")
@Description("Lists the item requirements on the item held.")
public void onItemRequirementList(@Flags("itemheld") Player player) {
Locale locale = plugin.getLang().getLocale(player);
player.sendMessage(Lang.getMessage(CommandMessage.ITEM_REQUIREMENT_LIST_HEADER, locale));
Requirements requirements = new Requirements(plugin);
for (Map.Entry<Skill, Integer> entry : requirements.getRequirements(ModifierType.ITEM, player.getInventory().getItemInMainHand()).entrySet()) {
player.sendMessage(TextUtil.replace(Lang.getMessage(CommandMessage.ITEM_REQUIREMENT_LIST_ENTRY, locale), "{skill}", entry.getKey().getDisplayName(locale), "{level}", String.valueOf(entry.getValue())));
}
}
Aggregations