Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-09-17 01:23:43 +02:00
Explicitly cast json loaded map in BlockIdData
Else json will start to cry sometimes
Dieser Commit ist enthalten in:
Ursprung
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) + ")");
|
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName() + " IN REMAP OF " + packetType + " (" + toNiceHex(oldId) + ")");
|
||||||
} else {
|
} else {
|
||||||
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName()
|
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;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class BlockIdData {
|
public class BlockIdData {
|
||||||
|
public static final String[] PREVIOUS = new String[0];
|
||||||
public static Map<String, String[]> blockIdMapping;
|
public static Map<String, String[]> blockIdMapping;
|
||||||
public static Map<String, String[]> fallbackReverseMapping;
|
public static Map<String, String[]> fallbackReverseMapping;
|
||||||
public static Int2ObjectMap<String> numberIdToString;
|
public static Int2ObjectMap<String> numberIdToString;
|
||||||
@ -20,44 +21,36 @@ public class BlockIdData {
|
|||||||
public static void init() {
|
public static void init() {
|
||||||
InputStream stream = MappingData.class.getClassLoader()
|
InputStream stream = MappingData.class.getClassLoader()
|
||||||
.getResourceAsStream("assets/viaversion/data/blockIds1.12to1.13.json");
|
.getResourceAsStream("assets/viaversion/data/blockIds1.12to1.13.json");
|
||||||
InputStreamReader reader = new InputStreamReader(stream);
|
try (InputStreamReader reader = new InputStreamReader(stream)) {
|
||||||
try {
|
Map<String, String[]> map = GsonUtil.getGson().fromJson(
|
||||||
blockIdMapping = new HashMap<>(GsonUtil.getGson().fromJson(
|
|
||||||
reader,
|
reader,
|
||||||
new TypeToken<Map<String, String[]>>() {
|
new TypeToken<Map<String, String[]>>() {
|
||||||
}.getType()
|
}.getType());
|
||||||
), 1F);
|
blockIdMapping = new HashMap<>(map);
|
||||||
fallbackReverseMapping = new HashMap<>();
|
fallbackReverseMapping = new HashMap<>();
|
||||||
for (Map.Entry<String, String[]> entry : blockIdMapping.entrySet()) {
|
for (Map.Entry<String, String[]> entry : blockIdMapping.entrySet()) {
|
||||||
for (String val : entry.getValue()) {
|
for (String val : entry.getValue()) {
|
||||||
String[] previous = fallbackReverseMapping.get(val);
|
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()));
|
fallbackReverseMapping.put(val, ObjectArrays.concat(previous, entry.getKey()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} catch (IOException e) {
|
||||||
try {
|
e.printStackTrace();
|
||||||
reader.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
// Ignored
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStream blockS = MappingData.class.getClassLoader()
|
InputStream blockS = MappingData.class.getClassLoader()
|
||||||
.getResourceAsStream("assets/viaversion/data/blockNumberToString1.12.json");
|
.getResourceAsStream("assets/viaversion/data/blockNumberToString1.12.json");
|
||||||
InputStreamReader blockR = new InputStreamReader(blockS);
|
try (InputStreamReader blockR = new InputStreamReader(blockS)) {
|
||||||
try {
|
Map<Integer, String> map = GsonUtil.getGson().fromJson(
|
||||||
numberIdToString = new Int2ObjectOpenHashMap<>(GsonUtil.getGson().fromJson(
|
|
||||||
blockR,
|
blockR,
|
||||||
new TypeToken<Map<Integer, String>>() {
|
new TypeToken<Map<Integer, String>>() {
|
||||||
}.getType()
|
}.getType()
|
||||||
));
|
);
|
||||||
} finally {
|
numberIdToString = new Int2ObjectOpenHashMap<>(map);
|
||||||
try {
|
} catch (IOException e) {
|
||||||
blockR.close();
|
e.printStackTrace();
|
||||||
} catch (IOException ignored) {
|
|
||||||
// Ignored
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// Ignored
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren