From eb211884de765de89291b52a5414517ed61f9e0c Mon Sep 17 00:00:00 2001 From: Konicai <71294714+Konicai@users.noreply.github.com> Date: Sat, 30 Oct 2021 23:22:04 -0400 Subject: [PATCH] Add client option to hide custom skulls (#2603) --- .../org/geysermc/connector/GeyserConnector.java | 1 - .../network/session/cache/PreferencesCache.java | 16 ++++++++++++++++ .../world/JavaUpdateTileEntityTranslator.java | 2 +- .../org/geysermc/connector/utils/ChunkUtils.java | 2 +- .../geysermc/connector/utils/SettingsUtils.java | 13 ++++++++++++- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 37bfd2413..17deca915 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -231,7 +231,6 @@ public class GeyserConnector { CooldownUtils.setDefaultShowCooldown(config.getShowCooldown()); DimensionUtils.changeBedrockNetherId(config.isAboveBedrockNetherBuilding()); // Apply End dimension ID workaround to Nether - SkullBlockEntityTranslator.ALLOW_CUSTOM_SKULLS = config.isAllowCustomSkulls(); // https://github.com/GeyserMC/Geyser/issues/957 RakNetConstants.MAXIMUM_MTU_SIZE = (short) config.getMtu(); diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/PreferencesCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/PreferencesCache.java index d477066c2..310ef7911 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/PreferencesCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/PreferencesCache.java @@ -41,11 +41,18 @@ public class PreferencesCache { */ @Setter private boolean prefersShowCoordinates = true; + /** * If the client's preference will be ignored, this will return false. */ private boolean allowShowCoordinates; + /** + * If the session wants custom skulls to be shown. + */ + @Setter + private boolean prefersCustomSkulls; + /** * Which CooldownType the client prefers. Initially set to {@link CooldownUtils#getDefaultShowCooldown()}. */ @@ -54,6 +61,8 @@ public class PreferencesCache { public PreferencesCache(GeyserSession session) { this.session = session; + + prefersCustomSkulls = session.getConnector().getConfig().isAllowCustomSkulls(); } /** @@ -68,4 +77,11 @@ public class PreferencesCache { allowShowCoordinates = !session.isReducedDebugInfo() && session.getConnector().getConfig().isShowCoordinates(); session.sendGameRule("showcoordinates", allowShowCoordinates && prefersShowCoordinates); } + + /** + * @return true if the session prefers custom skulls, and the config allows them. + */ + public boolean showCustomSkulls() { + return prefersCustomSkulls && session.getConnector().getConfig().isAllowCustomSkulls(); + } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTileEntityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTileEntityTranslator.java index 25c4684b1..9acceb0a5 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTileEntityTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTileEntityTranslator.java @@ -63,7 +63,7 @@ public class JavaUpdateTileEntityTranslator extends PacketTranslator= 2 || session.hasPermission("geyser.settings.server"); @@ -122,6 +129,10 @@ public class SettingsUtils { CooldownUtils.CooldownType cooldownType = CooldownUtils.CooldownType.VALUES[(int) response.next()]; session.getPreferencesCache().setCooldownPreference(cooldownType); } + + if (session.getConnector().getConfig().isAllowCustomSkulls()) { + session.getPreferencesCache().setPrefersCustomSkulls(response.next()); + } } if (canModifyServer) {