Search in sources :

Example 11 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project Essentials by EssentialsX.

the class Commandskull method run.

@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    String owner;
    if (args.length > 0 && user.isAuthorized("essentials.skull.others")) {
        if (!args[0].matches("^[A-Za-z0-9_]+$")) {
            throw new IllegalArgumentException(tl("alphaNames"));
        }
        owner = args[0];
    } else {
        owner = user.getName();
    }
    ItemStack itemSkull = user.getBase().getItemInHand();
    SkullMeta metaSkull = null;
    boolean spawn = false;
    if (itemSkull != null && itemSkull.getType() == Material.SKULL_ITEM && itemSkull.getDurability() == 3) {
        metaSkull = (SkullMeta) itemSkull.getItemMeta();
    } else if (user.isAuthorized("essentials.skull.spawn")) {
        itemSkull = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
        metaSkull = (SkullMeta) itemSkull.getItemMeta();
        spawn = true;
    } else {
        throw new Exception(tl("invalidSkull"));
    }
    if (metaSkull.hasOwner() && !user.isAuthorized("essentials.skull.modify")) {
        throw new Exception(tl("noPermissionSkull"));
    }
    metaSkull.setDisplayName("§fSkull of " + owner);
    metaSkull.setOwner(owner);
    itemSkull.setItemMeta(metaSkull);
    if (spawn) {
        InventoryWorkaround.addItems(user.getBase().getInventory(), itemSkull);
        user.sendMessage(tl("givenSkull", owner));
    } else {
        user.sendMessage(tl("skullChanged", owner));
    }
}
Also used : SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack)

Example 12 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project VoxelGamesLibv2 by VoxelGamesLib.

the class EditMode method gui.

@Subcommand("gui")
@CommandPermission("%admin")
public void gui(@Nonnull User sender) {
    if (editMode.contains(sender.getUuid())) {
        // TODO implement paginated invs
        InventoryMenuBuilder builder = new InventoryMenuBuilder().withSize(9).withTitle(Lang.legacy(LangKey.INV_MARKER));
        for (int i = 0; i < mapHandler.getMarkerDefinitions().size(); i++) {
            MarkerDefinition markerDefinition = mapHandler.getMarkerDefinitions().get(i);
            ItemStack is = new ItemBuilder(Material.SKULL_ITEM).durability(3).name(markerDefinition.getPrefix()).meta((itemMeta -> {
                char prefix = markerDefinition.getPrefix().toUpperCase().charAt(0);
                Skin skin = textureHandler.getSkin(prefix + "").orElseThrow(() -> new VoxelGameLibException("Unknown skull " + prefix));
                ((SkullMeta) itemMeta).setPlayerProfile(textureHandler.getPlayerProfile(skin));
                ((SkullMeta) itemMeta).setOwner(markerDefinition.getPrefix());
            })).build();
            builder.withItem(i, is, (player, clickType, itemStack) -> sender.getPlayer().performCommand("editmode skull " + itemStack.getItemMeta().getDisplayName()), ClickType.LEFT);
        }
        builder.show(sender.getPlayer());
    } else {
        Lang.msg(sender, LangKey.EDITMODE_NOT_ENABLED);
    }
}
Also used : ItemBuilder(com.voxelgameslib.voxelgameslib.utils.ItemBuilder) InventoryMenuBuilder(org.inventivetalent.menubuilder.inventory.InventoryMenuBuilder) VoxelGameLibException(com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException) Skin(org.mineskin.data.Skin) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) MarkerDefinition(com.voxelgameslib.voxelgameslib.map.MarkerDefinition) Subcommand(co.aikar.commands.annotation.Subcommand) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 13 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project VoxelGamesLibv2 by VoxelGamesLib.

the class EditMode method skull.

