Search in sources :

Example 46 with Skill

use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.

the class ForgingLeveler method onForge.

@EventHandler(priority = EventPriority.MONITOR)
public void onForge(InventoryClickEvent event) {
    if (OptionL.isEnabled(Skills.FORGING)) {
        // Check cancelled
        if (OptionL.getBoolean(Option.FORGING_CHECK_CANCELLED)) {
            if (event.isCancelled()) {
                return;
            }
        }
        Inventory inventory = event.getClickedInventory();
        if (inventory != null) {
            if (!(event.getWhoClicked() instanceof Player))
                return;
            Player player = (Player) event.getWhoClicked();
            ClickType click = event.getClick();
            // Only allow right and left clicks if inventory full
            if (click != ClickType.LEFT && click != ClickType.RIGHT && ItemUtils.isInventoryFull(player))
                return;
            // Make sure the click was successful
            if (event.getResult() != Event.Result.ALLOW)
                return;
            // Make sure cursor is empty
            if (player.getItemOnCursor().getType() != Material.AIR)
                return;
            InventoryAction action = event.getAction();
            // Only give if item was picked up
            if (action != InventoryAction.PICKUP_ALL && action != InventoryAction.MOVE_TO_OTHER_INVENTORY && action != InventoryAction.PICKUP_HALF && action != InventoryAction.DROP_ALL_SLOT && action != InventoryAction.DROP_ONE_SLOT && action != InventoryAction.HOTBAR_SWAP) {
                return;
            }
            if (inventory.getType().equals(InventoryType.ANVIL)) {
                if (event.getSlot() == 2) {
                    ItemStack addedItem = inventory.getItem(1);
                    ItemStack baseItem = inventory.getItem(0);
                    if (inventory.getLocation() != null) {
                        if (blockXpGainLocation(inventory.getLocation(), player))
                            return;
                    } else {
                        if (blockXpGainLocation(event.getWhoClicked().getLocation(), player))
                            return;
                    }
                    if (blockXpGainPlayer(player))
                        return;
                    Skill s = Skills.FORGING;
                    AnvilInventory anvil = (AnvilInventory) inventory;
                    if (addedItem != null && baseItem != null) {
                        if (addedItem.getType().equals(Material.ENCHANTED_BOOK)) {
                            if (ItemUtils.isArmor(baseItem.getType())) {
                                plugin.getLeveler().addXp(player, s, anvil.getRepairCost() * getXp(player, ForgingSource.COMBINE_ARMOR_PER_LEVEL));
                            } else if (ItemUtils.isWeapon(baseItem.getType())) {
                                plugin.getLeveler().addXp(player, s, anvil.getRepairCost() * getXp(player, ForgingSource.COMBINE_WEAPON_PER_LEVEL));
                            } else if (baseItem.getType().equals(Material.ENCHANTED_BOOK)) {
                                plugin.getLeveler().addXp(player, s, anvil.getRepairCost() * getXp(player, ForgingSource.COMBINE_BOOKS_PER_LEVEL));
                            } else {
                                plugin.getLeveler().addXp(player, s, anvil.getRepairCost() * getXp(player, ForgingSource.COMBINE_TOOL_PER_LEVEL));
                            }
                        }
                    }
                }
            } else if (inventory.getType().toString().equals("GRINDSTONE")) {
                if (event.getSlotType() != InventoryType.SlotType.RESULT)
                    return;
                if (inventory.getLocation() != null) {
                    if (blockXpGainLocation(inventory.getLocation(), player))
                        return;
                } else {
                    if (blockXpGainLocation(event.getWhoClicked().getLocation(), player))
                        return;
                }
                if (blockXpGainPlayer(player))
                    return;
                // Calculate total level
                int totalLevel = 0;
                // Get item in top slot
                ItemStack topItem = inventory.getItem(0);
                totalLevel += getTotalLevel(topItem);
                // Get item in bottom slot
                ItemStack bottomItem = inventory.getItem(1);
                totalLevel += getTotalLevel(bottomItem);
                plugin.getLeveler().addXp(player, Skills.FORGING, totalLevel * getXp(player, ForgingSource.GRINDSTONE_PER_LEVEL));
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Skill(com.archyx.aureliumskills.skills.Skill) ClickType(org.bukkit.event.inventory.ClickType) AnvilInventory(org.bukkit.inventory.AnvilInventory) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) AnvilInventory(org.bukkit.inventory.AnvilInventory) InventoryAction(org.bukkit.event.inventory.InventoryAction) EventHandler(org.bukkit.event.EventHandler)

Example 47 with Skill

use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.

the class SkillBossBar method loadOptions.

public void loadOptions() {
    mode = OptionL.getString(Option.BOSS_BAR_MODE);
    stayTime = OptionL.getInt(Option.BOSS_BAR_STAY_TIME);
    colors = new HashMap<>();
    styles = new HashMap<>();
    for (String entry : OptionL.getList(Option.BOSS_BAR_FORMAT)) {
        String[] splitEntry = entry.split(" ");
        Skill skill;
        BarColor color = BarColor.GREEN;
        BarStyle style = BarStyle.SOLID;
        skill = plugin.getSkillRegistry().getSkill(splitEntry[0].toUpperCase());
        if (skill == null) {
            plugin.getLogger().warning("Error loading boss bar format in config.yml: " + splitEntry[0] + " is not a valid Skill");
            skill = Skills.FARMING;
        }
        if (splitEntry.length > 1) {
            try {
                color = BarColor.valueOf(splitEntry[1].toUpperCase());
            } catch (IllegalArgumentException e) {
                plugin.getLogger().warning("Error loading boss bar format in config.yml: " + splitEntry[0] + " is not a valid BarColor");
            }
            if (splitEntry.length > 2) {
                try {
                    style = BarStyle.valueOf(splitEntry[2].toUpperCase());
                } catch (IllegalArgumentException e) {
                    plugin.getLogger().warning("Error loading boss bar format in config.yml: " + splitEntry[0] + " is not a valid BarStyle");
                }
            }
        }
        colors.put(skill, color);
        styles.put(skill, style);
    }
    for (Map.Entry<Player, BossBar> entry : singleBossBars.entrySet()) {
        entry.getValue().setVisible(false);
        entry.getValue().removeAll();
    }
    for (Map.Entry<Player, Map<Skill, BossBar>> entry : bossBars.entrySet()) {
        Map<Skill, BossBar> bossBars = entry.getValue();
        for (Map.Entry<Skill, BossBar> bossBarEntry : bossBars.entrySet()) {
            bossBarEntry.getValue().setVisible(false);
            bossBarEntry.getValue().removeAll();
        }
    }
    bossBars.clear();
    singleBossBars.clear();
}
Also used : Player(org.bukkit.entity.Player) BarStyle(org.bukkit.boss.BarStyle) BarColor(org.bukkit.boss.BarColor) BossBar(org.bukkit.boss.BossBar) Skill(com.archyx.aureliumskills.skills.Skill) HashMap(java.util.HashMap) Map(java.util.Map)

Example 48 with Skill

use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.

the class SkillBossBar method scheduleHide.

private void scheduleHide(Player player, Skill skill, BossBar bossBar) {
    if (mode.equals("single")) {
        final int currentAction = singleCurrentActions.get(player);
        new BukkitRunnable() {

            @Override
            public void run() {
                if (mode.equals("single")) {
                    if (currentAction == singleCurrentActions.get(player)) {
                        bossBar.setVisible(false);
                        singleCheckCurrentActions.remove(player);
                    }
                }
            }
        }.runTaskLater(plugin, stayTime);
    } else {
        Map<Skill, Integer> multiCurrentActions = currentActions.get(player);
        if (multiCurrentActions != null) {
            final int currentAction = multiCurrentActions.get(skill);
            new BukkitRunnable() {

                @Override
                public void run() {
                    if (!mode.equals("single")) {
                        Map<Skill, Integer> multiCurrentActions = currentActions.get(player);
                        if (multiCurrentActions != null) {
                            if (currentAction == multiCurrentActions.get(skill)) {
                                bossBar.setVisible(false);
                                checkCurrentActions.remove(player);
                            }
                        }
                    }
                }
            }.runTaskLater(plugin, stayTime);
        }
    }
}
Also used : Skill(com.archyx.aureliumskills.skills.Skill) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) HashMap(java.util.HashMap) Map(java.util.Map)

Example 49 with Skill

use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.

the class LevelProgressionMenu method init.

@Override
public void init(Player player, InventoryContents contents) {
    int currentLevel = playerData.getSkillLevel(skill);
    // Fill item
    if (options.isFillEnabled()) {
        contents.fill(ClickableItem.empty(options.getFillItem()));
    }
    SkillItem skillItem = (SkillItem) options.getItem(ItemType.SKILL);
    contents.set(skillItem.getPos(), ClickableItem.empty(skillItem.getItem(skill, playerData, player, locale)));
    BackItem backItem = (BackItem) options.getItem(ItemType.BACK);
    contents.set(backItem.getPos(), ClickableItem.of(backItem.getItem(player, locale), e -> SkillsMenu.getInventory(player, plugin).open(player)));
    CloseItem closeItem = (CloseItem) options.getItem(ItemType.CLOSE);
    contents.set(closeItem.getPos(), ClickableItem.of(closeItem.getItem(player, locale), e -> player.closeInventory()));
    RankItem rankItem = (RankItem) options.getItem(ItemType.RANK);
    contents.set(rankItem.getPos(), ClickableItem.empty(rankItem.getItem(skill, player, locale)));
    Pagination pagination = contents.pagination();
    ClickableItem[] items = new ClickableItem[36 * pages];
    if (options.isFillEnabled() && options.getFillItem() != null) {
        for (int i = 0; i < items.length; i++) {
            items[i] = ClickableItem.empty(options.getFillItem());
        }
    }
    UnlockedTemplate unlocked = (UnlockedTemplate) options.getTemplate(TemplateType.UNLOCKED);
    InProgressTemplate inProgress = (InProgressTemplate) options.getTemplate(TemplateType.IN_PROGRESS);
    LockedTemplate locked = (LockedTemplate) options.getTemplate(TemplateType.LOCKED);
    for (int i = pagination.getPage() * 24; i < pagination.getPage() * 24 + 24; i++) {
        if (i + 2 <= OptionL.getMaxLevel(skill)) {
            if (i + 2 <= currentLevel) {
                items[track.get(i)] = ClickableItem.empty(unlocked.getItem(skill, i + 2, player, locale));
            } else if (i + 2 == currentLevel + 1) {
                items[track.get(i)] = ClickableItem.empty(inProgress.getItem(skill, playerData, i + 2, player, locale));
            } else {
                items[track.get(i)] = ClickableItem.empty(locked.getItem(skill, i + 2, player, locale));
            }
        } else {
            if (options.isFillEnabled() && options.getFillItem() != null) {
                items[track.get(i)] = ClickableItem.empty(options.getFillItem());
            } else {
                items[track.get(i)] = ClickableItem.empty(new ItemStack(Material.AIR));
            }
        }
    }
    pagination.setItems(items);
    pagination.setItemsPerPage(36);
    int a = 0;
    for (int i = 9; i < 45; i++) {
        int row = i / 9;
        int column = i % 9;
        contents.set(row, column, pagination.getPageItems()[a]);
        a++;
    }
    NextPageItem nextPageItem = (NextPageItem) options.getItem(ItemType.NEXT_PAGE);
    if (pagination.getPage() + 1 < pages) {
        contents.set(nextPageItem.getPos(), ClickableItem.of(nextPageItem.getItem(player, locale), e -> {
            int page = pagination.next().getPage();
            SmartInventory inventory = getInventory(player, skill, page, plugin);
            if (inventory != null) {
                inventory.open(player, page);
            }
        }));
    }
    PreviousPageItem previousPageItem = (PreviousPageItem) options.getItem(ItemType.PREVIOUS_PAGE);
    if (pagination.getPage() - 1 >= 0) {
        contents.set(previousPageItem.getPos(), ClickableItem.of(previousPageItem.getItem(player, locale), e -> {
            int previous = pagination.previous().getPage();
            SmartInventory inventory = getInventory(player, skill, previous, plugin);
            if (inventory != null) {
                inventory.open(player, previous);
            }
        }));
    }
}
Also used : TemplateType(com.archyx.aureliumskills.menu.templates.TemplateType) MenuMessage(com.archyx.aureliumskills.lang.MenuMessage) SmartInventory(fr.minuskube.inv.SmartInventory) InProgressTemplate(com.archyx.aureliumskills.menu.templates.InProgressTemplate) OptionL(com.archyx.aureliumskills.configuration.OptionL) com.archyx.aureliumskills.menu.items(com.archyx.aureliumskills.menu.items) UnlockedTemplate(com.archyx.aureliumskills.menu.templates.UnlockedTemplate) Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) LockedTemplate(com.archyx.aureliumskills.menu.templates.LockedTemplate) AureliumSkills(com.archyx.aureliumskills.AureliumSkills) Lang(com.archyx.aureliumskills.lang.Lang) InventoryProvider(fr.minuskube.inv.content.InventoryProvider) InventoryContents(fr.minuskube.inv.content.InventoryContents) Locale(java.util.Locale) PlayerData(com.archyx.aureliumskills.data.PlayerData) Skill(com.archyx.aureliumskills.skills.Skill) Pagination(fr.minuskube.inv.content.Pagination) Material(org.bukkit.Material) ClickableItem(fr.minuskube.inv.ClickableItem) InProgressTemplate(com.archyx.aureliumskills.menu.templates.InProgressTemplate) ClickableItem(fr.minuskube.inv.ClickableItem) Pagination(fr.minuskube.inv.content.Pagination) SmartInventory(fr.minuskube.inv.SmartInventory) UnlockedTemplate(com.archyx.aureliumskills.menu.templates.UnlockedTemplate) ItemStack(org.bukkit.inventory.ItemStack) LockedTemplate(com.archyx.aureliumskills.menu.templates.LockedTemplate)

Example 50 with Skill

use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.

the class LootTableManager method loadLootTables.

public void loadLootTables() {
    // Check that new loot files do not exist yet for conversion
    boolean convertFishing = !new File(plugin.getDataFolder() + "/loot", "fishing.yml").exists();
    boolean convertExcavation = !new File(plugin.getDataFolder() + "/loot", "excavation.yml").exists();
    // Generate default loot files
    File lootDirectory = new File(plugin.getDataFolder() + "/loot");
    if (!lootDirectory.exists() || convertFishing || convertExcavation) {
        generateDefaultLootTables();
    }
    if (!lootDirectory.isDirectory())
        return;
    // Convert legacy file
    try {
        new LegacyLootConverter(plugin).convertLegacyFile(convertFishing, convertExcavation);
    } catch (IOException e) {
        plugin.getLogger().warning("Failed to convert legacy loot file, see below for error");
        e.printStackTrace();
    }
    lootTables.clear();
    File[] files = lootDirectory.listFiles();
    if (files == null)
        return;
    for (File lootTableFile : files) {
        if (!lootTableFile.isFile() || !lootTableFile.getName().endsWith(".yml")) {
            continue;
        }
        // Parse skill from file name
        String skillName = lootTableFile.getName().replace(".yml", "");
        Skill skill = plugin.getSkillRegistry().getSkill(skillName);
        if (skill == null)
            return;
        FileConfiguration config = YamlConfiguration.loadConfiguration(lootTableFile);
        // Try to update file
        matchConfig(config, lootTableFile);
        // Load corresponding loot table type
        LootTable lootTable = loadLootTable(lootTableFile, config);
        if (lootTable != null) {
            lootTables.put(skill, lootTable);
        }
    }
    // Send info message
    int tablesLoaded = 0;
    int poolsLoaded = 0;
    int lootLoaded = 0;
    for (LootTable table : lootTables.values()) {
        for (LootPool pool : table.getPools()) {
            poolsLoaded++;
            lootLoaded += pool.getLoot().size();
        }
        tablesLoaded++;
    }
    plugin.getLogger().info("Loaded " + lootLoaded + " loot entries in " + poolsLoaded + " pools and " + tablesLoaded + " tables");
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Skill(com.archyx.aureliumskills.skills.Skill) IOException(java.io.IOException) File(java.io.File)

Aggregations

Skill (com.archyx.aureliumskills.skills.Skill)54 PlayerData (com.archyx.aureliumskills.data.PlayerData)15 Locale (java.util.Locale)15 Player (org.bukkit.entity.Player)13 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)12 File (java.io.File)11 IOException (java.io.IOException)9 ItemStack (org.bukkit.inventory.ItemStack)8 EventHandler (org.bukkit.event.EventHandler)7 Stat (com.archyx.aureliumskills.stats.Stat)6 InvalidCommandArgument (co.aikar.commands.InvalidCommandArgument)5 SkillValue (com.archyx.aureliumskills.leaderboard.SkillValue)5 StatModifier (com.archyx.aureliumskills.modifier.StatModifier)5 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)5 AbilityData (com.archyx.aureliumskills.data.AbilityData)4 KeyIntPair (com.archyx.aureliumskills.util.misc.KeyIntPair)4 Map (java.util.Map)4 AureliumSkills (com.archyx.aureliumskills.AureliumSkills)3 OptionL (com.archyx.aureliumskills.configuration.OptionL)3 Lang (com.archyx.aureliumskills.lang.Lang)3