use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.
the class SkillsCommand method onTop.
@Subcommand("top")
@CommandAlias("skilltop")
@CommandCompletion("@skillTop")
@CommandPermission("aureliumskills.top")
@Description("Shows the top players in a skill")
@Syntax("Usage: /sk top <page> or /sk top [skill] <page>")
public void onTop(CommandSender sender, String[] args) {
Locale locale = plugin.getLang().getLocale(sender);
if (args.length == 0) {
List<SkillValue> lb = plugin.getLeaderboardManager().getPowerLeaderboard(1, 10);
sender.sendMessage(Lang.getMessage(CommandMessage.TOP_POWER_HEADER, locale));
for (SkillValue skillValue : lb) {
String name = Bukkit.getOfflinePlayer(skillValue.getId()).getName();
sender.sendMessage(Lang.getMessage(CommandMessage.TOP_POWER_ENTRY, locale).replace("{rank}", String.valueOf(lb.indexOf(skillValue) + 1)).replace("{player}", name != null ? name : "?").replace("{level}", String.valueOf(skillValue.getLevel())));
}
} else if (args.length == 1) {
if (args[0].equalsIgnoreCase("average")) {
List<SkillValue> lb = plugin.getLeaderboardManager().getAverageLeaderboard(1, 10);
sender.sendMessage(Lang.getMessage(CommandMessage.TOP_AVERAGE_HEADER, locale));
sendLeaderboardEntries(sender, locale, lb);
} else {
try {
int page = Integer.parseInt(args[0]);
List<SkillValue> lb = plugin.getLeaderboardManager().getPowerLeaderboard(page, 10);
sender.sendMessage(Lang.getMessage(CommandMessage.TOP_POWER_HEADER_PAGE, locale).replace("{page}", String.valueOf(page)));
for (SkillValue skillValue : lb) {
String name = Bukkit.getOfflinePlayer(skillValue.getId()).getName();
sender.sendMessage(Lang.getMessage(CommandMessage.TOP_POWER_ENTRY, locale).replace("{rank}", String.valueOf((page - 1) * 10 + lb.indexOf(skillValue) + 1)).replace("{player}", name != null ? name : "?").replace("{level}", String.valueOf(skillValue.getLevel())));
}
} catch (Exception e) {
Skill skill = plugin.getSkillRegistry().getSkill(args[0]);
if (skill != null) {
List<SkillValue> lb = plugin.getLeaderboardManager().getLeaderboard(skill, 1, 10);
sender.sendMessage(Lang.getMessage(CommandMessage.TOP_SKILL_HEADER, locale).replace("{skill}", skill.getDisplayName(locale)));
for (SkillValue skillValue : lb) {
String name = Bukkit.getOfflinePlayer(skillValue.getId()).getName();
sender.sendMessage(Lang.getMessage(CommandMessage.TOP_SKILL_ENTRY, locale).replace("{rank}", String.valueOf(lb.indexOf(skillValue) + 1)).replace("{player}", name != null ? name : "?").replace("{level}", String.valueOf(skillValue.getLevel())));
}
} else {
sender.sendMessage(Lang.getMessage(CommandMessage.TOP_USAGE, locale));
}
}
}
} else if (args.length == 2) {
if (args[0].equalsIgnoreCase("average")) {
try {
int page = Integer.parseInt(args[1]);
List<SkillValue> lb = plugin.getLeaderboardManager().getAverageLeaderboard(page, 10);
sender.sendMessage(TextUtil.replace(Lang.getMessage(CommandMessage.TOP_AVERAGE_HEADER_PAGE, locale), "{page}", String.valueOf(page)));
sendLeaderboardEntries(sender, locale, lb);
} catch (Exception e) {
sender.sendMessage(Lang.getMessage(CommandMessage.TOP_USAGE, locale));
}
} else {
Skill skill = plugin.getSkillRegistry().getSkill(args[0]);
if (skill != null) {
try {
int page = Integer.parseInt(args[1]);
List<SkillValue> lb = plugin.getLeaderboardManager().getLeaderboard(skill, page, 10);
sender.sendMessage(Lang.getMessage(CommandMessage.TOP_SKILL_HEADER_PAGE, locale).replace("{page}", String.valueOf(page)).replace("{skill}", skill.getDisplayName(locale)));
for (SkillValue skillValue : lb) {
String name = Bukkit.getOfflinePlayer(skillValue.getId()).getName();
sender.sendMessage(Lang.getMessage(CommandMessage.TOP_SKILL_ENTRY, locale).replace("{rank}", String.valueOf((page - 1) * 10 + lb.indexOf(skillValue) + 1)).replace("{player}", name != null ? name : "?").replace("{level}", String.valueOf(skillValue.getLevel())));
}
} catch (Exception e) {
sender.sendMessage(Lang.getMessage(CommandMessage.TOP_USAGE, locale));
}
} else {
sender.sendMessage(Lang.getMessage(CommandMessage.TOP_USAGE, locale));
}
}
}
}
use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.
the class SkillsCommand method onRank.
@Subcommand("rank")
@CommandAlias("skillrank")
@CommandPermission("aureliumskills.rank")
@Description("Shows your skill rankings")
public void onRank(Player player) {
Locale locale = plugin.getLang().getLocale(player);
player.sendMessage(Lang.getMessage(CommandMessage.RANK_HEADER, locale));
player.sendMessage(Lang.getMessage(CommandMessage.RANK_POWER, locale).replace("{rank}", String.valueOf(plugin.getLeaderboardManager().getPowerRank(player.getUniqueId()))).replace("{total}", String.valueOf(plugin.getLeaderboardManager().getPowerLeaderboard().size())));
for (Skill skill : plugin.getSkillRegistry().getSkills()) {
if (OptionL.isEnabled(skill)) {
player.sendMessage(Lang.getMessage(CommandMessage.RANK_ENTRY, locale).replace("{skill}", String.valueOf(skill.getDisplayName(locale))).replace("{rank}", String.valueOf(plugin.getLeaderboardManager().getSkillRank(skill, player.getUniqueId()))).replace("{total}", String.valueOf(plugin.getLeaderboardManager().getLeaderboard(skill).size())));
}
}
}
use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.
the class AbilityManager method loadOptions.
public void loadOptions() {
File file = new File(plugin.getDataFolder(), "abilities_config.yml");
if (!file.exists()) {
plugin.saveResource("abilities_config.yml", false);
}
FileConfiguration config = updateFile(file, YamlConfiguration.loadConfiguration(file));
migrateOptions(file, config);
// Loads ability options
int amountLoaded = 0;
int amountDisabled = 0;
long startTime = System.currentTimeMillis();
ConfigurationSection abilities = config.getConfigurationSection("abilities");
if (abilities != null) {
for (Skill skill : plugin.getSkillRegistry().getSkills()) {
String skillName = skill.name().toLowerCase(Locale.ENGLISH);
ConfigurationSection skillAbilities = abilities.getConfigurationSection(skillName);
if (skillAbilities != null) {
for (String abilityName : skillAbilities.getKeys(false)) {
// Check if ability is valid
boolean hasKey = false;
for (Ability ability : Ability.values()) {
if (abilityName.toUpperCase().equals(ability.name())) {
hasKey = true;
break;
}
}
if (hasKey) {
String path = "abilities." + skillName + "." + abilityName + ".";
Ability ability = Ability.valueOf(abilityName.toUpperCase());
boolean enabled = config.getBoolean(path + "enabled", true);
if (!enabled) {
amountDisabled++;
}
double baseValue = config.getDouble(path + "base", ability.getDefaultBaseValue());
double valuePerLevel = config.getDouble(path + "per_level", ability.getDefaultValuePerLevel());
// Get default unlock value
int defUnlock = 2;
for (int i = 0; i < skill.getAbilities().size(); i++) {
if (skill.getAbilities().get(i).get() == ability) {
defUnlock += i;
break;
}
}
int unlock = config.getInt(path + "unlock", defUnlock);
int levelUp = config.getInt(path + "level_up", 5);
int maxLevel = config.getInt(path + "max_level", 0);
// Load options
Set<String> optionKeys = getOptionKeys(ability);
Map<String, OptionValue> options = null;
if (optionKeys != null) {
options = new HashMap<>();
for (String key : optionKeys) {
Object value = config.get(path + key);
if (value != null) {
options.put(key, new OptionValue(value));
}
}
}
AbilityOption option;
// Checks if ability has 2 values
if (ability.hasTwoValues()) {
double baseValue2 = config.getDouble(path + "base_2", ability.getDefaultBaseValue2());
double valuePerLevel2 = config.getDouble(path + "per_level_2", ability.getDefaultValuePerLevel2());
if (options != null) {
option = new AbilityOption(enabled, baseValue, valuePerLevel, baseValue2, valuePerLevel2, unlock, levelUp, maxLevel, options);
} else {
option = new AbilityOption(enabled, baseValue, valuePerLevel, baseValue2, valuePerLevel2, unlock, levelUp, maxLevel);
}
} else {
if (options != null) {
option = new AbilityOption(enabled, baseValue, valuePerLevel, unlock, levelUp, maxLevel, options);
} else {
option = new AbilityOption(enabled, baseValue, valuePerLevel, unlock, levelUp, maxLevel);
}
}
abilityOptions.put(ability, option);
amountLoaded++;
}
}
}
}
}
ConfigurationSection manaAbilities = config.getConfigurationSection("mana_abilities");
if (manaAbilities != null) {
for (String manaAbilityName : manaAbilities.getKeys(false)) {
boolean hasKey = false;
for (MAbility manaAbility : MAbility.values()) {
if (manaAbilityName.toUpperCase().equals(manaAbility.name())) {
hasKey = true;
break;
}
}
if (hasKey) {
MAbility mAbility = MAbility.valueOf(manaAbilityName.toUpperCase());
String path = "mana_abilities." + manaAbilityName + ".";
boolean enabled = config.getBoolean(path + "enabled", true);
if (!enabled) {
amountDisabled++;
}
double baseValue = config.getDouble(path + "base_value", mAbility.getDefaultBaseValue());
double valuePerLevel = config.getDouble(path + "value_per_level", mAbility.getDefaultValuePerLevel());
double cooldown = config.getDouble(path + "cooldown", mAbility.getDefaultBaseCooldown());
double cooldownPerLevel = config.getDouble(path + "cooldown_per_level", mAbility.getDefaultCooldownPerLevel());
double manaCost = config.getDouble(path + "mana_cost", mAbility.getDefaultBaseManaCost());
double manaCostPerLevel = config.getDouble(path + "mana_cost_per_level", mAbility.getDefaultManaCostPerLevel());
int unlock = config.getInt(path + "unlock", 7);
int levelUp = config.getInt(path + "level_up", 7);
int maxLevel = config.getInt(path + "max_level", 0);
// Load options
Set<String> optionKeys = plugin.getManaAbilityManager().getOptionKeys(mAbility);
Map<String, OptionValue> options = null;
if (optionKeys != null) {
options = new HashMap<>();
for (String key : optionKeys) {
Object value = config.get(path + key);
if (value != null) {
options.put(key, new OptionValue(value));
}
}
}
ManaAbilityOption option;
if (options != null) {
option = new ManaAbilityOption(enabled, baseValue, valuePerLevel, cooldown, cooldownPerLevel, manaCost, manaCostPerLevel, unlock, levelUp, maxLevel, options);
} else {
option = new ManaAbilityOption(enabled, baseValue, valuePerLevel, cooldown, cooldownPerLevel, manaCost, manaCostPerLevel, unlock, levelUp, maxLevel);
}
manaAbilityOptions.put(mAbility, option);
amountLoaded++;
}
}
}
long endTime = System.currentTimeMillis();
long timeElapsed = endTime - startTime;
if (amountDisabled > 0) {
plugin.getLogger().info("Disabled " + amountDisabled + " Abilities");
}
plugin.getLogger().info("Loaded " + amountLoaded + " Ability Options in " + timeElapsed + "ms");
}
use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.
the class XpRequirements method loadXpRequirements.
public void loadXpRequirements() {
File file = new File(plugin.getDataFolder(), "xp_requirements.yml");
double oldMultiplier = 0.0;
if (!file.exists()) {
plugin.saveResource("xp_requirements.yml", false);
// Get old multiplier if xp requirements is new
oldMultiplier = plugin.getConfig().getDouble("skill-level-requirements-multiplier", 0.0);
}
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
loadDefaultSection(file, config, oldMultiplier);
// Load optional section for each skill
for (Skill skill : plugin.getSkillRegistry().getSkills()) {
// Remove to account for deleted section
skillXpRequirements.remove(skill);
loadSkillSection(file, config, skill);
}
}
use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.
the class MySqlStorageProvider 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 {
StringBuilder sqlBuilder = new StringBuilder("INSERT INTO SkillData (ID, ");
for (Skill skill : Skills.getOrderedValues()) {
sqlBuilder.append(skill.toString()).append("_LEVEL, ");
sqlBuilder.append(skill).append("_XP, ");
}
sqlBuilder.delete(sqlBuilder.length() - 2, sqlBuilder.length());
sqlBuilder.append(") VALUES(?, ");
for (int i = 0; i < Skills.getOrderedValues().size(); i++) {
sqlBuilder.append("?, ?, ");
}
sqlBuilder.delete(sqlBuilder.length() - 2, sqlBuilder.length());
sqlBuilder.append(") ");
sqlBuilder.append("ON DUPLICATE KEY UPDATE ");
for (Skill skill : Skills.getOrderedValues()) {
sqlBuilder.append(skill.toString()).append("_LEVEL=?, ");
sqlBuilder.append(skill).append("_XP=?, ");
}
sqlBuilder.delete(sqlBuilder.length() - 2, sqlBuilder.length());
// Add values to prepared statement
try (PreparedStatement statement = connection.prepareStatement(sqlBuilder.toString())) {
statement.setString(1, id.toString());
int index = 2;
for (int i = 0; i < 2; i++) {
for (Skill skill : Skills.getOrderedValues()) {
statement.setInt(index++, levels.get(skill));
statement.setDouble(index++, xpLevels.get(skill));
}
}
statement.executeUpdate();
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()));
}
}
}
Aggregations