Custom inventory UI

Discussion in 'Plugin Development' started by Peepeepoopoomantime, Sep 20, 2019.

Thread Status:
Not open for further replies.
  1. So, I have a custom inventory UI but I cant figure out how to make it so the players cant move any item in either inventories while its open, how would I go about doing this?
    Code:
    Public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    
    if (!(sender.instanceof Player)) {
    sender.sendMessage("Console cant do that");
    return true;
    }
    Player p = (Player) sender;
    Inventory inv = Bukkit.createInventory(null, 18, "Oop");
    
    ItemStack Oopo = new ItemStack(Material.STAINED_GLASS_PANE,1,
    (short) 1)
    ItemMeta OopoMeta = Oopo.getItemMeta();
    Oopo.setItemMeta(OopoMeta)
    
    inv.setItem(0, Oopo);
    p.openInventory(inv);
    
    return true;
    }
    }
    
     
    Last edited: Sep 20, 2019
  2. Offline

    timtower Administrator Administrator Moderator

  3. I edited my message so it includes the code now
     
  4. Offline

    timtower Administrator Administrator Moderator

    Do you handle events for it?
     
  5. What do you mean handle events?
     
  6. Offline

    timtower Administrator Administrator Moderator

    Any method that uses @EventHandler with inventory stuff.
     
  7. I did before but I removed it
     
  8. Offline

    KarimAKL

    @Peepeepoopoomantime You have to listen to the InventoryClickEvent, and then cancel it if it's your custom inventory.
     
  9. How do I specify which inventory its in?
     
  10. Offline

    KarimAKL

    @Peepeepoopoomantime Give the inventory a custom name, then check if the inventory has that name.
     
  11. How
     
  12. Offline

    wand555

    Get the open inventory and then the title and then check if it's the one you gave it earlier.
     
  13. Offline

    KarimAKL

    @wand555 That's only for <1.14, if it's >=1.14 you'll have to get the InventoryView from the event.
     
  14. Offline

    wand555

    @KarimAKL Wait, so player.getOpenInventory().getTitle() doesn't work anymore?
    I swear I used it in 1.14 before.
     
  15. Offline

    KarimAKL

    @wand555 It does, getOpenInventory() returns an InventoryView, not the Inventory.
     
Thread Status:
Not open for further replies.

Share This Page