Solved Creating an inventory not working on cancelling clicks on incorrect items

Discussion in 'Plugin Development' started by TheManiacGamers, Feb 20, 2016.

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

    TheManiacGamers

    Hello all!
    I really need your help,
    I am trying to create a few inventorys that can't be clicked in, except for certain items.
    In this case, I want 1 inventory to be able to be clicked on ONLY Blaze Powder and Nether Star, the rest doesn't do anything
    When clicking on the Blaze Powder or Nether Star, it opens a new inventory with the recipe displayed in it,
    This is working but when clicking on the items IN that second inventory (cmRecipesMighty), the player can move everything around.

    This was working at one stage, but the player couldn't use their inventory, or place items/etc so I edited the code, and now the player CAN use their inventory, but they can also move everything around in these inventorys.

    When the player takes the items out and tries to place 1 of them down, all the items get removed from their inventory that was taken FROM the Recipe Menu Inventory.

    Please take a look at my code and help me resolve this issue. Thanks!
    Code:
    package me.themaniacgamers.CM.Main.listeners;
    
    import com.sk89q.minecraft.util.commands.ChatColor;
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    import java.util.ArrayList;
    import java.util.List;
    
    /**
    * Created by Corey on 2/20/2016.
    */
    public class RecipesListener implements Listener {
    
        public static Inventory cmRecipes = Bukkit.createInventory(null, 27, "Recipes Menu");
        public static Inventory cmRecipesMighty = Bukkit.createInventory(null, 45, "Mighty Item Recipe");
        public static Inventory cmRecipesExtreme = Bukkit.createInventory(null, 45, "Extreme Item Recipe");
    
        static {
            // GO BACK ITEM
            ItemStack ArrowBack = new ItemStack(Material.ARROW, 1);
            ItemMeta ArrowBackMeta = ArrowBack.getItemMeta();
            ArrowBackMeta.setDisplayName(ChatColor.GRAY + "<<< " + ChatColor.RED + "" + ChatColor.BOLD + "Go " + ChatColor.RED + "" + ChatColor.BOLD + "Back" + ChatColor.GRAY + " <<<");
            ArrowBack.setItemMeta(ArrowBackMeta);
            // MIGHTY EFFECT ITEM
            ItemStack MightyEffect = new ItemStack(Material.BLAZE_POWDER, 1);
            ItemMeta MightyEffectMeta = MightyEffect.getItemMeta();
            MightyEffectMeta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "Mighty " + ChatColor.AQUA + "" + ChatColor.BOLD + "Boost");
            List<String> MightyEffectLore = new ArrayList<String>();
            MightyEffectLore.add(ChatColor.DARK_PURPLE + "" + ChatColor.BOLD + "HOW TO USE:");
            MightyEffectLore.add(ChatColor.BLUE + "Sneak + Right click");
            MightyEffectLore.add(ChatColor.AQUA + "Another player while holding this to give them a");
            MightyEffectLore.add(ChatColor.BLUE + "" + ChatColor.BOLD + "Mighty" + ChatColor.AQUA + " boost!");
            MightyEffectMeta.setLore(MightyEffectLore);
            MightyEffect.setItemMeta(MightyEffectMeta);
            // EXTREME EFFECT ITEM
            ItemStack ExtremeEffect = new ItemStack(Material.NETHER_STAR, 1);
            ItemMeta ExtremeEffectMeta = ExtremeEffect.getItemMeta();
            ExtremeEffectMeta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "Extreme " + ChatColor.AQUA + "" + ChatColor.BOLD + "Boost");
            List<String> ExtremeEffectLore = new ArrayList<String>();
            ExtremeEffectLore.add(ChatColor.DARK_PURPLE + "" + ChatColor.BOLD + "HOW TO USE:");
            ExtremeEffectLore.add(ChatColor.BLUE + "Sneak + Right click");
            ExtremeEffectLore.add(ChatColor.AQUA + "Another player while holding this to give them an");
            ExtremeEffectLore.add(ChatColor.BLUE + "" + ChatColor.BOLD + "Extreme" + ChatColor.AQUA + " boost!");
            ExtremeEffectMeta.setLore(ExtremeEffectLore);
            ExtremeEffect.setItemMeta(ExtremeEffectMeta);
    
            cmRecipes.setItem(0, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(1, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(2, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(3, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(4, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(5, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(6, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(7, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(8, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(9, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(10, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(11, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(12, new ItemStack(MightyEffect));
            cmRecipes.setItem(13, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(14, new ItemStack(ExtremeEffect));
            cmRecipes.setItem(15, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(16, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(17, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(18, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(19, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(20, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(21, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(22, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(23, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(24, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(25, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(26, new ItemStack(Material.BARRIER, 1));
            cmRecipesMighty.setItem(0, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(1, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(7, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(8, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(9, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(10, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(16, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(17, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(18, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(19, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(25, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(26, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(27, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(28, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(34, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(35, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(36, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(37, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(43, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(44, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(2, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(3, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(4, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(5, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(6, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(11, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(15, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(20, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(24, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(29, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(33, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(38, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(39, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(40, new ItemStack(ArrowBack));
            cmRecipesMighty.setItem(41, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(42, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(22, new ItemStack(Material.BLAZE_POWDER, 1));
            cmRecipesMighty.setItem(13, new ItemStack(Material.IRON_INGOT, 1));
            cmRecipesMighty.setItem(31, new ItemStack(Material.IRON_INGOT, 1));
            cmRecipesMighty.setItem(21, new ItemStack(Material.GOLD_INGOT, 1));
            cmRecipesMighty.setItem(23, new ItemStack(Material.GOLD_INGOT, 1));
        }
    
        @EventHandler(priority = EventPriority.HIGH)
        public void onRecipesInteract(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            ItemStack item = p.getItemInHand();
            if (p.getItemInHand().getType() == Material.WATCH) {
                if ((item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equals(ChatColor.BLUE + "" + ChatColor.BOLD + "Recipes " + ChatColor.AQUA + "" + ChatColor.BOLD + "Helper"))) {
                    if (p.hasPermission("CM.Recipes.Viewer")) {
                        p.openInventory(cmRecipes);
                    } else {
                        p.sendMessage(ChatColor.RED + "You don't have permission to interact with this [CM] item.");
                    }
                } else {
                    e.setCancelled(true);
                }
            } else {
                e.setCancelled(false);
            }
        }
    
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            Player player = (Player) event.getWhoClicked(); // The player that clicked the item
            ItemStack clicked = event.getCurrentItem(); // The item that was clicked
            Inventory inventory = event.getInventory(); // The inventory that was clicked in
            if (inventory.getName().equals(cmRecipes.getName())) {
                if (clicked.getType() == Material.BLAZE_POWDER) {
                    player.openInventory(cmRecipesMighty);
                    player.sendMessage(ChatColor.AQUA + "Loading the Recipe for the Mighty Item!");
                }
                if (clicked.getType() == Material.NETHER_STAR) {
                    player.openInventory(cmRecipesExtreme);
                    player.sendMessage(ChatColor.AQUA + "Loading the Recipe for the Extreme Item!");
                }
                if (clicked.getType() == Material.BARRIER) {
                    event.setCancelled(true);
                }
                if (clicked.getType() == Material.STAINED_GLASS_PANE) {
                    event.setCancelled(true);
                }
                event.setCancelled(true);
            }
            if (inventory.getName().equals(cmRecipesMighty.getName())) {
                if (clicked.getType() == Material.ARROW) {
                    player.openInventory(cmRecipes);
                    player.sendMessage(ChatColor.AQUA + "Going back to the main menu!");
                }
                if (clicked.getType() == Material.BLAZE_POWDER) {
                    event.setCancelled(true);
                }
                if (clicked.getType() == Material.NETHER_STAR) {
                    event.setCancelled(true);
                }
                if (clicked.getType() == Material.BARRIER) {
                    event.setCancelled(true);
                }
                if (clicked.getType() == Material.STAINED_GLASS_PANE) {
                    event.setCancelled(true);
                }
                if (clicked.getType() == Material.IRON_INGOT) {
                    event.setCancelled(true);
                }
                if (clicked.getType() == Material.GOLD_INGOT) {
                    event.setCancelled(true);
                }
                if (clicked.getType() == Material.IRON_FENCE) {
                    event.setCancelled(true);
                }
                event.setCancelled(true);
            }
            if (inventory.getName().equals(cmRecipesExtreme.getName())) {
                if (clicked.getType() == Material.ARROW) {
                    player.openInventory(cmRecipes);
                    player.sendMessage(ChatColor.AQUA + "Going back to the main menu!");
                }
                event.setCancelled(true);
            }
            event.setCancelled(false);
        }
    }
     
    Last edited: Feb 20, 2016
  2. Offline

    mine-care

    Right, this means that if it is blaze powder, barier, netherstar, stained glass pane, iron ingot, gold ingot or iron fence, it will cancel the event. IF it is nothing of the above, it will still cancel the event... Does that seem wrong just to me?

    To be more efficient and safer, dont compare names, compare the inventory objects directly.
     
  3. Offline

    TheManiacGamers

    I ended up getting this working!

    Code:
    package me.themaniacgamers.CM.Main.listeners;
    
    import com.sk89q.minecraft.util.commands.ChatColor;
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    import java.util.ArrayList;
    import java.util.List;
    
    /**
    * Created by Corey on 2/20/2016.
    */
    public class RecipesListener implements Listener {
    
        public static Inventory cmRecipes = Bukkit.createInventory(null, 27, "Recipes Menu");
        public static Inventory cmRecipesMighty = Bukkit.createInventory(null, 45, "Mighty Item Recipe");
        public static Inventory cmRecipesExtreme = Bukkit.createInventory(null, 45, "Extreme Item Recipe");
    
        static {
            // GO BACK ITEM
            ItemStack ArrowBack = new ItemStack(Material.ARROW, 1);
            ItemMeta ArrowBackMeta = ArrowBack.getItemMeta();
            ArrowBackMeta.setDisplayName(ChatColor.GRAY + "<<< " + ChatColor.RED + "" + ChatColor.BOLD + "Go " + ChatColor.RED + "" + ChatColor.BOLD + "Back" + ChatColor.GRAY + " <<<");
            ArrowBack.setItemMeta(ArrowBackMeta);
            // MIGHTY EFFECT ITEM
            ItemStack MightyEffect = new ItemStack(Material.BLAZE_POWDER, 1);
            ItemMeta MightyEffectMeta = MightyEffect.getItemMeta();
            MightyEffectMeta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "Mighty " + ChatColor.AQUA + "" + ChatColor.BOLD + "Boost");
            List<String> MightyEffectLore = new ArrayList<String>();
            MightyEffectLore.add(ChatColor.DARK_PURPLE + "" + ChatColor.BOLD + "HOW TO USE:");
            MightyEffectLore.add(ChatColor.BLUE + "Sneak + Right click");
            MightyEffectLore.add(ChatColor.AQUA + "Another player while holding this to give them a");
            MightyEffectLore.add(ChatColor.BLUE + "" + ChatColor.BOLD + "Mighty" + ChatColor.AQUA + " boost!");
            MightyEffectMeta.setLore(MightyEffectLore);
            MightyEffect.setItemMeta(MightyEffectMeta);
            // EXTREME EFFECT ITEM
            ItemStack ExtremeEffect = new ItemStack(Material.NETHER_STAR, 1);
            ItemMeta ExtremeEffectMeta = ExtremeEffect.getItemMeta();
            ExtremeEffectMeta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "Extreme " + ChatColor.AQUA + "" + ChatColor.BOLD + "Boost");
            List<String> ExtremeEffectLore = new ArrayList<String>();
            ExtremeEffectLore.add(ChatColor.DARK_PURPLE + "" + ChatColor.BOLD + "HOW TO USE:");
            ExtremeEffectLore.add(ChatColor.BLUE + "Sneak + Right click");
            ExtremeEffectLore.add(ChatColor.AQUA + "Another player while holding this to give them an");
            ExtremeEffectLore.add(ChatColor.BLUE + "" + ChatColor.BOLD + "Extreme" + ChatColor.AQUA + " boost!");
            ExtremeEffectMeta.setLore(ExtremeEffectLore);
            ExtremeEffect.setItemMeta(ExtremeEffectMeta);
    
            cmRecipes.setItem(0, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(1, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(2, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(3, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(4, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(5, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(6, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(7, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(8, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(9, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(10, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(11, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(12, new ItemStack(MightyEffect));
            cmRecipes.setItem(13, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(14, new ItemStack(ExtremeEffect));
            cmRecipes.setItem(15, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(16, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(17, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(18, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(19, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(20, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(21, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(22, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(23, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(24, new ItemStack(Material.BARRIER, 1));
            cmRecipes.setItem(25, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipes.setItem(26, new ItemStack(Material.BARRIER, 1));
            cmRecipesMighty.setItem(0, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(1, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(7, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(8, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(9, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(10, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(16, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(17, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(18, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(19, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(25, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(26, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(27, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(28, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(34, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(35, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(36, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(37, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(43, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(44, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesMighty.setItem(2, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(3, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(4, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(5, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(6, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(11, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(15, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(20, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(24, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(29, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(33, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(38, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(39, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(40, new ItemStack(ArrowBack));
            cmRecipesMighty.setItem(41, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(42, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesMighty.setItem(22, new ItemStack(Material.BLAZE_POWDER, 1));
            cmRecipesMighty.setItem(13, new ItemStack(Material.IRON_INGOT, 1));
            cmRecipesMighty.setItem(31, new ItemStack(Material.IRON_INGOT, 1));
            cmRecipesMighty.setItem(21, new ItemStack(Material.GOLD_INGOT, 1));
            cmRecipesMighty.setItem(23, new ItemStack(Material.GOLD_INGOT, 1));
            cmRecipesExtreme.setItem(0, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(1, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(7, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(8, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(9, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(10, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(16, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(17, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(18, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(19, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(25, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(26, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(27, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(28, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(34, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(35, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(36, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(37, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(43, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(44, new ItemStack(Material.IRON_FENCE, 1));
            cmRecipesExtreme.setItem(2, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesExtreme.setItem(3, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesExtreme.setItem(4, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesExtreme.setItem(5, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesExtreme.setItem(6, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesExtreme.setItem(11, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesExtreme.setItem(15, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesExtreme.setItem(20, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesExtreme.setItem(24, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesExtreme.setItem(29, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesExtreme.setItem(33, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesExtreme.setItem(38, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesExtreme.setItem(39, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesExtreme.setItem(40, new ItemStack(ArrowBack));
            cmRecipesExtreme.setItem(41, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesExtreme.setItem(42, new ItemStack(Material.STAINED_GLASS_PANE, 1));
            cmRecipesExtreme.setItem(22, new ItemStack(Material.BLAZE_POWDER, 1));
            cmRecipesExtreme.setItem(13, new ItemStack(Material.DIAMOND, 1));
            cmRecipesExtreme.setItem(31, new ItemStack(Material.DIAMOND, 1));
            cmRecipesExtreme.setItem(21, new ItemStack(Material.REDSTONE, 1));
            cmRecipesExtreme.setItem(23, new ItemStack(Material.REDSTONE, 1));
        }
    
        @EventHandler(priority = EventPriority.HIGH)
        public void onRecipesInteract(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            ItemStack item = p.getItemInHand();
            if (p.getItemInHand().getType() == Material.WATCH) {
                if ((item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equals(ChatColor.BLUE + "" + ChatColor.BOLD + "Recipes " + ChatColor.AQUA + "" + ChatColor.BOLD + "Helper"))) {
                    if (p.hasPermission("CM.Recipes.Viewer")) {
                        p.openInventory(cmRecipes);
                        p.sendMessage(ChatColor.AQUA + "Loading the Recipes Helper.");
                    } else {
                        p.sendMessage(ChatColor.RED + "You don't have permission to interact with this [CM] item.");
                    }
                } else {
                    e.setCancelled(true);
                }
            } else {
                e.setCancelled(false);
            }
        }
    
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            Player player = (Player) event.getWhoClicked(); // The player that clicked the item
            ItemStack clicked = event.getCurrentItem(); // The item that was clicked
            Inventory inventory = event.getInventory(); // The inventory that was clicked in
            if (inventory.getName().equals(cmRecipes.getName())) {
                if (clicked.getType() == Material.BLAZE_POWDER) {
                    player.openInventory(cmRecipesMighty);
                    player.sendMessage(ChatColor.AQUA + "Loading the recipe for the '" + ChatColor.BLUE + "Mighty" + ChatColor.AQUA + "' item!");
                    event.setCancelled(true);
                    return;
                }
                if (clicked.getType() == Material.NETHER_STAR) {
                    player.sendMessage(ChatColor.AQUA + "Loading the recipe for the '" + ChatColor.BLUE + "Extreme" + ChatColor.AQUA + "' item!");
                    player.openInventory(cmRecipesExtreme);
                    event.setCancelled(true);
                    return;
                }
                event.setCancelled(true);
    
            }
        }
    
        @EventHandler
        public void oncmRecipesMightyClick(InventoryClickEvent event) {
            Player player = (Player) event.getWhoClicked(); // The player that clicked the item
            ItemStack clicked = event.getCurrentItem(); // The item that was clicked
            Inventory inventory = event.getInventory(); // The inventory that was clicked in
            if (inventory.getName().equals(cmRecipesMighty.getName())) {
                if (clicked.getType() == Material.ARROW) {
                    player.openInventory(cmRecipes);
                    player.sendMessage(ChatColor.AQUA + "Going back to the main menu!");
                    event.setCancelled(true);
                    return;
                }
                event.setCancelled(true);
            }
        }
    
        @EventHandler
        public void oncmRecipesExtremeClick(InventoryClickEvent event) {
            Player player = (Player) event.getWhoClicked(); // The player that clicked the item
            ItemStack clicked = event.getCurrentItem(); // The item that was clicked
            Inventory inventory = event.getInventory(); // The inventory that was clicked in
            if (inventory.getName().equals(cmRecipesExtreme.getName())) {
                if (clicked.getType() == Material.ARROW) {
                    player.openInventory(cmRecipes);
                    player.sendMessage(ChatColor.AQUA + "Going back to the main menu!");
                    event.setCancelled(true);
                    return;
                }
                event.setCancelled(true);
            }
        }
    }
    Thanks though :)
     
Thread Status:
Not open for further replies.

Share This Page