mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
fix: preserve instance tag on #copy() (fix #112)
This commit is contained in:
parent
c0d3f01fa2
commit
5f49033842
@ -93,7 +93,7 @@ public abstract class Instance implements Block.Getter, Block.Setter,
|
||||
protected UUID uniqueId;
|
||||
|
||||
// instance custom data
|
||||
private final TagHandler tagHandler = TagHandler.newHandler();
|
||||
protected TagHandler tagHandler = TagHandler.newHandler();
|
||||
private final Scheduler scheduler = Scheduler.newScheduler();
|
||||
private final EventNode<InstanceEvent> eventNode;
|
||||
|
||||
|
@ -516,7 +516,8 @@ public class InstanceContainer extends Instance {
|
||||
public synchronized InstanceContainer copy() {
|
||||
InstanceContainer copiedInstance = new InstanceContainer(UUID.randomUUID(), getDimensionType());
|
||||
copiedInstance.srcInstance = this;
|
||||
copiedInstance.lastBlockChangeTime = lastBlockChangeTime;
|
||||
copiedInstance.tagHandler = this.tagHandler.copy();
|
||||
copiedInstance.lastBlockChangeTime = this.lastBlockChangeTime;
|
||||
for (Chunk chunk : chunks.values()) {
|
||||
final int chunkX = chunk.getChunkX();
|
||||
final int chunkZ = chunk.getChunkZ();
|
||||
|
@ -0,0 +1,28 @@
|
||||
package net.minestom.server.instance;
|
||||
|
||||
import net.minestom.server.tag.Tag;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
import net.minestom.server.world.DimensionTypeManager;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class InstanceContainerTest {
|
||||
|
||||
static {
|
||||
new DimensionTypeManager().addDimension(DimensionType.OVERWORLD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyPreservesTag() {
|
||||
var tag = Tag.String("test");
|
||||
var instance = new InstanceContainer(UUID.randomUUID(), DimensionType.OVERWORLD);
|
||||
instance.setTag(tag, "123");
|
||||
|
||||
var copyInstance = instance.copy();
|
||||
var result = copyInstance.getTag(tag);
|
||||
assertEquals("123", result);
|
||||
}
|
||||
}
|
@ -29,4 +29,25 @@ public class TagTransientTest {
|
||||
assertEquals("abcdef", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tagHandlerCopyPreservesTransient() {
|
||||
var tagHandler = TagHandler.newHandler();
|
||||
Tag<String> tag = Tag.Transient("a");
|
||||
tagHandler.setTag(tag, "abcdef");
|
||||
|
||||
var copyHandler = tagHandler.copy();
|
||||
var result = copyHandler.getTag(tag);
|
||||
assertEquals("abcdef", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asCompoundDoesNotPreserveTransient() {
|
||||
var tagHandler = TagHandler.newHandler();
|
||||
Tag<String> tag = Tag.Transient("a");
|
||||
tagHandler.setTag(tag, "abcdef");
|
||||
|
||||
var compound = tagHandler.asCompound();
|
||||
assertNull(compound.get("a"));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user