Jikoo / OpenInv

Open anyone's inventory as a chest, real-time!
GNU General Public License v3.0
119 stars 41 forks source link

isAnySilentContainer() performance problems due to use of block state snapshots #233

Closed NewwindServer closed 3 months ago

NewwindServer commented 3 months ago

A player with no permissions can lag/crash a server that is running OpenInv, simply by rapidly right clicking a chest which has a lot of NBT (i.e full of shulkers)

image

This is because OpenInv calls getState() on Block which copies the full NBT of the block entity each time to create a snapshot of the block state.

Luckily, paper added an override which allows us to pass in the boolean parameter useSnapshot=false to disable taking snapshots of the block entity, which aren't being used in the first place.

 /**
     * Captures the current state of this block. You may then cast that state
     * into any accepted type, such as Furnace or Sign.
     * <p>
     * The returned object will never be updated, and you are not guaranteed
     * that (for example) a sign is still a sign after you capture its state.
     *
     * @return BlockState with the current state of this block.
     */
    @NotNull
    BlockState getState();

    // Paper start
    /**
     * @see #getState() optionally disables use of snapshot, to operate on real block data
     * @param useSnapshot if this block is a TE, should we create a fully copy of the TileEntity
     * @return BlockState with the current state of this block
     */
    @NotNull
    BlockState getState(boolean useSnapshot);
    // Paper end