Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.inamine.Heads;
- import java.lang.reflect.Field;
- import java.util.UUID;
- import org.bukkit.Material;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.SkullMeta;
- import org.bukkit.plugin.java.JavaPlugin;
- import com.mojang.authlib.GameProfile;
- import com.mojang.authlib.properties.Property;
- public class Main extends JavaPlugin
- {
- public void onEnable()
- {
- }
- public void onDisable()
- {
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
- {
- Player player = (Player) sender;
- player.getInventory().addItem(getHead(args[0]));
- return true;
- }
- public static ItemStack getHead(String name)
- {
- for (Heads head : Heads.values())
- {
- if (head.getName().equalsIgnoreCase(name))
- {
- return head.getItemStack();
- }
- }
- return null;
- }
- public static ItemStack createSkull(String url, String name)
- {
- ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
- if (url.isEmpty()) return head;
- SkullMeta headMeta = (SkullMeta) head.getItemMeta();
- GameProfile profile = new GameProfile(UUID.randomUUID(), null);
- profile.getProperties().put("textures", new Property("textures", url));
- try
- {
- Field profileField = headMeta.getClass().getDeclaredField("profile");
- profileField.setAccessible(true);
- profileField.set(headMeta, profile);
- }
- catch (IllegalArgumentException|NoSuchFieldException|SecurityException | IllegalAccessException error)
- {
- error.printStackTrace();
- }
- head.setItemMeta(headMeta);
- return head;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement