Advertisement
Deltric

Heads

May 4th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1.     public static ItemStack getHeadStack(HeadObject object) throws InstantiationException, NumberFormatException
  2.     {
  3.         UUID uuid = UUID.fromString(object.uuid);
  4.  
  5.         GameProfile profile = GameProfile.of(uuid);
  6.         profile
  7.             .getPropertyMap()
  8.             .put("textures", ProfileProperty.of(object.displayName, object.value));
  9.  
  10.         List<Text> lore = new ArrayList<>();
  11.         if(object.displayLore != null)
  12.         {
  13.             for(String line : object.displayLore)
  14.             {
  15.                 lore.add(TextSerializers.FORMATTING_CODE.deserialize(line));
  16.             }
  17.         }
  18.        
  19.         ItemStack stack =
  20.             Sponge.getGame()
  21.                 .getRegistry()
  22.                 .createBuilder(ItemStack.Builder.class)
  23.                 .itemType(ItemTypes.SKULL)
  24.                 .add(Keys.DISPLAY_NAME, Text.of(TextColors.AQUA, object.displayName))
  25.                 .add(Keys.ITEM_LORE, lore)
  26.                 .build();
  27.  
  28.         Optional<SkullData> opSkullData =
  29.             Optional.of(
  30.                 Sponge.getGame()
  31.                     .getDataManager()
  32.                     .getManipulatorBuilder(SkullData.class)
  33.                     .get()
  34.                     .create()
  35.                     .set(Keys.SKULL_TYPE, SkullTypes.PLAYER));
  36.  
  37.         Optional<RepresentedPlayerData> opSkinData =
  38.             Optional.of(
  39.                 Sponge.getGame()
  40.                     .getDataManager()
  41.                     .getManipulatorBuilder(RepresentedPlayerData.class)
  42.                     .get()
  43.                     .create()
  44.                     .set(Keys.REPRESENTED_PLAYER, profile));
  45.  
  46.         SkullData skullData = opSkullData.orElseThrow(InstantiationError::new);
  47.         RepresentedPlayerData skinData = opSkinData.orElseThrow(InstantiationException::new);
  48.  
  49.         stack.offer(skullData);
  50.         stack.offer(skinData);
  51.         return stack;
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement