Skip to content

Commit ba8d8a5

Browse files
committed
chore: split logic per platform
1 parent 2221b08 commit ba8d8a5

File tree

6 files changed

+417
-351
lines changed

6 files changed

+417
-351
lines changed

Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitQueueCoordinator.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
import java.util.ArrayList;
5454
import java.util.Collection;
55+
import java.util.Objects;
5556
import java.util.function.Consumer;
5657

5758
public class BukkitQueueCoordinator extends BasicQueueCoordinator {
@@ -210,8 +211,13 @@ public boolean enqueue() {
210211
BaseBlock block = getWorld().getBlock(blockVector3).toBaseBlock(tag);
211212
getWorld().setBlock(blockVector3, block, getSideEffectSet(SideEffectState.NONE));
212213
} catch (WorldEditException ignored) {
213-
StateWrapper sw = new StateWrapper(tag);
214-
sw.restoreTag(getWorld().getName(), blockVector3.getX(), blockVector3.getY(), blockVector3.getZ());
214+
StateWrapper.INSTANCE.restore(
215+
getWorld().getName(),
216+
blockVector3.getX(),
217+
blockVector3.getY(),
218+
blockVector3.getZ(),
219+
tag
220+
);
215221
}
216222
});
217223
}
@@ -295,9 +301,7 @@ private void setWorldBlock(int x, int y, int z, @NonNull BaseBlock block, @NonNu
295301
existing.setBlockData(blockData, false);
296302
if (block.hasNbtData()) {
297303
CompoundTag tag = block.getNbtData();
298-
StateWrapper sw = new StateWrapper(tag);
299-
300-
sw.restoreTag(existing);
304+
StateWrapper.INSTANCE.restore(existing, Objects.requireNonNull(tag));
301305
}
302306
}
303307
}

Bukkit/src/main/java/com/plotsquared/bukkit/queue/LimitedRegionWrapperQueue.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.bukkit.generator.LimitedRegion;
3535
import org.checkerframework.checker.nullness.qual.NonNull;
3636

37+
import java.util.Objects;
38+
3739
/**
3840
* Wraps a {@link LimitedRegion} inside a {@link com.plotsquared.core.queue.QueueCoordinator} so it can be written to.
3941
*
@@ -44,7 +46,6 @@ public class LimitedRegionWrapperQueue extends DelegateQueueCoordinator {
4446
private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + LimitedRegionWrapperQueue.class.getSimpleName());
4547

4648
private final LimitedRegion limitedRegion;
47-
private boolean useOtherRestoreTagMethod = false;
4849

4950
/**
5051
* @since 6.9.0
@@ -64,20 +65,11 @@ public boolean setBlock(final int x, final int y, final int z, @NonNull final Ba
6465
boolean result = setBlock(x, y, z, id.toImmutableState());
6566
if (result && id.hasNbtData()) {
6667
CompoundTag tag = id.getNbtData();
67-
StateWrapper sw = new StateWrapper(tag);
6868
try {
69-
if (useOtherRestoreTagMethod && getWorld() != null) {
70-
sw.restoreTag(getWorld().getName(), x, y, z);
71-
} else {
72-
sw.restoreTag(limitedRegion.getBlockState(x, y, z).getBlock());
73-
}
69+
StateWrapper.INSTANCE.restore(limitedRegion.getBlockState(x, y, z).getBlock(), Objects.requireNonNull(tag));
7470
} catch (IllegalArgumentException e) {
7571
LOGGER.error("Error attempting to populate tile entity into the world at location {},{},{}", x, y, z, e);
7672
return false;
77-
} catch (IllegalStateException e) {
78-
useOtherRestoreTagMethod = true;
79-
LOGGER.warn("IllegalStateException attempting to populate tile entity into the world at location {},{},{}. " +
80-
"Possibly on <=1.17.1, switching to secondary method.", x, y, z, e);
8173
}
8274
}
8375
return result;
@@ -113,9 +105,8 @@ public boolean setEntity(@NonNull final Entity entity) {
113105

114106
@Override
115107
public boolean setTile(final int x, final int y, final int z, @NonNull final CompoundTag tag) {
116-
StateWrapper sw = new StateWrapper(tag);
117108
try {
118-
return sw.restoreTag(limitedRegion.getBlockState(x, y, z).getBlock());
109+
return StateWrapper.INSTANCE.restore(limitedRegion.getBlockState(x, y, z).getBlock(), tag);
119110
} catch (IllegalArgumentException e) {
120111
LOGGER.error("Error attempting to populate tile entity into the world at location {},{},{}", x, y, z, e);
121112
return false;

Bukkit/src/main/java/com/plotsquared/bukkit/schematic/BukkitSchematicHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import com.sk89q.jnbt.CompoundTag;
2828
import org.checkerframework.checker.nullness.qual.NonNull;
2929

30+
import java.util.Objects;
31+
3032
/**
3133
* Schematic Handler.
3234
*/
@@ -39,8 +41,8 @@ public BukkitSchematicHandler(final @NonNull WorldUtil worldUtil, @NonNull Progr
3941
}
4042

4143
@Override
42-
public boolean restoreTile(QueueCoordinator queue, CompoundTag ct, int x, int y, int z) {
43-
return new StateWrapper(ct).restoreTag(queue.getWorld().getName(), x, y, z);
44+
public boolean restoreTile(QueueCoordinator queue, CompoundTag tag, int x, int y, int z) {
45+
return StateWrapper.INSTANCE.restore(Objects.requireNonNull(queue.getWorld()).getName(), x, y, z, tag);
4446
}
4547

4648
}

0 commit comments

Comments
 (0)