24
24
import com .velocitypowered .proxy .util .except .QuietDecoderException ;
25
25
import io .netty .buffer .ByteBuf ;
26
26
27
+ import java .util .Arrays ;
28
+ import java .util .Objects ;
29
+
27
30
public class KnownPacksPacket implements MinecraftPacket {
28
31
29
32
private static final int MAX_LENGTH_PACKS = Integer .getInteger ("velocity.max-known-packs" , 64 );
@@ -36,6 +39,10 @@ public KnownPacksPacket() {
36
39
packs = new KnownPack [0 ];
37
40
}
38
41
42
+ public KnownPacksPacket (KnownPack [] packs ) {
43
+ this .packs = packs ;
44
+ }
45
+
39
46
@ Override
40
47
public void decode (ByteBuf buf , ProtocolUtils .Direction direction ,
41
48
ProtocolVersion protocolVersion ) {
@@ -68,6 +75,17 @@ public boolean handle(MinecraftSessionHandler handler) {
68
75
return handler .handle (this );
69
76
}
70
77
78
+ public KnownPack [] getPacks () {
79
+ return packs ;
80
+ }
81
+
82
+ @ Override
83
+ public String toString () {
84
+ return "KnownPacksPacket{" +
85
+ "packs=" + Arrays .toString (packs ) +
86
+ '}' ;
87
+ }
88
+
71
89
public record KnownPack (String namespace , String id , String version ) {
72
90
private static KnownPack read (ByteBuf buf ) {
73
91
return new KnownPack (ProtocolUtils .readString (buf ), ProtocolUtils .readString (buf ), ProtocolUtils .readString (buf ));
@@ -78,5 +96,26 @@ private void write(ByteBuf buf) {
78
96
ProtocolUtils .writeString (buf , id );
79
97
ProtocolUtils .writeString (buf , version );
80
98
}
99
+
100
+ @ Override
101
+ public boolean equals (Object o ) {
102
+ if (o == null || getClass () != o .getClass ()) return false ;
103
+ KnownPack knownPack = (KnownPack ) o ;
104
+ return Objects .equals (id , knownPack .id ) && Objects .equals (version , knownPack .version ) && Objects .equals (namespace , knownPack .namespace );
105
+ }
106
+
107
+ @ Override
108
+ public int hashCode () {
109
+ return Objects .hash (namespace , id , version );
110
+ }
111
+
112
+ @ Override
113
+ public String toString () {
114
+ return "KnownPack{" +
115
+ "namespace='" + namespace + '\'' +
116
+ ", id='" + id + '\'' +
117
+ ", version='" + version + '\'' +
118
+ '}' ;
119
+ }
81
120
}
82
121
}
0 commit comments