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));
}
}
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);
}
}
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);
}
}
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");
}
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);
}
Aggregations