package ghast; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import lombok.experimental.UtilityClass; import net.minecraft.server.v1_12_R1.BlockPosition; import net.minecraft.server.v1_12_R1.TileEntitySkull; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.SkullType; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; import org.bukkit.block.Skull; import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.UUID; @UtilityClass @SuppressWarnings("unused") public class BuildHelper { /** * Установка черепа. *

* После установки, необходимо выполнить skull.update(true); * * @param location место установки. * @param face куда будет повёрнут череп. * @return Блок типа {@link Skull} */ public Skull placeSkull(Location location, BlockFace face) { Location fixedLocation = GhastTools.copyLocation(location); fixedLocation.setZ(fixedLocation.getZ() - 1); Block block = location.getWorld().getBlockAt(location); block.setType(Material.SKULL); Skull skull = (Skull) block.getState(); skull.setRotation(face); org.bukkit.material.Skull skullMaterial = (org.bukkit.material.Skull) skull.getData(); skullMaterial.setFacingDirection(BlockFace.SELF); return skull; } /** * Установка головы игрока. *

* После установки, необходимо выполнить skull.update(true); * * @param location место установки. * @param face куда будет повёрнута голова. * @return Блок типа {@link Skull} */ public static Skull placePlayerHead(Location location, BlockFace face) { Location fixedLocation = GhastTools.copyLocation(location); fixedLocation.setZ(fixedLocation.getZ() - 1); Block block = fixedLocation.getWorld().getBlockAt(fixedLocation); block.setType(Material.SKULL); Skull skull = (Skull) block.getState(); skull.setSkullType(SkullType.PLAYER); skull.setRotation(face); org.bukkit.material.Skull skullMaterial = (org.bukkit.material.Skull) skull.getData(); skullMaterial.setFacingDirection(BlockFace.SELF); return skull; } /** * Установка текстурированной головы игрока. * * @param location место установки. * @param face куда будет повёрнута голова. * @param skinUrl URL на текстуру * @return Блок типа {@link Skull} */ public static Skull placePlayerHead(Location location, BlockFace face, String skinUrl) { Skull playerHead = placePlayerHead(location, face); playerHead.update(true); setPlayerHeadSkin(playerHead, skinUrl); return playerHead; } /** * Установка текстуры для головы игрока. * * @param skull блок головы игрока * @param skinUrl URL на текстуру */ public static void setPlayerHeadSkin(Skull skull, String skinUrl) { ((TileEntitySkull) (((CraftWorld) skull.getWorld()) .getHandle() .getTileEntity(new BlockPosition(skull.getX(), skull.getY(), skull.getZ())))) .setGameProfile(generateTexturedPlayerProfile(skinUrl)); } public Sign placeSignWall(Location location, BlockFace face) { Block block = location.getWorld().getBlockAt(location); block.setType(Material.WALL_SIGN); Sign sign = (Sign) block.getState(); org.bukkit.material.Sign signMaterial = (org.bukkit.material.Sign) sign.getData(); signMaterial.setFacingDirection(face); return sign; } private GameProfile generateTexturedPlayerProfile(String skinUrl) { GameProfile gameProfile = new GameProfile(UUID.randomUUID(), null); gameProfile.getProperties().put("textures", new Property("textures", Base64.getEncoder().encodeToString( ("{textures:{SKIN:{url:\"" + skinUrl + "\"}}}").getBytes(StandardCharsets.UTF_8)))); return gameProfile; } }