Solved How do i add another menu?

Discussion in 'Plugin Development' started by CraterHater, Jun 1, 2015.

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

    CraterHater

    Code:
    package First;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    public class first extends JavaPlugin implements Listener{
      
        @EventHandler
         public void onDeath(PlayerDeathEvent event) {
             Player player = event.getEntity();
             player.getInventory().clear();
             player.getInventory().addItem(new ItemStack(Material.WATCH));
         }
      
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
          
        }
        private void openGUI(Player player) {
            Inventory inv = Bukkit.createInventory(null, 9, ChatColor.DARK_RED + "Server Menu");
          
            ItemStack survival = new ItemStack (Material.DIAMOND_SWORD);
            ItemMeta survivalMeta = survival.getItemMeta();
            ItemStack creative = new ItemStack (Material.DRAGON_EGG);
            ItemMeta creativeMeta = creative.getItemMeta();
          
            survivalMeta.setDisplayName(ChatColor.DARK_BLUE + "PvpArena");
            survival.setItemMeta(survivalMeta);
          
            creativeMeta.setDisplayName(ChatColor.DARK_GREEN + "Mount Shop");
            creative.setItemMeta(creativeMeta);
          
            inv.setItem(3, survival);
            inv.setItem(5, creative);
          
            player.openInventory(inv);
        }
      
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            if(!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Server Menu"))
                    return;
            Player player = (Player) event.getWhoClicked();
            event.setCancelled(true);
            if(event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR ||!event.getCurrentItem().hasItemMeta()) {
                player.closeInventory();
                return;
            }
            switch (event.getCurrentItem().getType()) {
            case DIAMOND_SWORD:
                Location loc = new Location(Bukkit.getWorld("WarpPvp"), 0, 100, 0);
                player.teleport(loc);
                player.closeInventory();
                break;
            case DRAGON_EGG:
                //HERE I WANT THE MENU TO OPEN UP
                player.closeInventory();
                break;
            default:
                player.closeInventory();
                break;
            }
        }
      
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            event.getPlayer().getInventory().clear();
            event.getPlayer().getInventory().addItem(new ItemStack(Material.WATCH));
          
        }
      
    
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            Action a = event.getAction();
            ItemStack is = event.getItem();
          
            if(a == Action.PHYSICAL ||  is == null ||  is.getType()==Material.AIR)
                return;
          
            if(is.getType()==Material.WATCH)
                openGUI(event.getPlayer());
              
          
        }
      
    }
    
    
    
    
    
      
    
    
    I would like to add another menu accessible when clicking on the dragon egg. How do i do that? i would like it to have 9 slots.


    Most resent code:
    Code:
    package First;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    public class first extends JavaPlugin implements Listener{
        private static final Inventory q = null;
        @EventHandler
         public void onDeath(PlayerDeathEvent event) {
             Player player = event.getEntity();
             player.getInventory().clear();
             player.getInventory().addItem(new ItemStack(Material.WATCH));
         }
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
        
        }
        private void openGUI(Player player) {
            Inventory inv = Bukkit.createInventory(null, 9, ChatColor.DARK_RED + "Server Menu");
        
            ItemStack survival = new ItemStack (Material.DIAMOND_SWORD);
            ItemMeta survivalMeta = survival.getItemMeta();
            ItemStack creative = new ItemStack (Material.DRAGON_EGG);
            ItemMeta creativeMeta = creative.getItemMeta();
        
            survivalMeta.setDisplayName(ChatColor.DARK_BLUE + "PvpArena");
            survival.setItemMeta(survivalMeta);
        
            creativeMeta.setDisplayName(ChatColor.DARK_GREEN + "Mount Shop");
            creative.setItemMeta(creativeMeta);
        
            inv.setItem(3, survival);
            inv.setItem(5, creative);
        
            player.openInventory(inv);
        }
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            if(!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Server Menu"))
                    return;
            Player player = (Player) event.getWhoClicked();
            event.setCancelled(true);
            if(event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR ||!event.getCurrentItem().hasItemMeta()) {
                player.closeInventory();
                return;
            }
            switch (event.getCurrentItem().getType()) {
            case DIAMOND_SWORD:
                Location loc = new Location(Bukkit.getWorld("WarpPvp"), 0, 100, 0);
                player.teleport(loc);
                player.closeInventory();
                break;
            case DRAGON_EGG:
                player.closeInventory();
                player.openInventory(q);
                break;
            default:
                player.closeInventory();
                break;
            }
        }
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            event.getPlayer().getInventory().clear();
            event.getPlayer().getInventory().addItem(new ItemStack(Material.WATCH));
        
        }
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            Action a = event.getAction();
            ItemStack is = event.getItem();
        
            if(a == Action.PHYSICAL ||  is == null ||  is.getType()==Material.AIR)
                return;
        
            if(is.getType()==Material.WATCH)
                openGUI(event.getPlayer());
            
        
        }
        @EventHandler
        public void onPlayerJoinEvent(PlayerJoinEvent event) {
            event.getPlayer().sendMessage(ChatColor.DARK_RED + "Welcome!");
        
        
        }
        @EventHandler
        public void openGUI1(Player player) {
            Inventory q = Bukkit.createInventory(null, 9, ChatColor.DARK_RED + "Mount Menu");
        
            ItemStack Dragon = new ItemStack (Material.DRAGON_EGG);
            ItemMeta DragonMeta = Dragon.getItemMeta();
          
            DragonMeta.setDisplayName(ChatColor.DARK_BLUE + "Buy egg, Cost: [24 Diamonds]");
            Dragon.setItemMeta(DragonMeta);
          
            q.setItem(4, Dragon);
        
        }
        @EventHandler
        public void onInventoryClick1(InventoryClickEvent event) {
            if(!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Mount Menu"))
                    return;
            Player player = (Player) event.getWhoClicked();
            event.setCancelled(true);
            if(event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR ||!event.getCurrentItem().hasItemMeta()) {
                player.closeInventory();
                return;
            }
            switch (event.getCurrentItem().getType()) {
            case DRAGON_EGG:
                player.closeInventory();
                break;
            default:
                player.closeInventory();
                break;
    }
        }
    }
     
    Last edited: Jun 3, 2015
  2. Offline

    CrystallFTW

    @CraterHater create a new method :
    Code:
    public static Inventory openInventory(){
    Inventory inv = Bukkit.createInventory(null,9,name);
    ///itemstacks
    return inv;
    }
     
  3. Offline

    CraterHater

    That doesn't seem to work... it gives me all kinds of errors that are unfixable.
     
  4. Offline

    bwfcwalshy Retired Staff

    @CraterHater All errors are fixable. What errors do you have? Stacktrace? Code?

    EDIT: I wouldn't do it like that for a two reasons. 1. Static. 2. That returns the inventory, I would just accept a player argument and open it like that.
     
  5. Offline

    CraterHater

    How exactly am i supposed to do it? i am not so experienced in Java.

    Code:
    package First;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    public class first extends JavaPlugin implements Listener{
       
       
       
        @EventHandler
         public void onDeath(PlayerDeathEvent event) {
             Player player = event.getEntity();
             player.getInventory().clear();
             player.getInventory().addItem(new ItemStack(Material.WATCH));
         }
       
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
           
        }
        private void openGUI(Player player) {
            Inventory inv = Bukkit.createInventory(null, 9, ChatColor.DARK_RED + "Server Menu");
           
            ItemStack survival = new ItemStack (Material.DIAMOND_SWORD);
            ItemMeta survivalMeta = survival.getItemMeta();
            ItemStack creative = new ItemStack (Material.DRAGON_EGG);
            ItemMeta creativeMeta = creative.getItemMeta();
           
            survivalMeta.setDisplayName(ChatColor.DARK_BLUE + "PvpArena");
            survival.setItemMeta(survivalMeta);
           
            creativeMeta.setDisplayName(ChatColor.DARK_GREEN + "Mount Shop");
            creative.setItemMeta(creativeMeta);
           
            inv.setItem(3, survival);
            inv.setItem(5, creative);
           
            player.openInventory(inv);
        }
       
       
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            if(!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Server Menu"))
                    return;
            Player player = (Player) event.getWhoClicked();
            event.setCancelled(true);
            if(event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR ||!event.getCurrentItem().hasItemMeta()) {
                player.closeInventory();
                return;
            }
            switch (event.getCurrentItem().getType()) {
            case DIAMOND_SWORD:
                Location loc = new Location(Bukkit.getWorld("WarpPvp"), 0, 100, 0);
                player.teleport(loc);
                player.closeInventory();
                break;
            case DRAGON_EGG:
                player.openInventory(inv1); //WHY DOESN'T THIS ONE OPEN THE INVENTORY IT GIVES ERROR HERE.
                player.closeInventory();
                break;
            default:
                player.closeInventory();
                break;
            }
        }
       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            event.getPlayer().getInventory().clear();
            event.getPlayer().getInventory().addItem(new ItemStack(Material.WATCH));
           
        }
       
    
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            Action a = event.getAction();
            ItemStack is = event.getItem();
           
            if(a == Action.PHYSICAL ||  is == null ||  is.getType()==Material.AIR)
                return;
           
            if(is.getType()==Material.WATCH)
                openGUI(event.getPlayer());
               
           
        }
        @EventHandler
        public void onPlayerJoinEvent(PlayerJoinEvent event) {
            event.getPlayer().sendMessage(ChatColor.DARK_RED + "Welcome!");
           
           
        }
        public static Inventory openInventory(){
            Inventory inv1 = Bukkit.createInventory(null,9);
            ItemStack Dragon = new ItemStack (Material.EGG);
            ItemMeta DragonMeta = Dragon.getItemMeta();
           
            DragonMeta.setDisplayName(ChatColor.DARK_PURPLE + "Buy Egg, Cost: [24Diamonds]");
            Dragon.setItemMeta(DragonMeta);
            return inv1;
       
    }
    }
       
    
    
    
    
    
    
       
     
    
    this is my main class.

    and this is my second class:
    Code:
    package First;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class mount {
    
        public static Inventory openInventory(){
            Inventory inv1 = Bukkit.createInventory(null,9);
            ItemStack Dragon = new ItemStack (Material.EGG);
            ItemMeta DragonMeta = Dragon.getItemMeta();
           
            DragonMeta.setDisplayName(ChatColor.DARK_PURPLE + "Buy Egg, Cost: [24Diamonds]");
            Dragon.setItemMeta(DragonMeta);
            return inv1;
           
            }
    }
    
     
  6. Offline

    CrystallFTW

    @CraterHater player.openInventory(SecondClass.openInventory());
    add this whenever you want the player to open the menu.
    By the way you should add the item in the inventory to be displayed.
    inv.setItem(slot,Dragon); or inv.addItem(Dragon);
     
  7. Offline

    VG.Developments

    When they click the dragon egg, open a new inventory?
     
  8. Offline

    nverdier

    What's wrong with it being static?
     
    KingFaris11 likes this.
  9. Offline

    CraterHater

    Yes

    I updated my code and it now is:

    Main class:
    Code:
    package First;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    public class first extends JavaPlugin implements Listener{
      
      
      
        private static final Inventory q = null;
        @EventHandler
         public void onDeath(PlayerDeathEvent event) {
             Player player = event.getEntity();
             player.getInventory().clear();
             player.getInventory().addItem(new ItemStack(Material.WATCH));
         }
      
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
          
        }
        private void openGUI(Player player) {
            Inventory inv = Bukkit.createInventory(null, 9, ChatColor.DARK_RED + "Server Menu");
          
            ItemStack survival = new ItemStack (Material.DIAMOND_SWORD);
            ItemMeta survivalMeta = survival.getItemMeta();
            ItemStack creative = new ItemStack (Material.DRAGON_EGG);
            ItemMeta creativeMeta = creative.getItemMeta();
          
            survivalMeta.setDisplayName(ChatColor.DARK_BLUE + "PvpArena");
            survival.setItemMeta(survivalMeta);
          
            creativeMeta.setDisplayName(ChatColor.DARK_GREEN + "Mount Shop");
            creative.setItemMeta(creativeMeta);
          
            inv.setItem(3, survival);
            inv.setItem(5, creative);
          
            player.openInventory(inv);
        }
      
      
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            if(!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Server Menu"))
                    return;
            Player player = (Player) event.getWhoClicked();
            event.setCancelled(true);
            if(event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR ||!event.getCurrentItem().hasItemMeta()) {
                player.closeInventory();
                return;
            }
            switch (event.getCurrentItem().getType()) {
            case DIAMOND_SWORD:
                Location loc = new Location(Bukkit.getWorld("WarpPvp"), 0, 100, 0);
                player.teleport(loc);
                player.closeInventory();
                break;
            case DRAGON_EGG:
                player.openInventory(q);
                player.closeInventory();
                break;
            default:
                player.closeInventory();
                break;
            }
        }
      
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            event.getPlayer().getInventory().clear();
            event.getPlayer().getInventory().addItem(new ItemStack(Material.WATCH));
          
        }
      
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            Action a = event.getAction();
            ItemStack is = event.getItem();
          
            if(a == Action.PHYSICAL ||  is == null ||  is.getType()==Material.AIR)
                return;
          
            if(is.getType()==Material.WATCH)
                openGUI(event.getPlayer());
              
          
        }
        @EventHandler
        public void onPlayerJoinEvent(PlayerJoinEvent event) {
            event.getPlayer().sendMessage(ChatColor.DARK_RED + "Welcome!");
          
          
        }
        public static Inventory openInventory(){
            Inventory inv1 = Bukkit.createInventory(null,9);
            ItemStack Dragon = new ItemStack (Material.EGG);
            ItemMeta DragonMeta = Dragon.getItemMeta();
          
            DragonMeta.setDisplayName(ChatColor.DARK_PURPLE + "Buy Egg, Cost: [24Diamonds]");
            Dragon.setItemMeta(DragonMeta);
            return inv1;
      
    }
    }
       
    and my second class:

    Code:
    package First;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    public class mount implements Listener{
        {
           
        }
        @EventHandler
        private void openGUI(Player player) {
            Inventory q = Bukkit.createInventory(null, 9, ChatColor.DARK_RED + "Mount Menu");
          
            ItemStack Dragon = new ItemStack (Material.EGG);
            ItemMeta DragonMeta = Dragon.getItemMeta();
           
            DragonMeta.setDisplayName(ChatColor.DARK_BLUE + "Buy egg, Cost: [24 Diamonds]");
            Dragon.setItemMeta(DragonMeta);
           
            q.setItem(4, Dragon);
          
            player.openInventory(q);
        }
      
      
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            if(!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Mount Menu"))
                    return;
            Player player = (Player) event.getWhoClicked();
            event.setCancelled(true);
            if(event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR ||!event.getCurrentItem().hasItemMeta()) {
                player.closeInventory();
                return;
            }
            switch (event.getCurrentItem().getType()) {
            case EGG:
                player.closeInventory();
                break;
               
            default:
                player.closeInventory();
                break;
            }       
          
        }
        @EventHandler
        public void onPlayerJoinEvent(PlayerJoinEvent event) {
            event.getPlayer().sendMessage(ChatColor.DARK_RED + "Welcome!");
          
          
        }
        public static Inventory openInventory(){
            Inventory inv1 = Bukkit.createInventory(null,9);
            ItemStack Dragon = new ItemStack (Material.EGG);
            ItemMeta DragonMeta = Dragon.getItemMeta();
          
            DragonMeta.setDisplayName(ChatColor.DARK_PURPLE + "Buy Egg, Cost: [24Diamonds]");
            Dragon.setItemMeta(DragonMeta);
            return inv1;
      
    }
    }
       
    can anyone tell me why it is not working.
     
    Last edited by a moderator: Jun 2, 2015
  10. Offline

    bwfcwalshy Retired Staff

    It was in the same class at the time of that post (or it seemed like it (I was in a rush while looking at it))
     
  11. Offline

    nverdier

    Your point? What's wrong with that?
     
  12. Offline

    bwfcwalshy Retired Staff

    @nverdier No point having a static when it is being used in the same class in a non static method.
     
  13. Offline

    CraterHater

    Can you tell me whats wrong with the two classes above?
     
  14. Offline

    nverdier

    If it doesn't modify the state of the object or use any instance variables, then there's no point not having it static.

    Anyhow, getting offtopic. If you wish we can continue this elsewhere.
     
    Last edited by a moderator: Jun 2, 2015
  15. Offline

    CraterHater

    I changed it a bit, compressed it into one class still isn't working. It isn't opening up the inventory when you click on the dragon egg. It is not giving errors.

    Code:
    package First;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    public class first extends JavaPlugin implements Listener{
      
      
      
        private static final Inventory q = null;
        @EventHandler
         public void onDeath(PlayerDeathEvent event) {
             Player player = event.getEntity();
             player.getInventory().clear();
             player.getInventory().addItem(new ItemStack(Material.WATCH));
         }
      
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
          
        }
        private void openGUI(Player player) {
            Inventory inv = Bukkit.createInventory(null, 9, ChatColor.DARK_RED + "Server Menu");
          
            ItemStack survival = new ItemStack (Material.DIAMOND_SWORD);
            ItemMeta survivalMeta = survival.getItemMeta();
            ItemStack creative = new ItemStack (Material.DRAGON_EGG);
            ItemMeta creativeMeta = creative.getItemMeta();
          
            survivalMeta.setDisplayName(ChatColor.DARK_BLUE + "PvpArena");
            survival.setItemMeta(survivalMeta);
          
            creativeMeta.setDisplayName(ChatColor.DARK_GREEN + "Mount Shop");
            creative.setItemMeta(creativeMeta);
          
            inv.setItem(3, survival);
            inv.setItem(5, creative);
          
            player.openInventory(inv);
        }
      
      
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            if(!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Server Menu"))
                    return;
            Player player = (Player) event.getWhoClicked();
            event.setCancelled(true);
            if(event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR ||!event.getCurrentItem().hasItemMeta()) {
                player.closeInventory();
                return;
            }
            switch (event.getCurrentItem().getType()) {
            case DIAMOND_SWORD:
                Location loc = new Location(Bukkit.getWorld("WarpPvp"), 0, 100, 0);
                player.teleport(loc);
                player.closeInventory();
                break;
            case DRAGON_EGG:
                player.closeInventory();
                player.openInventory(q);
                break;
            default:
                player.closeInventory();
                break;
            }
        }
      
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            event.getPlayer().getInventory().clear();
            event.getPlayer().getInventory().addItem(new ItemStack(Material.WATCH));
          
        }
      
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            Action a = event.getAction();
            ItemStack is = event.getItem();
          
            if(a == Action.PHYSICAL ||  is == null ||  is.getType()==Material.AIR)
                return;
          
            if(is.getType()==Material.WATCH)
                openGUI(event.getPlayer());
              
          
        }
        @EventHandler
        public void onPlayerJoinEvent(PlayerJoinEvent event) {
            event.getPlayer().sendMessage(ChatColor.DARK_RED + "Welcome!");
          
          
        }
      
        @EventHandler
        public void openGUI1(Player player) {
            Inventory q = Bukkit.createInventory(null, 9, ChatColor.DARK_RED + "Mount Menu");
          
            ItemStack Dragon = new ItemStack (Material.DRAGON_EGG);
            ItemMeta DragonMeta = Dragon.getItemMeta();
           
            DragonMeta.setDisplayName(ChatColor.DARK_BLUE + "Buy egg, Cost: [24 Diamonds]");
            Dragon.setItemMeta(DragonMeta);
           
            q.setItem(4, Dragon);
          
        }
        @EventHandler
        public void onInventoryClick1(InventoryClickEvent event) {
            if(!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Mount Menu"))
                    return;
            Player player = (Player) event.getWhoClicked();
            event.setCancelled(true);
            if(event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR ||!event.getCurrentItem().hasItemMeta()) {
                player.closeInventory();
                return;
            }
            switch (event.getCurrentItem().getType()) {
            case DRAGON_EGG:
                player.closeInventory();
                break;
            default:
                player.closeInventory();
                break;
    }
        }
    }
       
     
  16. Offline

    87pen

    @CraterHater
    Are you just trying to make it so when someone clicks a dragon egg in the watch menu it opens up a different menu?
    If so this is the simplest way I see doing it,
    Code:
    package me.kowagatte.multiplemenus;
    
    import java.util.Arrays;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    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 org.bukkit.material.MaterialData;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class MultipleMenus extends JavaPlugin implements Listener{
      
        public void onEnable(){
            Bukkit.getPluginManager().registerEvents(this, this);
        }
      
        @EventHandler
        public void onClockRightClick(PlayerInteractEvent e){
            Player p = (Player)e.getPlayer();
            if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
                if(e.getItem() != null && e.getItem().equals(new ItemStack(Material.WATCH))){
                    Inventory inv = Bukkit.createInventory(null, 9, "Main menu");
                  
                    ItemStack next = createItem("Next Page", "Scroll to the next page!", Material.GLASS, 1);
                  
                    inv.setItem(8, next);
              
                    p.openInventory(inv);
                }
            }
        }
      
          public ItemStack createItem(String name, String lore, Material m, int amount){
                ItemStack i = new MaterialData(m).toItemStack(amount);
                ItemMeta im = i.getItemMeta();
                im.setDisplayName(name);
                im.setLore(Arrays.asList(new String[] { lore }));
                i.setItemMeta(im);
                return i;
              }
        
          @EventHandler
          public void onInventoryClick(InventoryClickEvent e){
              Player p = (Player)e.getWhoClicked();
              if(e.getInventory().getName().equalsIgnoreCase("Main menu")){
                  if(e.getCurrentItem() != null){
                      if(e.getCurrentItem().getItemMeta().getDisplayName().equals("Next Page")){
                            Inventory inv = Bukkit.createInventory(null, 9, "Second menu");
                            e.setCancelled(true);
                            p.closeInventory();
                            p.openInventory(inv);
                      }
                  }
              }
          }
    
    }
    
     
    Last edited: Jun 9, 2015
  17. Offline

    CraterHater

    Thanks
     
Thread Status:
Not open for further replies.

Share This Page