Fix null translate chat message fields

This commit is contained in:
Matsv 2017-06-12 21:28:26 +02:00
parent e9878f68b9
commit 961991a316
No known key found for this signature in database
GPG Key ID: 97CEC2A2EA31350F

View File

@ -10,6 +10,7 @@
package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.packets;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.Rewriter;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.AdvancementTranslations;
@ -50,7 +51,7 @@ public class ChatPackets1_12 extends Rewriter<Protocol1_11_1To1_12> {
} catch (Exception e) {
// Only print if ViaVer debug is enabled
if (Via.getManager().isDebug()) {
System.out.println("Failed to handle translations");
ViaBackwards.getPlatform().getLogger().severe("Failed to handle translations");
e.printStackTrace();
}
}
@ -58,15 +59,17 @@ public class ChatPackets1_12 extends Rewriter<Protocol1_11_1To1_12> {
});
}
});
}
// TODO improve this, not copying will cause ConcurrentModificationException
public void handleTranslations(JsonObject object) {
JsonObject copiedObj = copy(object);
if (object.isJsonObject()) {
for (Map.Entry<String, JsonElement> entry : copiedObj.entrySet()) {
// Get the text that doesn't exist for 1.11 <
if (entry.getKey().equalsIgnoreCase("translate")) {
if (entry.getKey().equalsIgnoreCase("translate") && AdvancementTranslations.has(entry.getValue().getAsString())) {
String trans = entry.getValue().getAsString();
object.remove("translate");
object.addProperty("translate", AdvancementTranslations.get(trans));