Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,22 @@ public void contributePointers(final ConsoleCommandSender viewer, final net.kyor
static final class PlayerPointers extends BukkitFacet<Player> implements Facet.Pointers<Player> {

private static final MethodHandle LOCALE_SUPPORTED;
private static final boolean LEGACY;

static {
final MethodHandle asLocale = findMethod(Player.class, "getLocale", Locale.class);
final MethodHandle asString = findMethod(Player.class, "getLocale", String.class);
LOCALE_SUPPORTED = asLocale != null ? asLocale : asString;
boolean legacy = false;
MethodHandle handle = findMethod(Player.class, "getLocale", Locale.class);

if (handle == null) {
handle = findMethod(Player.class, "getLocale", String.class);
if (handle == null) {
handle = findMethod(Player.Spigot.class, "getLocale", String.class);
legacy = true;
}
}

LEGACY = legacy;
LOCALE_SUPPORTED = handle;
}

PlayerPointers() {
Expand All @@ -439,7 +450,8 @@ public void contributePointers(final Player viewer, final net.kyori.adventure.po
builder.withDynamic(Identity.LOCALE, () -> {
if (LOCALE_SUPPORTED != null) {
try {
final Object result = LOCALE_SUPPORTED.invoke(viewer);
final Object target = LEGACY ? viewer.spigot() : viewer;
final Object result = LOCALE_SUPPORTED.invoke(target);
return result instanceof Locale ? (Locale) result : Translator.parseLocale((String) result);
} catch (final Throwable error) {
logError(error, "Failed to call getLocale() for %s", viewer);
Expand Down