Advertisement
gmoehra

(Base64) - Conversão - FreshCoal Heads

Sep 29th, 2019
1,827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. // ////// //
  2. // CLASSE //
  3. // ////// //
  4.  
  5. import com.mojang.authlib.GameProfile;
  6. import com.mojang.authlib.properties.Property;
  7. import org.bukkit.Material;
  8. import org.bukkit.inventory.ItemFlag;
  9. import org.bukkit.inventory.ItemStack;
  10. import org.bukkit.inventory.meta.*;
  11. import org.bukkit.util.io.BukkitObjectInputStream;
  12. import org.bukkit.util.io.BukkitObjectOutputStream;
  13. import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
  14.  
  15. import java.lang.reflect.Field;
  16. import java.util.Base64;
  17. import java.util.List;
  18. import java.util.UUID;
  19.  
  20. public class ConverterUrl {
  21.  
  22. private ItemStack is;
  23.  
  24. public static ItemStack executar(String url) {
  25. ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
  26. if (url.isEmpty())
  27. return item;
  28.  
  29. SkullMeta itemMeta = (SkullMeta) item.getItemMeta();
  30. GameProfile profile = new GameProfile(UUID.randomUUID(), null);
  31. byte[] encodedData = Base64.getEncoder()
  32. .encode(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes());
  33. profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
  34. Field profileField = null;
  35. try {
  36. profileField = itemMeta.getClass().getDeclaredField("profile");
  37. profileField.setAccessible(true);
  38. profileField.set(itemMeta, profile);
  39. } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
  40. e.printStackTrace();
  41. }
  42. item.setItemMeta(itemMeta);
  43. return item;
  44. }
  45.  
  46. }
  47.  
  48.  
  49.  
  50. // ///////// //
  51. // COMO USAR //
  52. // ///////// //
  53.  
  54. ConverterUrl.executar("http://textures.minecraft.net/texture/1ae1612b9a4c56254c275a62f46d3035e91cd4e85ec3718231d4514853b5e1e5");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement