77import net .minestom .server .network .packet .server .common .PluginMessagePacket ;
88import net .minestom .server .network .player .PlayerConnection ;
99import net .minestom .server .utils .PacketSendingUtils ;
10- import net .minestom .server .utils .validate .Check ;
1110import org .jetbrains .annotations .NotNull ;
1211import org .jetbrains .annotations .Nullable ;
1312
1413import java .util .ArrayList ;
1514import java .util .Collection ;
1615import java .util .Collections ;
1716import java .util .List ;
17+ import java .util .Objects ;
1818
1919/**
2020 * BungeeCord Messaging interface.
@@ -95,7 +95,7 @@ static boolean isIdentifier(@Nullable String channel) {
9595 * @return the byte array containing the serialized message
9696 */
9797 static byte @ NotNull [] write (@ NotNull BungeeMessage message ) {
98- Check . notNull (message , "Message cannot be null" );
98+ Objects . requireNonNull (message , "Message cannot be null" );
9999 return switch (message ) {
100100 case BungeeRequest request -> writeRequest (request );
101101 case BungeeResponse response -> writeResponse (response );
@@ -112,7 +112,7 @@ static boolean isIdentifier(@Nullable String channel) {
112112 * @return the byte array containing the serialized request
113113 */
114114 static byte @ NotNull [] writeRequest (@ NotNull BungeeRequest request ) {
115- Check . notNull (request , "Request cannot be null" );
115+ Objects . requireNonNull (request , "Request cannot be null" );
116116 return NetworkBuffer .makeArray (BungeeRequest .SERIALIZER , request );
117117 }
118118
@@ -125,7 +125,7 @@ static boolean isIdentifier(@Nullable String channel) {
125125 * @throws IllegalStateException if there are leftover bytes in the buffer after reading the request
126126 */
127127 static @ NotNull BungeeRequest readRequest (byte @ NotNull [] bytes ) throws IllegalStateException {
128- Check . notNull (bytes , "Bytes cannot be null!" );
128+ Objects . requireNonNull (bytes , "Bytes cannot be null!" );
129129 return readRequest (NetworkBuffer .wrap (bytes , 0 , bytes .length ));
130130 }
131131
@@ -138,7 +138,7 @@ static boolean isIdentifier(@Nullable String channel) {
138138 * @throws IllegalStateException if there are leftover bytes in the buffer after reading the request
139139 */
140140 static @ NotNull BungeeRequest readRequest (@ NotNull NetworkBuffer buffer ) throws IllegalStateException {
141- Check . notNull (buffer , "Buffer cannot be null!" );
141+ Objects . requireNonNull (buffer , "Buffer cannot be null!" );
142142 return BungeeProtocol .read (buffer , BungeeRequest .SERIALIZER );
143143 }
144144
@@ -151,7 +151,7 @@ static boolean isIdentifier(@Nullable String channel) {
151151 * @return the byte array containing the serialized response
152152 */
153153 static byte @ NotNull [] writeResponse (@ NotNull BungeeResponse response ) {
154- Check . notNull (response , "Response cannot be null" );
154+ Objects . requireNonNull (response , "Response cannot be null" );
155155 return NetworkBuffer .makeArray (BungeeResponse .SERIALIZER , response );
156156 }
157157
@@ -163,7 +163,7 @@ static boolean isIdentifier(@Nullable String channel) {
163163 * @throws IllegalStateException if there are leftover bytes in the buffer after reading the request
164164 */
165165 static @ NotNull BungeeResponse readResponse (byte @ NotNull [] bytes ) throws IllegalStateException {
166- Check . notNull (bytes , "Bytes cannot be null!" );
166+ Objects . requireNonNull (bytes , "Bytes cannot be null!" );
167167 return readResponse (NetworkBuffer .wrap (bytes , 0 , bytes .length ));
168168 }
169169
@@ -176,7 +176,7 @@ static boolean isIdentifier(@Nullable String channel) {
176176 * @throws IllegalStateException if there are leftover bytes in the buffer after reading the request
177177 */
178178 static @ NotNull BungeeResponse readResponse (@ NotNull NetworkBuffer buffer ) throws IllegalStateException {
179- Check . notNull (buffer , "Buffer cannot be null!" );
179+ Objects . requireNonNull (buffer , "Buffer cannot be null!" );
180180 return BungeeProtocol .read (buffer , BungeeResponse .SERIALIZER );
181181 }
182182
@@ -191,7 +191,7 @@ static boolean isIdentifier(@Nullable String channel) {
191191 * @throws IllegalStateException if there are leftover bytes in the buffer after reading the request
192192 */
193193 static @ Nullable BungeeResponse readResponse (@ NotNull PlayerPluginMessageEvent event ) throws IllegalStateException {
194- Check . notNull (event , "Event cannot be null" );
194+ Objects . requireNonNull (event , "Event cannot be null" );
195195 if (!isIdentifier (event .getIdentifier ())) return null ;
196196 return readResponse (event .getMessage ());
197197 }
@@ -207,8 +207,8 @@ static boolean isIdentifier(@Nullable String channel) {
207207 * @param message the message to send
208208 */
209209 static void send (@ NotNull PlayerConnection connection , @ NotNull BungeeMessage message ) {
210- Check . notNull (connection , "Connection cannot be null" );
211- Check . notNull (message , "Message cannot be null" );
210+ Objects . requireNonNull (connection , "Connection cannot be null" );
211+ Objects . requireNonNull (message , "Message cannot be null" );
212212 connection .sendPacket (message .toPacket ());
213213 }
214214
@@ -222,8 +222,8 @@ static void send(@NotNull PlayerConnection connection, @NotNull BungeeMessage me
222222 * @param message the message to send
223223 */
224224 static void send (@ NotNull Audience audience , @ NotNull BungeeMessage message ) {
225- Check . notNull (audience , "Audience cannot be null" );
226- Check . notNull (message , "Message cannot be null" );
225+ Objects . requireNonNull (audience , "Audience cannot be null" );
226+ Objects . requireNonNull (message , "Message cannot be null" );
227227 PacketSendingUtils .sendPacket (audience , message .toPacket ());
228228 }
229229
@@ -236,9 +236,9 @@ static void send(@NotNull Audience audience, @NotNull BungeeMessage message) {
236236 * @throws IllegalArgumentException if the collection is empty
237237 */
238238 static void sendSingle (@ NotNull Collection <? extends Audience > audiences , @ NotNull BungeeMessage message ) {
239- Check . notNull (audiences , "Audiences cannot be null" );
240- Check . notNull (message , "Message cannot be null" );
241- Check . argCondition (audiences .isEmpty (), "Audiences cannot be empty" );
239+ Objects . requireNonNull (audiences , "Audiences cannot be null" );
240+ Objects . requireNonNull (message , "Message cannot be null" );
241+ if (audiences .isEmpty ()) throw new IllegalArgumentException ( "Audiences cannot be empty" );
242242 List <Audience > collection = new ArrayList <>(audiences );
243243 Collections .shuffle (collection );
244244 BungeeMessage .send (collection .getFirst (), message );
@@ -278,7 +278,7 @@ static void sendSingle(@NotNull Collection<? extends Audience> audiences, @NotNu
278278 * @param connection the player connection to send the message to
279279 */
280280 default void send (@ NotNull PlayerConnection connection ) {
281- Check . notNull (connection , "Connection cannot be null" );
281+ Objects . requireNonNull (connection , "Connection cannot be null" );
282282 BungeeMessage .send (connection , this );
283283 }
284284
@@ -291,7 +291,7 @@ default void send(@NotNull PlayerConnection connection) {
291291 * @param audience the audience to send the message
292292 */
293293 default void send (@ NotNull Audience audience ) {
294- Check . notNull (audience , "Audience cannot be null" );
294+ Objects . requireNonNull (audience , "Audience cannot be null" );
295295 BungeeMessage .send (audience , this );
296296 }
297297
@@ -305,8 +305,8 @@ default void send(@NotNull Audience audience) {
305305 * @throws IllegalArgumentException if the collection is empty
306306 */
307307 default void sendSingle (@ NotNull Collection <? extends Audience > audiences ) {
308- Check . notNull (audiences , "Audience cannot be null" );
309- Check . argCondition (audiences .isEmpty (), "Audiences cannot be empty" );
308+ Objects . requireNonNull (audiences , "Audience cannot be null" );
309+ if (audiences .isEmpty ()) throw new IllegalArgumentException ( "Audiences cannot be empty" );
310310 BungeeMessage .sendSingle (audiences , this );
311311 }
312312}
0 commit comments