Skip to content

Commit b55dcca

Browse files
committed
Fix 1.8-1.11 getLocale
1 parent 48df019 commit b55dcca

File tree

1 file changed

+20
-2
lines changed
  • src/main/java/me/rothes/protocolstringreplacer/api/user

1 file changed

+20
-2
lines changed

src/main/java/me/rothes/protocolstringreplacer/api/user/PsrUser.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import org.bukkit.permissions.Permission;
2626

2727
import javax.annotation.Nonnull;
28+
import java.lang.reflect.Field;
29+
import java.lang.reflect.InvocationTargetException;
30+
import java.lang.reflect.Method;
2831
import java.util.ArrayList;
2932
import java.util.Arrays;
3033
import java.util.HashMap;
@@ -36,6 +39,15 @@
3639

3740
public class PsrUser {
3841

42+
private static Method getLocaleLegacy = getLegacyMethod();
43+
44+
private static Method getLegacyMethod() {
45+
try {
46+
return Player.Spigot.class.getDeclaredMethod("getLocale");
47+
} catch (NoSuchMethodException ignored) {}
48+
return null;
49+
}
50+
3951
private UUID uuid;
4052
private Player player;
4153
private CommandSender sender;
@@ -65,7 +77,10 @@ public PsrUser(Player player) {
6577
if (ProtocolStringReplacer.getInstance().getServerMajorVersion() >= 12) {
6678
setClientLocale(getPlayer().getLocale());
6779
} else {
68-
setClientLocale(((Player) getPlayer().spigot()).getLocale());
80+
Player.Spigot spigot = getPlayer().spigot();
81+
try {
82+
setClientLocale((String) getLocaleLegacy.invoke(spigot));
83+
} catch (IllegalAccessException | InvocationTargetException ignored) {}
6984
}
7085
}
7186

@@ -76,7 +91,10 @@ public PsrUser(UUID uuid) {
7691
if (ProtocolStringReplacer.getInstance().getServerMajorVersion() >= 12) {
7792
setClientLocale(getPlayer().getLocale());
7893
} else {
79-
setClientLocale(((Player) getPlayer().spigot()).getLocale());
94+
Player.Spigot spigot = getPlayer().spigot();
95+
try {
96+
setClientLocale((String) getLocaleLegacy.invoke(spigot));
97+
} catch (IllegalAccessException | InvocationTargetException ignored) {}
8098
}
8199
}
82100

0 commit comments

Comments
 (0)