3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-08 17:20:24 +01:00

store constructor

Dieser Commit ist enthalten in:
creeper123123321 2019-01-15 14:21:37 -02:00
Ursprung 1325d53950
Commit 193084927b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1

Datei anzeigen

@ -5,6 +5,7 @@ import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -12,20 +13,20 @@ import java.util.Map;
public class BlockConnectionStorage extends StoredObject { public class BlockConnectionStorage extends StoredObject {
private Map<Long, Map<Short, Short>> blockStorage = createLongObjectMap(); private Map<Long, Map<Short, Short>> blockStorage = createLongObjectMap();
private static Class<?> fastUtilLongObjectHashMap; private static Constructor<?> fastUtilLongObjectHashMap;
private static Class<?> fastUtilShortShortHashMap; private static Constructor<?> fastUtilShortShortHashMap;
static { static {
try { try {
fastUtilLongObjectHashMap = Class.forName("it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap"); fastUtilLongObjectHashMap = Class.forName("it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap").getConstructor();
Via.getPlatform().getLogger().info("Using FastUtil Long2ObjectOpenHashMap for block connections"); Via.getPlatform().getLogger().info("Using FastUtil Long2ObjectOpenHashMap for block connections");
} catch (ClassNotFoundException ignored) { } catch (ClassNotFoundException | NoSuchMethodException ignored) {
} }
try { try {
fastUtilShortShortHashMap = Class.forName("it.unimi.dsi.fastutil.shorts.Short2ShortOpenHashMap"); fastUtilShortShortHashMap = Class.forName("it.unimi.dsi.fastutil.shorts.Short2ShortOpenHashMap").getConstructor();
Via.getPlatform().getLogger().info("Using FastUtil Short2ShortOpenHashMap for block connections"); Via.getPlatform().getLogger().info("Using FastUtil Short2ShortOpenHashMap for block connections");
} catch (ClassNotFoundException ignored) { } catch (ClassNotFoundException | NoSuchMethodException ignored) {
} }
} }
@ -91,8 +92,8 @@ public class BlockConnectionStorage extends StoredObject {
private <T> Map<Long, T> createLongObjectMap() { private <T> Map<Long, T> createLongObjectMap() {
if (fastUtilLongObjectHashMap != null) { if (fastUtilLongObjectHashMap != null) {
try { try {
return (Map<Long, T>) fastUtilLongObjectHashMap.getConstructor().newInstance(); return (Map<Long, T>) fastUtilLongObjectHashMap.newInstance();
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -102,8 +103,8 @@ public class BlockConnectionStorage extends StoredObject {
private Map<Short, Short> createShortShortMap() { private Map<Short, Short> createShortShortMap() {
if (fastUtilShortShortHashMap != null) { if (fastUtilShortShortHashMap != null) {
try { try {
return (Map<Short, Short>) fastUtilShortShortHashMap.getConstructor().newInstance(); return (Map<Short, Short>) fastUtilShortShortHashMap.newInstance();
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }