Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-287

Chest "Lock" tag doesn't work as intended.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • No plugins required, just spigot or craftbukkit any 1.8 version.

      Will keep this simple, as I already have the fix but not fully up to date with submitting a patch to NMS code.

      You can lock a chest no problem you can open the locked chest with the correctly name item. The bug is if you try to open the chest without a correctly named item, the chest animation starts and the chest stays open, BUT the inventory isn't shown to the player, as expected. This has been like it since release but never got round to reporting it my bad.

      I decided in this case it was quicker for me to show you the code causing the issue than somebody explaining how to fix a patch. I have fully tested the fix and it works, when you see the tiny change that fixes it your see why I am posting it.

      Keeping it simple, logic is just in the wrong order, the Inventory open event is called THEN its checks to see if it was a locked chest, hence the describe out come above,.

      The class can be found in craftbukkit or spigot source in the package net.minecraft.server EntityPlayer.java . Method starts at line 633 here is the part with the logic order issues, I won't insult you and explain it you see it as soon as you read it.

      public void openContainer(IInventory iinventory) {
              // CraftBukkit start - Inventory open hook
              Container container;
              if (iinventory instanceof ITileEntityContainer) {
                  container = ((ITileEntityContainer)iinventory).createContainer(this.inventory, this);
              } else {
                  container = new ContainerChest(this.inventory, iinventory, this);
              }
              container = CraftEventFactory.callInventoryOpenEvent(this, container);
              if (container == null) {
                  return;
              }
              // CraftBukkit end
              if (this.activeContainer != this.defaultContainer) {
                  this.closeInventory();
              }
      
              if (iinventory instanceof ITileInventory) {
                  ITileInventory itileinventory = (ITileInventory) iinventory;
      
                  if (itileinventory.q_() && !this.a(itileinventory.i()) && !this.v()) {
                      this.playerConnection.sendPacket(new PacketPlayOutChat(new ChatMessage("container.isLocked", new Object[] { iinventory.getScoreboardDisplayName()}), (byte) 2));
                      this.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect("random.door_close", this.locX, this.locY, this.locZ, 1.0F, 1.0F));
                      return;
                  }
              }
      

      Thanks for all your hard work.

      Regards
      relicum

      .

            Thinkofdeath Thinkofname
            Relicum Chris Lutte
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: