Explicitly cast json loaded map in BlockIdData

Else json will start to cry sometimes
This commit is contained in:
KennyTV 2020-06-09 20:38:50 +02:00
parent d14a74f29e
commit 6513df10e7
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 16 additions and 23 deletions

View File

@ -429,7 +429,7 @@ public abstract class Protocol<C1 extends ClientboundPacketType, C2 extends Clie
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName() + " IN REMAP OF " + packetType + " (" + toNiceHex(oldId) + ")");
} else {
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName()
+ " IN REMAP OF 0x" + toNiceHex(oldId) + "->0x" + toNiceHex(newId));
+ " IN REMAP OF " + toNiceHex(oldId) + "->" + toNiceHex(newId));
}
throw e;
}

View File

@ -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<String, String[]> blockIdMapping;
public static Map<String, String[]> fallbackReverseMapping;
public static Int2ObjectMap<String> 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<String, String[]> map = GsonUtil.getGson().fromJson(
reader,
new TypeToken<Map<String, String[]>>() {
}.getType()
), 1F);
}.getType());
blockIdMapping = new HashMap<>(map);
fallbackReverseMapping = new HashMap<>();
for (Map.Entry<String, String[]> 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<Integer, String> map = GsonUtil.getGson().fromJson(
blockR,
new TypeToken<Map<Integer, String>>() {
}.getType()
));
} finally {
try {
blockR.close();
} catch (IOException ignored) {
// Ignored
}
);
numberIdToString = new Int2ObjectOpenHashMap<>(map);
} catch (IOException e) {
e.printStackTrace();
}
// Ignored
}
}