4747public class ChangeSetExtent extends AbstractDelegateExtent {
4848
4949 private final ChangeSet changeSet ;
50+ private boolean enabled ;
5051
5152 /**
5253 * Create a new instance.
@@ -55,31 +56,65 @@ public class ChangeSetExtent extends AbstractDelegateExtent {
5556 * @param changeSet the change set
5657 */
5758 public ChangeSetExtent (Extent extent , ChangeSet changeSet ) {
59+ this (extent , changeSet , true );
60+ }
61+
62+ /**
63+ * Create a new instance.
64+ *
65+ * @param extent the extent
66+ * @param changeSet the change set
67+ * @param enabled if the extent is enabled
68+ */
69+ public ChangeSetExtent (Extent extent , ChangeSet changeSet , boolean enabled ) {
5870 super (extent );
5971 checkNotNull (changeSet );
6072 this .changeSet = changeSet ;
73+ this .enabled = true ;
74+ }
75+
76+ /**
77+ * If this extent is enabled and should perform change tracking.
78+ *
79+ * @return if enabled
80+ */
81+ public boolean isEnabled () {
82+ return this .enabled ;
83+ }
84+
85+ /**
86+ * Sets whether this extent is enabled and should perform change tracking.
87+ *
88+ * @param enabled whether to enable
89+ */
90+ public void setEnabled (boolean enabled ) {
91+ this .enabled = enabled ;
6192 }
6293
6394 @ Override
6495 public <B extends BlockStateHolder <B >> boolean setBlock (BlockVector3 location , B block ) throws WorldEditException {
65- BaseBlock previous = getFullBlock (location );
66- changeSet .add (new BlockChange (location , previous , block ));
96+ if (enabled ) {
97+ BaseBlock previous = getFullBlock (location );
98+ changeSet .add (new BlockChange (location , previous , block ));
99+ }
67100 return super .setBlock (location , block );
68101 }
69102
70103 @ Override
71104 public boolean setBiome (BlockVector3 position , BiomeType biome ) {
72- BiomeType previous = getBiome (position );
73- changeSet .add (new BiomeChange3D (position , previous , biome ));
105+ if (enabled ) {
106+ BiomeType previous = getBiome (position );
107+ changeSet .add (new BiomeChange3D (position , previous , biome ));
108+ }
74109 return super .setBiome (position , biome );
75110 }
76111
77112 @ Nullable
78113 @ Override
79114 public Entity createEntity (Location location , BaseEntity state ) {
80115 Entity entity = super .createEntity (location , state );
81- if (entity != null ) {
82- changeSet .add (new EntityCreate (location , entity . getState () , entity ));
116+ if (enabled && entity != null ) {
117+ changeSet .add (new EntityCreate (location , state , entity ));
83118 }
84119 return entity ;
85120 }
@@ -89,7 +124,7 @@ public Entity createEntity(Location location, BaseEntity state) {
89124 @ Nullable
90125 public Entity createEntity (Location location , BaseEntity state , UUID uuid ) {
91126 Entity entity = super .createEntity (location , state , uuid );
92- if (entity != null ) {
127+ if (enabled && entity != null ) {
93128 changeSet .add (new EntityCreate (location , entity .getState (), entity ));
94129 }
95130 return entity ;
@@ -107,6 +142,9 @@ public List<? extends Entity> getEntities(Region region) {
107142 }
108143
109144 private List <? extends Entity > wrapEntities (List <? extends Entity > entities ) {
145+ if (!enabled ) {
146+ return entities ;
147+ }
110148 List <Entity > newList = new ArrayList <>(entities .size ());
111149 for (Entity entity : entities ) {
112150 newList .add (new TrackedEntity (entity ));
0 commit comments