Head Owner Not Being Recognized

Discussion in 'Spigot Plugin Development' started by Bladian, May 10, 2015.

  1. I currently have an InventoryClickEvent which checks if the player clicks the head of the Mojang player MHF_CHICKEN. Unfortunately after a lot of debugging I noticed that it is never able to check if it's the the chicken's head being clicked.

    Code (Text):
        public void onClick(InventoryClickEvent e) {

            HumanEntity he = e.getWhoClicked();
            if (he instanceof Player) {
                Bukkit.broadcastMessage("It works!");
                Player p = (Player) he;
                Inventory inv = e.getInventory();
                if (inv != null) {
                    Bukkit.broadcastMessage("It works!");
                    if (inv.getName().equals("MOUNTS")) {
                        Bukkit.broadcastMessage("It works!");
                        if (e.getCurrentItem() != null) {
                            Bukkit.broadcastMessage("It works!");
                            ItemStack is = e.getCurrentItem();
                            if (is.getType() == Material.SKULL_ITEM) {
                                Bukkit.broadcastMessage("It works!");
                                SkullMeta meta = (SkullMeta) is.getItemMeta();
                                if(meta.hasOwner()) {
                                    Bukkit.broadcastMessage("It works!");
                                    if(meta.getOwner().equals("MHF_Chicken")) {
                                        Bukkit.broadcastMessage("It works!");
                                        if(Configs.getPlayerConfig(p).getBoolean("mounts.chicken")) {
                                            Utils.spawnEntity(new CustomChicken(p.getWorld()), p.getLocation(), p);


    The meta owner does not seem to work.

    Here is how I create the heads.

    Code (Text):
    public static ItemStack createMobHead(String head, String mount, Player p) {

            String display;

            String path = "mounts." + mount;

            if(Core.getInstance().getConfig().getBoolean(path + ".default")) {
                String displayC = Configs.getLanguageConfig().getString(path + ".display");
                display = ChatColor.translateAlternateColorCodes('&', displayC);
            else {
                if(Configs.getPlayerConfig(p).getBoolean(path)) {
                    String displayC = Configs.getLanguageConfig().getString(path) + "§4[§a" + Configs.getInstance().getLanguageConfig().getString("head-owned")+ "§4]";
                    display = ChatColor.translateAlternateColorCodes('&', displayC);
                else {
                    String displayC = Configs.getLanguageConfig().getString(path) + " §4[§e" + Core.getInstance().getConfig().getInt(mount + ".price") + "§4]";
                    display = ChatColor.translateAlternateColorCodes('&', displayC);


            ItemStack skull = createItem(Material.SKULL_ITEM, 1, (byte) 3, display, null);

            SkullMeta meta = (SkullMeta) skull.getItemMeta();

            return skull;
    Any help?
  2. Notice how is "Chicken" and not "CHICKEN"? Im not sure which is correct but what you should really do is check if it equalsIgnoreCase () so that the case doesnt matter.
  3. And of course, I make the simplest mistake know to man.

    Will test it out when I get back home.

    #3 Bladian, May 11, 2015
    Last edited: May 11, 2015
  4. Okay after much research I realized that wasn't the problem, but rather that my custom config always returns false.

    This is where I create it and where I get it.

    Code (Text):
    public void createPlayerConfig(Player p) throws IOException {

            FileConfiguration fileConfiguration;
            File file = new File(Core.getInstance().getDataFolder() + File.separator + p.getUniqueId() + ".yml");

            if (!file.exists()) {
                fileConfiguration = YamlConfiguration.loadConfiguration(file);
                fileConfiguration.set("name", p.getName());
                fileConfiguration.set("mounts.chicken", false);
                fileConfiguration.set("mounts.cow", true);
                fileConfiguration.set("mounts.pig", true);
                fileConfiguration.set("mounts.sheep", true);
                fileConfiguration.set("mounts.zombie", true);
                fileConfiguration.set("mounts.creeper", true);
                fileConfiguration.set("mounts.skeleton", true);
                fileConfiguration.set("mounts.spider", true);
                fileConfiguration.set("mounts.enderman", true);

    Where I get it:

    Code (Text):
    public static FileConfiguration getPlayerConfig(Player p) {

            File plugins = Core.getInstance().getDataFolder().getParentFile();
            File folder = new File(plugins.getPath() + File.separator + p.getUniqueId() + ".yml");
            FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(folder);

            return fileConfiguration;
    The config shows that it works perfectly:

    Code (Text):
    name: Bladian
      chicken: false
      cow: true
      pig: true
      sheep: true
      zombie: true
      creeper: true
      skeleton: true
      spider: true
      enderman: true
    But everytime I use it, it always returns false. Any help?
  5. Looks like you are setting it to false... so it returning false seems correct.
  6. The cow also returns false though.

    Basically every head returns false, even though it's not.
  7. Yep, so I double checked everything and came to the conclusion, that it returns false no matter what I do. Hmmm