@Subcommand("skull")
@CommandPermission("%admin")
@Syntax("<name> - the name of the skull")
public void skull(@Nonnull User sender, @Nonnull String name) {
    if (editMode.contains(sender.getUuid())) {
        ItemStack skull = new ItemBuilder(Material.SKULL_ITEM).durability(3).name(name).meta((itemMeta -> {
            char prefix = name.toUpperCase().charAt(0);
            Skin skin = textureHandler.getSkin(prefix + "").orElseThrow(() -> new VoxelGameLibException("Unknown skull " + prefix));
            ((SkullMeta) itemMeta).setPlayerProfile(textureHandler.getPlayerProfile(skin));
            ((SkullMeta) itemMeta).setOwner(name);
        })).build();
        sender.getPlayer().getInventory().setItemInMainHand(skull);
    } else {
        Lang.msg(sender, LangKey.EDITMODE_NOT_ENABLED);
    }
}
Also used : ItemBuilder(com.voxelgameslib.voxelgameslib.utils.ItemBuilder) VoxelGameLibException(com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException) Skin(org.mineskin.data.Skin) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) Subcommand(co.aikar.commands.annotation.Subcommand) Syntax(co.aikar.commands.annotation.Syntax) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 14 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project Ublisk by Derkades.

the class Item method setSkullOwner.

@SuppressWarnings("deprecation")
public Item setSkullOwner(String playerName) {
    if (item.getItemMeta() instanceof SkullMeta) {
        SkullMeta meta = (SkullMeta) item.getItemMeta();
        meta.setOwner(playerName);
        item.setItemMeta(meta);
        return this;
    }
    throw new UnsupportedOperationException("Item is not a player skull");
}
Also used : SkullMeta(org.bukkit.inventory.meta.SkullMeta)

Example 15 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project Village_Defense by Plajer.

the class SpectatorItemEvents method openSpectatorMenu.

private void openSpectatorMenu(World world, Player p) {
    Inventory inventory = plugin.getServer().createInventory(null, Util.serializeInt(ArenaRegistry.getArena(p).getPlayers().size()), ChatManager.colorMessage("In-Game.Spectator.Spectator-Menu-Name"));
    for (Player player : world.getPlayers()) {
        if (ArenaRegistry.getArena(player) != null && !UserManager.getUser(player.getUniqueId()).isFakeDead()) {
            ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1);
            SkullMeta meta = (SkullMeta) skull.getItemMeta();
            meta.setOwner(player.getName());
            meta.setDisplayName(player.getName());
            meta.setLore(Collections.singletonList(ChatManager.colorMessage("In-Game.Spectator.Target-Player-Health").replaceAll("%health%", String.valueOf(Util.round(player.getHealth(), 2)))));
            skull.setDurability((short) SkullType.PLAYER.ordinal());
            skull.setItemMeta(meta);
            inventory.addItem(skull);
        }
    }
    p.openInventory(inventory);
}
Also used : Player(org.bukkit.entity.Player) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory)

Aggregations

SkullMeta (org.bukkit.inventory.meta.SkullMeta)59 ItemStack (org.bukkit.inventory.ItemStack)43 ItemMeta (org.bukkit.inventory.meta.ItemMeta)22 Enchantment (org.bukkit.enchantments.Enchantment)10 LeatherArmorMeta (org.bukkit.inventory.meta.LeatherArmorMeta)10 ArrayList (java.util.ArrayList)9 PotionMeta (org.bukkit.inventory.meta.PotionMeta)9 UUID (java.util.UUID)8 Player (org.bukkit.entity.Player)8 BookMeta (org.bukkit.inventory.meta.BookMeta)7 EnchantmentStorageMeta (org.bukkit.inventory.meta.EnchantmentStorageMeta)7 Entry (java.util.Map.Entry)6 FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)5 PotionEffect (org.bukkit.potion.PotionEffect)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Pattern (org.bukkit.block.banner.Pattern)4 Inventory (org.bukkit.inventory.Inventory)4 BannerMeta (org.bukkit.inventory.meta.BannerMeta)4 Property (com.mojang.authlib.properties.Property)3