diff --git a/pom.xml b/pom.xml index ecdc404..ad7328a 100644 --- a/pom.xml +++ b/pom.xml @@ -133,10 +133,16 @@ 2.12.0 compile + + + + + + - com.comphenix.protocol + com.github.dmulloy2 ProtocolLib - 5.0.0 + master-SNAPSHOT provided diff --git a/src/main/java/me/rothes/protocolstringreplacer/packetlisteners/PacketListenerManager.java b/src/main/java/me/rothes/protocolstringreplacer/packetlisteners/PacketListenerManager.java index 2afc116..82f9e76 100644 --- a/src/main/java/me/rothes/protocolstringreplacer/packetlisteners/PacketListenerManager.java +++ b/src/main/java/me/rothes/protocolstringreplacer/packetlisteners/PacketListenerManager.java @@ -6,6 +6,7 @@ import me.rothes.protocolstringreplacer.PsrLocalization; import me.rothes.protocolstringreplacer.packetlisteners.client.CloseWindow; import me.rothes.protocolstringreplacer.packetlisteners.client.SettingsLocale; +import me.rothes.protocolstringreplacer.packetlisteners.client.SettingsLocaleUpper20; import me.rothes.protocolstringreplacer.packetlisteners.client.itemstack.SetCreativeSlot; import me.rothes.protocolstringreplacer.packetlisteners.client.itemstack.WindowClick; import me.rothes.protocolstringreplacer.packetlisteners.server.actionbar.ChatActionBar; @@ -143,7 +144,12 @@ public void addListeners() { listeners.add(new WindowClick()); listeners.add(new SetCreativeSlot()); listeners.add(new CloseWindow()); - listeners.add(new SettingsLocale()); + if ((ProtocolStringReplacer.getInstance().getServerMajorVersion() == 20 && ProtocolStringReplacer.getInstance().getServerMinorVersion() >= 2) + || ProtocolStringReplacer.getInstance().getServerMajorVersion() > 20) { + listeners.add(new SettingsLocaleUpper20()); + } else { + listeners.add(new SettingsLocale()); + } for (AbstractPacketListener listener : listeners) { try { diff --git a/src/main/java/me/rothes/protocolstringreplacer/packetlisteners/client/SettingsLocaleUpper20.java b/src/main/java/me/rothes/protocolstringreplacer/packetlisteners/client/SettingsLocaleUpper20.java new file mode 100644 index 0000000..77d9e13 --- /dev/null +++ b/src/main/java/me/rothes/protocolstringreplacer/packetlisteners/client/SettingsLocaleUpper20.java @@ -0,0 +1,49 @@ +package me.rothes.protocolstringreplacer.packetlisteners.client; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketEvent; +import me.rothes.protocolstringreplacer.api.user.PsrUser; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.Field; +import java.util.Locale; + +public class SettingsLocaleUpper20 extends AbstractClientPacketListener { + + private Field language; + + public SettingsLocaleUpper20() { + super(PacketType.Play.Client.SETTINGS); + } + + @Override + protected void process(@NotNull PacketEvent packetEvent) { + PsrUser user = getEventUser(packetEvent); + if (user == null) { + return; + } + Object record = packetEvent.getPacket().getModifier().read(0); + String read; + try { + read = (String) field().get(record); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + user.setClientLocale(read.toLowerCase(Locale.ROOT).replace('-', '_')); + } + + private Field field() { + if (language == null) { + language = PacketType.Play.Client.SETTINGS.getPacketClass().getDeclaredFields()[0].getType().getDeclaredFields()[0]; + language.setAccessible(true); + } + return language; + } + + @Override + protected boolean canWrite(@NotNull PacketEvent packetEvent) { + // We just read it. + return true; + } + +}