From b871eb3d54627ec6211604aefde4724879bbeb46 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Thu, 6 Aug 2020 14:26:27 -0400 Subject: [PATCH] Fix data watcher cloning in 1.16 Fixes #925 --- .../protocol/wrappers/WrappedDataWatcher.java | 11 ++++++-- .../protocol/BukkitInitialization.java | 26 +++++++++++++++++-- .../wrappers/WrappedDataWatcherTest.java | 10 +++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/comphenix/protocol/wrappers/WrappedDataWatcher.java b/src/main/java/com/comphenix/protocol/wrappers/WrappedDataWatcher.java index 6321a105..5122cf48 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/WrappedDataWatcher.java +++ b/src/main/java/com/comphenix/protocol/wrappers/WrappedDataWatcher.java @@ -35,6 +35,7 @@ import com.google.common.base.Optional; import com.google.common.collect.ImmutableBiMap; import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; import org.bukkit.entity.Entity; import org.bukkit.inventory.ItemStack; @@ -132,7 +133,8 @@ public class WrappedDataWatcher extends AbstractWrapper implements Iterable worlds = Collections.singletonList(world); + when(mockedServer.getWorlds()).thenReturn(worlds); + // Inject this fake server Bukkit.setServer(mockedServer); } diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java index 473a1502..fd0fc25d 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java @@ -104,4 +104,14 @@ public class WrappedDataWatcherTest { watcher.setObject(0, serializer, 1); assertTrue(watcher.hasIndex(0)); } + + @Test + public void testDeepClone() { + WrappedDataWatcher watcher = new WrappedDataWatcher(); + watcher.setObject(0, Registry.get(Integer.class), 1); + + WrappedDataWatcher cloned = watcher.deepClone(); + assertEquals(1, cloned.asMap().size()); + assertEquals(1, (Object) cloned.getInteger(0)); + } }