use of com.archyx.aureliumskills.data.PlayerData in project BetonQuest by BetonQuest.
the class AureliumSkillsExperienceEvent method execute.
@Override
protected Void execute(final String playerID) throws QuestRuntimeException {
final Player player = PlayerConverter.getPlayer(playerID);
final PlayerData playerData = aureliumSkills.getPlayerManager().getPlayerData(player);
if (playerData == null) {
return null;
}
final int amount = amountVar.getInt(playerID);
if (isLevel) {
final int currentLevel = playerData.getSkillLevel(skill);
for (int i = 1; i <= amount; i++) {
final double requiredXP = aureliumSkills.getLeveler().getXpRequirements().getXpRequired(skill, currentLevel + i);
AureliumAPI.addXpRaw(player, skill, requiredXP);
}
} else {
AureliumAPI.addXpRaw(player, skill, amount);
}
return null;
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class AureliumSkills method registerCommands.
private void registerCommands() {
commandManager.enableUnstableAPI("help");
commandManager.usePerIssuerLocale(true, false);
commandManager.getCommandContexts().registerContext(Stat.class, c -> {
String input = c.popFirstArg();
Stat stat = statRegistry.getStat(input);
if (stat != null) {
return stat;
} else {
throw new InvalidCommandArgument("Stat " + input + " not found!");
}
});
commandManager.getCommandContexts().registerContext(Skill.class, c -> {
String input = c.popFirstArg();
Skill skill = skillRegistry.getSkill(input);
if (skill != null) {
return skill;
} else {
throw new InvalidCommandArgument("Skill " + input + " not found!");
}
});
commandManager.getCommandCompletions().registerAsyncCompletion("skills", c -> {
List<String> values = new ArrayList<>();
for (Skill skill : skillRegistry.getSkills()) {
if (OptionL.isEnabled(skill)) {
values.add(skill.toString().toLowerCase(Locale.ENGLISH));
}
}
return values;
});
commandManager.getCommandCompletions().registerAsyncCompletion("skills_global", c -> {
List<String> values = new ArrayList<>();
values.add("global");
for (Skill skill : skillRegistry.getSkills()) {
if (OptionL.isEnabled(skill)) {
values.add(skill.toString().toLowerCase(Locale.ENGLISH));
}
}
return values;
});
commandManager.getCommandCompletions().registerAsyncCompletion("skillTop", c -> {
List<String> values = new ArrayList<>();
for (Skill skill : skillRegistry.getSkills()) {
if (OptionL.isEnabled(skill)) {
values.add(skill.toString().toLowerCase(Locale.ENGLISH));
}
}
values.add("average");
return values;
});
commandManager.getCommandCompletions().registerAsyncCompletion("stats", c -> {
List<String> values = new ArrayList<>();
for (Stat stat : statRegistry.getStats()) {
values.add(stat.toString().toLowerCase(Locale.ENGLISH));
}
return values;
});
commandManager.getCommandCompletions().registerAsyncCompletion("lang", c -> Lang.getDefinedLanguagesSet());
commandManager.getCommandCompletions().registerAsyncCompletion("modifiers", c -> {
Player player = c.getPlayer();
PlayerData playerData = getPlayerManager().getPlayerData(player);
if (playerData != null) {
return playerData.getStatModifiers().keySet();
}
return null;
});
commandManager.getCommandCompletions().registerAsyncCompletion("item_keys", c -> itemRegistry.getKeys());
commandManager.registerCommand(new SkillsCommand(this));
commandManager.registerCommand(new StatsCommand(this));
commandManager.registerCommand(new ManaCommand(this));
if (OptionL.getBoolean(Option.ENABLE_SKILL_COMMANDS)) {
if (OptionL.isEnabled(Skills.FARMING)) {
commandManager.registerCommand(new SkillCommands.FarmingCommand(this));
}
if (OptionL.isEnabled(Skills.FORAGING)) {
commandManager.registerCommand(new SkillCommands.ForagingCommand(this));
}
if (OptionL.isEnabled(Skills.MINING)) {
commandManager.registerCommand(new SkillCommands.MiningCommand(this));
}
if (OptionL.isEnabled(Skills.FISHING)) {
commandManager.registerCommand(new SkillCommands.FishingCommand(this));
}
if (OptionL.isEnabled(Skills.EXCAVATION)) {
commandManager.registerCommand(new SkillCommands.ExcavationCommand(this));
}
if (OptionL.isEnabled(Skills.ARCHERY)) {
commandManager.registerCommand(new SkillCommands.ArcheryCommand(this));
}
if (OptionL.isEnabled(Skills.DEFENSE)) {
commandManager.registerCommand(new SkillCommands.DefenseCommand(this));
}
if (OptionL.isEnabled(Skills.FIGHTING)) {
commandManager.registerCommand(new SkillCommands.FightingCommand(this));
}
if (OptionL.isEnabled(Skills.ENDURANCE)) {
commandManager.registerCommand(new SkillCommands.EnduranceCommand(this));
}
if (OptionL.isEnabled(Skills.AGILITY)) {
commandManager.registerCommand(new SkillCommands.AgilityCommand(this));
}
if (OptionL.isEnabled(Skills.ALCHEMY)) {
commandManager.registerCommand(new SkillCommands.AlchemyCommand(this));
}
if (OptionL.isEnabled(Skills.ENCHANTING)) {
commandManager.registerCommand(new SkillCommands.EnchantingCommand(this));
}
if (OptionL.isEnabled(Skills.SORCERY)) {
commandManager.registerCommand(new SkillCommands.SorceryCommand(this));
}
if (OptionL.isEnabled(Skills.HEALING)) {
commandManager.registerCommand(new SkillCommands.HealingCommand(this));
}
if (OptionL.isEnabled(Skills.FORGING)) {
commandManager.registerCommand(new SkillCommands.ForgingCommand(this));
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class AureliumSkills method onDisable.
public void onDisable() {
for (PlayerData playerData : playerManager.getPlayerDataMap().values()) {
storageProvider.save(playerData.getPlayer(), false);
}
playerManager.getPlayerDataMap().clear();
File file = new File(this.getDataFolder(), "config.yml");
if (file.exists()) {
// Reloads config
reloadConfig();
// Save config
saveConfig();
}
regionManager.saveAllRegions(false, true);
regionManager.clearRegionMap();
backupAutomatically();
itemRegistry.saveToFile();
// Remove fleeting
AgilityAbilities agilityAbilities = new AgilityAbilities(this);
for (Player player : Bukkit.getOnlinePlayers()) {
agilityAbilities.removeFleetingQuit(player);
}
}
use of com.archyx.aureliumskills.data.PlayerData 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.data.PlayerData in project AureliumSkills by Archy-X.
the class ManaCommand method onMana.
@Default
@CommandPermission("aureliumskills.mana")
@Description("Display your or another player's current and max mana")
public void onMana(CommandSender sender, @Flags("other") @CommandPermission("aureliumskills.mana.other") @Optional Player player) {
if (sender instanceof Player && player == null) {
Player target = (Player) sender;
PlayerData playerData = plugin.getPlayerManager().getPlayerData(target);
if (playerData == null)
return;
Locale locale = playerData.getLocale();
sender.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.MANA_DISPLAY, locale), "{current}", NumberUtil.format1(playerData.getMana()), "{max}", NumberUtil.format1(playerData.getMaxMana())));
} else if (player != null) {
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
Locale locale = playerData.getLocale();
sender.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.MANA_DISPLAY_OTHER, locale), "{player}", player.getName(), "{current}", NumberUtil.format1(playerData.getMana()), "{max}", NumberUtil.format1(playerData.getMaxMana())));
} else {
sender.sendMessage(AureliumSkills.getPrefix(Lang.getDefaultLanguage()) + Lang.getMessage(CommandMessage.MANA_CONSOLE_SPECIFY_PLAYER, Lang.getDefaultLanguage()));
}
}
Aggregations