#639: Deep clone itemmetas persistent container on clone
After this commit, spigot now creates a deep copy of the itemmeta's persistent data container when the itemmeta instance is cloned. This change fixes the bug that, after cloning itemmeta, the container instance the cloned meta would point to was equal to the original one. This resulted in two itemmeta instances sharing a single persistent container. By: Bjarne Koll <LynxPlay101@gmail.com>
This commit is contained in:
@@ -310,4 +310,20 @@ public class PersistentDataContainerTest extends AbstractTestingBase {
|
||||
return primitive;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItemMetaClone() {
|
||||
ItemMeta itemMeta = createNewItemMeta();
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
itemMeta.getPersistentDataContainer().set(VALID_KEY, PersistentDataType.STRING, "notch");
|
||||
|
||||
ItemMeta clonedMeta = itemMeta.clone();
|
||||
PersistentDataContainer clonedContainer = clonedMeta.getPersistentDataContainer();
|
||||
|
||||
assertNotSame(container, clonedContainer);
|
||||
assertEquals(container, clonedContainer);
|
||||
|
||||
clonedContainer.set(VALID_KEY, PersistentDataType.STRING, "dinnerbone");
|
||||
assertNotEquals(container, clonedContainer);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user