mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 14:05:25 +01:00
39 lines
1.3 KiB
Java
39 lines
1.3 KiB
Java
package com.gamingmesh.jobs.stuff;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map.Entry;
|
|
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.enchantments.Enchantment;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
|
|
public class GiveItem {
|
|
public static boolean GiveItemForPlayer(Player player, int id, int meta, int qty, String name, List<String> lore, HashMap<Enchantment, Integer> hashMap) {
|
|
@SuppressWarnings("deprecation")
|
|
ItemStack itemStack = new ItemStack(Material.getMaterial(id), qty, (short) meta);
|
|
ItemMeta ItemMeta = itemStack.getItemMeta();
|
|
|
|
if (lore != null) {
|
|
List<String> TranslatedLore = new ArrayList<String>();
|
|
for (String oneLore : lore) {
|
|
TranslatedLore.add(ChatColor.translateAlternateColorCodes('&', oneLore.replace("[player]", player.getName())));
|
|
}
|
|
ItemMeta.setLore(TranslatedLore);
|
|
}
|
|
for (Entry<Enchantment, Integer> OneEnchant : hashMap.entrySet()) {
|
|
ItemMeta.addEnchant(OneEnchant.getKey(), OneEnchant.getValue(), true);
|
|
}
|
|
if (name != null)
|
|
ItemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
|
|
itemStack.setItemMeta(ItemMeta);
|
|
player.getInventory().addItem(itemStack);
|
|
player.getPlayer().updateInventory();
|
|
return true;
|
|
}
|
|
}
|