本文整理汇总了Java中org.bukkit.inventory.meta.SkullMeta类的典型用法代码示例。如果您正苦于以下问题:Java SkullMeta类的具体用法?Java SkullMeta怎么用?Java SkullMeta使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SkullMeta类属于org.bukkit.inventory.meta包,在下文中一共展示了SkullMeta类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHeadPlayer
import org.bukkit.inventory.meta.SkullMeta; //导入依赖的package包/类
public static ItemStack createHeadPlayer(String displayname, String username, List<String> lore) {
ItemStack playerHead = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
SkullMeta sm = (SkullMeta)playerHead.getItemMeta();
sm.setOwner(username);
ArrayList<String> colorLore = new ArrayList<>();
if (lore != null) {
lore.forEach(str -> colorLore.add(Utils.colorize(str)));
sm.setLore(colorLore);
}
sm.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_ATTRIBUTES,
ItemFlag.HIDE_DESTROYS, ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_PLACED_ON, ItemFlag.HIDE_UNBREAKABLE);
sm.setDisplayName(Utils.colorize(displayname));
playerHead.setItemMeta(sm);
return playerHead;
}
示例2: getSkull
import org.bukkit.inventory.meta.SkullMeta; //导入依赖的package包/类
public static ItemStack getSkull(String url) {
ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
if (url.isEmpty())
return head;
SkullMeta headMeta = (SkullMeta) head.getItemMeta();
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes());
profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
Field profileField = null;
try {
profileField = headMeta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(headMeta, profile);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
e1.printStackTrace();
}
head.setItemMeta(headMeta);
return head;
}
示例3: setItemStackSkin
import org.bukkit.inventory.meta.SkullMeta; //导入依赖的package包/类
public static void setItemStackSkin(ItemStack itemStack, String skin) {
final ItemMeta meta = itemStack.getItemMeta();
if (!(meta instanceof SkullMeta)) {
return;
}
String newSkin = skin;
if (newSkin.contains("textures.minecraft.net")) {
if (!newSkin.startsWith("http://")) {
newSkin = "http://" + newSkin;
}
try {
final Class<?> cls = createClass("org.bukkit.craftbukkit.VERSION.inventory.CraftMetaSkull");
final Object real = cls.cast(meta);
final Field field = real.getClass().getDeclaredField("profile");
field.setAccessible(true);
field.set(real, getNonPlayerProfile(newSkin));
itemStack.setItemMeta(SkullMeta.class.cast(real));
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException | ClassNotFoundException e) {
Bukkit.getLogger().log(Level.WARNING, "Failed to set url of itemstack.", e);
}
} else {
((SkullMeta) meta).setOwner(skin);
itemStack.setItemMeta(meta);
}
}
示例4: createPlayerHead
import org.bukkit.inventory.meta.SkullMeta; //导入依赖的package包/类
private ItemStack createPlayerHead(Player player)
{
AbstractPlayerData playerData = SamaGamesAPI.get().getPlayerManager().getPlayerData(player.getUniqueId());
ItemStack stack = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
SkullMeta meta = (SkullMeta) stack.getItemMeta();
meta.setOwner(player.getName());
meta.setDisplayName(PlayerUtils.getFullyFormattedPlayerName(player));
List<String> lore = new ArrayList<>();
lore.add(ChatColor.GRAY + "Pièces : " + ChatColor.GOLD + NumberUtils.format(playerData.getCoins()));
lore.add(ChatColor.GRAY + "Perles : " + ChatColor.GREEN + NumberUtils.format(this.hub.getInteractionManager().getGraouManager().getPlayerPearls(player.getUniqueId()).size()));
lore.add(ChatColor.GRAY + "Poussière d'" + ChatColor.AQUA + "\u272F" + ChatColor.GRAY + " : " + ChatColor.AQUA + NumberUtils.format(playerData.getPowders()));
meta.setLore(lore);
stack.setItemMeta(meta);
return stack;
}
示例5: createSkullItemStack
import org.bukkit.inventory.meta.SkullMeta; //导入依赖的package包/类
public static ItemStack createSkullItemStack(String uuid, String textureValue, String textureSignature) {
WrappedGameProfile wrappedProfile = new WrappedGameProfile(UUID.fromString(uuid), null);
wrappedProfile.getProperties().put("textures", new WrappedSignedProperty("textures", textureValue, textureSignature));
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
SkullMeta sm = (SkullMeta) skull.getItemMeta();
Field profileField = null;
try {
profileField = sm.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(sm, wrappedProfile.getHandle());
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
e1.printStackTrace();
}
skull.setItemMeta(sm);
return skull;
}
示例6: getNameComponent
import org.bukkit.inventory.meta.SkullMeta; //导入依赖的package包/类
public static BaseComponent getNameComponent(ItemStack item) {
if (item == null) throw new IllegalArgumentException();
if (item.hasItemMeta() && item.getItemMeta().hasDisplayName())
return new TextComponent(item.getItemMeta().getDisplayName());
Material type = item.getType();
if (type == Material.SKULL_ITEM && item.getDurability() == 3) {
SkullMeta meta = (SkullMeta) item.getItemMeta();
if (meta.hasOwner()) {
return new TranslatableComponent("item.skull.player.name", meta.getOwner());
} else {
return new TranslatableComponent("item.skull.char.name");
}
} else {
return new TranslatableComponent(getUnlocalizedName(item));
}
}
示例7: activateHeadByURL
import org.bukkit.inventory.meta.SkullMeta; //导入依赖的package包/类
public static ItemStack activateHeadByURL(String skinUrl, ItemStack itemStack) {
if (itemStack.getType() == Material.SKULL_ITEM) {
SkullMeta meta = (SkullMeta) itemStack.getItemMeta();
try {
final Class<?> cls = ReflectionLib.getClassFromName("org.bukkit.craftbukkit.VERSION.inventory.CraftMetaSkull");
final Object real = cls.cast(meta);
final Field field = real.getClass().getDeclaredField("profile");
field.setAccessible(true);
field.set(real, getNonPlayerProfile(skinUrl));
meta = SkullMeta.class.cast(real);
itemStack.setItemMeta(meta);
itemStack = new ItemStackBuilder(itemStack).setDisplayName("TMP");
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
Bukkit.getLogger().log(Level.WARNING, "Failed to set url of itemstack.", e);
}
}
return itemStack;
}
示例8: onPlayerDeath
import org.bukkit.inventory.meta.SkullMeta; //导入依赖的package包/类
/**
* Drop player head on kill
*
* @param event Event
*/
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event)
{
ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
SkullMeta skullMeta = (SkullMeta)head.getItemMeta();
skullMeta.setOwner(event.getEntity().getName());
skullMeta.setDisplayName(ChatColor.AQUA + "Tête de " + event.getEntity().getName());
head.setItemMeta(skullMeta);
event.getDrops().add(head);
List<PotionEffect> effectList = new ArrayList<>();
effectList.addAll(event.getEntity().getActivePotionEffects());
this.effects.put(event.getEntity().getName(), effectList);
}
示例9: onPlayerInteract
import org.bukkit.inventory.meta.SkullMeta; //导入依赖的package包/类
/**
* Give old player enchants on head eating
*
* @param event Event
*/
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (event.getItem() == null || event.getItem().getType() != Material.SKULL_ITEM || event.getItem().getDurability() != 3
|| (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK))
return;
SkullMeta skullMeta = (SkullMeta)event.getItem().getItemMeta();
List<PotionEffect> effectList = this.effects.get(skullMeta.getOwner());
if (effectList != null)
{
effectList.forEach(event.getPlayer()::addPotionEffect);
this.effects.remove(skullMeta.getOwner());
event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.BURP, 1F, 1F);
}
}
示例10: gui
import org.bukkit.inventory.meta.SkullMeta; //导入依赖的package包/类
@Subcommand("gui")
@CommandPermission("%admin")
public void gui(@Nonnull User sender) {
if (editMode.contains(sender.getUuid())) {
PagedInventory inventory = inventoryHandler.createInventory(PagedInventory.class, sender, Lang.legacy(LangKey.INV_MARKER), 9);
Map<ItemStack, BiConsumer<ItemStack, User>> content = new HashMap<>();
mapHandler.getMarkerDefinitions().forEach(markerDefinition -> {
ItemStack is = new ItemBuilder(Material.SKULL_ITEM).durability(3).name(markerDefinition.getPrefix())
.meta((itemMeta -> ((SkullMeta) itemMeta).setOwner(markerDefinition.getPrefix()))).build();
content.put(is, (item, user) -> user.getPlayer().performCommand("editmode skull " + is.getItemMeta().getDisplayName()));
});
inventory.autoConstructPages(content.keySet().toArray(new ItemStack[content.size()]));
content.forEach(inventory::addClickAction);
inventory.open();
} else {
Lang.msg(sender, LangKey.EDITMODE_NOT_ENABLED);
}
}
示例11: applyTextureToMeta
import org.bukkit.inventory.meta.SkullMeta; //导入依赖的package包/类
public static SkullMeta applyTextureToMeta(Object meta, Object profile) throws Exception {
if (meta == null) {
throw new IllegalArgumentException("meta cannot be null");
}
if (profile == null) {
throw new IllegalArgumentException("profile cannot be null");
}
Object baseNBTTag = NBTTagCompound.newInstance();
Object ownerNBTTag = NBTTagCompound.newInstance();
GameProfileSerializerMethodResolver.resolve(new ResolverQuery("serialize", NBTTagCompound, GameProfile)).invoke(null, ownerNBTTag, profile);
NBTTagCompoundMethodResolver.resolve(new ResolverQuery("set", String.class, NBTBase)).invoke(baseNBTTag, "SkullOwner", ownerNBTTag);
SkullMeta newMeta = (SkullMeta) CraftMetaSkullConstructorResolver.resolve(new Class[]{NBTTagCompound}).newInstance(baseNBTTag);
Field profileField = CraftMetaSkullFieldResolver.resolve("profile");
profileField.set(meta, profile);
profileField.set(newMeta, profile);
return newMeta;
}
示例12: createHeadPlayer
import org.bukkit.inventory.meta.SkullMeta; //导入依赖的package包/类
public static ItemStack createHeadPlayer(String displayname, String username, List<String> lore) {
ItemStack playerHead = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
SkullMeta sm = (SkullMeta) playerHead.getItemMeta();
sm.setOwner(username);
ArrayList<String> colorLore = new ArrayList<>();
if (lore != null) {
lore.forEach(str -> colorLore.add(Utils.colorize(str)));
sm.setLore(colorLore);
}
sm.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_ATTRIBUTES,
ItemFlag.HIDE_DESTROYS, ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_PLACED_ON, ItemFlag.HIDE_UNBREAKABLE);
sm.setDisplayName(Utils.colorize(displayname));
playerHead.setItemMeta(sm);
return playerHead;
}
示例13: getSkullFromURL
import org.bukkit.inventory.meta.SkullMeta; //导入依赖的package包/类
public static ItemStack getSkullFromURL(String url, String name)
throws Exception {
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
SkullMeta sm = (SkullMeta) skull.getItemMeta();
sm.setOwner("NacOJerk");
skull.setItemMeta(sm);
url = Base64Coder.encodeString("{textures:{SKIN:{url:\"" + url
+ "\"}}}");
GameProfile gp = new GameProfile(UUID.randomUUID(), name);
gp.getProperties().put("textures", new Property("textures", url));
Object isskull = asNMSCopy(skull);
Object nbt = getNMS("NBTTagCompound").getConstructor().newInstance();
Method serialize = getNMS("GameProfileSerializer").getMethod(
"serialize", getNMS("NBTTagCompound"), GameProfile.class);
serialize.invoke(null, nbt, gp);
Object nbtr = isskull.getClass().getMethod("getTag").invoke(isskull);
nbtr.getClass().getMethod("set", String.class, getNMS("NBTBase"))
.invoke(nbtr, "SkullOwner", nbt);
isskull.getClass().getMethod("setTag", getNMS("NBTTagCompound"))
.invoke(isskull, nbtr);
skull = asBukkitCopy(isskull);
return skull;
}
示例14: setSkullTexture
import org.bukkit.inventory.meta.SkullMeta; //导入依赖的package包/类
@Override
public SkullMeta setSkullTexture(SkullMeta meta, String skinUrl) {
if (meta == null) {
return meta;
}
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
profile.getProperties().put("textures", new Property("textures", new String(Utils.getSkullTexture(skinUrl))));
try {
Field profileField = meta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(meta, profile);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
return meta;
}
示例15: createMemberMenu
import org.bukkit.inventory.meta.SkullMeta; //导入依赖的package包/类
public static List<Inventory> createMemberMenu(Clans clan){
Clan clanProfile = new Clan(clan);
List<Inventory> pages = new ArrayList<Inventory>();
int page = 1;
pages.add(Bukkit.createInventory(null, 54, "Page "+page));
List<ca.damocles.accountsystem.Character> clansmen = clanProfile.getClansmen();
for(ca.damocles.accountsystem.Character members : clansmen){
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short)SkullType.PLAYER.ordinal());
SkullMeta meta = (SkullMeta) skull.getItemMeta();
meta.setOwningPlayer(Bukkit.getOfflinePlayer(members.uuid));
skull.setItemMeta(meta);
if(pages.get(pages.size()-1).firstEmpty() == -1){
page = page+1;
pages.add(Bukkit.createInventory(null, 54, "Page "+page));
pages.get(pages.size()-1).addItem(skull);
}else{
pages.get(pages.size()-1).addItem(skull);
}
members.getPlayer().updateInventory();
}
return pages;
}