Solved NamespacedKey cannot be resolved to a type

Discussion in 'Plugin Development' started by LucaForever, Nov 9, 2020.

  1. Offline

    LucaForever

    I was trying to add a recipe, and i literally copied from the spigot website the code:

    Code:
    package org.---.utilites;
    
    import org.---.commands.FlyCommand;
    import org.---.commands.GameUICommand;
    import org.---.commands.HelloCommand;
    import org.---.commands.gamemode.Adventure;
    import org.--.commands.gamemode.Creative;
    import org.---.commands.gamemode.Spectator;
    import org.---.commands.gamemode.Survival;
    import org.---.listeners.InventoryClickListener;
    import org.---.listeners.JoinListeners;
    import org.---.ui.GamesUI;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    [B]import org.bukkit.NamespacedKey[/B]
    
    public class Main extends JavaPlugin
    {
        @Override
        public void onEnable()
        {
            saveDefaultConfig();
            //commands
            new HelloCommand(this);
            new GameUICommand(this);
            new FlyCommand(this);
          
            //gamemodes
            new Creative(this);
            new Survival(this);
            new Adventure(this);
            new Spectator(this);
          
            //listeners
            new JoinListeners(this);
            new InventoryClickListener(this);
          
            //ui initializer
            GamesUI.initialaize();
          
            //recipe
            ItemStack item = new ItemStack(Material.DIAMOND_SWORD);
    
            ItemMeta meta = item.getItemMeta();
    
            meta.setDisplayName(ChatColor.GREEN + "Emerald Sword");
    
            item.setItemMeta(meta);
    
            item.addEnchantment(Enchantment.DAMAGE_ALL, 5);
    [B]
            NamespacedKey key = new NamespacedKey(this, "emerald_sword");
    [/B]
            ShapedRecipe recipe = new ShapedRecipe(key, item);
    
            recipe.shape(" E ", " E ", " S ");
    
            recipe.setIngredient('E', Material.EMERALD);
            recipe.setIngredient('S', Material.STICK);
    
            Bukkit.addRecipe(recipe);
        }
    }
    

    Here are the errors:
    upload_2020-11-9_21-31-42.png

    ok i just found out that namespacedkey is 1.12 and im on 1.8.9

    but i dont know how to do it still[/I][/INDENT]
     
    Last edited: Nov 11, 2020
  2. Offline

    timtower Moderator Moderator

    @LucaForever Remove the key variable.
    And try to use [code] <code here> [/code]
    Then it is actually readable.
     
  3. Offline

    LucaForever

    I did, but i already fixed this. Thanks for responding tho
     

Share This Page