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));
}
}
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);
}
}
Aggregations