mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-23 02:25:19 +01:00
Explicitly cast json loaded map in BlockIdData
Else json will start to cry sometimes
This commit is contained in:
parent
d14a74f29e
commit
6513df10e7
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user