Search in sources :

Example 61 with PlayerData

use of com.archyx.aureliumskills.data.PlayerData 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));
    }
}
Also used : Locale(java.util.Locale) Skill(com.archyx.aureliumskills.skills.Skill) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 62 with PlayerData

use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.

the class SkillsCommand method listModifiers.

private void listModifiers(CommandSender sender, @Optional @Flags("other") Player player, @Optional Stat stat, Locale locale) {
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData != null) {
        StringBuilder message;
        if (stat == null) {
            message = new StringBuilder(StatModifier.applyPlaceholders(Lang.getMessage(CommandMessage.MODIFIER_LIST_ALL_STATS_HEADER, locale), player));
            for (String key : playerData.getStatModifiers().keySet()) {
                StatModifier modifier = playerData.getStatModifiers().get(key);
                message.append("\n").append(StatModifier.applyPlaceholders(Lang.getMessage(CommandMessage.MODIFIER_LIST_ALL_STATS_ENTRY, locale), modifier, player, locale));
            }
        } else {
            message = new StringBuilder(StatModifier.applyPlaceholders(Lang.getMessage(CommandMessage.MODIFIER_LIST_ONE_STAT_HEADER, locale), stat, player, locale));
            for (String key : playerData.getStatModifiers().keySet()) {
                StatModifier modifier = playerData.getStatModifiers().get(key);
                if (modifier.getStat() == stat) {
                    message.append("\n").append(StatModifier.applyPlaceholders(Lang.getMessage(CommandMessage.MODIFIER_LIST_ONE_STAT_ENTRY, locale), modifier, player, locale));
                }
            }
        }
        sender.sendMessage(message.toString());
    } else {
        sender.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.NO_PROFILE, locale));
    }
}
Also used : PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 63 with PlayerData

use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.

the class SkillsCommand method onRemoveAll.

@Subcommand("modifier removeall")
@CommandCompletion("@players @stats")
@CommandPermission("aureliumskills.modifier.removeall")
@Description("Removes all stat modifiers from a player.")
public void onRemoveAll(CommandSender sender, @Flags("other") @Optional Player player, @Optional Stat stat, @Default("false") boolean silent) {
    Locale locale = plugin.getLang().getLocale(sender);
    if (player == null) {
        if (sender instanceof Player) {
            Player target = (Player) sender;
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(target);
            removeAllModifiers(sender, stat, silent, locale, target, playerData);
        } else {
            if (!silent) {
                sender.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.MODIFIER_REMOVEALL_PLAYERS_ONLY, locale));
            }
        }
    } else {
        PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
        removeAllModifiers(sender, stat, silent, locale, player, playerData);
    }
}
Also used : Locale(java.util.Locale) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 64 with PlayerData

use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.

the class SkillsCommand method onLanguage.

@Subcommand("lang")
@CommandCompletion("@lang")
@CommandPermission("aureliumskills.lang")
@Description("Changes your player language")
public void onLanguage(Player player, String language) {
    Locale locale = new Locale(language.toLowerCase(Locale.ENGLISH));
    if (Lang.hasLocale(locale)) {
        PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
        if (playerData == null)
            return;
        playerData.setLocale(locale);
        plugin.getCommandManager().setPlayerLocale(player, locale);
        player.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.LANG_SET, locale).replace("{lang}", Lang.getDefinedLanguages().get(locale)));
    } else {
        player.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.LANG_NOT_FOUND, plugin.getLang().getLocale(player)));
    }
}
Also used : Locale(java.util.Locale) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 65 with PlayerData

use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.

the class SkillsCommand method onBackupLoad.

@Subcommand("backup load")
@CommandPermission("aureliumskills.backup.load")
public void onBackupLoad(CommandSender sender, String fileName) {
    StorageProvider storageProvider = plugin.getStorageProvider();
    Locale locale = plugin.getLang().getLocale(sender);
    if (storageProvider != null) {
        File file = new File(plugin.getDataFolder() + "/backups/" + fileName);
        if (file.exists()) {
            if (file.getName().endsWith(".yml")) {
                // Require player to double type command
                if (sender instanceof Player) {
                    PlayerData playerData = plugin.getPlayerManager().getPlayerData((Player) sender);
                    if (playerData == null)
                        return;
                    Object typed = playerData.getMetadata().get("backup_command");
                    if (typed != null) {
                        if (typed instanceof String) {
                            String typedFile = (String) typed;
                            if (typedFile.equals(file.getName())) {
                                sender.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.BACKUP_LOAD_LOADING, locale));
                                storageProvider.loadBackup(YamlConfiguration.loadConfiguration(file), sender);
                                playerData.getMetadata().remove("backup_command");
                            } else {
                                backupLoadConfirm(playerData, sender, file);
                            }
                        } else {
                            backupLoadConfirm(playerData, sender, file);
                        }
                    } else {
                        backupLoadConfirm(playerData, sender, file);
                    }
                } else {
                    sender.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.BACKUP_LOAD_LOADING, locale));
                    storageProvider.loadBackup(YamlConfiguration.loadConfiguration(file), sender);
                }
            } else {
                sender.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.BACKUP_LOAD_MUST_BE_YAML, locale));
            }
        } else {
            // If file does not exist
            sender.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.BACKUP_LOAD_FILE_NOT_FOUND, locale));
        }
    }
}
Also used : Locale(java.util.Locale) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) StorageProvider(com.archyx.aureliumskills.data.storage.StorageProvider) NBTFile(de.tr7zw.changeme.nbtapi.NBTFile) File(java.io.File) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Aggregations

PlayerData (com.archyx.aureliumskills.data.PlayerData)111 Player (org.bukkit.entity.Player)54 EventHandler (org.bukkit.event.EventHandler)43 Locale (java.util.Locale)27 ItemStack (org.bukkit.inventory.ItemStack)25 Skill (com.archyx.aureliumskills.skills.Skill)15 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)10 Stat (com.archyx.aureliumskills.stats.Stat)9 AttributeInstance (org.bukkit.attribute.AttributeInstance)8 PlayerLootDropEvent (com.archyx.aureliumskills.api.event.PlayerLootDropEvent)7 StatModifier (com.archyx.aureliumskills.modifier.StatModifier)7 Material (org.bukkit.Material)7 LivingEntity (org.bukkit.entity.LivingEntity)7 KeyIntPair (com.archyx.aureliumskills.util.misc.KeyIntPair)6 AureliumSkills (com.archyx.aureliumskills.AureliumSkills)5 OptionL (com.archyx.aureliumskills.configuration.OptionL)5 AbilityData (com.archyx.aureliumskills.data.AbilityData)5 File (java.io.File)5 IOException (java.io.IOException)5 PlayerDataLoadEvent (com.archyx.aureliumskills.data.PlayerDataLoadEvent)4