Inventory GUIs

Discussion in 'Plugin Development' started by DomThePotato, Apr 3, 2015.

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

    DomThePotato

    Hello,

    Hello. I will get right to it. Basically I want to make a kind of roleplay plugin for my friends and I to play with. So right now I am making the 'quit' command which as it would, allow you to quit your job. So because it looks cool, I am making and inventory GUI. Although the problem I have encountered isn't to do with forming the GUI.

    So this is what I have done:

    Code:
    @EventHandler
                    public void on(InventoryClickEvent e){
                   
                      if (!ChatColor.stripColor(e.getInventory().getName()).equalsIgnoreCase("Are you sure?")) {
                            e.setCancelled(true);
                          return;
                      }
                      Player p = (Player)e.getWhoClicked();
                      e.setCancelled(true);
                      if ((e.getCurrentItem().equals(null)) || (e.getCurrentItem().equals(Material.AIR)) || (!e.getCurrentItem().hasItemMeta())||e.getCurrentItem().equals(cancel.getItemMeta().equals(cancelmeta))){
                        p.closeInventory();
                          p.sendMessage("§3Cancelled operation.");
                        return;
                      }
    What I cannot get my head around, at all:

    I want it so that if they click on a cancel block then it will close the inventory. But my problem is I have tried so many methods but the inventory will just not close when I click cancel as many times I have tried.

    Code:
                   ItemStack cancel = new ItemStack(Material.STAINED_GLASS_PANE, 1, DyeColor.BLUE.getData());
            ItemMeta cancelmeta = cancel.getItemMeta();
    Code:
                    cancelmeta.setDisplayName("§1§lCancel");
                    List<String> clore = new ArrayList();
                    clore.add("§1Cancel your choice.");
                    cancelmeta.setLore(clore);
                    cancel.setItemMeta(cancelmeta);
    That is all the cancel stuff. I have tried so hard with it and I am losing patience with myself so sorry if some of this makes no sense.

    Thanks for looking at this post; Hope you can help! :D

    ~Dominic :D
     
  2. Offline

    Tecno_Wizard

    @DomThePotato, in the javadocs, the close inventory method CLEARLY states that closing an inventory inside of the inventory event WILL NOT WORK. You need a scheduler.
     
  3. Offline

    Zombie_Striker

    e.setcancelEvent(true);
    e.getPlayer().closeInventory();
     
  4. Offline

    caderape

    @DomThePotato
    Code:
    if ((e.getCurrentItem().equals(null)) || (e.getCurrentItem().equals(Material.AIR)) || (!e.getCurrentItem().hasItemMeta())||e.getCurrentItem().equals(cancel.getItemMeta().equals(cancelmeta))){
    i'm not sure the equals work like that. Use == for check if it's null. You cannot compare an itemstack and a material. It's e.getcurrentItem.getttype. And..

    e.getCurrentItem().equals(cancel.getItemMeta().equals(cancelmeta))

    what is that ?

    You should try something like this.
    Code:
    if (e.getcurrentItem() != null && e.getCurrentItem.getType() != Material.AIR && e.getCurrentItem().HasItemMeta()) {
    //code
     
  5. Offline

    WeeSkilz

    Another problem with your code is that if you try to interact with any item in any inventory other than the one named "Are you sure?" It won't work because you cancelled the event.
     
Thread Status:
Not open for further replies.

Share This Page