Solved Custom crafting recipes help

Discussion in 'Plugin Development' started by iLiveorLose, Apr 15, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    iLiveorLose

    That did the trick. Except that didn't fix the problem, I can still create mega slimeballs with normal emerald blocks instead of "Shiny emerald block"s.
     
  2. Offline

    Zombie_Striker

    @iLiveorLose
    This is because you are still using the code that was posted. Although you don't have to re-write your code now (although I do recommend that you should later), you should read every single line that is written, and debug each line. Print out messages saying what each value is equal to, that way you can figure out what is not working correctly.
     
  3. Offline

    iLiveorLose

    After I've tried debugging a lot, it still isn't working. I tried shrecipe.getResult().getData() and also emeraldblock.getData() for the setIngredient but it didn't work no matter what I tried.\

    EDIT: by any chance, does it make a difference if I do Bukkit.getServer().addRecipe(sbrecipe) AFTER I make sure it has a certain Item Meta?
     
  4. Offline

    Zombie_Striker

    @iLiveorLose
    Yes, that is most likely it. The event is only triggered when the crafted recipe exist. In essence, adding the recipe inside the event is simular to saying "Add a recipe if the recipe has been added" Move that line to the onEnable.
     
  5. Offline

    iLiveorLose

    Ok, after I moved those lines, the sbrecipe and shrecipe are underlined red, and I tried moving the recipes outside of the event method and the whole thing was underlined, so I moved it into it's own method, and then everything that had the words sbrecipe and shrecipe were underlined. I feel like I should know how to fix this, but I'm really clueless as to how this could be fixed.
     
  6. Offline

    mcdorli

    Read that link I posted.
     
  7. Offline

    Lordloss

    Not knowing how to declare variables / using variable scope properly has nothing to do with beeing "rusty"..
    This also counts for the last comment you wrote.

    For this you just need very very basic java, like the stuff you learn in the first couple of chapters in beginner tutorials.
     
  8. Offline

    iLiveorLose

    @Zombie_Striker
    I tried what you told me to do with the ItemStack instances, and it worked, but now with the ShapedRecipe's outside of the method and with the Bukkit.getServer().addRecipes() in the onEnable, the crafting recipes don't work anymore. None of them. Please help.

    @mcdorli
    @Lordloss
    I knew how to do that, but for some reason when I tried that it didn't work, then I tried it again, and bingo. Sorry if I looked like an idiot and made you waste your time correcting my error.
     
  9. Offline

    Zombie_Striker

    @iLiveorLose
    At this point, it seems I should explain what you want to do.

    1. What you want to do is create ItemStack fields which hold the instance of each Itemstack you want. This is only the instance, and should not be edited at this point. Since they are fields, when the class if first created (I.e before onEnable is called). We want this to happen because we want to be able to reference these itemstacks in all other methods in the class.
    2. After the fields are created, onEnabled is called. That is when you want to now edit the values of the itemstack, meaning you would set the displayname, type,ect. in the onEnabled. We do this because you cannot set values of objects outside of method blocks.
    3. After you have set all the values of the itemstack, you should then add the recipe. This can be done in the onEnabled, but after you set all the values for the itemstacks. We want to add the recipe after we set the itemstack's values because we want to have the "result" of crafting the item to have all the data specified before.
    Please understand the above, and try having the code match what is described above. After that, post the code.
     
  10. Offline

    iLiveorLose

    @Zombie_Striker
    Still can't craft anything, heres the code:
    Code:
    package me.liveorlose.megaslime;
    
    import java.util.Arrays;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.PrepareItemCraftEvent;
    import org.bukkit.inventory.CraftingInventory;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Test extends JavaPlugin implements Listener {
    
        private ItemStack emeraldblock = new ItemStack(Material.EMERALD_BLOCK, 1);
        private ItemStack slimeball = new ItemStack(Material.SLIME_BALL, 1);
    
        private ShapedRecipe shrecipe = new ShapedRecipe(emeraldblock);
        private ShapedRecipe sbrecipe = new ShapedRecipe(slimeball);
    
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            emeraldblock.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
    
            ItemMeta emeraldmeta = emeraldblock.getItemMeta();
            emeraldmeta.setDisplayName(ChatColor.GREEN.toString() + ChatColor.BOLD
                    + "Shiny emerald block");
            emeraldmeta.setLore(Arrays.asList(ChatColor.GREEN
                    + "This emerald block", ChatColor.GREEN + "is enchanted with",
                    ChatColor.GREEN + "an odd " + ChatColor.GOLD.toString()
                            + ChatColor.BOLD + "presence" + ChatColor.GREEN + "."));
            emeraldblock.setItemMeta(emeraldmeta);
            /**********/
            slimeball.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta slimeballmeta = slimeball.getItemMeta();
            slimeballmeta.setDisplayName(ChatColor.GREEN.toString()
                    + ChatColor.BOLD + "Mega slimeball");
            slimeballmeta.setLore(Arrays.asList(ChatColor.GREEN
                    + "This mega slimeball",
                    ChatColor.GREEN + "came directly from",
                    ChatColor.GREEN + "the " + ChatColor.GREEN.toString()
                            + ChatColor.BOLD + ChatColor.UNDERLINE + "Slime King"
                            + ChatColor.RESET.toString() + ChatColor.GREEN
                            + " itself."));
            slimeball.setItemMeta(slimeballmeta);
           
            Bukkit.getServer().addRecipe(shrecipe);
            Bukkit.getServer().addRecipe(sbrecipe);
        }
    
        @SuppressWarnings({ "deprecation" })
        @EventHandler
        public void onPrepareCraft(PrepareItemCraftEvent e) {
            shrecipe.shape("@@@", "@X@", "@@@");
            shrecipe.setIngredient('@', Material.MONSTER_EGG,
                    EntityType.SLIME.getTypeId());
            shrecipe.setIngredient('X', Material.EMERALD_BLOCK);
            //
            sbrecipe.shape("EEE", "ESE", "EEE");
            sbrecipe.setIngredient('S', Material.SLIME_BALL);
            sbrecipe.setIngredient('E', shrecipe.getResult().getData());
    
            if (e.isRepair() || !e.getRecipe().equals(sbrecipe))
                return;
            CraftingInventory inv = e.getInventory();
            for (ItemStack item : inv.getMatrix()) {
                if (!item
                        .getItemMeta()
                        .getDisplayName()
                        .equals(ChatColor.GREEN.toString() + ChatColor.BOLD
                                + "Shiny emerald block")) {
                    return;
                }
                inv.setResult(slimeball);
            }
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label,
                String[] args) {
            if (cmd.getName().equalsIgnoreCase("thisis")) {
                Player p = (Player) sender;
                Inventory pi = p.getInventory();
                pi.addItem(emeraldblock);
            }
            return true;
        }
    }
    
     
  11. Offline

    Zombie_Striker

    You have to set these values after you set all the values for the itemstack. Right now, you are creating a recipe for base game emerald blocsk and slime blocks (without any displaynames or lores.)

    It should look like the following:

     
  12. Offline

    iLiveorLose

    Code:
    package me.liveorlose.megaslime;
    
    import java.util.Arrays;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.PrepareItemCraftEvent;
    import org.bukkit.inventory.CraftingInventory;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Test extends JavaPlugin implements Listener {
    
        private ItemStack emeraldblock = new ItemStack(Material.EMERALD_BLOCK, 1);
        private ItemStack slimeball = new ItemStack(Material.SLIME_BALL, 1);
    
        private ShapedRecipe shrecipe;
        private ShapedRecipe sbrecipe;
    
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            emeraldblock.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
    
            ItemMeta emeraldmeta = emeraldblock.getItemMeta();
            emeraldmeta.setDisplayName(ChatColor.GREEN.toString() + ChatColor.BOLD
                    + "Shiny emerald block");
            emeraldmeta.setLore(Arrays.asList(ChatColor.GREEN
                    + "This emerald block", ChatColor.GREEN + "is enchanted with",
                    ChatColor.GREEN + "an odd " + ChatColor.GOLD.toString()
                            + ChatColor.BOLD + "presence" + ChatColor.GREEN + "."));
            emeraldblock.setItemMeta(emeraldmeta);
            /**********/
            slimeball.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta slimeballmeta = slimeball.getItemMeta();
            slimeballmeta.setDisplayName(ChatColor.GREEN.toString()
                    + ChatColor.BOLD + "Mega slimeball");
            slimeballmeta.setLore(Arrays.asList(ChatColor.GREEN
                    + "This mega slimeball",
                    ChatColor.GREEN + "came directly from",
                    ChatColor.GREEN + "the " + ChatColor.GREEN.toString()
                            + ChatColor.BOLD + ChatColor.UNDERLINE + "Slime King"
                            + ChatColor.RESET.toString() + ChatColor.GREEN
                            + " itself."));
            slimeball.setItemMeta(slimeballmeta);
           
            shrecipe = new ShapedRecipe(emeraldblock);
    
            sbrecipe = new ShapedRecipe(slimeball);
           
            Bukkit.getServer().addRecipe(shrecipe);
            Bukkit.getServer().addRecipe(sbrecipe);
        }
    
        @SuppressWarnings({ "deprecation" })
        @EventHandler
        public void onPrepareCraft(PrepareItemCraftEvent e) {
            shrecipe.shape("@@@", "@X@", "@@@");
            shrecipe.setIngredient('@', Material.MONSTER_EGG,
                    EntityType.SLIME.getTypeId());
            shrecipe.setIngredient('X', Material.EMERALD_BLOCK);
            //
            sbrecipe.shape("EEE", "ESE", "EEE");
            sbrecipe.setIngredient('S', Material.SLIME_BALL);
            sbrecipe.setIngredient('E', shrecipe.getResult().getData());
    
            if (e.isRepair() || !e.getRecipe().equals(sbrecipe))
                return;
            CraftingInventory inv = e.getInventory();
            for (ItemStack item : inv.getMatrix()) {
                if (!item
                        .getItemMeta()
                        .getDisplayName()
                        .equals(ChatColor.GREEN.toString() + ChatColor.BOLD
                                + "Shiny emerald block")) {
                    return;
                }
                inv.setResult(slimeball);
            }
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label,
                String[] args) {
            if (cmd.getName().equalsIgnoreCase("thisis")) {
                Player p = (Player) sender;
                Inventory pi = p.getInventory();
                pi.addItem(emeraldblock);
            }
            return true;
        }
    }
    
    Still doesn't work, nothing can be crafted.
     
  13. Offline

    Jetsinsu

    I found this video helpful even though I don't understand what he is saying. It should give you an idea of how to craft items with special items on them like displayname, lore, enchantment, custom items, etc.....
     
  14. Offline

    iLiveorLose

    Thank you so much, I think you fixed my problem. The only problem is that (not because of you) my plugin won't load because it says "Plugin already initialized" and it is caused by line 17 of my MegaSlime (main) class.

    MegaSlime:
    Code:
    package me.liveorlose.megaslime;
    
    import java.util.Arrays;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.EntityType;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class MegaSlime extends JavaPlugin { // Line 17. This is where the error is caused.
    
        public static ItemStack emeraldblock = new ItemStack(
                Material.EMERALD_BLOCK, 1);
        {
            emeraldblock.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta emeraldmeta = emeraldblock.getItemMeta();
            emeraldmeta.setDisplayName(ChatColor.GREEN.toString() + ChatColor.BOLD
                    + "Shiny emerald block");
            emeraldmeta.setLore(Arrays.asList(ChatColor.GREEN
                    + "This emerald block", ChatColor.GREEN + "is enchanted with",
                    ChatColor.GREEN + "an odd " + ChatColor.GOLD.toString()
                            + ChatColor.BOLD + "presence" + ChatColor.GREEN + "."));
            emeraldblock.setItemMeta(emeraldmeta);
        }
    
        public static ItemStack slimeball = new ItemStack(Material.SLIME_BALL, 1);
        {
            slimeball.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta slimeballmeta = slimeball.getItemMeta();
            slimeballmeta.setDisplayName(ChatColor.GREEN.toString()
                    + ChatColor.BOLD + "Mega slimeball");
            slimeballmeta.setLore(Arrays.asList(ChatColor.GREEN
                    + "This mega slimeball",
                    ChatColor.GREEN + "came directly from",
                    ChatColor.GREEN + "the " + ChatColor.GREEN.toString()
                            + ChatColor.BOLD + ChatColor.UNDERLINE + "Slime King"
                            + ChatColor.RESET.toString() + ChatColor.GREEN
                            + " itself."));
            slimeball.setItemMeta(slimeballmeta);
        }
    
        @SuppressWarnings("deprecation")
        public static ItemStack slimeEgg = new ItemStack(Material.MONSTER_EGG, 1,
                EntityType.SLIME.getTypeId());
        {
            slimeEgg.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta slimeEggMeta = slimeEgg.getItemMeta();
            slimeEggMeta.setDisplayName(ChatColor.AQUA.toString() + ChatColor.BOLD
                    + ChatColor.MAGIC + "|||" + ChatColor.GREEN.toString()
                    + ChatColor.BOLD + ChatColor.UNDERLINE + "Slime King Spawn Egg"
                    + ChatColor.AQUA.toString() + ChatColor.BOLD + ChatColor.MAGIC
                    + "|||");
            slimeEggMeta.setLore(Arrays.asList(ChatColor.GOLD.toString()
                    + ChatColor.BOLD + "This eggs contains a very",
                    ChatColor.GOLD.toString() + ChatColor.BOLD
                            + "strong aura of power.", ChatColor.AQUA
                            + "Right click to summon Slime King Boss."));
            slimeEgg.setItemMeta(slimeEggMeta);
        }
    
        public static ItemStack diamondBlock = new ItemStack(
                Material.DIAMOND_BLOCK, 1);
        {
            diamondBlock.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta diamondMeta = diamondBlock.getItemMeta();
            diamondMeta.setDisplayName(ChatColor.RED.toString() + ChatColor.BOLD
                    + "Shiny diamond block");
            diamondMeta.setLore(Arrays.asList(ChatColor.RED + "This diamond block",
                    ChatColor.RED + "is enchanted with", ChatColor.RED + "an odd "
                            + ChatColor.GOLD.toString() + ChatColor.BOLD
                            + "presence" + ChatColor.RESET.toString()
                            + ChatColor.RED + "."));
            diamondBlock.setItemMeta(diamondMeta);
        }
    
        public static ItemStack cream = new ItemStack(Material.MAGMA_CREAM, 1);
        {
            cream.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta creamMeta = cream.getItemMeta();
            creamMeta.setDisplayName(ChatColor.RED.toString() + ChatColor.BOLD
                    + "Mega magma cream");
            creamMeta.setLore(Arrays.asList(ChatColor.RED + "This mega cream",
                    ChatColor.RED + "came directly from",
                    ChatColor.RED + "the " + ChatColor.RED.toString()
                            + ChatColor.BOLD + ChatColor.UNDERLINE + "Magma Lord"
                            + ChatColor.RESET.toString() + ChatColor.RED
                            + " itself."));
            cream.setItemMeta(creamMeta);
        }
    
        @SuppressWarnings("deprecation")
        public static ItemStack cubeEgg = new ItemStack(Material.MONSTER_EGG, 1,
                EntityType.MAGMA_CUBE.getTypeId());
        {
            cubeEgg.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta cubeMeta = cubeEgg.getItemMeta();
            cubeMeta.setDisplayName(ChatColor.AQUA.toString() + ChatColor.BOLD
                    + ChatColor.MAGIC + "|||" + ChatColor.RED.toString()
                    + ChatColor.BOLD + ChatColor.UNDERLINE + "Magma Lord Spawn Egg"
                    + ChatColor.AQUA.toString() + ChatColor.BOLD + ChatColor.MAGIC
                    + "|||");
            cubeMeta.setLore(Arrays.asList(ChatColor.GOLD.toString()
                    + ChatColor.BOLD + "This eggs contains an extemely",
                    ChatColor.GOLD.toString() + ChatColor.BOLD
                            + "strong aura of ruthless power.", ChatColor.AQUA
                            + "Right click to summon Magma Lord Boss."));
            cubeEgg.setItemMeta(cubeMeta);
        }
    
        public void onEnable() {
            getServer().addRecipe(shrecipe);
            getServer().addRecipe(sbrecipe);
            getServer().addRecipe(serecipe);
            getServer().addRecipe(drecipe);
            getServer().addRecipe(crrecipe);
            getServer().addRecipe(merecipe);
            Bukkit.getServer().getPluginManager().registerEvents(new SlimeListener(null), this);
        }
       
        /* Slime King recipes */
        @SuppressWarnings("deprecation")
        ShapedRecipe shrecipe = new ShapedRecipe(emeraldblock)
                .shape("@@@", "@X@", "@@@")
                .setIngredient('@', Material.MONSTER_EGG,
                        EntityType.SLIME.getTypeId())
                .setIngredient('X', Material.EMERALD_BLOCK);
    
        ShapedRecipe sbrecipe = new ShapedRecipe(slimeball)
                .shape("EEE", "ESE", "EEE")
                .setIngredient('E', Material.EMERALD_BLOCK)
                .setIngredient('S', Material.SLIME_BALL);
    
        @SuppressWarnings("deprecation")
        ShapedRecipe serecipe = new ShapedRecipe(slimeEgg)
                .shape("MMM", "MGM", "MMM")
                .setIngredient('M', Material.SLIME_BALL)
                .setIngredient('S', Material.MONSTER_EGG,
                        EntityType.SLIME.getTypeId());
        /* Magma Lord recipes */
    
        @SuppressWarnings("deprecation")
        ShapedRecipe drecipe = new ShapedRecipe(diamondBlock)
                .shape("MMM", "MDM", "MMM")
                .setIngredient('M', Material.MONSTER_EGG,
                        EntityType.MAGMA_CUBE.getTypeId())
                .setIngredient('D', Material.DIAMOND_BLOCK);
    
        ShapedRecipe crrecipe = new ShapedRecipe(cream).shape("III", "ICI", "III")
                .setIngredient('C', Material.MAGMA_CREAM)
                .setIngredient('I', Material.DIAMOND_BLOCK);
    
        @SuppressWarnings("deprecation")
        ShapedRecipe merecipe = new ShapedRecipe(cubeEgg)
                .shape("BBB", "BAB", "BBB")
                .setIngredient('A', Material.MONSTER_EGG,
                        EntityType.MAGMA_CUBE.getTypeId())
                .setIngredient('B', Material.MAGMA_CREAM);
    }
    
    SlimeListener:
    Code:
    package me.liveorlose.megaslime;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.inventory.PrepareItemCraftEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    
    import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
    
    public class SlimeListener implements Listener {
    
        private MegaSlime plugin;
    
        public SlimeListener(MegaSlime plugin) {
            this.plugin = plugin;
        }
    
        public void onEnable() {
        }
    
        @EventHandler
        public void onPrepare(PrepareItemCraftEvent e) {
            if (e.isRepair()) {
                e.getInventory().setResult(new ItemStack(Material.AIR, 1));
            }
            if((e.getInventory().getResult() != null) && (e.getInventory().getResult().equals(plugin.sbrecipe))){
                if((e.getInventory().getItem(1) != null) && (e.getInventory().getItem(1).hasItemMeta()) && (e.getInventory().getItem(1).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(1).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(1).hasItemMeta()) 
                        && (e.getInventory().getItem(2) != null) && (e.getInventory().getItem(2).hasItemMeta()) && (e.getInventory().getItem(2).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(2).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(2).hasItemMeta())
                        && (e.getInventory().getItem(3) != null) && (e.getInventory().getItem(3).hasItemMeta()) && (e.getInventory().getItem(3).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(3).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(3).hasItemMeta())
                        && (e.getInventory().getItem(4) != null) && (e.getInventory().getItem(4).hasItemMeta()) && (e.getInventory().getItem(4).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(4).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(4).hasItemMeta())
                        && (e.getInventory().getItem(6) != null) && (e.getInventory().getItem(6).hasItemMeta()) && (e.getInventory().getItem(6).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(6).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(6).hasItemMeta())
                        && (e.getInventory().getItem(7) != null) && (e.getInventory().getItem(7).hasItemMeta()) && (e.getInventory().getItem(7).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(7).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(7).hasItemMeta())
                        && (e.getInventory().getItem(8) != null) && (e.getInventory().getItem(8).hasItemMeta()) && (e.getInventory().getItem(8).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(8).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(8).hasItemMeta())
                        && (e.getInventory().getItem(9) != null) && (e.getInventory().getItem(9).hasItemMeta()) && (e.getInventory().getItem(9).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(9).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(9).hasItemMeta())
                        ){
                }
            }
            if((e.getInventory().getResult() != null) && (e.getInventory().getResult().equals(plugin.serecipe))){
                if((e.getInventory().getItem(1) != null) && (e.getInventory().getItem(1).hasItemMeta()) && (e.getInventory().getItem(1).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(1).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(1).hasItemMeta()) 
                        && (e.getInventory().getItem(2) != null) && (e.getInventory().getItem(2).hasItemMeta()) && (e.getInventory().getItem(2).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(2).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(2).hasItemMeta())
                        && (e.getInventory().getItem(3) != null) && (e.getInventory().getItem(3).hasItemMeta()) && (e.getInventory().getItem(3).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(3).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(3).hasItemMeta())
                        && (e.getInventory().getItem(4) != null) && (e.getInventory().getItem(4).hasItemMeta()) && (e.getInventory().getItem(4).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(4).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(4).hasItemMeta())
                        && (e.getInventory().getItem(6) != null) && (e.getInventory().getItem(6).hasItemMeta()) && (e.getInventory().getItem(6).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(6).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(6).hasItemMeta())
                        && (e.getInventory().getItem(7) != null) && (e.getInventory().getItem(7).hasItemMeta()) && (e.getInventory().getItem(7).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(7).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(7).hasItemMeta())
                        && (e.getInventory().getItem(8) != null) && (e.getInventory().getItem(8).hasItemMeta()) && (e.getInventory().getItem(8).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(8).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(8).hasItemMeta())
                        && (e.getInventory().getItem(9) != null) && (e.getInventory().getItem(9).hasItemMeta()) && (e.getInventory().getItem(9).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(9).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(9).hasItemMeta())
                        ){
                }
            }
        }
    
        @SuppressWarnings("static-access")
        @EventHandler
        public void playerInteract(PlayerInteractEvent e) {
            if (e.getPlayer().getInventory().getItemInHand().getType()
                    .equals(plugin.slimeEgg)) {
                if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                    WorldGuardPlugin wg = (WorldGuardPlugin) Bukkit.getServer()
                            .getPluginManager().getPlugin("WorldGuard");
                    if (wg.canBuild(e.getPlayer(), e.getPlayer().getLocation())) {
                        // do something if player can build
                    } else {
                        // do something else if player can't build
                        e.setCancelled(true);
                        e.getPlayer()
                                .sendMessage(
                                        ChatColor.RED
                                                + "You can not summon this boss in this area.");
                    }
                }
            } else if (e.getPlayer().getInventory().getItemInHand().getType()
                    .equals(plugin.cubeEgg)) {
                if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                    WorldGuardPlugin wg = (WorldGuardPlugin) Bukkit.getServer()
                            .getPluginManager().getPlugin("WorldGuard");
                    if (wg.canBuild(e.getPlayer(), e.getPlayer().getLocation())) {
                        // do something if player can build
                    } else {
                        // do something else if player can't build
                        e.setCancelled(true);
                        e.getPlayer()
                                .sendMessage(
                                        ChatColor.RED
                                                + "You can not summon this boss in this area.");
                    }
                }
            }
        }
    }
    
    @Zombie_Striker
    Do you know anything about this?

    Thank you both.
     
  15. Offline

    Zombie_Striker

    Rememver, there can be only one class that extends Java plugin.That means you cant have other classes extends Java plugin, and you can use "new (Class that extends JavaPlugin)".
     
  16. Offline

    iLiveorLose

    Only MegaSlime extends JavaPlugin...
     
  17. Offline

    mcdorli

    Dou you do new megaSlime() anywhere in your plugin?
     
  18. Offline

    iLiveorLose

    No.
     
  19. Offline

    mcdorli

    Then check if you have 2 different versions of this plugin in your plugins folder.
     
  20. Offline

    iLiveorLose

    Nope only 1.
     
  21. Offline

    mcdorli

    Can you show us all the classes from the plugin?
     
  22. Offline

    iLiveorLose

    I did. Scroll up. The one that extends javaplugin and the listener.
     
  23. Offline

    iLiveorLose

    @mcdorli
    @Zombie_Striker
    Never mind, turns out that I'm an idiot. I was trying to load it through plugman when it was already loaded. The error message was that I didn't use the symbol in the crafting recipe, which is true, because when I copied and pasted my original recipe and changed the symbols and stuff, I forgot to change 1 for the slimeball. But now, I can still craft using normal emerald blocks, which I think the problem is with how I register events.

    Registered events with:
    Code:
    Bukkit.getServer().getPluginManager().registerEvents(new SlimeListener(null), this);
    
    That's the only way it would let me register the events (besides putting "this" inside of new SlimeListener(), which didn't work either).

    Here is my Listener class:
    Code:
    package me.liveorlose.megaslime;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.inventory.PrepareItemCraftEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    
    import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
    
    public class SlimeListener implements Listener {
    
        private MegaSlime plugin;
    
        public SlimeListener(MegaSlime plugin) {
            this.plugin = plugin;
        }
    
        public void onEnable() {
        }
    
        @EventHandler
        public void onPrepare(PrepareItemCraftEvent e) {
            if (e.isRepair()) {
                e.getInventory().setResult(new ItemStack(Material.AIR, 1));
            }
            if((e.getInventory().getResult() != null) && (e.getInventory().getResult().equals(plugin.sbrecipe))){
                if((e.getInventory().getItem(1) != null) && (e.getInventory().getItem(1).hasItemMeta()) && (e.getInventory().getItem(1).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(1).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(1).hasItemMeta())
                        && (e.getInventory().getItem(2) != null) && (e.getInventory().getItem(2).hasItemMeta()) && (e.getInventory().getItem(2).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(2).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(2).hasItemMeta())
                        && (e.getInventory().getItem(3) != null) && (e.getInventory().getItem(3).hasItemMeta()) && (e.getInventory().getItem(3).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(3).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(3).hasItemMeta())
                        && (e.getInventory().getItem(4) != null) && (e.getInventory().getItem(4).hasItemMeta()) && (e.getInventory().getItem(4).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(4).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(4).hasItemMeta())
                        && (e.getInventory().getItem(6) != null) && (e.getInventory().getItem(6).hasItemMeta()) && (e.getInventory().getItem(6).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(6).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(6).hasItemMeta())
                        && (e.getInventory().getItem(7) != null) && (e.getInventory().getItem(7).hasItemMeta()) && (e.getInventory().getItem(7).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(7).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(7).hasItemMeta())
                        && (e.getInventory().getItem(8) != null) && (e.getInventory().getItem(8).hasItemMeta()) && (e.getInventory().getItem(8).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(8).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(8).hasItemMeta())
                        && (e.getInventory().getItem(9) != null) && (e.getInventory().getItem(9).hasItemMeta()) && (e.getInventory().getItem(9).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(9).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(9).hasItemMeta())
                        ){
                }
            }
            if((e.getInventory().getResult() != null) && (e.getInventory().getResult().equals(plugin.serecipe))){
                if((e.getInventory().getItem(1) != null) && (e.getInventory().getItem(1).hasItemMeta()) && (e.getInventory().getItem(1).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(1).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(1).hasItemMeta())
                        && (e.getInventory().getItem(2) != null) && (e.getInventory().getItem(2).hasItemMeta()) && (e.getInventory().getItem(2).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(2).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(2).hasItemMeta())
                        && (e.getInventory().getItem(3) != null) && (e.getInventory().getItem(3).hasItemMeta()) && (e.getInventory().getItem(3).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(3).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(3).hasItemMeta())
                        && (e.getInventory().getItem(4) != null) && (e.getInventory().getItem(4).hasItemMeta()) && (e.getInventory().getItem(4).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(4).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(4).hasItemMeta())
                        && (e.getInventory().getItem(6) != null) && (e.getInventory().getItem(6).hasItemMeta()) && (e.getInventory().getItem(6).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(6).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(6).hasItemMeta())
                        && (e.getInventory().getItem(7) != null) && (e.getInventory().getItem(7).hasItemMeta()) && (e.getInventory().getItem(7).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(7).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(7).hasItemMeta())
                        && (e.getInventory().getItem(8) != null) && (e.getInventory().getItem(8).hasItemMeta()) && (e.getInventory().getItem(8).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(8).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(8).hasItemMeta())
                        && (e.getInventory().getItem(9) != null) && (e.getInventory().getItem(9).hasItemMeta()) && (e.getInventory().getItem(9).getItemMeta().hasEnchant(Enchantment.DURABILITY)) && (e.getInventory().getItem(9).getItemMeta().getEnchantLevel(Enchantment.DURABILITY) == 4) && (e.getInventory().getItem(9).hasItemMeta())
                        ){
                }
            }
        }
    
        @SuppressWarnings("static-access")
        @EventHandler
        public void playerInteract(PlayerInteractEvent e) {
            if (e.getPlayer().getInventory().getItemInHand().getType()
                    .equals(plugin.slimeEgg)) {
                if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                    WorldGuardPlugin wg = (WorldGuardPlugin) Bukkit.getServer()
                            .getPluginManager().getPlugin("WorldGuard");
                    if (wg.canBuild(e.getPlayer(), e.getPlayer().getLocation())) {
                        // do something if player can build
                    } else {
                        // do something else if player can't build
                        e.setCancelled(true);
                        e.getPlayer()
                                .sendMessage(
                                        ChatColor.RED
                                                + "You can not summon this boss in this area.");
                    }
                }
            } else if (e.getPlayer().getInventory().getItemInHand().getType()
                    .equals(plugin.cubeEgg)) {
                if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                    WorldGuardPlugin wg = (WorldGuardPlugin) Bukkit.getServer()
                            .getPluginManager().getPlugin("WorldGuard");
                    if (wg.canBuild(e.getPlayer(), e.getPlayer().getLocation())) {
                        // do something if player can build
                    } else {
                        // do something else if player can't build
                        e.setCancelled(true);
                        e.getPlayer()
                                .sendMessage(
                                        ChatColor.RED
                                                + "You can not summon this boss in this area.");
                    }
                }
            }
        }
    }
    
    I tried to inherit the crafting recipes from the main method, so I used that constructor. I guess it worked nicely for the Listener but not for the main class. Any help?

    P.S: I also tried registering the events in the Listener class, no luck.

    EDIT: Nevermind again, I fixed the whole problem in general. Big thanks to the guy who gave me the video.
     
    Last edited: Apr 24, 2016
Thread Status:
Not open for further replies.

Share This Page