18
18
import com .comphenix .protocol .wrappers .WrappedDataWatcher .Registry ;
19
19
import com .comphenix .protocol .wrappers .WrappedDataWatcher .Serializer ;
20
20
import com .comphenix .protocol .wrappers .WrappedDataWatcher .WrappedDataWatcherObject ;
21
+
21
22
import net .minecraft .world .entity .projectile .EntityEgg ;
22
23
import org .bukkit .craftbukkit .v1_20_R4 .entity .CraftEgg ;
23
24
import org .bukkit .craftbukkit .v1_20_R4 .entity .CraftEntity ;
25
+ import org .bukkit .entity .Entity ;
24
26
import org .junit .jupiter .api .BeforeAll ;
25
27
import org .junit .jupiter .api .Disabled ;
26
28
import org .junit .jupiter .api .Test ;
33
35
* @author dmulloy2
34
36
*/
35
37
public class WrappedDataWatcherTest {
38
+ private static Entity mockEntity ;
36
39
37
40
@ BeforeAll
38
41
public static void prepare () {
39
42
BukkitInitialization .initializeAll ();
43
+
44
+ EntityEgg nmsEgg = new EntityEgg (null , 0 , 0 , 0 );
45
+ mockEntity = new CraftEgg (null , nmsEgg );
40
46
}
41
47
42
48
@ Test
43
- @ Disabled // TODO -- need to fix data watchers
49
+ @ Disabled // TODO -- SETTER is null
44
50
public void testBytes () {
45
- // Create a fake lightning strike and get its watcher
46
- EntityEgg nmsEgg = new EntityEgg (null , 0 , 0 , 0 );
47
- CraftEntity craftEgg = new CraftEgg (null , nmsEgg );
48
- WrappedDataWatcher wrapper = WrappedDataWatcher .getEntityWatcher (craftEgg );
51
+ WrappedDataWatcher watcher = WrappedDataWatcher .getEntityWatcher (mockEntity );
49
52
50
- WrappedWatchableObject watchable = wrapper .getWatchableObject (0 );
53
+ WrappedWatchableObject watchable = watcher .getWatchableObject (0 );
51
54
WrappedDataWatcherObject object = watchable .getWatcherObject ();
52
55
53
56
// Make sure the serializers work
54
57
assertEquals (object .getSerializer (), Registry .get (Byte .class ));
55
58
56
59
// Make sure we can set existing objects
57
- wrapper .setObject (0 , (byte ) 21 );
58
- assertEquals (21 , (byte ) wrapper .getByte (0 ));
60
+ watcher .setObject (0 , (byte ) 21 );
61
+ assertEquals (21 , (byte ) watcher .getByte (0 ));
59
62
}
60
63
61
64
@ Test
62
- @ Disabled // TODO -- need to fix data watchers
65
+ @ Disabled // TODO -- SETTER is null
63
66
public void testStrings () {
64
- WrappedDataWatcher wrapper = new WrappedDataWatcher ( );
67
+ WrappedDataWatcher watcher = WrappedDataWatcher . getEntityWatcher ( mockEntity );
65
68
66
69
// Make sure we can create watcher objects
67
70
Serializer serializer = Registry .get (String .class );
68
71
WrappedDataWatcherObject object = new WrappedDataWatcherObject (3 , serializer );
69
- wrapper .setObject (object , "Test" );
72
+ watcher .setObject (object , "Test" );
70
73
71
- assertEquals (wrapper .getString (3 ), "Test" );
74
+ assertEquals (watcher .getString (3 ), "Test" );
72
75
}
73
76
74
77
@ Test
75
- @ Disabled // TODO -- need to fix data watchers
78
+ @ Disabled // TODO -- need a better example for floats
76
79
public void testFloats () {
77
80
WrappedDataWatcher wrapper = new WrappedDataWatcher ();
78
81
@@ -85,35 +88,28 @@ public void testFloats() {
85
88
}
86
89
87
90
@ Test
88
- @ Disabled // TODO -- need to fix data watchers
89
91
public void testSerializers () {
90
92
Serializer blockPos = Registry .get (net .minecraft .core .BlockPosition .class , false );
91
93
Serializer optionalBlockPos = Registry .get (net .minecraft .core .BlockPosition .class , true );
92
94
assertNotSame (blockPos , optionalBlockPos );
93
95
94
- // assertNull(Registry.get(ItemStack.class, false));
96
+ // assertNull(Registry.get(ItemStack.class, false)); // TODO
95
97
assertNotNull (Registry .get (UUID .class , true ));
96
98
}
97
99
98
100
@ Test
99
- @ Disabled // TODO -- need to fix data watchers
100
101
public void testHasIndex () {
101
- WrappedDataWatcher watcher = new WrappedDataWatcher ();
102
- Serializer serializer = Registry .get (Integer .class );
103
-
104
- assertFalse (watcher .hasIndex (0 ));
105
- watcher .setObject (0 , serializer , 1 );
106
- assertTrue (watcher .hasIndex (0 ));
102
+ WrappedDataWatcher watcher = WrappedDataWatcher .getEntityWatcher (mockEntity );
103
+ assertTrue (watcher .hasIndex (1 ));
104
+ assertFalse (watcher .hasIndex (9999 ));
107
105
}
108
106
109
107
@ Test
110
- @ Disabled // TODO -- need to fix data watchers
111
108
public void testDeepClone () {
112
- WrappedDataWatcher watcher = new WrappedDataWatcher ();
113
- watcher .setObject (0 , Registry .get (Integer .class ), 1 );
114
-
109
+ WrappedDataWatcher watcher = WrappedDataWatcher .getEntityWatcher (mockEntity );
115
110
WrappedDataWatcher cloned = watcher .deepClone ();
116
- assertEquals (1 , cloned .asMap ().size ());
117
- assertEquals (1 , (Object ) cloned .getInteger (0 ));
111
+
112
+ assertEquals (watcher .size (), cloned .size ());
113
+ assertEquals (watcher .getObject (1 ), cloned .getObject (1 ));
118
114
}
119
115
}
0 commit comments