From fd01b9a6d29f8d6eafddf83f188e1556152e1b23 Mon Sep 17 00:00:00 2001 From: Myles Date: Wed, 11 Oct 2017 21:12:02 +0100 Subject: [PATCH] Don't display achievement broadcasts to 1.12+ #757 --- .../Protocol1_12To1_11_1.java | 6 +++++- .../TranslateRewriter.java | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/TranslateRewriter.java diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java index 89ffcb518..942fb73df 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java @@ -104,6 +104,10 @@ public class Protocol1_12To1_11_1 extends Protocol { if (!Via.getConfig().is1_12NBTArrayFix()) return; try { JsonElement obj = new JsonParser().parse(wrapper.get(Type.STRING, 0)); + if (!TranslateRewriter.toClient(obj, wrapper.user())) { + wrapper.cancel(); + return; + } ChatItemRewriter.toClient(obj, wrapper.user()); wrapper.set(Type.STRING, 0, obj.toString()); } catch (Exception e) { @@ -386,7 +390,7 @@ public class Protocol1_12To1_11_1 extends Protocol { newId += 3; return newId; } - + @Override protected void register(ViaProviders providers) { providers.register(InventoryQuickMoveProvider.class, new InventoryQuickMoveProvider()); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/TranslateRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/TranslateRewriter.java new file mode 100644 index 000000000..4a09752c1 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/TranslateRewriter.java @@ -0,0 +1,19 @@ +package us.myles.ViaVersion.protocols.protocol1_12to1_11_1; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import us.myles.ViaVersion.api.data.UserConnection; + +public class TranslateRewriter { + public static boolean toClient(JsonElement element, UserConnection user) { + if (element instanceof JsonObject) { + JsonObject obj = (JsonObject) element; + if(obj.has("translate")) { + if(obj.get("translate").getAsString().equals("chat.type.achievement")) { + return false; + } + } + } + return true; + } +}