Search in sources :

Example 6 with KeyIntPair

use of com.archyx.aureliumskills.util.misc.KeyIntPair in project AureliumSkills by Archy-X.

the class SkillsCommand method onItemGive.

@Subcommand("item give")
@CommandPermission("aureliumskills.item.give")
@CommandCompletion("@players @item_keys")
public void onItemGive(CommandSender sender, @Flags("other") Player player, String key, @Default("-1") int amount) {
    ItemStack item = plugin.getItemRegistry().getItem(key);
    Locale locale = plugin.getLang().getLocale(sender);
    if (item != null) {
        if (amount != -1) {
            item.setAmount(amount);
        }
        ItemStack leftoverItem = ItemUtils.addItemToInventory(player, item);
        sender.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.ITEM_GIVE_SENDER, locale), "{amount}", String.valueOf(item.getAmount()), "{key}", key, "{player}", player.getName()));
        if (!sender.equals(player)) {
            player.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.ITEM_GIVE_RECEIVER, locale), "{amount}", String.valueOf(item.getAmount()), "{key}", key));
        }
        // Add to unclaimed items if leftover
        if (leftoverItem != null) {
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
            if (playerData != null) {
                playerData.getUnclaimedItems().add(new KeyIntPair(key, leftoverItem.getAmount()));
                player.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(LevelerMessage.UNCLAIMED_ITEM, locale));
            }
        }
    } else {
        sender.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.ITEM_UNREGISTER_NOT_REGISTERED, locale), "{key}", key));
    }
}
Also used : Locale(java.util.Locale) ItemStack(org.bukkit.inventory.ItemStack) KeyIntPair(com.archyx.aureliumskills.util.misc.KeyIntPair) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 7 with KeyIntPair

use of com.archyx.aureliumskills.util.misc.KeyIntPair in project AureliumSkills by Archy-X.

the class ItemReward method giveReward.

@Override
public void giveReward(Player player, Skill skill, int level) {
    ItemStack item = plugin.getItemRegistry().getItem(itemKey);
    // Send warning if item not found
    if (item == null) {
        plugin.getLogger().warning("Could not find a registered item with key " + itemKey + " when granting " + "item reward (" + StringUtils.capitalize(skill.toString().toLowerCase(Locale.ROOT)) + " " + level + ")");
        return;
    }
    if (amount != -1) {
        item.setAmount(amount);
    }
    // Attempt item give
    ItemStack leftoverItem = ItemUtils.addItemToInventory(player, item);
    // Handle items that could not fit in the inventory
    if (leftoverItem != null) {
        PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
        if (playerData == null)
            return;
        // Add unclaimed item key and amount to player data
        playerData.getUnclaimedItems().add(new KeyIntPair(itemKey, leftoverItem.getAmount()));
        // Notify player
        plugin.getServer().getScheduler().runTaskLater(plugin, () -> player.sendMessage(AureliumSkills.getPrefix(playerData.getLocale()) + Lang.getMessage(LevelerMessage.UNCLAIMED_ITEM, playerData.getLocale())), 1);
    }
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) KeyIntPair(com.archyx.aureliumskills.util.misc.KeyIntPair) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Aggregations

PlayerData (com.archyx.aureliumskills.data.PlayerData)7 KeyIntPair (com.archyx.aureliumskills.util.misc.KeyIntPair)7 AbilityData (com.archyx.aureliumskills.data.AbilityData)4 StatModifier (com.archyx.aureliumskills.modifier.StatModifier)4 Skill (com.archyx.aureliumskills.skills.Skill)4 IOException (java.io.IOException)4 ItemStack (org.bukkit.inventory.ItemStack)3 AbstractAbility (com.archyx.aureliumskills.ability.AbstractAbility)2 PlayerDataLoadEvent (com.archyx.aureliumskills.data.PlayerDataLoadEvent)2 Stat (com.archyx.aureliumskills.stats.Stat)2 File (java.io.File)2 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 AureliumSkills (com.archyx.aureliumskills.AureliumSkills)1 Lang (com.archyx.aureliumskills.lang.Lang)1 MenuMessage (com.archyx.aureliumskills.lang.MenuMessage)1 ItemUtils (com.archyx.aureliumskills.util.item.ItemUtils)1 ClickableItem (fr.minuskube.inv.ClickableItem)1 SmartInventory (fr.minuskube.inv.SmartInventory)1 InventoryContents (fr.minuskube.inv.content.InventoryContents)1