Create Inventory

Discussion in 'Plugin Development' started by spacemoehre, Sep 21, 2014.

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

    spacemoehre

    How can I create an Inventory, that opens if I have an action with a specific item? Like on servers, where u can jump into other lobbys. Please do not write how to get the action or the ItemInHand. Just the line which opens such a inventory. I had this idea of setting a chest and open the inventory when the in the beginning described situation happens. But i think there just could be another way.
     
  2. Offline

    Skionz

    spacemoehre
    Code:
    player.openInventory(inventory);
     
  3. Offline

    SmooshCakez

    You can create an inventory with items in it and listen for InventoryClickEvent, then check if it was that item, and teleport them to the other lobby (using BungeeCord or whatever proxy you have that connects multiple servers). To open the inventory, Player.openInventory(Inventory);
     
  4. Offline

    CoolGuy2001

    spacemoehre
    Here is a fully working plugin's code. Have fun! :)
    Code:
    public class HatGUI extends JavaPlugin implements Listener
    {
            private Inventory hat;
         
            public void onEnable()
            {
                    getLogger().info("Enabled!");
                    getServer().getPluginManager().registerEvents(this, this);
            }
            public void setupInv()
            {
                    hat = getServer().createInventory(null, 9, ChatColor.RED + "Hat Menu");
                 
                    ItemStack RedItem = new ItemStack(Material.REDSTONE_BLOCK, 1);
            ItemMeta r = RedItem.getItemMeta();
            r.setDisplayName(ChatColor.RED + "Redstone Hat");
            r.setLore(Arrays.asList(ChatColor.RED + "Be A Redstoner!"));
            RedItem.setItemMeta(r);
            inv.addItem(RedItem);
            }
            @EventHandler
            public void onJoin(PlayerJoinEvent e)
            {
                    ItemStack joinItem = new ItemStack(Material.IRON_AXE, 1); // <--- Change that item
                    ItemMeta im = joinItem.getItemMeta();
                    im.setDisplayName(ChatColor.GREEN + "Hat Menu");
                    joinItem.setItemMeta(im);
                    Player p = e.getPlayer();
                    if(p.getInventory().contains(joinItem))
                    {
                            return;
                    } else if(!p.getInventory().contains(joinItem))
                    {
                            p.getInventory().setItem(1, joinItem);
                    }
            }
            @EventHandler
            public void onOpenMenu(PlayerInteractEvent e)
            {
                    Player p = e.getPlayer();
                    if(e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR)
                    {
                            if(p.getItemInhand().getItemMeta() == null) return;
                            if(p.getItemInhand() == null) return;
                            //Checking for correct item
                            if(p.getItemInhand().getItemMeta().getDisplayName().contains("Hat Menu"))
                            {
                                    setupInv();
                                    p.openInventory(hat);
                            }
                    }
            }
            @EventHandler
            public void onClick(InventoryClickEvent e)
            {
                    if(e.getWhoClicked() instanceof Player)
                    {
                            Player p = (Player) e.getWhoClicked();
                            setupInv();
                            if(e.getInventory().equals(hat))
                            {
                                    e.setCancelled(true);
                                    ItemStack i = e.getCurrentItem();
                                    p.getInventory().setHelmet(i);
                                    p.sendMessage("You have put on a new hat!");
                                    p.closeInventory();
                            }
                    }
            }
    }
    Not my code by the way, so sorry for messiness!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  5. Offline

    es359


    Ehh, Spoonfeed much...? CoolGuy2001
     
  6. Offline

    CoolGuy2001

    es359 Yeah, I a feeling nice today! Lol
     
    es359 likes this.
  7. Offline

    Gnat008

    CoolGuy2001
    It may seem nice, but it isn't usually helpful in the long run. ;)
     
  8. Offline

    CoolGuy2001

    Gnat008 I guess, well oops, I was bored.
     
  9. Offline

    Skionz

    He's right, it didn't help me. I used to be a major spoon food/feed begger (not sure if thats the right grammar :p)
     
  10. Offline

    ChipDev

    I still am..
    Code:java
    1. Spoon s = new Spoon(Material.COPPER);
    2. s.setEater(new OfflinePlayer("Kanss"));
    3. s.setFeeder(s.getEater());

    This is a spoon feed of how to create meh
     
    Skionz and bwfcwalshy like this.
Thread Status:
Not open for further replies.

Share This Page