Get inventory title?

Discussion in 'Plugin Development' started by ScottDurkin_, Oct 7, 2019.

  1. Offline


    Hi all,

    Working on a plugin and I require a chest inventory title, but for some reason the option of get title is not showing?


    Any ideas?
  2. Offline


    Only InventoryViews do have titles. Try item#getCustomName()
  3. Offline


    Doesn't seem to work at all..
  4. Offline


    What happens? Could you post your current code?
  5. Offline


    Here you go.

        public void OnChestPlace(BlockPlaceEvent e)
            Chest chest = (Chest)e.getBlock();
  6. Offline



    Sorry about that
    ScottDurkin_ likes this.
  7. Online


    @ScottDurkin_ The block isn't neccessarily a chest, you should check if it is.
    ScottDurkin_ likes this.
  8. Offline


    1. As @robertlit said, you should check if the block placed is a chest, before casting it to Chest.
    2. You should check and cast the block's BlockState to Chest, not the block itself.
    3. '#' isn't used in Java, i think it comes from URL anchors; whenever someone types '#', just replace it with a '.' (if that's appropriate there)
    DerDonut likes this.
  9. Offline


    Thanks everyone for the help.

    Just had a question on another snippet of code.
    I am trying to cancel the event of opening a chest then sending packets to the player of the chest opening without actually seeing the inventory.

    Here is the code:
        public void onInventoryOpen(InventoryOpenEvent e)
            Player player = (Player)e.getPlayer();
            if(e.getView().getTitle().equals(m_Main.Format("&c&lMEGA &6&lMystery Box")))
                OpenChestPacket(m_ChestLocation, player);
                player.sendMessage(m_Main.Format("&cYou tried to open a mystery crate with no key?"));
        public void OpenChestPacket(Location chest, Player player)
            BlockPosition pos = new BlockPosition(chest.getBlockX(), chest.getBlockY(), chest.getBlockZ());
            PacketPlayOutBlockAction packet = new PacketPlayOutBlockAction(pos, Blocks.CHEST, 1, 1);
            ((CraftPlayer) m_Player).getHandle().playerConnection.sendPacket(packet);

    The m_ChestLocation get's set when placing the chest down.

    I solved this by using a PlayerInteractEvent.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Oct 8, 2019

Share This Page