allow setting if chat preview is enabled in WrappedServerPing (#1623)

This commit is contained in:
Pasqual Koschmieder 2022-06-11 18:35:12 +02:00 committed by GitHub
parent aed98abac6
commit e202503c09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -51,6 +51,7 @@ public class WrappedServerPing extends AbstractWrapper implements ClonableWrappe
private static FieldAccessor PLAYERS = Accessors.getFieldAccessor(SERVER_PING, MinecraftReflection.getServerPingPlayerSampleClass(), true);
private static FieldAccessor VERSION = Accessors.getFieldAccessor(SERVER_PING, MinecraftReflection.getServerPingServerDataClass(), true);
private static FieldAccessor FAVICON = Accessors.getFieldAccessor(SERVER_PING, String.class, true);
private static FieldAccessor PREVIEWS_CHAT = Accessors.getFieldAccessor(SERVER_PING, boolean.class, true);
// For converting to the underlying array
private static EquivalentConverter<Iterable<? extends WrappedGameProfile>> PROFILE_CONVERT =
@ -181,6 +182,24 @@ public class WrappedServerPing extends AbstractWrapper implements ClonableWrappe
FAVICON.set(handle, (image != null) ? image.toEncodedText() : null);
}
/**
* Retrieve whether chat preview is enabled on the server.
* @return whether chat preview is enabled on the server.
* @since 1.19
*/
public boolean isChatPreviewEnabled() {
return (Boolean) PREVIEWS_CHAT.get(handle);
}
/**
* Sets whether chat preview is enabled on the server.
* @param chatPreviewEnabled true if enabled, false otherwise.
* @since 1.19
*/
public void setChatPreviewEnabled(boolean chatPreviewEnabled) {
PREVIEWS_CHAT.set(handle, chatPreviewEnabled);
}
/**
* Retrieve the displayed number of online players.
* @return The displayed number.

View File

@ -2,6 +2,7 @@ package com.comphenix.protocol.wrappers;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import com.comphenix.protocol.BukkitInitialization;
@ -31,11 +32,13 @@ public class WrappedServerPingTest {
serverPing.setVersionName("Minecraft 123");
serverPing.setVersionProtocol(4);
serverPing.setFavicon(tux);
serverPing.setChatPreviewEnabled(true);
assertEquals(5, serverPing.getPlayersOnline());
assertEquals(10, serverPing.getPlayersMaximum());
assertEquals("Minecraft 123", serverPing.getVersionName());
assertEquals(4, serverPing.getVersionProtocol());
assertTrue(serverPing.isChatPreviewEnabled());
assertArrayEquals(original, serverPing.getFavicon().getData());