|
123 | 123 | import net.kyori.adventure.platform.facet.FacetPointers;
|
124 | 124 | import net.kyori.adventure.platform.facet.FacetPointers.Type;
|
125 | 125 | import net.kyori.adventure.pointer.Pointers;
|
| 126 | +import net.kyori.adventure.pointer.PointersSupplier; |
126 | 127 | import net.kyori.adventure.resource.ResourcePackInfoLike;
|
127 | 128 | import net.kyori.adventure.resource.ResourcePackRequest;
|
128 | 129 | import net.kyori.adventure.resource.ResourcePackRequestLike;
|
@@ -152,7 +153,16 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
152 | 153 |
|
153 | 154 | private static final ComponentLogger logger = ComponentLogger.logger(ConnectedPlayer.class);
|
154 | 155 |
|
155 |
| - private final Identity identity = new IdentityImpl(); |
| 156 | + private static final @NotNull PointersSupplier<ConnectedPlayer> POINTERS_SUPPLIER = |
| 157 | + PointersSupplier.<ConnectedPlayer>builder() |
| 158 | + .resolving(Identity.UUID, Player::getUniqueId) |
| 159 | + .resolving(Identity.NAME, Player::getUsername) |
| 160 | + .resolving(Identity.DISPLAY_NAME, player -> Component.text(player.getUsername())) |
| 161 | + .resolving(Identity.LOCALE, Player::getEffectiveLocale) |
| 162 | + .resolving(PermissionChecker.POINTER, Player::getPermissionChecker) |
| 163 | + .resolving(FacetPointers.TYPE, player -> Type.PLAYER) |
| 164 | + .build(); |
| 165 | + |
156 | 166 | /**
|
157 | 167 | * The actual Minecraft connection. This is actually a wrapper object around the Netty channel.
|
158 | 168 | */
|
@@ -181,14 +191,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
181 | 191 | private final ResourcePackHandler resourcePackHandler;
|
182 | 192 | private final BundleDelimiterHandler bundleHandler = new BundleDelimiterHandler(this);
|
183 | 193 |
|
184 |
| - private final @NotNull Pointers pointers = |
185 |
| - Player.super.pointers().toBuilder() |
186 |
| - .withDynamic(Identity.UUID, this::getUniqueId) |
187 |
| - .withDynamic(Identity.NAME, this::getUsername) |
188 |
| - .withDynamic(Identity.DISPLAY_NAME, () -> Component.text(this.getUsername())) |
189 |
| - .withDynamic(Identity.LOCALE, this::getEffectiveLocale) |
190 |
| - .withStatic(PermissionChecker.POINTER, getPermissionChecker()) |
191 |
| - .withStatic(FacetPointers.TYPE, Type.PLAYER).build(); |
192 | 194 | private @Nullable String clientBrand;
|
193 | 195 | private @Nullable Locale effectiveLocale;
|
194 | 196 | private final @Nullable IdentifiedKey playerKey;
|
@@ -257,7 +259,7 @@ public BundleDelimiterHandler getBundleHandler() {
|
257 | 259 |
|
258 | 260 | @Override
|
259 | 261 | public @NonNull Identity identity() {
|
260 |
| - return this.identity; |
| 262 | + return Identity.identity(this.getUniqueId()); |
261 | 263 | }
|
262 | 264 |
|
263 | 265 | @Override
|
@@ -363,7 +365,7 @@ public void setModInfo(ModInfo modInfo) {
|
363 | 365 |
|
364 | 366 | @Override
|
365 | 367 | public @NotNull Pointers pointers() {
|
366 |
| - return this.pointers; |
| 368 | + return POINTERS_SUPPLIER.view(this); |
367 | 369 | }
|
368 | 370 |
|
369 | 371 | @Override
|
@@ -396,14 +398,20 @@ public ProtocolVersion getProtocolVersion() {
|
396 | 398 | }
|
397 | 399 |
|
398 | 400 | /**
|
399 |
| - * Translates the message in the user's locale. |
| 401 | + * Translates the message in the user's locale, falling back to the default locale if not set. |
400 | 402 | *
|
401 | 403 | * @param message the message to translate
|
402 | 404 | * @return the translated message
|
403 | 405 | */
|
404 | 406 | public Component translateMessage(Component message) {
|
405 |
| - Locale locale = ClosestLocaleMatcher.INSTANCE |
406 |
| - .lookupClosest(getEffectiveLocale() == null ? Locale.getDefault() : getEffectiveLocale()); |
| 407 | + Locale locale = this.getEffectiveLocale(); |
| 408 | + if (locale == null && settings != null) { |
| 409 | + locale = settings.getLocale(); |
| 410 | + } |
| 411 | + if (locale == null) { |
| 412 | + locale = Locale.getDefault(); |
| 413 | + } |
| 414 | + locale = ClosestLocaleMatcher.INSTANCE.lookupClosest(locale); |
407 | 415 | return GlobalTranslator.render(message, locale);
|
408 | 416 | }
|
409 | 417 |
|
@@ -1361,14 +1369,6 @@ public Collection<ChannelIdentifier> getClientsideChannels() {
|
1361 | 1369 | return playerKey;
|
1362 | 1370 | }
|
1363 | 1371 |
|
1364 |
| - private class IdentityImpl implements Identity { |
1365 |
| -
|
1366 |
| - @Override |
1367 |
| - public @NonNull UUID uuid() { |
1368 |
| - return ConnectedPlayer.this.getUniqueId(); |
1369 |
| - } |
1370 |
| - } |
1371 |
| -
|
1372 | 1372 | @Override
|
1373 | 1373 | public ProtocolState getProtocolState() {
|
1374 | 1374 | return connection.getState().toProtocolState();
|
|
0 commit comments