14
14
import com .comphenix .protocol .wrappers .BukkitConverters ;
15
15
import com .comphenix .protocol .wrappers .WrappedChatComponent ;
16
16
import com .comphenix .protocol .wrappers .WrappedGameProfile ;
17
+ import com .comphenix .protocol .wrappers .WrappedServerPing ;
18
+
17
19
import com .google .common .collect .ImmutableList ;
18
20
19
21
import org .bukkit .Bukkit ;
27
29
* Represents a server ping packet data.
28
30
* @author Kristian
29
31
*/
30
- public class LegacyServerPing extends AbstractWrapper implements ServerPingImpl {
32
+ public final class LegacyServerPing extends AbstractWrapper implements ServerPingImpl {
31
33
private static final Class <?> GAME_PROFILE = MinecraftReflection .getGameProfileClass ();
32
34
33
35
// For converting to the underlying array
@@ -132,32 +134,27 @@ public static LegacyServerPing fromJson(String json) {
132
134
133
135
/**
134
136
* Retrieve the message of the day.
135
- * @return The messge of the day.
137
+ * @return The message of the day.
136
138
*/
137
- public WrappedChatComponent getMotD () {
138
- return WrappedChatComponent .fromHandle (DESCRIPTION .get (handle ));
139
+ @ Override
140
+ public Object getMotD () {
141
+ return DESCRIPTION .get (handle );
139
142
}
140
143
141
144
/**
142
145
* Set the message of the day.
143
146
* @param description - message of the day.
144
147
*/
148
+ @ Override
145
149
public void setMotD (Object description ) {
146
150
DESCRIPTION .set (handle , description );
147
151
}
148
152
149
- /**
150
- * Set the message of the day.
151
- * @param message - the message.
152
- */
153
- public void setMotD (String message ) {
154
- setMotD (WrappedChatComponent .fromLegacyText (message ));
155
- }
156
-
157
153
/**
158
154
* Retrieve the compressed PNG file that is being displayed as a favicon.
159
155
* @return The favicon, or NULL if no favicon will be displayed.
160
156
*/
157
+ @ Override
161
158
public String getFavicon () {
162
159
return (String ) FAVICON .get (handle );
163
160
}
@@ -166,6 +163,7 @@ public String getFavicon() {
166
163
* Set the compressed PNG file that is being displayed.
167
164
* @param image - the new compressed image or NULL if no favicon should be displayed.
168
165
*/
166
+ @ Override
169
167
public void setFavicon (String image ) {
170
168
FAVICON .set (handle , image );
171
169
}
@@ -197,6 +195,7 @@ public void setChatPreviewEnabled(boolean chatPreviewEnabled) {
197
195
* @return whether the server enforces secure chat.
198
196
* @since 1.19.1
199
197
*/
198
+ @ Override
200
199
public boolean isEnforceSecureChat () {
201
200
int index = MinecraftVersion .FEATURE_PREVIEW_UPDATE .atOrAbove () ? 0 : 1 ;
202
201
return (Boolean ) BOOLEAN_ACCESSORS [index ].get (handle );
@@ -207,6 +206,7 @@ public boolean isEnforceSecureChat() {
207
206
* @param enforceSecureChat true if enabled, false otherwise.
208
207
* @since 1.19.1
209
208
*/
209
+ @ Override
210
210
public void setEnforceSecureChat (boolean enforceSecureChat ) {
211
211
int index = MinecraftVersion .FEATURE_PREVIEW_UPDATE .atOrAbove () ? 0 : 1 ;
212
212
BOOLEAN_ACCESSORS [index ].set (handle , enforceSecureChat );
@@ -218,6 +218,7 @@ public void setEnforceSecureChat(boolean enforceSecureChat) {
218
218
* @throws IllegalStateException If the player count has been hidden via {@link #setPlayersVisible(boolean)}.
219
219
* @see #setPlayersOnline(int)
220
220
*/
221
+ @ Override
221
222
public int getPlayersOnline () {
222
223
if (players == null )
223
224
throw new IllegalStateException ("The player count has been hidden." );
@@ -231,6 +232,7 @@ public int getPlayersOnline() {
231
232
* negative, as well as higher than the player maximum.
232
233
* @param online - online players.
233
234
*/
235
+ @ Override
234
236
public void setPlayersOnline (int online ) {
235
237
if (players == null )
236
238
resetPlayers ();
@@ -243,6 +245,7 @@ public void setPlayersOnline(int online) {
243
245
* @throws IllegalStateException If the player maximum has been hidden via {@link #setPlayersVisible(boolean)}.
244
246
* @see #setPlayersMaximum(int)
245
247
*/
248
+ @ Override
246
249
public int getPlayersMaximum () {
247
250
if (players == null )
248
251
throw new IllegalStateException ("The player maximum has been hidden." );
@@ -256,6 +259,7 @@ public int getPlayersMaximum() {
256
259
* is less than the player count.
257
260
* @param maximum - maximum player count.
258
261
*/
262
+ @ Override
259
263
public void setPlayersMaximum (int maximum ) {
260
264
if (players == null )
261
265
resetPlayers ();
@@ -268,6 +272,7 @@ public void setPlayersMaximum(int maximum) {
268
272
* Note that this may set the current player count and maximum to their respective real values.
269
273
* @param visible - TRUE if it should be visible, FALSE otherwise.
270
274
*/
275
+ @ Override
271
276
public void setPlayersVisible (boolean visible ) {
272
277
if (arePlayersVisible () != visible ) {
273
278
if (visible ) {
@@ -287,6 +292,7 @@ public void setPlayersVisible(boolean visible) {
287
292
* If not, the client will display ??? in the same location.
288
293
* @return TRUE if the player statistics is visible, FALSE otherwise.
289
294
*/
295
+ @ Override
290
296
public boolean arePlayersVisible () {
291
297
return players != null ;
292
298
}
@@ -295,6 +301,7 @@ public boolean arePlayersVisible() {
295
301
* Retrieve a copy of all the logged in players.
296
302
* @return Logged in players or an empty list if no player names will be displayed.
297
303
*/
304
+ @ Override
298
305
public ImmutableList <WrappedGameProfile > getPlayers () {
299
306
if (players == null )
300
307
return ImmutableList .of ();
@@ -306,33 +313,21 @@ public ImmutableList<WrappedGameProfile> getPlayers() {
306
313
307
314
/**
308
315
* Set the displayed list of logged in players.
309
- * @param profile - every logged in player.
316
+ * @param playerSample - every logged in player.
310
317
*/
311
- public void setPlayers (Object profile ) {
318
+ @ Override
319
+ public void setPlayers (Iterable <? extends WrappedGameProfile > playerSample ) {
312
320
if (players == null )
313
321
resetPlayers ();
314
- PLAYERS_PROFILES .set (players , profile );
315
- }
316
322
317
- /**
318
- * Set the displayed lst of logged in players.
319
- * @param players - the players to display.
320
- */
321
- public void setBukkitPlayers (Iterable <? extends Player > players ) {
322
- final List <WrappedGameProfile > profiles = new ArrayList <>();
323
-
324
- for (Player player : players ) {
325
- Object profile = ENTITY_HUMAN_PROFILE .get (BukkitUnwrapper .getInstance ().unwrapItem (player ));
326
- profiles .add (WrappedGameProfile .fromHandle (profile ));
327
- }
328
-
329
- setPlayers (profiles );
323
+ PLAYERS_PROFILES .set (players , PROFILE_CONVERT .getGeneric (playerSample ));
330
324
}
331
325
332
326
/**
333
327
* Retrieve the version name of the current server.
334
328
* @return The version name.
335
329
*/
330
+ @ Override
336
331
public String getVersionName () {
337
332
return (String ) VERSION_NAME .get (version );
338
333
}
@@ -341,6 +336,7 @@ public String getVersionName() {
341
336
* Set the version name of the current server.
342
337
* @param name - the new version name.
343
338
*/
339
+ @ Override
344
340
public void setVersionName (String name ) {
345
341
VERSION_NAME .set (version , name );
346
342
}
@@ -349,6 +345,7 @@ public void setVersionName(String name) {
349
345
* Retrieve the protocol number.
350
346
* @return The protocol.
351
347
*/
348
+ @ Override
352
349
public int getVersionProtocol () {
353
350
return (Integer ) VERSION_PROTOCOL .get (version );
354
351
}
@@ -357,6 +354,7 @@ public int getVersionProtocol() {
357
354
* Set the version protocol
358
355
* @param protocol - the protocol number.
359
356
*/
357
+ @ Override
360
358
public void setVersionProtocol (int protocol ) {
361
359
VERSION_PROTOCOL .set (version , protocol );
362
360
}
@@ -367,11 +365,11 @@ public void setVersionProtocol(int protocol) {
367
365
*/
368
366
public LegacyServerPing deepClone () {
369
367
LegacyServerPing copy = new LegacyServerPing ();
370
- WrappedChatComponent motd = getMotD ();
368
+ Object motd = getMotD ();
371
369
372
370
copy .setPlayers (getPlayers ());
373
371
copy .setFavicon (getFavicon ());
374
- copy .setMotD (motd != null ? motd . deepClone () : null );
372
+ copy .setMotD (motd != null ? WrappedChatComponent . fromHandle ( motd ). getHandle () : null );
375
373
copy .setVersionName (getVersionName ());
376
374
copy .setVersionProtocol (getVersionProtocol ());
377
375
0 commit comments