WorldEdit for Bukkit

WorldEdit for Bukkit

21M Downloads

`Int2BaseBlockMap` can contain 2 entries with a same key

emilyy-dev opened this issue ยท 2 comments

commented

WorldEdit Version

7.2.13

Platform Version

git-Paper-379, fabric-loader-0.14.11-1.19.3

Confirmations

  • I am using the most recent Minecraft release.
  • I am using a version of WorldEdit compatible with my Minecraft version.
  • I am using the latest or recommended version of my platform software.
  • I am NOT using a hybrid server, e.g. a server that combines Bukkit and Forge. Examples include Arclight, Mohist, and Cardboard.
  • I am NOT using a fork of WorldEdit, such as FastAsyncWorldEdit (FAWE) or AsyncWorldEdit (AWE)

Bug Description

Int2BaseBlockMap (accessible via BlockMap.createForBaseBlock()) is capable of containing at most two entries with the same key, one with a tile entity and another with a regular block.

Expected Behavior

There should be 0 or 1 entries for any given location.

Reproduction Steps

  1. Create a BlockMap via BlockMap.createForBaseBlock()
  2. Call put for any location as key, and as value a tile entity's BaseBlock
  3. Call put again with the same key but a regular block's BaseBlock as value
  4. Examining the map shows that there are two entries for that key, one for each block

Anything Else?

As far as I can tell this happens because the put method does not remove any potential entries from the uncommon map in the case the internal id is valid. I'd presume a fix for it could be something along the lines of

         int oldId = commonMap.put(key, internalId);
-        return assumeAsBlock(oldId);
+        return BlockStateIdAccess.isValidInternalId(oldId) ? assumeAsBlock(oldId) : uncommonMap.remove(key);

Although this (hopefully rightfully) assumes that only either the common map or the uncommon map will contain a key, but not both.
I tried to write some unit tests for put returning the previous value and a following get returning the new one but my computer turned into a potato upon building worldedit.

commented

This issue has been automatically marked as stale because it has not been fully confirmed. It will be closed if no further activity occurs. Thank you for your contributions.

commented

Closed by b8b8926