Advertisement
WillyBYT

Main Class

Aug 31st, 2017
3,560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. package me.inamine.Heads;
  2.  
  3. import java.lang.reflect.Field;
  4. import java.util.UUID;
  5.  
  6. import org.bukkit.Material;
  7. import org.bukkit.command.Command;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.inventory.ItemStack;
  11. import org.bukkit.inventory.meta.SkullMeta;
  12. import org.bukkit.plugin.java.JavaPlugin;
  13.  
  14. import com.mojang.authlib.GameProfile;
  15. import com.mojang.authlib.properties.Property;
  16.  
  17. public class Main extends JavaPlugin
  18. {
  19.  
  20.     public void onEnable()
  21.     {
  22.    
  23.     }
  24.  
  25.  
  26.     public void onDisable()
  27.     {
  28.        
  29.     }
  30.    
  31.     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
  32.     {
  33.         Player player = (Player) sender;
  34.         player.getInventory().addItem(getHead(args[0]));
  35.        
  36.         return true;
  37.     }
  38.  
  39.     public static ItemStack getHead(String name)
  40.     {
  41.         for (Heads head : Heads.values())
  42.         {
  43.             if (head.getName().equalsIgnoreCase(name))
  44.             {
  45.                 return head.getItemStack();
  46.             }
  47.         }
  48.         return null;
  49.     }
  50.    
  51.     public static ItemStack createSkull(String url, String name)
  52.     {
  53.         ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
  54.         if (url.isEmpty()) return head;
  55.        
  56.         SkullMeta headMeta = (SkullMeta) head.getItemMeta();
  57.         GameProfile profile = new GameProfile(UUID.randomUUID(), null);
  58.        
  59.         profile.getProperties().put("textures", new Property("textures", url));
  60.        
  61.         try
  62.         {
  63.             Field profileField = headMeta.getClass().getDeclaredField("profile");
  64.             profileField.setAccessible(true);
  65.             profileField.set(headMeta, profile);
  66.            
  67.         }
  68.         catch (IllegalArgumentException|NoSuchFieldException|SecurityException | IllegalAccessException error)
  69.         {
  70.             error.printStackTrace();
  71.         }
  72.         head.setItemMeta(headMeta);
  73.         return head;
  74.     }
  75.    
  76.        
  77.    
  78.    
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement