From 6513df10e7e8cbb574d005d55b4f82210139a904 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Tue, 9 Jun 2020 20:38:50 +0200 Subject: [PATCH] Explicitly cast json loaded map in BlockIdData Else json will start to cry sometimes --- .../ViaVersion/api/protocol/Protocol.java | 2 +- .../data/BlockIdData.java | 37 ++++++++----------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java index b629ab98f..ff57ebdb8 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java @@ -429,7 +429,7 @@ public abstract class Protocol0x" + toNiceHex(newId)); + + " IN REMAP OF " + toNiceHex(oldId) + "->" + toNiceHex(newId)); } throw e; } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java index 2e914f432..24c9255d4 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java @@ -13,6 +13,7 @@ import java.util.HashMap; import java.util.Map; public class BlockIdData { + public static final String[] PREVIOUS = new String[0]; public static Map blockIdMapping; public static Map fallbackReverseMapping; public static Int2ObjectMap numberIdToString; @@ -20,44 +21,36 @@ public class BlockIdData { public static void init() { InputStream stream = MappingData.class.getClassLoader() .getResourceAsStream("assets/viaversion/data/blockIds1.12to1.13.json"); - InputStreamReader reader = new InputStreamReader(stream); - try { - blockIdMapping = new HashMap<>(GsonUtil.getGson().fromJson( + try (InputStreamReader reader = new InputStreamReader(stream)) { + Map map = GsonUtil.getGson().fromJson( reader, new TypeToken>() { - }.getType() - ), 1F); + }.getType()); + blockIdMapping = new HashMap<>(map); fallbackReverseMapping = new HashMap<>(); for (Map.Entry entry : blockIdMapping.entrySet()) { for (String val : entry.getValue()) { String[] previous = fallbackReverseMapping.get(val); - if (previous == null) previous = new String[0]; + if (previous == null) previous = PREVIOUS; fallbackReverseMapping.put(val, ObjectArrays.concat(previous, entry.getKey())); } } - } finally { - try { - reader.close(); - } catch (IOException ignored) { - // Ignored - } + } catch (IOException e) { + e.printStackTrace(); } InputStream blockS = MappingData.class.getClassLoader() .getResourceAsStream("assets/viaversion/data/blockNumberToString1.12.json"); - InputStreamReader blockR = new InputStreamReader(blockS); - try { - numberIdToString = new Int2ObjectOpenHashMap<>(GsonUtil.getGson().fromJson( + try (InputStreamReader blockR = new InputStreamReader(blockS)) { + Map map = GsonUtil.getGson().fromJson( blockR, new TypeToken>() { }.getType() - )); - } finally { - try { - blockR.close(); - } catch (IOException ignored) { - // Ignored - } + ); + numberIdToString = new Int2ObjectOpenHashMap<>(map); + } catch (IOException e) { + e.printStackTrace(); } + // Ignored } }