Java Code Examples for org.bukkit.inventory.meta.SkullMeta#hasOwner()

The following examples show how to use org.bukkit.inventory.meta.SkullMeta#hasOwner() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Recipes.java    From ProRecipes with GNU General Public License v2.0 6 votes vote down vote up
public ItemStack checkTexture(ItemStack i, ConfigurationSection s, String path){
	if(i == null || i.getType() != MinecraftVersion.getMaterial("SKULL_ITEM","PLAYER_HEAD")){
		return i;
	}
	if(s == null){
		return i;
	}
	SkullMeta meta = (SkullMeta) i.getItemMeta();
	if(meta.hasOwner()){
		return i;
	}
	if(s.contains(path)){
		String texture = s.getString(path + ".texture");
		String id = s.getString(path + ".uuid");
		return ItemUtils.createHead(UUID.fromString(id), i, texture);
	}else{
		return i;
	}
}
 
Example 2
Source File: Utils.java    From Shopkeepers with GNU General Public License v3.0 6 votes vote down vote up
public static boolean isCustomHeadItem(ItemStack item) {
	if (item == null) return false;
	if (item.getType() != Material.SKULL_ITEM) {
		return false;
	}
	if (item.getDurability() != SkullType.PLAYER.ordinal()) {
		return false;
	}

	ItemMeta meta = item.getItemMeta();
	if (meta instanceof SkullMeta) {
		SkullMeta skullMeta = (SkullMeta) meta;
		if (skullMeta.hasOwner() && skullMeta.getOwner() == null) {
			// custom head items usually don't have a valid owner
			return true;
		}
	}
	return false;
}
 
Example 3
Source File: NMS.java    From ArmorStandTools with MIT License 5 votes vote down vote up
private String skullOwner(ItemStack is) {
    if(is == null || is.getItemMeta() == null || !(is.getItemMeta() instanceof SkullMeta)) {
        return "";
    }
    SkullMeta skull = (SkullMeta) is.getItemMeta();
    if(skull.hasOwner()) {
        return ",SkullOwner:\"" + skull.getOwningPlayer().getName() + "\"";
    } else {
        return "";
    }
}
 
Example 4
Source File: ArmorStandGUI.java    From ArmorStandTools with MIT License 5 votes vote down vote up
private String plrHeadName(ArmorStand as) {
    if(as.getHelmet() == null) return null;
    if(!(as.getHelmet().getItemMeta() instanceof SkullMeta)) return null;
    SkullMeta meta = (SkullMeta) as.getHelmet().getItemMeta();
    if(!meta.hasOwner()) return null;
    return meta.getOwningPlayer().getName();
}
 
Example 5
Source File: MainListener.java    From ArmorStandTools with MIT License 4 votes vote down vote up
@EventHandler
public void onSignChange(final SignChangeEvent event) {
    if(event.getBlock().hasMetadata("armorStand")) {
        final Block b = event.getBlock();
        final ArmorStand as = getArmorStand(b);
        if (as != null) {
            StringBuilder sb = new StringBuilder();
            for (String line : event.getLines()) {
                if (line != null && line.length() > 0) {
                    sb.append(ChatColor.translateAlternateColorCodes('&', line));
                }
            }
            String input = sb.toString();
            if(b.hasMetadata("setName")) {
                if (input.length() > 0) {
                    as.setCustomName(input);
                    as.setCustomNameVisible(true);
                } else {
                    as.setCustomName("");
                    as.setCustomNameVisible(false);
                    as.setCustomNameVisible(false);
                }
            } else if(b.hasMetadata("setSkull")) {
                if(MC_USERNAME_PATTERN.matcher(input).matches()) {
                    b.setMetadata("protected", new FixedMetadataValue(plugin, true));
                    event.getPlayer().sendMessage(ChatColor.GOLD + Config.pleaseWait);
                    String cmd = "minecraft:give " + event.getPlayer().getName() + " minecraft:player_head{SkullOwner:\"" + input + "\"} 1";
                    String current = b.getWorld().getGameRuleValue("sendCommandFeedback");
                    b.getWorld().setGameRuleValue("sendCommandFeedback", "false");
                    Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd);
                    b.getWorld().setGameRuleValue("sendCommandFeedback", current);
                    boolean found = false;
                    for(int slot : event.getPlayer().getInventory().all(Material.PLAYER_HEAD).keySet()) {
                        ItemStack skull = event.getPlayer().getInventory().getItem(slot);
                        SkullMeta sm = (SkullMeta) skull.getItemMeta();
                        if(sm.hasOwner() && input.equalsIgnoreCase(sm.getOwningPlayer().getName())) {
                            as.setHelmet(skull);
                            event.getPlayer().sendMessage(ChatColor.GREEN + Config.appliedHead + ChatColor.GOLD + " " + input);
                            event.getPlayer().getInventory().setItem(slot, null);
                            found = true;
                            break;
                        }
                    }
                    if(!found) {
                        event.getPlayer().sendMessage(ChatColor.GOLD + Config.headFailed);
                    }
                } else {
                    event.getPlayer().sendMessage(ChatColor.RED + input + " " + Config.invalidName);
                }
            }
        }
        event.setCancelled(true);
        b.removeMetadata("armorStand", plugin);
        b.removeMetadata("setName", plugin);
        b.removeMetadata("setSkull", plugin);
        b.setType(Material.AIR);
    }
}