Add client option to hide custom skulls (#2603)

This commit is contained in:
Konicai 2021-10-30 23:22:04 -04:00 committed by GitHub
parent f883dfdf2c
commit eb211884de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 4 deletions

View file

@ -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();

View file

@ -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();
}
}

View file

@ -63,7 +63,7 @@ public class JavaUpdateTileEntityTranslator extends PacketTranslator<ServerUpdat
}
BlockEntityUtils.updateBlockEntity(session, translator.getBlockEntityTag(id, packet.getNbt(), blockState), packet.getPosition());
// Check for custom skulls.
if (SkullBlockEntityTranslator.ALLOW_CUSTOM_SKULLS && packet.getNbt().contains("SkullOwner")) {
if (session.getPreferencesCache().showCustomSkulls() && packet.getNbt().contains("SkullOwner")) {
SkullBlockEntityTranslator.spawnPlayer(session, packet.getNbt(), blockState);
}

View file

@ -294,7 +294,7 @@ public class ChunkUtils {
bedrockBlockEntities[i] = blockEntityTranslator.getBlockEntityTag(tagName, tag, blockState);
// Check for custom skulls
if (SkullBlockEntityTranslator.ALLOW_CUSTOM_SKULLS && tag.contains("SkullOwner")) {
if (session.getPreferencesCache().showCustomSkulls() && tag.contains("SkullOwner")) {
SkullBlockEntityTranslator.spawnPlayer(session, tag, blockState);
}
i++;

View file

@ -50,7 +50,10 @@ public class SettingsUtils {
.iconPath("textures/ui/settings_glyph_color_2x.png");
// Only show the client title if any of the client settings are available
boolean showClientSettings = session.getPreferencesCache().isAllowShowCoordinates() || CooldownUtils.getDefaultShowCooldown() != CooldownUtils.CooldownType.DISABLED;
boolean showClientSettings = session.getPreferencesCache().isAllowShowCoordinates()
|| CooldownUtils.getDefaultShowCooldown() != CooldownUtils.CooldownType.DISABLED
|| session.getConnector().getConfig().isAllowCustomSkulls();
if (showClientSettings) {
builder.label("geyser.settings.title.client");
@ -66,6 +69,10 @@ public class SettingsUtils {
cooldownDropdown.option("options.off", session.getPreferencesCache().getCooldownPreference() == CooldownUtils.CooldownType.DISABLED);
builder.dropdown(cooldownDropdown);
}
if (session.getConnector().getConfig().isAllowCustomSkulls()) {
builder.toggle("geyser.settings.option.customSkulls", session.getPreferencesCache().isPrefersCustomSkulls());
}
}
boolean canModifyServer = session.getOpPermissionLevel() >= 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) {