From 43a5b856a8090dd82b8dae9c85708656ccdfb4f7 Mon Sep 17 00:00:00 2001 From: CCpcalvin Date: Thu, 24 Aug 2023 18:22:15 +0800 Subject: [PATCH] Use deepcopy in `Entity.Clone` --- lib/src/basic/types/area.dart | 2 +- lib/src/basic/types/entity.dart | 3 ++- pubspec.yaml | 1 + test/entity_clone_test.dart | 22 ++++++++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 test/entity_clone_test.dart diff --git a/lib/src/basic/types/area.dart b/lib/src/basic/types/area.dart index f5d3346..ca976a8 100644 --- a/lib/src/basic/types/area.dart +++ b/lib/src/basic/types/area.dart @@ -67,7 +67,7 @@ class Area { dz = (loc2.z - loc1.z).abs(); } - Map getRanges() { + Map getRanges() { var ret = {}; ret['x'] = loc1.x; ret['y'] = loc1.y; diff --git a/lib/src/basic/types/entity.dart b/lib/src/basic/types/entity.dart index 48c19c6..b04a544 100644 --- a/lib/src/basic/types/entity.dart +++ b/lib/src/basic/types/entity.dart @@ -1,6 +1,7 @@ // ignore_for_file: non_constant_identifier_names import 'package:objd/core.dart'; +import 'package:deep_collection/deep_collection.dart'; export 'entities.dart'; abstract class EntityClass { @@ -287,7 +288,7 @@ class Entity extends GsonValue implements EntityClass { Entity.clone(Entity ent) : selector = ent.selector, playerName = ent.playerName, - arguments = Map.from(ent.arguments); + arguments = ent.arguments.deepCopy(); /// Entity is an util class to convert an argument list into the Minecraft Entity format(@p...) Entity({ diff --git a/pubspec.yaml b/pubspec.yaml index e3f7974..8e2f38b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,6 +11,7 @@ environment: dependencies: ansicolor: ^2.0.1 archive: ^3.3.7 + deep_collection: ^1.0.2 gson: ^0.1.6-dev dev_dependencies: lints: ^2.1.1 diff --git a/test/entity_clone_test.dart b/test/entity_clone_test.dart new file mode 100644 index 0000000..64cf2ae --- /dev/null +++ b/test/entity_clone_test.dart @@ -0,0 +1,22 @@ +import 'package:objd/core.dart'; +import 'package:test/test.dart'; + +import 'test_widget.dart'; + +void main() { + group('Entity Clone', () { + Entity newEntity = Entity(tags: ['test']); + Entity clonedEntity = newEntity.copyWith(tags: ['testCloned']); + + command( + 'Original Entity', + Execute.as(newEntity, children: [Say("hi")]), + 'execute as @e[tag=test] run say hi', + ); + command( + 'Cloned Entity', + Execute.as(clonedEntity, children: [Say("hi")]), + 'execute as @e[tag=test,tag=testCloned] run say hi', + ); + }); +}